Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions integrations/dsh/plugins/powercontext/CODEX_DESKTOP_HANDOFF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Codex Desktop handoff qualification

The default target registry includes a detectable Codex Desktop adapter even before it has launch qualification. `TargetCatalog.list()` marks it unavailable for native preflight and offers manual delivery; `TargetCatalog.diagnose()` can run read-only detection without exposing the internal configuration key. Host routes must explicitly expose that diagnostic operation if the product needs to display its result. Native preflight and launch require real acceptance evidence for the exact application and CLI version and the shared receiver prompt builder. `createCodexDesktopRuntime` takes the embedded CLI path, actual Desktop `CODEX_HOME`, Host delivery root, and the Host's persistent 32-byte generation key. Optional setup inputs are an absolute PowerContext executable and the intended non-secret Server URL. The generation key is used for keyed configuration fingerprints and is never emitted by the adapter.

The runtime queries the embedded app-server without creating a thread: `plugin/installed`, `hooks/list`, `config/read`, `configRequirements/read`, and `mcpServerStatus/list`. It checks the installed and enabled PowerContext plugin and required receiver tools. In the target directory it requires the enabled, trusted PowerContext SessionStart and PreToolUse hooks, and uses the installed plugin's own settings, credentials and Scope resolver for a new session. It compares the effective MCP endpoint and authorization configuration against the hook endpoint, and obtains the Server identity through the existing read-only identity operation. A changed target Scope, credential, hook or configuration changes the keyed generation and invalidates the preflight. The same persistent Host key reproduces the generation after restart.

For the qualified app version the runtime reads the saved local Desktop permission selection and checks app-server managed restrictions. The version-qualified mappings are `read-only` to `:read-only`, `auto` and `guardian-approvals` to `:workspace`, and `full-access` to `:danger-full-access`. Unknown, ambiguous or unsupported selections fail closed. It runs the embedded `codex sandbox` with that profile and managed configuration to hash a temporary private file in the delivery store; immediately before launch it hashes the exact package through that sandbox and compares the persisted SHA-256. Host readability alone is not sufficient.

The mapping is based on the inspected application build, not a public deep-link permission parameter. The actual application can have in-memory or per-session permission choices and environment variables that differ from the DSH process. Verify the chosen profile and effective plugin environment in a real new Desktop chat before qualification; do not infer them from the CLI probe alone. Revalidate after changing the app version, selected permissions, managed policy, `CODEX_HOME`, plugin, connection, hooks or workspace. Custom Desktop permission selections are not yet qualified.

Installation is performed only through the existing consented preflight and `powercontext setup codex`. With an explicit `source`, supply the marketplace root: for this repository that is the repository root containing `.agents/plugins/marketplace.json`, not the plugin directory. With no `source`, the CLI currently uses its remote `oceanbase/powercontext` marketplace at `master`; this requires network access and is not an offline bundled installation. The embedded CLI directory is prepended to PATH for Desktop-only installations. Setup completion still requires the user to restart or verify the Desktop target; interrupted or failed setup is indeterminate because it may have partially written configuration.

## Real-host acceptance

Coordinate with the local user and preserve existing sessions and drafts. Use a disposable project and a real PowerContext Server; do not edit application-private databases or submit the receiver prompt automatically.

1. Record app build, embedded CLI version, actual `codex://` system handler, Desktop `CODEX_HOME`, selected profile and target configuration. Verify that the app-server and new Desktop chat use the same plugin, credentials, environment and managed policy. Confirm hook trust and the receiver tools in the actual Desktop session.
2. Verify the canonical directory, target Server and Scope before the new-session hook injects context. Check a conflicting binding and a changed configuration between preflight and launch; neither may silently rebind.
3. Verify the selected Desktop sandbox reads the exact persisted package and SHA-256. A denied or modified package must stop automatic delivery. Confirm a profile change invalidates preflight.
4. With a user-approved launch, check that `codex://threads/new` opens a new local chat in the intended directory, with the complete prompt in the composer and **not sent**. Check non-ASCII paths and preservation of the source session and draft.
5. Only after the user explicitly sends the draft, verify the real receiver reads the exact package, invokes Continue and ACK, and the existing receipt verifier accepts the intended attempt, Server, Scope and identity. Check restart recovery and stale or wrong receipts. An OS open is not receiver acceptance.

