subharness 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +3 -3
  2. package/dist/adapters/approval-context.d.ts +2 -0
  3. package/dist/adapters/approval-context.js +9 -0
  4. package/dist/adapters/approval-context.js.map +1 -0
  5. package/dist/adapters/approval-lifetime.d.ts +8 -0
  6. package/dist/adapters/approval-lifetime.js +50 -0
  7. package/dist/adapters/approval-lifetime.js.map +1 -0
  8. package/dist/adapters/claude-approvals.d.ts +4 -0
  9. package/dist/adapters/claude-approvals.js +32 -0
  10. package/dist/adapters/claude-approvals.js.map +1 -0
  11. package/dist/adapters/claude-permissions.js +1 -1
  12. package/dist/adapters/claude-permissions.js.map +1 -1
  13. package/dist/adapters/claude.js +30 -1
  14. package/dist/adapters/claude.js.map +1 -1
  15. package/dist/adapters/codex-approvals.d.ts +6 -0
  16. package/dist/adapters/codex-approvals.js +111 -0
  17. package/dist/adapters/codex-approvals.js.map +1 -0
  18. package/dist/adapters/codex.js +32 -2
  19. package/dist/adapters/codex.js.map +1 -1
  20. package/dist/adapters/fx-approvals.d.ts +2 -0
  21. package/dist/adapters/fx-approvals.js +14 -0
  22. package/dist/adapters/fx-approvals.js.map +1 -0
  23. package/dist/adapters/fx.js +49 -18
  24. package/dist/adapters/fx.js.map +1 -1
  25. package/dist/adapters/types.d.ts +2 -0
  26. package/dist/adapters/types.js.map +1 -1
  27. package/dist/approvals/schema.d.ts +4 -0
  28. package/dist/approvals/schema.js +70 -0
  29. package/dist/approvals/schema.js.map +1 -0
  30. package/dist/approvals/types.d.ts +47 -0
  31. package/dist/approvals/types.js +2 -0
  32. package/dist/approvals/types.js.map +1 -0
  33. package/dist/cli/args.d.ts +2 -1
  34. package/dist/cli/args.js +20 -2
  35. package/dist/cli/args.js.map +1 -1
  36. package/dist/cli/dashboard-client.d.ts +5 -1
  37. package/dist/cli/dashboard-client.js +161 -14
  38. package/dist/cli/dashboard-client.js.map +1 -1
  39. package/dist/cli/dashboard-detail-view.d.ts +16 -0
  40. package/dist/cli/dashboard-detail-view.js +163 -0
  41. package/dist/cli/dashboard-detail-view.js.map +1 -0
  42. package/dist/cli/dashboard-history-view.d.ts +29 -0
  43. package/dist/cli/dashboard-history-view.js +211 -0
  44. package/dist/cli/dashboard-history-view.js.map +1 -0
  45. package/dist/cli/dashboard-input.d.ts +14 -0
  46. package/dist/cli/dashboard-input.js +118 -0
  47. package/dist/cli/dashboard-input.js.map +1 -0
  48. package/dist/cli/dashboard-layout.d.ts +12 -1
  49. package/dist/cli/dashboard-layout.js +29 -27
  50. package/dist/cli/dashboard-layout.js.map +1 -1
  51. package/dist/cli/dashboard-renderer.d.ts +30 -2
  52. package/dist/cli/dashboard-renderer.js +125 -7
  53. package/dist/cli/dashboard-renderer.js.map +1 -1
  54. package/dist/cli/dashboard-style.d.ts +9 -0
  55. package/dist/cli/dashboard-style.js +36 -0
  56. package/dist/cli/dashboard-style.js.map +1 -0
  57. package/dist/cli/dashboard.d.ts +3 -1
  58. package/dist/cli/dashboard.js +127 -12
  59. package/dist/cli/dashboard.js.map +1 -1
  60. package/dist/cli/help.js +7 -0
  61. package/dist/cli/help.js.map +1 -1
  62. package/dist/cli/input.d.ts +1 -0
  63. package/dist/cli/input.js +23 -17
  64. package/dist/cli/input.js.map +1 -1
  65. package/dist/cli/main.js +1 -1
  66. package/dist/cli/main.js.map +1 -1
  67. package/dist/cli/output.js +17 -1
  68. package/dist/cli/output.js.map +1 -1
  69. package/dist/runtime/approval-registry.d.ts +27 -0
  70. package/dist/runtime/approval-registry.js +126 -0
  71. package/dist/runtime/approval-registry.js.map +1 -0
  72. package/dist/runtime/coordinator.d.ts +17 -1
  73. package/dist/runtime/coordinator.js +124 -6
  74. package/dist/runtime/coordinator.js.map +1 -1
  75. package/dist/runtime/dashboard.d.ts +42 -0
  76. package/dist/runtime/dashboard.js.map +1 -1
  77. package/dist/runtime/select-native.d.ts +2 -1
  78. package/dist/runtime/select-native.js +2 -2
  79. package/dist/runtime/select-native.js.map +1 -1
  80. package/dist/runtime/service.js +24 -1
  81. package/dist/runtime/service.js.map +1 -1
  82. package/dist/runtime/types.d.ts +9 -1
  83. package/dist/runtime/types.js.map +1 -1
  84. package/dist/runtime/worker-approvals.d.ts +21 -0
  85. package/dist/runtime/worker-approvals.js +51 -0
  86. package/dist/runtime/worker-approvals.js.map +1 -0
  87. package/dist/runtime/worker-client.js +35 -7
  88. package/dist/runtime/worker-client.js.map +1 -1
  89. package/dist/runtime/worker-server.d.ts +2 -0
  90. package/dist/runtime/worker-server.js +39 -10
  91. package/dist/runtime/worker-server.js.map +1 -1
  92. package/package.json +1 -1
  93. package/sdk/access-config.md +28 -0
  94. package/sdk/adapter-contract.md +2 -10
  95. package/sdk/agent-skill.md +6 -3
  96. package/sdk/approvals.md +118 -0
  97. package/sdk/cli/dashboard-design.md +38 -4
  98. package/sdk/cli/dashboard-inspection.md +25 -0
  99. package/sdk/cli/index.md +11 -5
  100. package/sdk/cli/output.md +7 -3
  101. package/sdk/completion-notifications.md +2 -0
  102. package/sdk/distribution.md +52 -0
  103. package/sdk/evals.md +9 -3
  104. package/sdk/fx.md +1 -1
  105. package/sdk/index.md +1 -0
  106. package/sdk/message-delivery.md +1 -1
  107. package/sdk/permissions.md +4 -4
  108. package/sdk/pr-integration.md +1 -1
  109. package/sdk/sessions.md +4 -1
  110. package/sdk/v1-runtime.md +3 -3
package/README.md CHANGED
@@ -33,7 +33,7 @@ npx skills add vercel-labs/subharness
33
33
 
34
34
  The installer requires access to the subharness repository while the repository is internal. See the [agent-skill reference](sdk/agent-skill.md) for installation behavior and boundaries.
35
35
 