The official [deep-link reference](https://learn.chatgpt.com/docs/reference/commands#deep-links) documents `codex://threads/new` with `path` and `prompt`, and says the prompt remains unsent. The [hook documentation](https://learn.chatgpt.com/docs/hooks) requires trust for non-managed hooks. Documentation and isolated probes do not establish that an installed app passed these real-host checks.
36 changes: 26 additions & 10 deletions integrations/dsh/plugins/powercontext/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6875,7 +6875,7 @@ const ACTIVE = new Set([
"installing",
"verifying"
]);
const CHECK_TIMEOUT_MS$1 = 2e4;
const PREFLIGHT_CHECK_TIMEOUT_MS = 45e3;
const INSTALL_TIMEOUT_MS = 12e4;
const UNUSED_READY_RETENTION_MS = 30 * 864e5;
function preflightRecords(root, maxRecords) {
Expand Down Expand Up @@ -7060,7 +7060,7 @@ var PreflightService = class {
});
}
return this.inspect(call$1, updated, adapter, set);
}, installing ? INSTALL_TIMEOUT_MS + CHECK_TIMEOUT_MS$1 : CHECK_TIMEOUT_MS$1);
}, installing ? INSTALL_TIMEOUT_MS + PREFLIGHT_CHECK_TIMEOUT_MS : PREFLIGHT_CHECK_TIMEOUT_MS);
}
async validateForPrepare(context, input) {
this.options.authority.requireLocal();
Expand Down Expand Up @@ -7100,7 +7100,7 @@ var PreflightService = class {
signal: AbortSignal.any([
context.signal,
this.options.signal,
AbortSignal.timeout(CHECK_TIMEOUT_MS$1)
AbortSignal.timeout(PREFLIGHT_CHECK_TIMEOUT_MS)
])
};
if (latest !== void 0) await this.options.authority.verifySource(call$1, binding.source, latest);
Expand Down Expand Up @@ -7340,7 +7340,7 @@ var PreflightService = class {
this.options.records.save(preflightKey(record$3.preflightId), next);
return next;
}
run(context, record$3, work, timeoutMs = CHECK_TIMEOUT_MS$1) {
run(context, record$3, work, timeoutMs = PREFLIGHT_CHECK_TIMEOUT_MS) {
const id = record$3.preflightId;
const controller = new AbortController();
const deadline = AbortSignal.timeout(timeoutMs);
Expand Down Expand Up @@ -7482,38 +7482,54 @@ const TARGETS = [
];
var TargetCatalog = class {
adapters = /* @__PURE__ */ new Map();
platform;
constructor(adapters = [], platform = process.platform) {
this.platform = platform;
for (const adapter of adapters) {
if (!NATIVE_TARGET_IDS.includes(adapter.id) || this.adapters.has(adapter.id)) throw new Error("Invalid or duplicate handoff adapter");
if (adapter.qualification.platform === platform) this.adapters.set(adapter.id, adapter);
this.adapters.set(adapter.id, adapter);
}
}
list() {
return TARGETS.map(([targetId, name$1, kind]) => {
const adapter = this.adapters.get(targetId);
const qualification = adapter?.qualification;
const qualified = qualification?.platform === this.platform && Boolean(qualification.evidence.trim());
return {
targetId,
name: name$1,
kind,
qualification: adapter?.qualification ?? null,
availability: adapter ? "requires_preflight" : "unavailable",
action: adapter ? "preflight" : kind === "framework" ? "developer_setup" : kind === "evaluation" ? "evaluation_only" : "manual_setup_or_export"
qualification: qualified ? qualification : null,
diagnostics: adapter ? "available" : "unavailable",
availability: qualified ? "requires_preflight" : "unavailable",
action: qualified ? "preflight" : kind === "framework" ? "developer_setup" : kind === "evaluation" ? "evaluation_only" : "manual_setup_or_export"
};
});
}
require(targetId) {
if (!TARGETS.some(([id]) => id === targetId)) throw new HandoffError("payload_invalid");
const adapter = this.adapters.get(targetId);
if (!adapter) throw new HandoffError("integration_unavailable");
if (!adapter || adapter.qualification?.platform !== this.platform || !adapter.qualification.evidence.trim()) throw new HandoffError("integration_unavailable");
return adapter;
}
/** Detection is read-only and available even before a target has launch qualification. */
async diagnose(targetId, signal) {
if (!TARGETS.some(([id]) => id === targetId)) throw new HandoffError("payload_invalid");
const adapter = this.adapters.get(targetId);
if (!adapter) throw new HandoffError("integration_unavailable");
const result$1 = await adapter.detect(signal);
return result$1.state === "present" ? {
state: "present",
version: result$1.version
} : { state: result$1.state };
}
};

//#endregion
//#region src/handoff/launch.ts
const SCHEMA = "powercontext.dsh-launch-attempts.v1";
const MAX_ATTEMPTS = 64;
const CHECK_TIMEOUT_MS = 3e4;
const CHECK_TIMEOUT_MS = PREFLIGHT_CHECK_TIMEOUT_MS + 15e3;
function launchRecords(root) {
return new HandoffRecords(root, SCHEMA);
}
Expand Down
Loading