36
- See [package distribution](sdk/distribution.md) for development checkouts, local tarballs, and package boundaries. subharness uses the [Apache License 2.0](LICENSE).
36
+ See [package distribution](sdk/distribution.md) for development checkouts, local tarballs, and package boundaries. Maintainers publish through the [GitHub release procedure](sdk/distribution.md#github-release-publishing). subharness uses the [Apache License 2.0](LICENSE).
37
37
 
38
38
  ## Delegate from your coding agent
39
39
 
@@ -68,7 +68,7 @@ subharness run claude --prompt-file ./review-task.txt
68
68
  subharness run codex --prompt-file - < ./task.txt
69
69
  ```
70
70
 
71
- Use `subharness dashboard` in a terminal to watch agents managed by the local coordinator. The live view groups agents by repository/worktree, pins the checkout containing the launch directory first, and orders other groups by their latest agent update. Each group shows current agents followed by finished runs, with harness, task title, elapsed time, and status. Finished history is retained for the coordinator’s lifetime. It has compact group labels and no controls or application banner; Ctrl+C closes the view without stopping agents.
71
+ Use `subharness dashboard` in a terminal to watch agents managed by the local coordinator. The live view groups agents by repository/worktree, pins the checkout containing the launch directory first, and orders other groups by their latest agent update. Each group shows current agents followed by finished runs, with harness, task title, elapsed time, and status. Finished history is retained for the coordinator’s lifetime. Use Up/Down to select a run and Enter to open its agent session’s request history. Queued requests appear first, followed by remaining requests newest first. Enter expands a request’s prompt and response; Escape returns to the overview. Completed statuses are green, and a compact Sub-agents footer summarizes direct child agents. The overview has no application banner or footer. Ctrl+C closes the view without stopping agents.
72
72
 
73
73
  ## Define a reusable specialist
74
74
 
@@ -155,7 +155,7 @@ This checkout includes six [repository roles](sdk/project-team.md): architecture
155
155
 
156
156
  ## Boundaries
157
157
 
158
- The local coordinator retains sessions and responses across command exits, but does not restore queues after coordinator or environment loss. External assistant reactivation depends on that assistant's host. Native requests needing interactive permission/input fail with actionable `INPUT_REQUIRED`; they are not automatically approved. CLI delegation requires the native shell to reach the coordinator over loopback HTTP; a sandbox that blocks local networking must be configured by the caller.
158
+ The local coordinator retains sessions and responses across command exits, but does not restore queues after coordinator or environment loss. External assistant reactivation depends on that assistant's host. Supported native permission requests return structured schemas and keep the original operation pending. The caller answers with `subharness respond <request-id> --content <json>` and observes the same task. See [permission request examples](sdk/approvals.md). Unsupported interactive input still fails with actionable `INPUT_REQUIRED`; no request is automatically approved. CLI delegation requires the native shell to reach the coordinator over loopback HTTP; a sandbox that blocks local networking must be configured by the caller.
159
159
 
160
160
  `resume` is available as a command, but v1 adapters report `RECOVERY_UNSUPPORTED` when prompt-free native recovery is unavailable. Failed work is not automatically replayed or migrated.
161
161
 
@@ -0,0 +1,2 @@
1
+ /** Native envelopes can include private configuration unrelated to the requested action. */
2
+ export declare function approvalContext(source: Record<string, unknown>, fields: readonly string[]): Record<string, unknown>;
@@ -0,0 +1,9 @@
1
+ /** Native envelopes can include private configuration unrelated to the requested action. */
2
+ export function approvalContext(source, fields) {
3
+ const result = {};
4
+ for (const key of fields)
5
+ if (Object.hasOwn(source, key) && source[key] !== undefined)
6
+ result[key] = structuredClone(source[key]);
7
+ return result;
8
+ }
9
+ //# sourceMappingURL=approval-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-context.js","sourceRoot":"","sources":["../../src/adapters/approval-context.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,UAAU,eAAe,CAAC,MAA+B,EAAE,MAAyB;IACxF,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,MAAM;QAAE,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACjI,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** Native envelopes can include private configuration unrelated to the requested action. */\nexport function approvalContext(source: Record<string, unknown>, fields: readonly string[]): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const key of fields) if (Object.hasOwn(source,key) && source[key] !== undefined) result[key] = structuredClone(source[key]);\n return result;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ApprovalContent, ApprovalHandler, NativeApprovalRequest } from "../approvals/types.js";
2
+ /** Owns callback lifetimes independently of an outstanding native turn. */
3
+ export declare class NativeApprovals {
4
+ private readonly pending;
5
+ request(id: string | number, request: NativeApprovalRequest, handler: ApprovalHandler, parent?: AbortSignal): Promise<ApprovalContent>;
6
+ withdraw(id: string | number): void;
7
+ clear(): void;
8
+ }
@@ -0,0 +1,50 @@
1
+ import { AgentError } from "../errors.js";
2
+ import { validateApprovalContent, validateApprovalSchema } from "../approvals/schema.js";
3
+ /** Owns callback lifetimes independently of an outstanding native turn. */
4
+ export class NativeApprovals {
5
+ pending = new Map();
6
+ async request(id, request, handler, parent) {
7
+ if (this.pending.has(id) || this.pending.size >= 32)
8
+ throw new AgentError("INPUT_REQUIRED", "The native permission request cannot be admitted.");
9
+ let snapshot;
10
+ try {
11
+ const serialized = JSON.stringify(request);
12
+ if (Buffer.byteLength(serialized) > 64 * 1024)
13
+ throw new Error();
14
+ snapshot = JSON.parse(serialized);
15
+ validateApprovalSchema(snapshot.requestedSchema);
16
+ }
17
+ catch {
18
+ throw new AgentError("INPUT_REQUIRED", "The native permission request is unsupported or exceeds the supported size.");
19
+ }
20
+ const schema = structuredClone(snapshot.requestedSchema);
21
+ const controller = new AbortController();
22
+ this.pending.set(id, controller);
23
+ const abort = () => controller.abort();
24
+ parent?.addEventListener("abort", abort, { once: true });
25
+ if (parent?.aborted)
26
+ abort();
27
+ let rejectAbort;
28
+ const withdrawn = new Promise((_resolve, reject) => {
29
+ rejectAbort = () => reject(new AgentError("REQUEST_EXPIRED", "The native permission request is no longer pending."));
30
+ controller.signal.addEventListener("abort", rejectAbort, { once: true });
31
+ });
32
+ try {
33
+ if (controller.signal.aborted)
34
+ throw new AgentError("REQUEST_EXPIRED", "The native permission request is no longer pending.");
35
+ const content = await Promise.race([handler(snapshot, controller.signal), withdrawn]);
36
+ if (controller.signal.aborted)
37
+ throw new AgentError("REQUEST_EXPIRED", "The native permission request is no longer pending.");
38
+ return validateApprovalContent(schema, content);
39
+ }
40
+ finally {
41
+ parent?.removeEventListener("abort", abort);
42
+ controller.signal.removeEventListener("abort", rejectAbort);
43
+ this.pending.delete(id);
44
+ }
45
+ }
46
+ withdraw(id) { this.pending.get(id)?.abort(); }
47
+ clear() { for (const controller of this.pending.values())
48
+ controller.abort(); }
49
+ }
50
+ //# sourceMappingURL=approval-lifetime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-lifetime.js","sourceRoot":"","sources":["../../src/adapters/approval-lifetime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGzF,2EAA2E;AAC3E,MAAM,OAAO,eAAe;IACT,OAAO,GAAG,IAAI,GAAG,EAAoC,CAAC;IAEvE,KAAK,CAAC,OAAO,CAAC,EAAmB,EAAE,OAA8B,EAAE,OAAwB,EAAE,MAAoB;QAC/G,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE;YAAE,MAAM,IAAI,UAAU,CAAC,gBAAgB,EAAE,mDAAmD,CAAC,CAAC;QACjJ,IAAI,QAA+B,CAAC;QACpC,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC3C,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,IAAI;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAC;YACjE,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAClC,sBAAsB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACnD,CAAC;QAAC,MAAM,CAAC;YAAC,MAAM,IAAI,UAAU,CAAC,gBAAgB,EAAE,6EAA6E,CAAC,CAAC;QAAC,CAAC;QAClI,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACzD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,IAAI,CAAC,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AAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,EAAmB,IAAU,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACtE,KAAK,KAAW,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CACtF","sourcesContent":["import { AgentError } from \"../errors.js\";\nimport { validateApprovalContent, validateApprovalSchema } from \"../approvals/schema.js\";\nimport type { ApprovalContent, ApprovalHandler, NativeApprovalRequest } from \"../approvals/types.js\";\n\n/** Owns callback lifetimes independently of an outstanding native turn. */\nexport class NativeApprovals {\n private readonly pending = new Map<string | number, AbortController>();\n\n async request(id: string | number, request: NativeApprovalRequest, handler: ApprovalHandler, parent?: AbortSignal): Promise<ApprovalContent> {\n if (this.pending.has(id) || this.pending.size >= 32) throw new AgentError(\"INPUT_REQUIRED\", \"The native permission request cannot be admitted.\");\n let snapshot: NativeApprovalRequest;\n try {\n const serialized = JSON.stringify(request);\n if (Buffer.byteLength(serialized) > 64 * 1024) throw new Error();\n snapshot = JSON.parse(serialized);\n validateApprovalSchema(snapshot.requestedSchema);\n } catch { throw new AgentError(\"INPUT_REQUIRED\", \"The native permission request is unsupported or exceeds the supported size.\"); }\n const schema = structuredClone(snapshot.requestedSchema);\n const controller = new AbortController();\n this.pending.set(id, controller);\n const abort = () => controller.abort();\n parent?.addEventListener(\"abort\", abort, { once: true });\n if (parent?.aborted) abort();\n let rejectAbort!: () => void;\n const withdrawn = new Promise<never>((_resolve, reject) => {\n rejectAbort = () => reject(new AgentError(\"REQUEST_EXPIRED\", \"The native permission request is no longer pending.\"));\n controller.signal.addEventListener(\"abort\", rejectAbort, { once: true });\n });\n try {\n if (controller.signal.aborted) throw new AgentError(\"REQUEST_EXPIRED\", \"The native permission request is no longer pending.\");\n const content = await Promise.race([handler(snapshot, controller.signal), withdrawn]);\n if (controller.signal.aborted) throw new AgentError(\"REQUEST_EXPIRED\", \"The native permission request is no longer pending.\");\n return validateApprovalContent(schema, content);\n } finally {\n parent?.removeEventListener(\"abort\", abort);\n controller.signal.removeEventListener(\"abort\", rejectAbort);\n this.pending.delete(id);\n }\n }\n\n withdraw(id: string | number): void { this.pending.get(id)?.abort(); }\n clear(): void { for (const controller of this.pending.values()) controller.abort(); }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { CanUseTool, PermissionResult } from "@anthropic-ai/claude-agent-sdk";
2
+ import type { ApprovalHandler } from "../approvals/types.js";
3
+ import { NativeApprovals } from "./approval-lifetime.js";
4
+ export declare function claudeApproval(approvals: NativeApprovals, handler: ApprovalHandler, toolName: string, input: Record<string, unknown>, metadata: Parameters<CanUseTool>[2]): Promise<PermissionResult>;
@@ -0,0 +1,32 @@
1
+ import { approvalContext } from "./approval-context.js";
2
+ /** Only native session suggestions that add grants can be reused without changing policy. */
3
+ function reusable(suggestions) {
4
+ return !!suggestions?.length && suggestions.every(suggestion => suggestion.destination === "session"
5
+ && ((suggestion.type === "addRules" && suggestion.behavior === "allow" && suggestion.rules.length > 0)
6
+ || (suggestion.type === "addDirectories" && suggestion.directories.length > 0)));
7
+ }
8
+ export async function claudeApproval(approvals, handler, toolName, input, metadata) {
9
+ const originalInput = structuredClone(input);
10
+ const suggestions = metadata.suggestions && structuredClone(metadata.suggestions);
11
+ const session = !metadata.suppressAlwaysAllowRule && reusable(suggestions);
12
+ const request = {
13
+ kind: "permission", harness: "claudeCode", message: metadata.title ?? `Allow native tool ${toolName}?`,
14
+ requestedSchema: { type: "object", properties: { decision: { type: "string", oneOf: [
15
+ { const: "allow_once", title: "Allow once" },
16
+ ...(session ? [{ const: "allow_session", title: "Allow for this session using the suggested permissions" }] : []),
17
+ { const: "deny", title: "Deny" },
18
+ ] } }, required: ["decision"] },
19
+ context: { toolName, input: originalInput, ...approvalContext(metadata, ["blockedPath", "decisionReason", "title", "displayName", "description", "defaultToNo", "suppressAlwaysAllowRule", "toolUseID", "agentID", "requestId"]),
20
+ ...(metadata.matchedAskRule ? { matchedAskRule: approvalContext(metadata.matchedAskRule, ["source", "toolName", "ruleContent"]) } : {}),
21
+ ...(metadata.mcpServer ? { mcpServer: approvalContext(metadata.mcpServer, ["name", "source"]) } : {}),
22
+ ...(suggestions ? { suggestions: suggestions.map(suggestion => ({ ...approvalContext(suggestion, ["type", "destination", "behavior", "mode", "directories"]), ...("rules" in suggestion ? { rules: suggestion.rules.map(rule => approvalContext(rule, ["toolName", "ruleContent"])) } : {}) })) } : {}),
23
+ },
24
+ };
25
+ const content = await approvals.request(metadata.requestId, request, handler, metadata.signal);
26
+ if (metadata.signal.aborted)
27
+ return { behavior: "deny", message: "The permission request is no longer pending." };
28
+ if (content.decision === "deny")
29
+ return { behavior: "deny", message: "The caller denied permission for this tool." };
30
+ return { behavior: "allow", updatedInput: originalInput, ...(content.decision === "allow_session" ? { updatedPermissions: suggestions } : {}) };
31
+ }
32
+ //# sourceMappingURL=claude-approvals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-approvals.js","sourceRoot":"","sources":["../../src/adapters/claude-approvals.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,6FAA6F;AAC7F,SAAS,QAAQ,CAAC,WAA2C;IAC3D,OAAO,CAAC,CAAC,WAAW,EAAE,MAAM,IAAI,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,KAAK,SAAS;WAC/F,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,UAAU,IAAI,UAAU,CAAC,QAAQ,KAAK,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;eACjG,CAAC,UAAU,CAAC,IAAI,KAAK,gBAAgB,IAAI,UAAU,CAAC,WAAW,CAA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EAAC,OAAO,EAAC,6CAA6C,EAAC,CAAC;IAChH,OAAO,EAAC,QAAQ,EAAC,OAAO,EAAC,YAAY,EAAC,aAAa,EAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,eAAe,CAAC,CAAC,CAAC,EAAC,kBAAkB,EAAC,WAAW,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAC,CAAC;AACzI,CAAC","sourcesContent":["import type { CanUseTool, PermissionResult, PermissionUpdate } from \"@anthropic-ai/claude-agent-sdk\";\nimport type { ApprovalHandler, NativeApprovalRequest } from \"../approvals/types.js\";\nimport { approvalContext } from \"./approval-context.js\";\nimport { NativeApprovals } from \"./approval-lifetime.js\";\n\n/** Only native session suggestions that add grants can be reused without changing policy. */\nfunction reusable(suggestions: PermissionUpdate[] | undefined): suggestions is PermissionUpdate[] {\n return !!suggestions?.length && suggestions.every(suggestion => suggestion.destination === \"session\"\n && ((suggestion.type === \"addRules\" && suggestion.behavior === \"allow\" && suggestion.rules.length > 0)\n || (suggestion.type === \"addDirectories\" && suggestion.directories.length > 0)));\n}\nexport async function claudeApproval(\n approvals: NativeApprovals, handler: ApprovalHandler, toolName: string,\n input: Record<string, unknown>, metadata: Parameters<CanUseTool>[2],\n): Promise<PermissionResult> {\n const originalInput = structuredClone(input);\n const suggestions = metadata.suggestions && structuredClone(metadata.suggestions);\n const session = !metadata.suppressAlwaysAllowRule && reusable(suggestions);\n const request: NativeApprovalRequest = {\n kind: \"permission\", harness: \"claudeCode\", message: metadata.title ?? `Allow native tool ${toolName}?`,\n requestedSchema: {type:\"object\",properties:{decision:{type:\"string\",oneOf:[\n {const:\"allow_once\",title:\"Allow once\"},\n ...(session ? [{const:\"allow_session\",title:\"Allow for this session using the suggested permissions\"}] : []),\n {const:\"deny\",title:\"Deny\"},\n ]}},required:[\"decision\"]},\n context: {toolName,input:originalInput,...approvalContext(metadata,[\"blockedPath\",\"decisionReason\",\"title\",\"displayName\",\"description\",\"defaultToNo\",\"suppressAlwaysAllowRule\",\"toolUseID\",\"agentID\",\"requestId\"]),\n ...(metadata.matchedAskRule ? {matchedAskRule:approvalContext(metadata.matchedAskRule,[\"source\",\"toolName\",\"ruleContent\"])} : {}),\n ...(metadata.mcpServer ? {mcpServer:approvalContext(metadata.mcpServer,[\"name\",\"source\"])} : {}),\n ...(suggestions ? {suggestions:suggestions.map(suggestion=>({...approvalContext(suggestion,[\"type\",\"destination\",\"behavior\",\"mode\",\"directories\"]),...(\"rules\" in suggestion ? {rules:suggestion.rules.map(rule=>approvalContext(rule,[\"toolName\",\"ruleContent\"]))} : {})}))} : {}),\n },\n };\n const content = await approvals.request(metadata.requestId, request, handler, metadata.signal);\n if (metadata.signal.aborted) return {behavior:\"deny\",message:\"The permission request is no longer pending.\"};\n if (content.decision === \"deny\") return {behavior:\"deny\",message:\"The caller denied permission for this tool.\"};\n return {behavior:\"allow\",updatedInput:originalInput,...(content.decision === \"allow_session\" ? {updatedPermissions:suggestions} : {})};\n}\n"]}
@@ -17,7 +17,7 @@ export function claudeDelegationPermissions(options) {
17
17
  launchers.push(path, `"${path}"`);
18
18
  const commands = [
19
19
  ...names.map(name => `run subagent:${name}`),
20
- "list", "--help", "send", "wait", "status", "queue", "cancel", "resume",
20
+ "list", "--help", "send", "wait", "status", "queue", "cancel", "resume", "respond",
21
21
  ];
22
22
  return commands.flatMap(command => launchers.map(launcher => `Bash(${launcher} ${command} *)`));
23
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"claude-permissions.js","sourceRoot":"","sources":["../../src/adapters/claude-permissions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,oFAAoF;AACpF,MAAM,UAAU,2BAA2B,CAAC,OAAuB;IACjE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IACzD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACxC,8EAA8E;IAC9E,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,UAAU,CAAC,gBAAgB,EAAE,kHAAkH,CAAC,CAAC;IAC7J,CAAC;IACD,MAAM,SAAS,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,gFAAgF;IAChF,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,GAAG,CAAC,CAAC;IACxE,MAAM,QAAQ,GAAG;QACf,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,gBAAgB,IAAI,EAAE,CAAC;QAC5C,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;KACxE,CAAC;IACF,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,QAAQ,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC;AAClG,CAAC","sourcesContent":["import type { AdapterOptions } from \"./types.js\";\nimport { shellQuote } from \"../shell.js\";\nimport { isAbsolute } from \"node:path\";\nimport { AgentError } from \"../errors.js\";\n\n/** Only the native permission evaluator decides whether a shell call is allowed. */\nexport function claudeDelegationPermissions(options: AdapterOptions): string[] {\n const names = Object.keys(options.agent.subagents ?? {});\n if (names.length === 0) return [];\n const path = options.env.AGENT_CLI_PATH;\n // Bash rules treat '*' as a wildcard even when it occurs inside shell quotes.\n if (!path || !isAbsolute(path) || /[\\x00-\\x1f\\x7f*]/u.test(path)) {\n throw new AgentError(\"INVALID_CONFIG\", \"The session launcher needs an absolute path without wildcards or control characters for Claude Code permissions.\");\n }\n const launchers = [shellQuote(path)];\n // Native matching is textual: harmless quote changes need exact separate rules.\n if (/^[A-Za-z0-9_./-]+$/u.test(path)) launchers.push(path, `\"${path}\"`);\n const commands = [\n ...names.map(name => `run subagent:${name}`),\n \"list\", \"--help\", \"send\", \"wait\", \"status\", \"queue\", \"cancel\", \"resume\",\n ];\n return commands.flatMap(command => launchers.map(launcher => `Bash(${launcher} ${command} *)`));\n}\n"]}
1
+ {"version":3,"file":"claude-permissions.js","sourceRoot":"","sources":["../../src/adapters/claude-permissions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,oFAAoF;AACpF,MAAM,UAAU,2BAA2B,CAAC,OAAuB;IACjE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IACzD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACxC,8EAA8E;IAC9E,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,UAAU,CAAC,gBAAgB,EAAE,kHAAkH,CAAC,CAAC;IAC7J,CAAC;IACD,MAAM,SAAS,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,gFAAgF;IAChF,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,GAAG,CAAC,CAAC;IACxE,MAAM,QAAQ,GAAG;QACf,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,gBAAgB,IAAI,EAAE,CAAC;QAC5C,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS;KACnF,CAAC;IACF,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,QAAQ,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC;AAClG,CAAC","sourcesContent":["import type { AdapterOptions } from \"./types.js\";\nimport { shellQuote } from \"../shell.js\";\nimport { isAbsolute } from \"node:path\";\nimport { AgentError } from \"../errors.js\";\n\n/** Only the native permission evaluator decides whether a shell call is allowed. */\nexport function claudeDelegationPermissions(options: AdapterOptions): string[] {\n const names = Object.keys(options.agent.subagents ?? {});\n if (names.length === 0) return [];\n const path = options.env.AGENT_CLI_PATH;\n // Bash rules treat '*' as a wildcard even when it occurs inside shell quotes.\n if (!path || !isAbsolute(path) || /[\\x00-\\x1f\\x7f*]/u.test(path)) {\n throw new AgentError(\"INVALID_CONFIG\", \"The session launcher needs an absolute path without wildcards or control characters for Claude Code permissions.\");\n }\n const launchers = [shellQuote(path)];\n // Native matching is textual: harmless quote changes need exact separate rules.\n if (/^[A-Za-z0-9_./-]+$/u.test(path)) launchers.push(path, `\"${path}\"`);\n const commands = [\n ...names.map(name => `run subagent:${name}`),\n \"list\", \"--help\", \"send\", \"wait\", \"status\", \"queue\", \"cancel\", \"resume\", \"respond\",\n ];\n return commands.flatMap(command => launchers.map(launcher => `Bash(${launcher} ${command} *)`));\n}\n"]}
@@ -10,6 +10,8 @@ import { ClaudeInput } from "./claude-input.js";
10
10
  import { claudeDelegationPermissions } from "./claude-permissions.js";
11
11
  import { claudeSettings, verifyClaudeAccess, verifyClaudePolicy, verifyClaudeOptions } from "./claude-auth.js";
12
12
  import { ClaudeSettingsUnavailable, claudeDefaultUnavailable, readClaudeAppliedSettings, verifyAppliedClaudeEffort } from "./claude-settings.js";
13
+ import { NativeApprovals } from "./approval-lifetime.js";
14
+ import { claudeApproval } from "./claude-approvals.js";
13
15
  import { ClaudeProcessOwner } from "./claude-process.js";
14
16
  const dependencies = {
15
17
  query,
@@ -59,7 +61,11 @@ export function createClaudeOpener(deps) {
59
61
  const input = new ClaudeInput();
60
62
  const processOwner = new ClaudeProcessOwner();
61
63
  let inputFailure;
64
+ const approvals = new NativeApprovals();
65
+ let acceptingApprovals = false;
62
66
  const requireInput = (toolName) => {
67
+ acceptingApprovals = false;
68
+ approvals.clear();
63
69
  tools.stopAdmission();
64
70
  const subject = toolName && /^[A-Za-z_][A-Za-z0-9_-]{0,127}$/u.test(toolName)
65
71
  ? `approval for native tool ${toolName}`
@@ -85,11 +91,25 @@ export function createClaudeOpener(deps) {
85
91
  ? { type: "preset", preset: "claude_code", append: options.agent.instructions }
86
92
  : { type: "preset", preset: "claude_code" },
87
93
  settingSources: ["user", "project", "local"],
88
- canUseTool: async (toolName) => {
94
+ canUseTool: async (toolName, toolInput, metadata) => {
95
+ if (options.onApproval && acceptingApprovals && toolName !== "AskUserQuestion") {
96
+ try {
97
+ const answer = await claudeApproval(approvals, options.onApproval, toolName, toolInput, metadata);
98
+ if (!acceptingApprovals || metadata.signal.aborted)
99
+ return { behavior: "deny", message: "The permission request is no longer pending." };
100
+ return answer;
101
+ }
102
+ catch (error) {
103
+ if (error instanceof AgentError && error.code === "REQUEST_EXPIRED")
104
+ return { behavior: "deny", message: "The permission request is no longer pending." };
105
+ }
106
+ }
89
107
  requireInput(toolName);
90
108
  return { behavior: "deny", message: inputFailure.message, interrupt: true };
91
109
  },
92
110
  onElicitation: async () => {
111
+ acceptingApprovals = false;
112
+ approvals.clear();
93
113
  requireInput();
94
114
  try {
95
115
  await native.interrupt();
@@ -207,6 +227,8 @@ export function createClaudeOpener(deps) {
207
227
  if (message.type !== "result" || !active)
208
228
  continue;
209
229
  const current = active;
230
+ acceptingApprovals = false;
231
+ approvals.clear();
210
232
  await tools.drain();
211
233
  active = undefined;
212
234
  current.stop();
@@ -229,6 +251,8 @@ export function createClaudeOpener(deps) {
229
251
  // Native diagnostics may contain credentials; return a stable safe message.
230
252
  }
231
253
  finally {
254
+ acceptingApprovals = false;
255
+ approvals.clear();
232
256
  const code = closed ? "SESSION_CLOSED" : "HARNESS_ERROR";
233
257
  closed = true;
234
258
  input.close();
@@ -287,6 +311,7 @@ export function createClaudeOpener(deps) {
287
311
  let stop;
288
312
  const stopped = new Promise(resolve => { stop = resolve; });
289
313
  active = { resolve, reject, stopped, stop, interrupted: false };
314
+ acceptingApprovals = true;
290
315
  input.push({ type: "user", message: { role: "user", content: prompt }, parent_tool_use_id: null, uuid: randomUUID() });
291
316
  });
292
317
  },
@@ -302,6 +327,8 @@ export function createClaudeOpener(deps) {
302
327
  if (!current)
303
328
  return;
304
329
  current.interrupted = true;
330
+ acceptingApprovals = false;
331
+ approvals.clear();
305
332
  tools.stopAdmission();
306
333
  try {
307
334
  await native.interrupt();
@@ -315,6 +342,8 @@ export function createClaudeOpener(deps) {
315
342
  async resume() { throw new AgentError("RECOVERY_UNSUPPORTED", "Claude Code cannot retry failed execution without replaying input."); },
316
343
  async close() {
317
344
  closed = true;
345
+ acceptingApprovals = false;
346
+ approvals.clear();
318
347
  const pending = preflight;
319
348
  if (pending) {
320
349
  pending.cancel(new AgentError("SESSION_CLOSED", "The native session closed before submission."));
@@ -1 +1 @@
1
- {"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/adapters/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAA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C;gBACjC,MAAM,CAAC;oBACL,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC;oBAC5B,MAAM,IAAI,UAAU,CAAC,eAAe,EAAE,2CAA2C,CAAC,CAAC;gBACrF,CAAC;gBACD,MAAM,OAAO,CAAC,OAAO,CAAC;YACxB,CAAC;YACD,KAAK,CAAC,MAAM,KAAK,MAAM,IAAI,UAAU,CAAC,sBAAsB,EAAE,oEAAoE,CAAC,CAAC,CAAC,CAAC;YACtI,KAAK,CAAC,KAAK;gBACT,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,OAAO,GAAG,SAAS,CAAC;gBAC1B,IAAI,OAAO,EAAE,CAAC;oBACZ,OAAO,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,gBAAgB,EAAE,8CAA8C,CAAC,CAAC,CAAC;oBACjG,MAAM,OAAO,CAAC,OAAO,CAAC;gBACxB,CAAC;gBACD,KAAK,CAAC,aAAa,EAAE,CAAC;gBACtB,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;gBACtC,IAAI,CAAC;oBAAC,MAAM,OAAO,CAAC;gBAAC,CAAC;wBACd,CAAC;oBAAC,MAAM,QAAQ,CAAC;gBAAC,CAAC;YAC7B,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { access } from \"node:fs/promises\";\nimport { constants } from \"node:fs\";\nimport { delimiter, join } from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { query, resolveSettings, type AccountInfo, type Options, type SDKMessage, type SDKUserMessage, type Settings, type ModelInfo } from \"@anthropic-ai/claude-agent-sdk\";\nimport { AgentError } from \"../errors.js\";\nimport type { AdapterOptions, NativeSession } from \"./types.js\";\nimport { privateClaudeConfig } from \"./claude-config.js\";\nimport { claudeTools } from \"./claude-tools.js\";\nimport { ClaudeInput } from \"./claude-input.js\";\nimport { claudeDelegationPermissions } from \"./claude-permissions.js\";\nimport { claudeSettings, verifyClaudeAccess, verifyClaudePolicy, verifyClaudeOptions } from \"./claude-auth.js\";\nimport { ClaudeSettingsUnavailable, claudeDefaultUnavailable, readClaudeAppliedSettings, verifyAppliedClaudeEffort } from \"./claude-settings.js\";\nimport { ClaudeProcessOwner } from \"./claude-process.js\";\n\ninterface ClaudeQuery extends AsyncIterable<SDKMessage> {\n accountInfo(): Promise<AccountInfo>;\n supportedModels(): Promise<ModelInfo[]>;\n interrupt(): Promise<unknown>;\n close(): void;\n getSettings?(): Promise<unknown>;\n setModel?(model?: string): Promise<void>;\n}\nexport interface ClaudeDependencies {\n query(args: {prompt: AsyncIterable<SDKUserMessage>; options: Options}): ClaudeQuery;\n executable(env: NodeJS.ProcessEnv): Promise<string>;\n managedSettings(cwd: string): Promise<Settings[]>;\n}\n\nconst dependencies: ClaudeDependencies = {\n query,\n async managedSettings(cwd) {\n const settings = await resolveSettings({cwd, settingSources:[\"user\", \"project\", \"local\"]});\n return settings.sources.filter(source => source.source === \"managed\").map(source => source.settings);\n },\n async executable(env) {\n for (const directory of (env.PATH ?? \"\").split(delimiter)) {\n const file = join(directory, \"claude\");\n try { await access(file, constants.X_OK); return file; } catch { /* Try the next PATH entry. */ }\n }\n throw new AgentError(\"HARNESS_UNAVAILABLE\", \"Install Claude Code and make claude available on PATH.\");\n },\n};\n\nfunction addCatalogEquivalentModels(expected: Set<string>, models: ModelInfo[], selected: string): void {\n expected.add(selected);\n for (const model of models) {\n if (model.value !== selected && model.resolvedModel !== selected) continue;\n expected.add(model.value);\n if (model.resolvedModel) expected.add(model.resolvedModel);\n }\n}\n\nexport const openClaude = createClaudeOpener(dependencies);\n\n/** Dependency injection is internal and replaces only the external SDK boundary in tests. */\nexport function createClaudeOpener(deps: ClaudeDependencies) {\n return async (options: AdapterOptions): Promise<NativeSession> => {\n if (options.harness.kind !== \"claudeCode\") throw new AgentError(\"INVALID_CONFIG\", \"Claude Code received configuration for a different harness.\");\n const permissionMode = options.harness.permissionMode;\n const settings = claudeSettings(options);\n const executable = await deps.executable(options.env);\n verifyClaudePolicy(await deps.managedSettings(options.cwd), settings.settings as Settings);\n const tools = claudeTools(options.agent);\n const allowedTools = [\n ...(options.harness.allowedTools ?? []),\n ...(tools.config.allowedTools ?? []),\n ...claudeDelegationPermissions(options),\n ];\n const config = await privateClaudeConfig(settings.settings as Settings);\n const input = new ClaudeInput<SDKUserMessage>();\n const processOwner = new ClaudeProcessOwner();\n let inputFailure: AgentError | undefined;\n const requireInput = (toolName?: string) => {\n tools.stopAdmission();\n const subject = toolName && /^[A-Za-z_][A-Za-z0-9_-]{0,127}$/u.test(toolName)\n ? `approval for native tool ${toolName}`\n : \"interactive input\";\n inputFailure = new AgentError(\"INPUT_REQUIRED\", `Claude Code needs ${subject}. Configure its native permissions before retrying.`);\n };\n let native: ClaudeQuery;\n try { native = deps.query({prompt: input, options: {\n pathToClaudeCodeExecutable: executable,\n spawnClaudeCodeProcess: processOwner.spawn,\n cwd: options.cwd,\n ...settings,\n ...tools.config,\n ...(allowedTools.length ? {allowedTools} : {}),\n ...(options.harness.disallowedTools !== undefined ? {disallowedTools:[...options.harness.disallowedTools]} : {}),\n ...(permissionMode !== undefined ? {permissionMode} : {}),\n ...(permissionMode === \"bypassPermissions\" ? {allowDangerouslySkipPermissions:true} : {}),\n settings: config.path,\n stderr: () => {},\n ...(options.harness.model ? {model: options.harness.model} : {}),\n systemPrompt: options.agent.instructions\n ? {type: \"preset\", preset: \"claude_code\", append: options.agent.instructions}\n : {type: \"preset\", preset: \"claude_code\"},\n settingSources: [\"user\", \"project\", \"local\"],\n canUseTool: async (toolName) => {\n requireInput(toolName);\n return {behavior: \"deny\", message: inputFailure!.message, interrupt: true};\n },\n onElicitation: async () => {\n requireInput();\n try { await native.interrupt(); } catch { native.close(); }\n return {action: \"decline\"};\n },\n }}); }\n catch {\n input.close();\n try { await processOwner.close(); }\n finally { await config.cleanup(); }\n throw new AgentError(\"HARNESS_UNAVAILABLE\", \"Claude Code could not start.\");\n }\n const expectedModels = new Set<string>();\n let retainedModel: string | undefined;\n try {\n verifyClaudeAccess(await native.accountInfo(), options.access);\n const models = await native.supportedModels();\n if (options.harness.model) {\n addCatalogEquivalentModels(expectedModels, models, options.harness.model);\n verifyClaudeOptions(models, options);\n try {\n const applied = await readClaudeAppliedSettings(native);\n if (!expectedModels.has(applied.model)) throw new AgentError(\"INVALID_CONFIG\", \"Claude Code selected a different model than requested.\");\n verifyAppliedClaudeEffort(applied.effort, options.harness.effort);\n retainedModel = applied.model;\n expectedModels.add(applied.model);\n } catch (error) {\n if (!(error instanceof ClaudeSettingsUnavailable)) throw error;\n }\n } else {\n if (!native.getSettings || !native.setModel) throw claudeDefaultUnavailable();\n let selected;\n try { selected = await readClaudeAppliedSettings(native); }\n catch (error) { if (error instanceof ClaudeSettingsUnavailable) throw claudeDefaultUnavailable(); throw error; }\n verifyClaudeOptions(models, options, selected.model);\n verifyAppliedClaudeEffort(selected.effort, options.harness.effort);\n addCatalogEquivalentModels(expectedModels, models, selected.model);\n try { await native.setModel(selected.model); } catch { throw claudeDefaultUnavailable(); }\n let pinned;\n try { pinned = await readClaudeAppliedSettings(native); }\n catch (error) { if (error instanceof ClaudeSettingsUnavailable) throw claudeDefaultUnavailable(); throw error; }\n if (!expectedModels.has(pinned.model)) throw claudeDefaultUnavailable();\n verifyAppliedClaudeEffort(pinned.effort, options.harness.effort);\n retainedModel = pinned.model;\n addCatalogEquivalentModels(expectedModels, models, pinned.model);\n }\n if (inputFailure) throw inputFailure;\n }\n catch (error) {\n input.close();\n native.close();\n try { await processOwner.close(); }\n finally { await config.cleanup(); }\n if (error instanceof AgentError) throw error;\n throw new AgentError(\"ACCESS_UNAVAILABLE\", \"Claude Code authentication could not be verified.\");\n }\n let closed = false;\n let preflight: {\n cancellation: Promise<never>;\n cancel(error: AgentError): void;\n stopped: Promise<void>;\n stop(): void;\n } | undefined;\n let sessionFailure: AgentError | undefined;\n let active: {\n resolve(text: string): void; reject(error: unknown): void;\n stopped: Promise<void>; stop(): void; interrupted: boolean;\n } | undefined;\n const reading = (async () => {\n try {\n for await (const message of native) {\n if (message.type === \"system\" && message.subtype === \"init\") {\n if (!expectedModels.has(message.model)) {\n sessionFailure = new AgentError(\"INVALID_CONFIG\", \"Claude Code selected a different model than requested.\");\n } else if (permissionMode !== undefined && message.permissionMode !== permissionMode) {\n sessionFailure = new AgentError(\"INVALID_CONFIG\", \"Claude Code reported a different permission mode than requested.\");\n }\n if (sessionFailure) {\n tools.stopAdmission();\n native.close();\n break;\n }\n }\n if (message.type !== \"result\" || !active) continue;\n const current = active;\n await tools.drain();\n active = undefined;\n current.stop();\n if (inputFailure) current.reject(inputFailure);\n else if (current.interrupted) current.reject(new AgentError(\"INTERRUPTED\", \"The native turn was interrupted.\"));\n else if (message.subtype === \"success\" && !message.is_error) {\n if (Buffer.byteLength(message.result, \"utf8\") > 1024 * 1024) {\n current.reject(new AgentError(\"RESPONSE_TOO_LARGE\", \"The Claude Code response exceeds 1 MiB.\"));\n } else current.resolve(message.result);\n }\n else current.reject(new AgentError(\"HARNESS_ERROR\", \"Claude Code could not complete the turn.\"));\n }\n } catch {\n // Native diagnostics may contain credentials; return a stable safe message.\n } finally {\n const code = closed ? \"SESSION_CLOSED\" : \"HARNESS_ERROR\";\n closed = true;\n input.close();\n await tools.drain();\n active?.reject(sessionFailure ?? inputFailure ?? new AgentError(code, \"The Claude Code process stopped before completing the turn.\"));\n active?.stop();\n active = undefined;\n try { await processOwner.close(); }\n finally { await config.cleanup(); }\n }\n })();\n return {\n async turn(prompt) {\n if (closed) return Promise.reject(sessionFailure ?? new AgentError(\"SESSION_CLOSED\", \"The native session has closed.\"));\n if (active || preflight) return Promise.reject(new AgentError(\"SESSION_BUSY\", \"A native turn is already active.\"));\n let cancel!: (error: AgentError) => void, stop!: () => void;\n const currentPreflight = {\n cancellation: new Promise<never>((_resolve, reject) => { cancel = reject; }),\n cancel(error: AgentError) { cancel(error); },\n stopped: new Promise<void>(resolve => { stop = resolve; }),\n stop() { stop(); },\n };\n preflight = currentPreflight;\n try {\n if (native.getSettings && retainedModel) {\n let applied;\n try { applied = await Promise.race([readClaudeAppliedSettings(native), currentPreflight.cancellation]); }\n catch (error) {\n if (error instanceof ClaudeSettingsUnavailable) throw new AgentError(\"INVALID_CONFIG\", \"Claude Code could not verify the retained session model before submission.\");\n throw error;\n }\n if (!expectedModels.has(applied.model)) throw new AgentError(\"INVALID_CONFIG\", \"Claude Code changed the retained session model before submission.\");\n verifyAppliedClaudeEffort(applied.effort, options.harness.effort);\n }\n if (closed) throw sessionFailure ?? new AgentError(\"SESSION_CLOSED\", \"The native session has closed.\");\n } finally {\n if (preflight === currentPreflight) preflight = undefined;\n currentPreflight.stop();\n }\n return await new Promise((resolve, reject) => {\n inputFailure = undefined;\n tools.start();\n let stop!: () => void;\n const stopped = new Promise<void>(resolve => { stop = resolve; });\n active = {resolve, reject, stopped, stop, interrupted:false};\n input.push({type:\"user\",message:{role:\"user\",content:prompt},parent_tool_use_id:null,uuid:randomUUID()});\n });\n },\n async steer() { throw new AgentError(\"UNSUPPORTED_DELIVERY\", \"Claude Code does not expose verified active steering.\"); },\n async interrupt() {\n const pending = preflight;\n if (pending) {\n pending.cancel(new AgentError(\"INTERRUPTED\", \"The native turn was interrupted before submission.\"));\n await pending.stopped;\n return;\n }\n const current = active;\n if (!current) return;\n current.interrupted = true;\n tools.stopAdmission();\n try { await native.interrupt(); }\n catch {\n current.interrupted = false;\n throw new AgentError(\"CANCEL_FAILED\", \"Claude Code did not confirm interruption.\");\n }\n await current.stopped;\n },\n async resume() { throw new AgentError(\"RECOVERY_UNSUPPORTED\", \"Claude Code cannot retry failed execution without replaying input.\"); },\n async close() {\n closed = true;\n const pending = preflight;\n if (pending) {\n pending.cancel(new AgentError(\"SESSION_CLOSED\", \"The native session closed before submission.\"));\n await pending.stopped;\n }\n tools.stopAdmission();\n input.close();\n native.close();\n const stopping = processOwner.close();\n try { await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CAAC;gBAC3B,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,KAAK,CAAC,aAAa,EAAE,CAAC;gBACtB,IAAI,CAAC;oBAAC,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;gBAAC,CAAC;gBACjC,MAAM,CAAC;oBACL,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC;oBAC5B,MAAM,IAAI,UAAU,CAAC,eAAe,EAAE,2CAA2C,CAAC,CAAC;gBACrF,CAAC;gBACD,MAAM,OAAO,CAAC,OAAO,CAAC;YACxB,CAAC;YACD,KAAK,CAAC,MAAM,KAAK,MAAM,IAAI,UAAU,CAAC,sBAAsB,EAAE,oEAAoE,CAAC,CAAC,CAAC,CAAC;YACtI,KAAK,CAAC,KAAK;gBACT,MAAM,GAAG,IAAI,CAAC;gBACd,kBAAkB,GAAG,KAAK,CAAC;gBAC3B,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,MAAM,OAAO,GAAG,SAAS,CAAC;gBAC1B,IAAI,OAAO,EAAE,CAAC;oBACZ,OAAO,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,gBAAgB,EAAE,8CAA8C,CAAC,CAAC,CAAC;oBACjG,MAAM,OAAO,CAAC,OAAO,CAAC;gBACxB,CAAC;gBACD,KAAK,CAAC,aAAa,EAAE,CAAC;gBACtB,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;gBACtC,IAAI,CAAC;oBAAC,MAAM,OAAO,CAAC;gBAAC,CAAC;wBACd,CAAC;oBAAC,MAAM,QAAQ,CAAC;gBAAC,CAAC;YAC7B,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { access } from \"node:fs/promises\";\nimport { constants } from \"node:fs\";\nimport { delimiter, join } from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { query, resolveSettings, type AccountInfo, type Options, type SDKMessage, type SDKUserMessage, type Settings, type ModelInfo } from \"@anthropic-ai/claude-agent-sdk\";\nimport { AgentError } from \"../errors.js\";\nimport type { AdapterOptions, NativeSession } from \"./types.js\";\nimport { privateClaudeConfig } from \"./claude-config.js\";\nimport { claudeTools } from \"./claude-tools.js\";\nimport { ClaudeInput } from \"./claude-input.js\";\nimport { claudeDelegationPermissions } from \"./claude-permissions.js\";\nimport { claudeSettings, verifyClaudeAccess, verifyClaudePolicy, verifyClaudeOptions } from \"./claude-auth.js\";\nimport { ClaudeSettingsUnavailable, claudeDefaultUnavailable, readClaudeAppliedSettings, verifyAppliedClaudeEffort } from \"./claude-settings.js\";\nimport { NativeApprovals } from \"./approval-lifetime.js\";\nimport { claudeApproval } from \"./claude-approvals.js\";\nimport { ClaudeProcessOwner } from \"./claude-process.js\";\n\ninterface ClaudeQuery extends AsyncIterable<SDKMessage> {\n accountInfo(): Promise<AccountInfo>;\n supportedModels(): Promise<ModelInfo[]>;\n interrupt(): Promise<unknown>;\n close(): void;\n getSettings?(): Promise<unknown>;\n setModel?(model?: string): Promise<void>;\n}\nexport interface ClaudeDependencies {\n query(args: {prompt: AsyncIterable<SDKUserMessage>; options: Options}): ClaudeQuery;\n executable(env: NodeJS.ProcessEnv): Promise<string>;\n managedSettings(cwd: string): Promise<Settings[]>;\n}\n\nconst dependencies: ClaudeDependencies = {\n query,\n async managedSettings(cwd) {\n const settings = await resolveSettings({cwd, settingSources:[\"user\", \"project\", \"local\"]});\n return settings.sources.filter(source => source.source === \"managed\").map(source => source.settings);\n },\n async executable(env) {\n for (const directory of (env.PATH ?? \"\").split(delimiter)) {\n const file = join(directory, \"claude\");\n try { await access(file, constants.X_OK); return file; } catch { /* Try the next PATH entry. */ }\n }\n throw new AgentError(\"HARNESS_UNAVAILABLE\", \"Install Claude Code and make claude available on PATH.\");\n },\n};\n\nfunction addCatalogEquivalentModels(expected: Set<string>, models: ModelInfo[], selected: string): void {\n expected.add(selected);\n for (const model of models) {\n if (model.value !== selected && model.resolvedModel !== selected) continue;\n expected.add(model.value);\n if (model.resolvedModel) expected.add(model.resolvedModel);\n }\n}\n\nexport const openClaude = createClaudeOpener(dependencies);\n\n/** Dependency injection is internal and replaces only the external SDK boundary in tests. */\nexport function createClaudeOpener(deps: ClaudeDependencies) {\n return async (options: AdapterOptions): Promise<NativeSession> => {\n if (options.harness.kind !== \"claudeCode\") throw new AgentError(\"INVALID_CONFIG\", \"Claude Code received configuration for a different harness.\");\n const permissionMode = options.harness.permissionMode;\n const settings = claudeSettings(options);\n const executable = await deps.executable(options.env);\n verifyClaudePolicy(await deps.managedSettings(options.cwd), settings.settings as Settings);\n const tools = claudeTools(options.agent);\n const allowedTools = [\n ...(options.harness.allowedTools ?? []),\n ...(tools.config.allowedTools ?? []),\n ...claudeDelegationPermissions(options),\n ];\n const config = await privateClaudeConfig(settings.settings as Settings);\n const input = new ClaudeInput<SDKUserMessage>();\n const processOwner = new ClaudeProcessOwner();\n let inputFailure: AgentError | undefined;\n const approvals = new NativeApprovals();\n let acceptingApprovals = false;\n const requireInput = (toolName?: string) => {\n acceptingApprovals = false;\n approvals.clear();\n tools.stopAdmission();\n const subject = toolName && /^[A-Za-z_][A-Za-z0-9_-]{0,127}$/u.test(toolName)\n ? `approval for native tool ${toolName}`\n : \"interactive input\";\n inputFailure = new AgentError(\"INPUT_REQUIRED\", `Claude Code needs ${subject}. Configure its native permissions before retrying.`);\n };\n let native: ClaudeQuery;\n try { native = deps.query({prompt: input, options: {\n pathToClaudeCodeExecutable: executable,\n spawnClaudeCodeProcess: processOwner.spawn,\n cwd: options.cwd,\n ...settings,\n ...tools.config,\n ...(allowedTools.length ? {allowedTools} : {}),\n ...(options.harness.disallowedTools !== undefined ? {disallowedTools:[...options.harness.disallowedTools]} : {}),\n ...(permissionMode !== undefined ? {permissionMode} : {}),\n ...(permissionMode === \"bypassPermissions\" ? {allowDangerouslySkipPermissions:true} : {}),\n settings: config.path,\n stderr: () => {},\n ...(options.harness.model ? {model: options.harness.model} : {}),\n systemPrompt: options.agent.instructions\n ? {type: \"preset\", preset: \"claude_code\", append: options.agent.instructions}\n : {type: \"preset\", preset: \"claude_code\"},\n settingSources: [\"user\", \"project\", \"local\"],\n canUseTool: async (toolName, toolInput, metadata) => {\n if (options.onApproval && acceptingApprovals && toolName !== \"AskUserQuestion\") {\n try {\n const answer = await claudeApproval(approvals, options.onApproval, toolName, toolInput, metadata);\n if (!acceptingApprovals || metadata.signal.aborted) return {behavior:\"deny\",message:\"The permission request is no longer pending.\"};\n return answer;\n }\n catch (error) {\n if (error instanceof AgentError && error.code === \"REQUEST_EXPIRED\") return {behavior:\"deny\",message:\"The permission request is no longer pending.\"};\n }\n }\n requireInput(toolName);\n return {behavior: \"deny\", message: inputFailure!.message, interrupt: true};\n },\n onElicitation: async () => {\n acceptingApprovals = false;\n approvals.clear();\n requireInput();\n try { await native.interrupt(); } catch { native.close(); }\n return {action: \"decline\"};\n },\n }}); }\n catch {\n input.close();\n try { await processOwner.close(); }\n finally { await config.cleanup(); }\n throw new AgentError(\"HARNESS_UNAVAILABLE\", \"Claude Code could not start.\");\n }\n const expectedModels = new Set<string>();\n let retainedModel: string | undefined;\n try {\n verifyClaudeAccess(await native.accountInfo(), options.access);\n const models = await native.supportedModels();\n if (options.harness.model) {\n addCatalogEquivalentModels(expectedModels, models, options.harness.model);\n verifyClaudeOptions(models, options);\n try {\n const applied = await readClaudeAppliedSettings(native);\n if (!expectedModels.has(applied.model)) throw new AgentError(\"INVALID_CONFIG\", \"Claude Code selected a different model than requested.\");\n verifyAppliedClaudeEffort(applied.effort, options.harness.effort);\n retainedModel = applied.model;\n expectedModels.add(applied.model);\n } catch (error) {\n if (!(error instanceof ClaudeSettingsUnavailable)) throw error;\n }\n } else {\n if (!native.getSettings || !native.setModel) throw claudeDefaultUnavailable();\n let selected;\n try { selected = await readClaudeAppliedSettings(native); }\n catch (error) { if (error instanceof ClaudeSettingsUnavailable) throw claudeDefaultUnavailable(); throw error; }\n verifyClaudeOptions(models, options, selected.model);\n verifyAppliedClaudeEffort(selected.effort, options.harness.effort);\n addCatalogEquivalentModels(expectedModels, models, selected.model);\n try { await native.setModel(selected.model); } catch { throw claudeDefaultUnavailable(); }\n let pinned;\n try { pinned = await readClaudeAppliedSettings(native); }\n catch (error) { if (error instanceof ClaudeSettingsUnavailable) throw claudeDefaultUnavailable(); throw error; }\n if (!expectedModels.has(pinned.model)) throw claudeDefaultUnavailable();\n verifyAppliedClaudeEffort(pinned.effort, options.harness.effort);\n retainedModel = pinned.model;\n addCatalogEquivalentModels(expectedModels, models, pinned.model);\n }\n if (inputFailure) throw inputFailure;\n }\n catch (error) {\n input.close();\n native.close();\n try { await processOwner.close(); }\n finally { await config.cleanup(); }\n if (error instanceof AgentError) throw error;\n throw new AgentError(\"ACCESS_UNAVAILABLE\", \"Claude Code authentication could not be verified.\");\n }\n let closed = false;\n let preflight: {\n cancellation: Promise<never>;\n cancel(error: AgentError): void;\n stopped: Promise<void>;\n stop(): void;\n } | undefined;\n let sessionFailure: AgentError | undefined;\n let active: {\n resolve(text: string): void; reject(error: unknown): void;\n stopped: Promise<void>; stop(): void; interrupted: boolean;\n } | undefined;\n const reading = (async () => {\n try {\n for await (const message of native) {\n if (message.type === \"system\" && message.subtype === \"init\") {\n if (!expectedModels.has(message.model)) {\n sessionFailure = new AgentError(\"INVALID_CONFIG\", \"Claude Code selected a different model than requested.\");\n } else if (permissionMode !== undefined && message.permissionMode !== permissionMode) {\n sessionFailure = new AgentError(\"INVALID_CONFIG\", \"Claude Code reported a different permission mode than requested.\");\n }\n if (sessionFailure) {\n tools.stopAdmission();\n native.close();\n break;\n }\n }\n if (message.type !== \"result\" || !active) continue;\n const current = active;\n acceptingApprovals = false;\n approvals.clear();\n await tools.drain();\n active = undefined;\n current.stop();\n if (inputFailure) current.reject(inputFailure);\n else if (current.interrupted) current.reject(new AgentError(\"INTERRUPTED\", \"The native turn was interrupted.\"));\n else if (message.subtype === \"success\" && !message.is_error) {\n if (Buffer.byteLength(message.result, \"utf8\") > 1024 * 1024) {\n current.reject(new AgentError(\"RESPONSE_TOO_LARGE\", \"The Claude Code response exceeds 1 MiB.\"));\n } else current.resolve(message.result);\n }\n else current.reject(new AgentError(\"HARNESS_ERROR\", \"Claude Code could not complete the turn.\"));\n }\n } catch {\n // Native diagnostics may contain credentials; return a stable safe message.\n } finally {\n acceptingApprovals = false;\n approvals.clear();\n const code = closed ? \"SESSION_CLOSED\" : \"HARNESS_ERROR\";\n closed = true;\n input.close();\n await tools.drain();\n active?.reject(sessionFailure ?? inputFailure ?? new AgentError(code, \"The Claude Code process stopped before completing the turn.\"));\n active?.stop();\n active = undefined;\n try { await processOwner.close(); }\n finally { await config.cleanup(); }\n }\n })();\n return {\n async turn(prompt) {\n if (closed) return Promise.reject(sessionFailure ?? new AgentError(\"SESSION_CLOSED\", \"The native session has closed.\"));\n if (active || preflight) return Promise.reject(new AgentError(\"SESSION_BUSY\", \"A native turn is already active.\"));\n let cancel!: (error: AgentError) => void, stop!: () => void;\n const currentPreflight = {\n cancellation: new Promise<never>((_resolve, reject) => { cancel = reject; }),\n cancel(error: AgentError) { cancel(error); },\n stopped: new Promise<void>(resolve => { stop = resolve; }),\n stop() { stop(); },\n };\n preflight = currentPreflight;\n try {\n if (native.getSettings && retainedModel) {\n let applied;\n try { applied = await Promise.race([readClaudeAppliedSettings(native), currentPreflight.cancellation]); }\n catch (error) {\n if (error instanceof ClaudeSettingsUnavailable) throw new AgentError(\"INVALID_CONFIG\", \"Claude Code could not verify the retained session model before submission.\");\n throw error;\n }\n if (!expectedModels.has(applied.model)) throw new AgentError(\"INVALID_CONFIG\", \"Claude Code changed the retained session model before submission.\");\n verifyAppliedClaudeEffort(applied.effort, options.harness.effort);\n }\n if (closed) throw sessionFailure ?? new AgentError(\"SESSION_CLOSED\", \"The native session has closed.\");\n } finally {\n if (preflight === currentPreflight) preflight = undefined;\n currentPreflight.stop();\n }\n return await new Promise((resolve, reject) => {\n inputFailure = undefined;\n tools.start();\n let stop!: () => void;\n const stopped = new Promise<void>(resolve => { stop = resolve; });\n active = {resolve, reject, stopped, stop, interrupted:false};\n acceptingApprovals = true;\n input.push({type:\"user\",message:{role:\"user\",content:prompt},parent_tool_use_id:null,uuid:randomUUID()});\n });\n },\n async steer() { throw new AgentError(\"UNSUPPORTED_DELIVERY\", \"Claude Code does not expose verified active steering.\"); },\n async interrupt() {\n const pending = preflight;\n if (pending) {\n pending.cancel(new AgentError(\"INTERRUPTED\", \"The native turn was interrupted before submission.\"));\n await pending.stopped;\n return;\n }\n const current = active;\n if (!current) return;\n current.interrupted = true;\n acceptingApprovals = false;\n approvals.clear();\n tools.stopAdmission();\n try { await native.interrupt(); }\n catch {\n current.interrupted = false;\n throw new AgentError(\"CANCEL_FAILED\", \"Claude Code did not confirm interruption.\");\n }\n await current.stopped;\n },\n async resume() { throw new AgentError(\"RECOVERY_UNSUPPORTED\", \"Claude Code cannot retry failed execution without replaying input.\"); },\n async close() {\n closed = true;\n acceptingApprovals = false;\n approvals.clear();\n const pending = preflight;\n if (pending) {\n pending.cancel(new AgentError(\"SESSION_CLOSED\", \"The native session closed before submission.\"));\n await pending.stopped;\n }\n tools.stopAdmission();\n input.close();\n native.close();\n const stopping = processOwner.close();\n try { await reading; }\n finally { await stopping; }\n },\n };\n };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { ApprovalContent, NativeApprovalRequest } from "../approvals/types.js";
2
+ export interface CodexApproval {
3
+ request: NativeApprovalRequest;
4
+ response(content: ApprovalContent): unknown;
5
+ }
6
+ export declare function codexApproval(method: string | undefined, params: any, item?: unknown): CodexApproval | undefined;
@@ -0,0 +1,111 @@
1
+ import { approvalContext } from "./approval-context.js";
2
+ import { AgentError } from "../errors.js";
3
+ const titles = { accept: "Allow once", acceptForSession: "Allow for this session", decline: "Deny", cancel: "Cancel the native operation" };
4
+ const unsupported = () => new AgentError("INPUT_REQUIRED", "Codex requested permissions that cannot be represented safely.");
5
+ export function codexApproval(method, params, item) {
6
+ if (method === "item/permissions/requestApproval")
7
+ return permissionProfile(params);
8
+ if (method !== "item/commandExecution/requestApproval" && method !== "item/fileChange/requestApproval")
9
+ return undefined;
10
+ if (method === "item/commandExecution/requestApproval" && params.kind !== undefined && !["command", "writeStdin"].includes(params.kind))
11
+ throw unsupported();
12
+ const decisions = params.availableDecisions ?? ["accept", "acceptForSession", "decline", "cancel"];
13
+ if (!Array.isArray(decisions))
14
+ throw unsupported();
15
+ const supported = [];
16
+ for (const decision of decisions) {
17
+ if (typeof decision === "string" && Object.hasOwn(titles, decision))
18
+ supported.push(decision);
19
+ else if (!decision || typeof decision !== "object" || (!Object.hasOwn(decision, "acceptWithExecpolicyAmendment") && !Object.hasOwn(decision, "applyNetworkPolicyAmendment")))
20
+ throw unsupported();
21
+ }
22
+ if (!supported.length || new Set(supported).size !== supported.length)
23
+ throw unsupported();
24
+ const message = method === "item/fileChange/requestApproval" ? "Allow the requested file change?"
25
+ : params.kind === "writeStdin" ? "Allow sending input to the existing terminal?" : "Allow the requested command execution?";
26
+ return {
27
+ request: { kind: "permission", harness: "codex", message,
28
+ requestedSchema: { type: "object", properties: { decision: { type: "string", oneOf: supported.map(value => ({ const: value, title: titles[value] })) } }, required: ["decision"] },
29
+ context: { ...approvalContext(params, ["threadId", "turnId", "itemId", "approvalId", "kind", "environmentId", "reason", "command", "cwd", "commandActions", "networkApprovalContext", "additionalPermissions", "grantRoot"]), ...(item ? { item: fileContext(item) } : {}) } },
30
+ response: content => ({ decision: content.decision }),
31
+ };
32
+ }
33
+ function object(value) { return typeof value === "object" && value !== null && !Array.isArray(value); }
34
+ function only(value, keys) { return Object.keys(value).every(key => keys.includes(key)); }
35
+ function permissionProfile(params) {
36
+ const profile = structuredClone(params.permissions);
37
+ if (!object(profile) || !only(profile, ["network", "fileSystem"]))
38
+ throw unsupported();
39
+ const grants = [];
40
+ if (profile.network != null) {
41
+ if (!object(profile.network) || !only(profile.network, ["enabled"]) || ![true, false, null].includes(profile.network.enabled))
42
+ throw unsupported();
43
+ if (profile.network.enabled === true)
44
+ grants.push({ id: "network", title: "Enable network access", apply: target => { target.network = { enabled: true }; } });
45
+ }
46
+ const fs = profile.fileSystem;
47
+ if (fs != null) {
48
+ const filesystemStart = grants.length;
49
+ if (!object(fs) || !only(fs, ["read", "write", "entries", "globScanMaxDepth"]))
50
+ throw unsupported();
51
+ if (fs.globScanMaxDepth !== undefined && (!Number.isInteger(fs.globScanMaxDepth) || fs.globScanMaxDepth < 0))
52
+ throw unsupported();
53
+ const init = (target) => target.fileSystem ??= { read: null, write: null, ...(fs.globScanMaxDepth !== undefined ? { globScanMaxDepth: fs.globScanMaxDepth } : {}) };
54
+ for (const access of ["read", "write"]) {
55
+ if (fs[access] == null)
56
+ continue;
57
+ if (!Array.isArray(fs[access]) || !fs[access].every((path) => typeof path === "string"))
58
+ throw unsupported();
59
+ fs[access].forEach((path, index) => grants.push({ id: `${access}_${index}`, title: `${access === "read" ? "Read" : "Write"}: ${path}`, apply: target => { (init(target)[access] ??= []).push(path); } }));
60
+ }
61
+ if (fs.entries !== undefined) {
62
+ if (!Array.isArray(fs.entries))
63
+ throw unsupported();
64
+ fs.entries.forEach((entry, index) => {
65
+ if (!object(entry) || !only(entry, ["path", "access"]) || !["read", "write", "deny"].includes(entry.access) || !validPath(entry.path))
66
+ throw unsupported();
67
+ if (entry.access !== "deny")
68
+ grants.push({ id: `entry_${index}`, title: `${entry.access === "read" ? "Read" : "Write"}: ${JSON.stringify(entry.path)}`, apply: target => { (init(target).entries ??= []).push(entry); } });
69
+ });
70
+ if (grants.length > filesystemStart) {
71
+ // Overlapping read/write/deny entries form one native policy; do not infer precedence.
72
+ grants.splice(filesystemStart);
73
+ grants.push({ id: "filesystem", title: "Requested filesystem access with its native restrictions", apply: target => { target.fileSystem = structuredClone(fs); } });
74
+ }
75
+ }
76
+ }
77
+ if (!grants.length)
78
+ throw unsupported();
79
+ return {
80
+ request: { kind: "permission", harness: "codex", message: "Select the additional permissions to grant and their duration. An empty selection denies all requested grants.",
81
+ requestedSchema: { type: "object", properties: { grants: { type: "array", items: { type: "string", anyOf: grants.map(grant => ({ const: grant.id, title: grant.title })) }, uniqueItems: true }, scope: { type: "string", oneOf: [{ const: "turn", title: "This turn" }, { const: "session", title: "This session" }] } }, required: ["grants", "scope"] }, context: approvalContext(params, ["threadId", "turnId", "itemId", "environmentId", "cwd", "reason", "permissions"]) },
82
+ response: content => {
83
+ const permissions = {};
84
+ for (const id of content.grants)
85
+ grants.find(grant => grant.id === id).apply(permissions);
86
+ if (permissions.fileSystem && profile.network?.enabled === false)
87
+ permissions.network = { enabled: false };
88
+ return { permissions, scope: content.scope };
89
+ },
90
+ };
91
+ }
92
+ function validPath(path) {
93
+ if (!object(path))
94
+ return false;
95
+ if (path.type === "path")
96
+ return only(path, ["type", "path"]) && typeof path.path === "string";
97
+ if (path.type === "glob_pattern")
98
+ return only(path, ["type", "pattern"]) && typeof path.pattern === "string";
99
+ if (path.type !== "special" || !only(path, ["type", "value"]) || !object(path.value))
100
+ return false;
101
+ const value = path.value;
102
+ if (["root", "minimal", "tmpdir", "slash_tmp"].includes(value.kind))
103
+ return only(value, ["kind"]);
104
+ if (value.kind === "project_roots")
105
+ return only(value, ["kind", "subpath"]) && (value.subpath === null || typeof value.subpath === "string");
106
+ return value.kind === "unknown" && only(value, ["kind", "path", "subpath"]) && typeof value.path === "string" && (value.subpath === null || typeof value.subpath === "string");
107
+ }
108
+ function fileContext(item) {
109
+ return { ...approvalContext(item, ["id", "type", "status"]), ...(Array.isArray(item.changes) ? { changes: item.changes.map((change) => ({ ...approvalContext(change, ["path", "diff"]), ...(object(change.kind) ? { kind: approvalContext(change.kind, ["type", "move_path"]) } : {}) })) } : {}) };
110
+ }
111
+ //# sourceMappingURL=codex-approvals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-approvals.js","sourceRoot":"","sources":["../../src/adapters/codex-approvals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,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AAe,CAAC,MAAM,EAAC,CAAC,MAAM,EAAC,MAAM,CAAC,CAAC,EAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,CAAC,CAAA,EAAC,IAAI,EAAC,eAAe,CAAC,MAAM,CAAC,IAAI,EAAC,CAAC,MAAM,EAAC,WAAW,CAAC,CAAC,EAAC,CAAA,CAAC,CAAA,EAAE,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAC,CAAC;AAClR,CAAC","sourcesContent":["import { approvalContext } from \"./approval-context.js\";\nimport { AgentError } from \"../errors.js\";\nimport type { ApprovalContent, NativeApprovalRequest } from \"../approvals/types.js\";\n\nexport interface CodexApproval {\n request: NativeApprovalRequest;\n response(content: ApprovalContent): unknown;\n}\nconst titles: Record<string,string> = {accept:\"Allow once\",acceptForSession:\"Allow for this session\",decline:\"Deny\",cancel:\"Cancel the native operation\"};\nconst unsupported = () => new AgentError(\"INPUT_REQUIRED\", \"Codex requested permissions that cannot be represented safely.\");\nexport function codexApproval(method: string | undefined, params: any, item?: unknown): CodexApproval | undefined {\n if (method === \"item/permissions/requestApproval\") return permissionProfile(params);\n if (method !== \"item/commandExecution/requestApproval\" && method !== \"item/fileChange/requestApproval\") return undefined;\n if (method === \"item/commandExecution/requestApproval\" && params.kind !== undefined && ![\"command\",\"writeStdin\"].includes(params.kind)) throw unsupported();\n const decisions: unknown = params.availableDecisions ?? [\"accept\",\"acceptForSession\",\"decline\",\"cancel\"];\n if (!Array.isArray(decisions)) throw unsupported();\n const supported: string[] = [];\n for (const decision of decisions) {\n if (typeof decision === \"string\" && Object.hasOwn(titles,decision)) supported.push(decision);\n else if (!decision || typeof decision !== \"object\" || (!Object.hasOwn(decision,\"acceptWithExecpolicyAmendment\") && !Object.hasOwn(decision,\"applyNetworkPolicyAmendment\"))) throw unsupported();\n }\n if (!supported.length || new Set(supported).size !== supported.length) throw unsupported();\n const message = method === \"item/fileChange/requestApproval\" ? \"Allow the requested file change?\"\n : params.kind === \"writeStdin\" ? \"Allow sending input to the existing terminal?\" : \"Allow the requested command execution?\";\n return {\n request: {kind:\"permission\",harness:\"codex\",message,\n requestedSchema:{type:\"object\",properties:{decision:{type:\"string\",oneOf:supported.map(value=>({const:value,title:titles[value]!}))}},required:[\"decision\"]},\n context:{...approvalContext(params,[\"threadId\",\"turnId\",\"itemId\",\"approvalId\",\"kind\",\"environmentId\",\"reason\",\"command\",\"cwd\",\"commandActions\",\"networkApprovalContext\",\"additionalPermissions\",\"grantRoot\"]),...(item ? {item:fileContext(item)} : {})}},\n response: content => ({decision:content.decision}),\n };\n}\n\nfunction object(value: unknown): value is Record<string,any> { return typeof value === \"object\" && value !== null && !Array.isArray(value); }\nfunction only(value: Record<string,any>, keys: string[]): boolean {return Object.keys(value).every(key=>keys.includes(key));}\nfunction permissionProfile(params: any): CodexApproval {\n const profile = structuredClone(params.permissions);\n if (!object(profile) || !only(profile,[\"network\",\"fileSystem\"])) throw unsupported();\n const grants: {id:string;title:string;apply:(target:any)=>void}[]=[];\n if (profile.network != null) {\n if (!object(profile.network) || !only(profile.network,[\"enabled\"]) || ![true,false,null].includes(profile.network.enabled)) throw unsupported();\n if (profile.network.enabled === true) grants.push({id:\"network\",title:\"Enable network access\",apply:target=>{target.network={enabled:true};}});\n }\n const fs = profile.fileSystem;\n if (fs != null) {\n const filesystemStart = grants.length;\n if (!object(fs) || !only(fs,[\"read\",\"write\",\"entries\",\"globScanMaxDepth\"])) throw unsupported();\n if (fs.globScanMaxDepth !== undefined && (!Number.isInteger(fs.globScanMaxDepth) || fs.globScanMaxDepth < 0)) throw unsupported();\n const init = (target:any) => target.fileSystem ??= {read:null,write:null,...(fs.globScanMaxDepth !== undefined ? {globScanMaxDepth:fs.globScanMaxDepth} : {})};\n for (const access of [\"read\",\"write\"]) {\n if (fs[access] == null) continue;\n if (!Array.isArray(fs[access]) || !fs[access].every((path:unknown)=>typeof path === \"string\")) throw unsupported();\n fs[access].forEach((path:string,index:number)=>grants.push({id:`${access}_${index}`,title:`${access === \"read\" ? \"Read\" : \"Write\"}: ${path}`,apply:target=>{(init(target)[access] ??= []).push(path);}}));\n }\n if (fs.entries !== undefined) {\n if (!Array.isArray(fs.entries)) throw unsupported();\n fs.entries.forEach((entry:any,index:number)=>{\n if (!object(entry) || !only(entry,[\"path\",\"access\"]) || ![\"read\",\"write\",\"deny\"].includes(entry.access) || !validPath(entry.path)) throw unsupported();\n if (entry.access !== \"deny\") grants.push({id:`entry_${index}`,title:`${entry.access === \"read\" ? \"Read\" : \"Write\"}: ${JSON.stringify(entry.path)}`,apply:target=>{(init(target).entries ??= []).push(entry);}});\n });\n if (grants.length > filesystemStart) {\n // Overlapping read/write/deny entries form one native policy; do not infer precedence.\n grants.splice(filesystemStart);\n grants.push({id:\"filesystem\",title:\"Requested filesystem access with its native restrictions\",apply:target=>{target.fileSystem=structuredClone(fs);}});\n }\n }\n }\n if (!grants.length) throw unsupported();\n return {\n request:{kind:\"permission\",harness:\"codex\",message:\"Select the additional permissions to grant and their duration. An empty selection denies all requested grants.\",\n requestedSchema:{type:\"object\",properties:{grants:{type:\"array\",items:{type:\"string\",anyOf:grants.map(grant=>({const:grant.id,title:grant.title}))},uniqueItems:true},scope:{type:\"string\",oneOf:[{const:\"turn\",title:\"This turn\"},{const:\"session\",title:\"This session\"}]}},required:[\"grants\",\"scope\"]},context:approvalContext(params,[\"threadId\",\"turnId\",\"itemId\",\"environmentId\",\"cwd\",\"reason\",\"permissions\"])},\n response: content=>{\n const permissions: any={};\n for (const id of content.grants as string[]) grants.find(grant=>grant.id===id)!.apply(permissions);\n if (permissions.fileSystem && profile.network?.enabled === false) permissions.network={enabled:false};\n return {permissions,scope:content.scope};\n },\n };\n}\nfunction validPath(path: any): boolean {\n if (!object(path)) return false;\n if (path.type === \"path\") return only(path,[\"type\",\"path\"]) && typeof path.path === \"string\";\n if (path.type === \"glob_pattern\") return only(path,[\"type\",\"pattern\"]) && typeof path.pattern === \"string\";\n if (path.type !== \"special\" || !only(path,[\"type\",\"value\"]) || !object(path.value)) return false;\n const value=path.value;\n if ([\"root\",\"minimal\",\"tmpdir\",\"slash_tmp\"].includes(value.kind)) return only(value,[\"kind\"]);\n if (value.kind === \"project_roots\") return only(value,[\"kind\",\"subpath\"]) && (value.subpath === null || typeof value.subpath === \"string\");\n return value.kind === \"unknown\" && only(value,[\"kind\",\"path\",\"subpath\"]) && typeof value.path === \"string\" && (value.subpath === null || typeof value.subpath === \"string\");\n}\n\nfunction fileContext(item: any): Record<string, unknown> {\n return {...approvalContext(item,[\"id\",\"type\",\"status\"]),...(Array.isArray(item.changes) ? {changes:item.changes.map((change: any)=>({...approvalContext(change,[\"path\",\"diff\"]),...(object(change.kind)?{kind:approvalContext(change.kind,[\"type\",\"move_path\"])}:{})}))} : {})};\n}\n"]}