oh-my-copilot 5.6.2 → 5.8.0

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 (264) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +2 -0
  4. package/bridge/__pycache__/gyoshu_bridge.cpython-312.pyc +0 -0
  5. package/bridge/claude-md-coordinator.cjs +2 -2
  6. package/bridge/cli.cjs +81405 -76559
  7. package/bridge/mcp-server.cjs +40048 -32187
  8. package/bridge/runtime-cli.cjs +943 -199
  9. package/bridge/team-mcp.cjs +716 -125
  10. package/bridge/team.js +1066 -290
  11. package/dist/__tests__/cli-win32-warning.test.js +7 -0
  12. package/dist/__tests__/cli-win32-warning.test.js.map +1 -1
  13. package/dist/__tests__/run-cjs-copilot-worker-routing.test.d.ts +2 -0
  14. package/dist/__tests__/run-cjs-copilot-worker-routing.test.d.ts.map +1 -0
  15. package/dist/__tests__/run-cjs-copilot-worker-routing.test.js +294 -0
  16. package/dist/__tests__/run-cjs-copilot-worker-routing.test.js.map +1 -0
  17. package/dist/__tests__/run-cjs-fail-closed-timeout.test.d.ts +2 -0
  18. package/dist/__tests__/run-cjs-fail-closed-timeout.test.d.ts.map +1 -0
  19. package/dist/__tests__/run-cjs-fail-closed-timeout.test.js +68 -0
  20. package/dist/__tests__/run-cjs-fail-closed-timeout.test.js.map +1 -0
  21. package/dist/__tests__/run-cjs-session-end-budget.test.d.ts +2 -0
  22. package/dist/__tests__/run-cjs-session-end-budget.test.d.ts.map +1 -0
  23. package/dist/__tests__/run-cjs-session-end-budget.test.js +171 -0
  24. package/dist/__tests__/run-cjs-session-end-budget.test.js.map +1 -0
  25. package/dist/__tests__/session-end-process-exit.test.js +70 -2
  26. package/dist/__tests__/session-end-process-exit.test.js.map +1 -1
  27. package/dist/cli/__tests__/doctor-conflicts-json.test.d.ts +2 -0
  28. package/dist/cli/__tests__/doctor-conflicts-json.test.d.ts.map +1 -0
  29. package/dist/cli/__tests__/doctor-conflicts-json.test.js +46 -0
  30. package/dist/cli/__tests__/doctor-conflicts-json.test.js.map +1 -0
  31. package/dist/cli/__tests__/team.test.js +67 -0
  32. package/dist/cli/__tests__/team.test.js.map +1 -1
  33. package/dist/cli/__tests__/wait-teleport-json.test.d.ts +2 -0
  34. package/dist/cli/__tests__/wait-teleport-json.test.d.ts.map +1 -0
  35. package/dist/cli/__tests__/wait-teleport-json.test.js +64 -0
  36. package/dist/cli/__tests__/wait-teleport-json.test.js.map +1 -0
  37. package/dist/cli/commands/__tests__/smoke-tier2.test.d.ts +2 -0
  38. package/dist/cli/commands/__tests__/smoke-tier2.test.d.ts.map +1 -0
  39. package/dist/cli/commands/__tests__/smoke-tier2.test.js +110 -0
  40. package/dist/cli/commands/__tests__/smoke-tier2.test.js.map +1 -0
  41. package/dist/cli/commands/__tests__/team-status-json.test.d.ts +2 -0
  42. package/dist/cli/commands/__tests__/team-status-json.test.d.ts.map +1 -0
  43. package/dist/cli/commands/__tests__/team-status-json.test.js +141 -0
  44. package/dist/cli/commands/__tests__/team-status-json.test.js.map +1 -0
  45. package/dist/cli/commands/factory.d.ts +2 -0
  46. package/dist/cli/commands/factory.d.ts.map +1 -1
  47. package/dist/cli/commands/factory.js +8 -1
  48. package/dist/cli/commands/factory.js.map +1 -1
  49. package/dist/cli/commands/smoke.d.ts +36 -0
  50. package/dist/cli/commands/smoke.d.ts.map +1 -0
  51. package/dist/cli/commands/smoke.js +169 -0
  52. package/dist/cli/commands/smoke.js.map +1 -0
  53. package/dist/cli/commands/team.d.ts +2 -0
  54. package/dist/cli/commands/team.d.ts.map +1 -1
  55. package/dist/cli/commands/team.js +124 -10
  56. package/dist/cli/commands/team.js.map +1 -1
  57. package/dist/cli/index.d.ts.map +1 -1
  58. package/dist/cli/index.js +70 -10
  59. package/dist/cli/index.js.map +1 -1
  60. package/dist/cli/win32-warning.d.ts +7 -1
  61. package/dist/cli/win32-warning.d.ts.map +1 -1
  62. package/dist/cli/win32-warning.js +9 -1
  63. package/dist/cli/win32-warning.js.map +1 -1
  64. package/dist/constants/names.d.ts +1 -0
  65. package/dist/constants/names.d.ts.map +1 -1
  66. package/dist/constants/names.js +1 -0
  67. package/dist/constants/names.js.map +1 -1
  68. package/dist/factory/__tests__/check-run.test.js +2 -2
  69. package/dist/factory/__tests__/check-run.test.js.map +1 -1
  70. package/dist/factory/__tests__/listener.test.js +1 -1
  71. package/dist/factory/__tests__/listener.test.js.map +1 -1
  72. package/dist/factory/__tests__/status.test.js +42 -0
  73. package/dist/factory/__tests__/status.test.js.map +1 -1
  74. package/dist/factory/listener.d.ts.map +1 -1
  75. package/dist/factory/listener.js +7 -8
  76. package/dist/factory/listener.js.map +1 -1
  77. package/dist/factory/status.d.ts +19 -1
  78. package/dist/factory/status.d.ts.map +1 -1
  79. package/dist/factory/status.js +49 -8
  80. package/dist/factory/status.js.map +1 -1
  81. package/dist/factory/watchdog.d.ts.map +1 -1
  82. package/dist/factory/watchdog.js +14 -0
  83. package/dist/factory/watchdog.js.map +1 -1
  84. package/dist/factory/watchdog.test.js +45 -0
  85. package/dist/factory/watchdog.test.js.map +1 -1
  86. package/dist/hooks/session-end/__tests__/action-runner.test.js +5 -0
  87. package/dist/hooks/session-end/__tests__/action-runner.test.js.map +1 -1
  88. package/dist/hooks/session-end/__tests__/chain-enqueuer.test.js +186 -1
  89. package/dist/hooks/session-end/__tests__/chain-enqueuer.test.js.map +1 -1
  90. package/dist/hooks/session-end/__tests__/chain-link-env-passthrough.test.d.ts +2 -0
  91. package/dist/hooks/session-end/__tests__/chain-link-env-passthrough.test.d.ts.map +1 -0
  92. package/dist/hooks/session-end/__tests__/chain-link-env-passthrough.test.js +49 -0
  93. package/dist/hooks/session-end/__tests__/chain-link-env-passthrough.test.js.map +1 -0
  94. package/dist/hooks/session-end/__tests__/foreground-bootstrap.test.js +30 -1
  95. package/dist/hooks/session-end/__tests__/foreground-bootstrap.test.js.map +1 -1
  96. package/dist/hooks/session-end/__tests__/spawn-next.test.js +104 -3
  97. package/dist/hooks/session-end/__tests__/spawn-next.test.js.map +1 -1
  98. package/dist/hooks/session-end/__tests__/worker.test.js +6 -0
  99. package/dist/hooks/session-end/__tests__/worker.test.js.map +1 -1
  100. package/dist/hooks/session-end/action-runner.d.ts.map +1 -1
  101. package/dist/hooks/session-end/action-runner.js +2 -1
  102. package/dist/hooks/session-end/action-runner.js.map +1 -1
  103. package/dist/hooks/session-end/chain-enqueuer.d.ts +70 -7
  104. package/dist/hooks/session-end/chain-enqueuer.d.ts.map +1 -1
  105. package/dist/hooks/session-end/chain-enqueuer.js +354 -82
  106. package/dist/hooks/session-end/chain-enqueuer.js.map +1 -1
  107. package/dist/hooks/session-end/foreground-bootstrap.d.ts.map +1 -1
  108. package/dist/hooks/session-end/foreground-bootstrap.js +24 -16
  109. package/dist/hooks/session-end/foreground-bootstrap.js.map +1 -1
  110. package/dist/hooks/session-end/index.d.ts +2 -3
  111. package/dist/hooks/session-end/index.d.ts.map +1 -1
  112. package/dist/hooks/session-end/index.js +11 -13
  113. package/dist/hooks/session-end/index.js.map +1 -1
  114. package/dist/hooks/session-end/spawn-next.d.ts +81 -4
  115. package/dist/hooks/session-end/spawn-next.d.ts.map +1 -1
  116. package/dist/hooks/session-end/spawn-next.js +141 -14
  117. package/dist/hooks/session-end/spawn-next.js.map +1 -1
  118. package/dist/hooks/session-end/wiki-foreground-bootstrap.d.ts +17 -0
  119. package/dist/hooks/session-end/wiki-foreground-bootstrap.d.ts.map +1 -0
  120. package/dist/hooks/session-end/wiki-foreground-bootstrap.js +20 -0
  121. package/dist/hooks/session-end/wiki-foreground-bootstrap.js.map +1 -0
  122. package/dist/hooks/session-end/worker.d.ts.map +1 -1
  123. package/dist/hooks/session-end/worker.js +11 -6
  124. package/dist/hooks/session-end/worker.js.map +1 -1
  125. package/dist/lib/__tests__/atomic-write.test.js +32 -1
  126. package/dist/lib/__tests__/atomic-write.test.js.map +1 -1
  127. package/dist/lib/__tests__/mode-state-lock.test.js +121 -12
  128. package/dist/lib/__tests__/mode-state-lock.test.js.map +1 -1
  129. package/dist/lib/atomic-write.d.ts +13 -3
  130. package/dist/lib/atomic-write.d.ts.map +1 -1
  131. package/dist/lib/atomic-write.js +29 -15
  132. package/dist/lib/atomic-write.js.map +1 -1
  133. package/dist/lib/mode-state-io.d.ts +2 -2
  134. package/dist/lib/mode-state-io.d.ts.map +1 -1
  135. package/dist/lib/mode-state-io.js +16 -10
  136. package/dist/lib/mode-state-io.js.map +1 -1
  137. package/dist/mcp/__tests__/host-smoke-tool.test.d.ts +2 -0
  138. package/dist/mcp/__tests__/host-smoke-tool.test.d.ts.map +1 -0
  139. package/dist/mcp/__tests__/host-smoke-tool.test.js +174 -0
  140. package/dist/mcp/__tests__/host-smoke-tool.test.js.map +1 -0
  141. package/dist/mcp/disable-tools.d.ts.map +1 -1
  142. package/dist/mcp/disable-tools.js +1 -0
  143. package/dist/mcp/disable-tools.js.map +1 -1
  144. package/dist/mcp/tool-registry.d.ts.map +1 -1
  145. package/dist/mcp/tool-registry.js +2 -0
  146. package/dist/mcp/tool-registry.js.map +1 -1
  147. package/dist/shared/types.d.ts +11 -0
  148. package/dist/shared/types.d.ts.map +1 -1
  149. package/dist/smoke/__tests__/copilot-chain-scenario.test.d.ts +2 -0
  150. package/dist/smoke/__tests__/copilot-chain-scenario.test.d.ts.map +1 -0
  151. package/dist/smoke/__tests__/copilot-chain-scenario.test.js +154 -0
  152. package/dist/smoke/__tests__/copilot-chain-scenario.test.js.map +1 -0
  153. package/dist/smoke/__tests__/copilot-sdk-driver.test.d.ts +2 -0
  154. package/dist/smoke/__tests__/copilot-sdk-driver.test.d.ts.map +1 -0
  155. package/dist/smoke/__tests__/copilot-sdk-driver.test.js +591 -0
  156. package/dist/smoke/__tests__/copilot-sdk-driver.test.js.map +1 -0
  157. package/dist/smoke/__tests__/copilot-sdk-scenarios.test.d.ts +2 -0
  158. package/dist/smoke/__tests__/copilot-sdk-scenarios.test.d.ts.map +1 -0
  159. package/dist/smoke/__tests__/copilot-sdk-scenarios.test.js +362 -0
  160. package/dist/smoke/__tests__/copilot-sdk-scenarios.test.js.map +1 -0
  161. package/dist/smoke/__tests__/copilot-session-eval.test.d.ts +2 -0
  162. package/dist/smoke/__tests__/copilot-session-eval.test.d.ts.map +1 -0
  163. package/dist/smoke/__tests__/copilot-session-eval.test.js +264 -0
  164. package/dist/smoke/__tests__/copilot-session-eval.test.js.map +1 -0
  165. package/dist/smoke/__tests__/copilot-smoke.test.d.ts +2 -0
  166. package/dist/smoke/__tests__/copilot-smoke.test.d.ts.map +1 -0
  167. package/dist/smoke/__tests__/copilot-smoke.test.js +482 -0
  168. package/dist/smoke/__tests__/copilot-smoke.test.js.map +1 -0
  169. package/dist/smoke/copilot-binary.d.ts +21 -0
  170. package/dist/smoke/copilot-binary.d.ts.map +1 -0
  171. package/dist/smoke/copilot-binary.js +46 -0
  172. package/dist/smoke/copilot-binary.js.map +1 -0
  173. package/dist/smoke/copilot-chain-scenario.d.ts +61 -0
  174. package/dist/smoke/copilot-chain-scenario.d.ts.map +1 -0
  175. package/dist/smoke/copilot-chain-scenario.js +253 -0
  176. package/dist/smoke/copilot-chain-scenario.js.map +1 -0
  177. package/dist/smoke/copilot-sdk-driver.d.ts +189 -0
  178. package/dist/smoke/copilot-sdk-driver.d.ts.map +1 -0
  179. package/dist/smoke/copilot-sdk-driver.js +637 -0
  180. package/dist/smoke/copilot-sdk-driver.js.map +1 -0
  181. package/dist/smoke/copilot-sdk-scenarios.d.ts +200 -0
  182. package/dist/smoke/copilot-sdk-scenarios.d.ts.map +1 -0
  183. package/dist/smoke/copilot-sdk-scenarios.js +620 -0
  184. package/dist/smoke/copilot-sdk-scenarios.js.map +1 -0
  185. package/dist/smoke/copilot-session-env.d.ts +75 -0
  186. package/dist/smoke/copilot-session-env.d.ts.map +1 -0
  187. package/dist/smoke/copilot-session-env.js +154 -0
  188. package/dist/smoke/copilot-session-env.js.map +1 -0
  189. package/dist/smoke/copilot-session-eval.d.ts +90 -0
  190. package/dist/smoke/copilot-session-eval.d.ts.map +1 -0
  191. package/dist/smoke/copilot-session-eval.js +323 -0
  192. package/dist/smoke/copilot-session-eval.js.map +1 -0
  193. package/dist/smoke/copilot-smoke.d.ts +166 -0
  194. package/dist/smoke/copilot-smoke.d.ts.map +1 -0
  195. package/dist/smoke/copilot-smoke.js +688 -0
  196. package/dist/smoke/copilot-smoke.js.map +1 -0
  197. package/dist/smoke/process-utils.d.ts +47 -0
  198. package/dist/smoke/process-utils.d.ts.map +1 -0
  199. package/dist/smoke/process-utils.js +99 -0
  200. package/dist/smoke/process-utils.js.map +1 -0
  201. package/dist/team/__tests__/runtime-v2.monitor.test.js +35 -0
  202. package/dist/team/__tests__/runtime-v2.monitor.test.js.map +1 -1
  203. package/dist/team/__tests__/scaling.test.js +13 -0
  204. package/dist/team/__tests__/scaling.test.js.map +1 -1
  205. package/dist/team/__tests__/sdk-transport.runtime.test.d.ts +2 -0
  206. package/dist/team/__tests__/sdk-transport.runtime.test.d.ts.map +1 -0
  207. package/dist/team/__tests__/sdk-transport.runtime.test.js +96 -0
  208. package/dist/team/__tests__/sdk-transport.runtime.test.js.map +1 -0
  209. package/dist/team/__tests__/sdk-transport.test.d.ts +2 -0
  210. package/dist/team/__tests__/sdk-transport.test.d.ts.map +1 -0
  211. package/dist/team/__tests__/sdk-transport.test.js +650 -0
  212. package/dist/team/__tests__/sdk-transport.test.js.map +1 -0
  213. package/dist/team/__tests__/tmux-session.pane-env.test.d.ts +2 -0
  214. package/dist/team/__tests__/tmux-session.pane-env.test.d.ts.map +1 -0
  215. package/dist/team/__tests__/tmux-session.pane-env.test.js +52 -0
  216. package/dist/team/__tests__/tmux-session.pane-env.test.js.map +1 -0
  217. package/dist/team/api-interop.d.ts.map +1 -1
  218. package/dist/team/api-interop.js +8 -0
  219. package/dist/team/api-interop.js.map +1 -1
  220. package/dist/team/runtime-v2.d.ts +33 -0
  221. package/dist/team/runtime-v2.d.ts.map +1 -1
  222. package/dist/team/runtime-v2.js +338 -24
  223. package/dist/team/runtime-v2.js.map +1 -1
  224. package/dist/team/scaling.d.ts.map +1 -1
  225. package/dist/team/scaling.js +5 -0
  226. package/dist/team/scaling.js.map +1 -1
  227. package/dist/team/sdk-host.d.ts +48 -0
  228. package/dist/team/sdk-host.d.ts.map +1 -0
  229. package/dist/team/sdk-host.js +604 -0
  230. package/dist/team/sdk-host.js.map +1 -0
  231. package/dist/team/sdk-policy.d.ts +79 -0
  232. package/dist/team/sdk-policy.d.ts.map +1 -0
  233. package/dist/team/sdk-policy.js +186 -0
  234. package/dist/team/sdk-policy.js.map +1 -0
  235. package/dist/team/sdk-transport.d.ts +164 -0
  236. package/dist/team/sdk-transport.d.ts.map +1 -0
  237. package/dist/team/sdk-transport.js +266 -0
  238. package/dist/team/sdk-transport.js.map +1 -0
  239. package/dist/team/tmux-session.d.ts +7 -0
  240. package/dist/team/tmux-session.d.ts.map +1 -1
  241. package/dist/team/tmux-session.js +80 -18
  242. package/dist/team/tmux-session.js.map +1 -1
  243. package/dist/team/types.d.ts +2 -0
  244. package/dist/team/types.d.ts.map +1 -1
  245. package/dist/team/types.js.map +1 -1
  246. package/dist/tools/host-smoke-tool.d.ts +34 -0
  247. package/dist/tools/host-smoke-tool.d.ts.map +1 -0
  248. package/dist/tools/host-smoke-tool.js +133 -0
  249. package/dist/tools/host-smoke-tool.js.map +1 -0
  250. package/docs/CLAUDE.md +1 -1
  251. package/docs/DEVELOPERS.md +122 -0
  252. package/docs/HOOKS.md +34 -2
  253. package/docs/MIGRATION.md +194 -3
  254. package/docs/REFERENCE.md +95 -1
  255. package/docs/TOOLS.md +32 -1
  256. package/package.json +11 -2
  257. package/plugin.json +1 -1
  258. package/scripts/dev/repro-state-lock.mjs +1 -1
  259. package/scripts/lib/atomic-write.mjs +4 -2
  260. package/scripts/lib/state-lock.mjs +21 -12
  261. package/scripts/run.cjs +141 -18
  262. package/scripts/session-start.mjs +13 -0
  263. package/scripts/wiki-session-end.mjs +2 -1
  264. package/templates/hooks/lib/atomic-write.mjs +4 -2
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Permission and tool policy for headless SDK team workers (`--transport sdk`).
3
+ *
4
+ * Pane workers run with `--allow-all-*`. An SDK worker gets no allow-all: its
5
+ * host answers every `onPermissionRequest` with {@link decideSdkPermission},
6
+ * and removes tools up front with {@link buildSdkExcludedTools}.
7
+ */
8
+ /** The subset of the SDK PermissionRequest the policy reads (SDK 1.0.16). */
9
+ export interface SdkPermissionRequest {
10
+ kind?: string;
11
+ fullCommandText?: string;
12
+ path?: unknown;
13
+ fileName?: unknown;
14
+ resolvedPath?: unknown;
15
+ serverName?: unknown;
16
+ toolName?: unknown;
17
+ url?: unknown;
18
+ [key: string]: unknown;
19
+ }
20
+ export interface SdkPolicyContext {
21
+ /** The worker's working directory (its worktree, or the leader cwd without worktrees). */
22
+ cwd: string;
23
+ /** The leader's team state root: inbox, status, heartbeat, shutdown ack, verdicts. */
24
+ stateRoot: string;
25
+ /** The oh-my-copilot plugin root (skills, agents, hook scripts are read from here). */
26
+ pluginRoot: string;
27
+ /** Extra read-only roots (the per-worker COPILOT_HOME). */
28
+ readRoots?: string[];
29
+ /** The plugin MCP server name (`t`). */
30
+ mcpServer: string;
31
+ /** `permissions.workerDenyTools`. */
32
+ denyTools?: string[];
33
+ /** `permissions.workerDenyUrls`. */
34
+ denyUrls?: string[];
35
+ platform?: NodeJS.Platform;
36
+ }
37
+ export interface SdkPermissionDecision {
38
+ approve: boolean;
39
+ reason: string;
40
+ }
41
+ /**
42
+ * Shell commands a worker must never run, whatever the config says:
43
+ * - team control other than `team api` (nested teams, shutdown of its own team);
44
+ * - `omg smoke` (would spend credits from inside a worker);
45
+ * - the multiplexers (the pane transport's control plane);
46
+ * - `git push` (workers commit in their worktree; the leader integrates).
47
+ *
48
+ * This is a denylist over the command text, not a sandbox: it stops the
49
+ * direct and quoted spellings a model actually writes, but a worker that
50
+ * builds the command indirectly (an alias, a script file, `Invoke-Expression`,
51
+ * an encoded command) is not stopped by it. The real boundaries are the
52
+ * write-path check, the credit cap and the per-worker COPILOT_HOME.
53
+ * Patterns run on {@link normalizeShellCommand}'s output.
54
+ */
55
+ export declare const SDK_SHELL_DENY_PATTERNS: ReadonlyArray<{
56
+ re: RegExp;
57
+ reason: string;
58
+ }>;
59
+ /** Strip quotes around single tokens (`"omg" 'team'` -> `omg team`) so quoting cannot dodge a pattern. */
60
+ export declare function normalizeShellCommand(command: string): string;
61
+ /** True when `p` is `root` or lies below it (realpath, case-folded on win32). */
62
+ export declare function isUnderRoot(p: string, root: string, platform?: NodeJS.Platform): boolean;
63
+ /** `shell(<prefix>)` entries of `workerDenyTools`, as command prefixes. */
64
+ export declare function shellDenyPrefixes(denyTools?: readonly string[]): string[];
65
+ export declare function decideSdkPermission(req: SdkPermissionRequest, ctx: SdkPolicyContext): SdkPermissionDecision;
66
+ /**
67
+ * Built-in tools that start or drive other agents. A worker is one agent on
68
+ * one credit cap; these would fan out work (and spend) outside the team's
69
+ * task and claim protocol.
70
+ */
71
+ export declare const SDK_AGENT_FANOUT_TOOLS: readonly string[];
72
+ /**
73
+ * `excludedTools` for an SDK worker session: the recursion fence (the
74
+ * `<server>-host_smoke` tool and {@link SDK_AGENT_FANOUT_TOOLS}) plus each bare
75
+ * `workerDenyTools` name; `<server>(<tool>)` becomes `<server>-<tool>`, the
76
+ * SDK's MCP tool name. `shell(<prefix>)` entries stay with the handler.
77
+ */
78
+ export declare function buildSdkExcludedTools(mcpServer: string, denyTools?: readonly string[]): string[];
79
+ //# sourceMappingURL=sdk-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-policy.d.ts","sourceRoot":"","sources":["../../src/team/sdk-policy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,6EAA6E;AAC7E,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACz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EAAO,GAAG,MAAM,EAAE,CAO7E;AAcD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,EAAE,gBAAgB,GAAG,qBAAqB,CA8C3G;AAQD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAQnD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,EAAE,CAcpG"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Permission and tool policy for headless SDK team workers (`--transport sdk`).
3
+ *
4
+ * Pane workers run with `--allow-all-*`. An SDK worker gets no allow-all: its
5
+ * host answers every `onPermissionRequest` with {@link decideSdkPermission},
6
+ * and removes tools up front with {@link buildSdkExcludedTools}.
7
+ */
8
+ import { realpathSync } from 'node:fs';
9
+ import { isAbsolute, resolve } from 'node:path';
10
+ /**
11
+ * Shell commands a worker must never run, whatever the config says:
12
+ * - team control other than `team api` (nested teams, shutdown of its own team);
13
+ * - `omg smoke` (would spend credits from inside a worker);
14
+ * - the multiplexers (the pane transport's control plane);
15
+ * - `git push` (workers commit in their worktree; the leader integrates).
16
+ *
17
+ * This is a denylist over the command text, not a sandbox: it stops the
18
+ * direct and quoted spellings a model actually writes, but a worker that
19
+ * builds the command indirectly (an alias, a script file, `Invoke-Expression`,
20
+ * an encoded command) is not stopped by it. The real boundaries are the
21
+ * write-path check, the credit cap and the per-worker COPILOT_HOME.
22
+ * Patterns run on {@link normalizeShellCommand}'s output.
23
+ */
24
+ export const SDK_SHELL_DENY_PATTERNS = [
25
+ // `\s+(?!\s|api\b)`: doubled whitespace must not let `team api` backtrack into a deny.
26
+ { re: /\b(?:omg|omc|oh-my-copilot|oh-my-claudecode)(?:\.cmd|\.ps1)?\s+team\s+(?!\s|api\b)/i, reason: 'team control outside `team api`' },
27
+ { re: /\bcli\.cjs["']?\s+team\s+(?!\s|api\b)/i, reason: 'team control outside `team api`' },
28
+ { re: /\b(?:omg|omc|oh-my-copilot)(?:\.cmd|\.ps1)?\s+smoke\b/i, reason: '`omg smoke` from a worker' },
29
+ { re: /(?:^|[\s;&|("'])(?:tmux|psmux)(?:\.exe)?\b/i, reason: 'multiplexer control' },
30
+ // `push` as git's subcommand: only global options (`-C <dir>`, `-c <k=v>`, `--flag[=v]`) may sit between.
31
+ { re: /(?:^|[\s;&|("'/\\])git(?:\.exe)?(?:\s+(?:-C\s+\S+|-c\s+\S+|--?[A-Za-z][\w-]*(?:=\S+)?))*\s+push\b/i, reason: '`git push` from a worker' },
32
+ // `$g="git"; & $g push` / `g=git; $g push`: git named, then pushed through a variable.
33
+ { re: /\bgit\b[\s\S]*\$\{?\w+\}?\s+push\b/i, reason: '`git push` from a worker' },
34
+ ];
35
+ /** Strip quotes around single tokens (`"omg" 'team'` -> `omg team`) so quoting cannot dodge a pattern. */
36
+ export function normalizeShellCommand(command) {
37
+ return command.replace(/(["'])([^"'\s]+)\1/g, '$2');
38
+ }
39
+ function canon(p, platform) {
40
+ let out = resolve(p);
41
+ try {
42
+ out = realpathSync.native(out);
43
+ }
44
+ catch { /* missing: keep the resolved form */ }
45
+ out = out.replace(/\\/g, '/').replace(/\/+$/, '');
46
+ return platform === 'win32' ? out.toLowerCase() : out;
47
+ }
48
+ /** True when `p` is `root` or lies below it (realpath, case-folded on win32). */
49
+ export function isUnderRoot(p, root, platform = process.platform) {
50
+ if (!p || !root)
51
+ return false;
52
+ const child = canon(p, platform);
53
+ const parent = canon(root, platform);
54
+ return child === parent || child.startsWith(`${parent}/`);
55
+ }
56
+ function requestPath(req, cwd) {
57
+ for (const key of ['resolvedPath', 'path', 'fileName']) {
58
+ const value = req[key];
59
+ if (typeof value === 'string' && value.trim()) {
60
+ return isAbsolute(value) ? value : resolve(cwd, value);
61
+ }
62
+ }
63
+ return null;
64
+ }
65
+ /** `shell(<prefix>)` entries of `workerDenyTools`, as command prefixes. */
66
+ export function shellDenyPrefixes(denyTools = []) {
67
+ const out = [];
68
+ for (const raw of denyTools) {
69
+ const m = /^shell\((.+)\)$/i.exec(raw.trim());
70
+ if (m && m[1].trim())
71
+ out.push(m[1].trim().replace(/:\*$/, ''));
72
+ }
73
+ return out;
74
+ }
75
+ function matchesDenyUrl(url, patterns) {
76
+ const lower = url.toLowerCase();
77
+ let host = '';
78
+ try {
79
+ host = new URL(url).hostname.toLowerCase();
80
+ }
81
+ catch { /* not a URL: substring match only */ }
82
+ return patterns.some((p) => {
83
+ const pattern = p.trim().toLowerCase();
84
+ if (!pattern)
85
+ return false;
86
+ if (host && (host === pattern || host.endsWith(`.${pattern}`)))
87
+ return true;
88
+ return lower.includes(pattern);
89
+ });
90
+ }
91
+ export function decideSdkPermission(req, ctx) {
92
+ const platform = ctx.platform ?? process.platform;
93
+ switch (req.kind) {
94
+ case 'read': {
95
+ const path = requestPath(req, ctx.cwd);
96
+ if (!path)
97
+ return { approve: true, reason: 'read without a path' };
98
+ const roots = [ctx.cwd, ctx.stateRoot, ctx.pluginRoot, ...(ctx.readRoots ?? [])];
99
+ return roots.some((root) => isUnderRoot(path, root, platform))
100
+ ? { approve: true, reason: 'read inside worker roots' }
101
+ : { approve: false, reason: `read outside worker roots: ${path}` };
102
+ }
103
+ case 'write': {
104
+ const path = requestPath(req, ctx.cwd);
105
+ if (!path)
106
+ return { approve: false, reason: 'write without a path' };
107
+ return isUnderRoot(path, ctx.cwd, platform) || isUnderRoot(path, ctx.stateRoot, platform)
108
+ ? { approve: true, reason: 'write inside worktree or team state' }
109
+ : { approve: false, reason: `write outside worktree and team state: ${path}` };
110
+ }
111
+ case 'shell': {
112
+ const command = String(req.fullCommandText ?? '');
113
+ if (!command.trim())
114
+ return { approve: false, reason: 'shell without command text' };
115
+ const normalized = normalizeShellCommand(command);
116
+ for (const { re, reason } of SDK_SHELL_DENY_PATTERNS) {
117
+ if (re.test(normalized))
118
+ return { approve: false, reason };
119
+ }
120
+ const spellings = [command.trim(), normalized.trim()];
121
+ for (const prefix of shellDenyPrefixes(ctx.denyTools)) {
122
+ if (spellings.some((s) => s === prefix || s.startsWith(`${prefix} `))) {
123
+ return { approve: false, reason: `permissions.workerDenyTools shell(${prefix})` };
124
+ }
125
+ }
126
+ return { approve: true, reason: 'shell' };
127
+ }
128
+ case 'url': {
129
+ const url = String(req.url ?? '');
130
+ return matchesDenyUrl(url, ctx.denyUrls ?? [])
131
+ ? { approve: false, reason: `permissions.workerDenyUrls: ${url}` }
132
+ : { approve: true, reason: 'url' };
133
+ }
134
+ case 'mcp':
135
+ return req.serverName === ctx.mcpServer
136
+ ? { approve: true, reason: `mcp server ${ctx.mcpServer}` }
137
+ : { approve: false, reason: `mcp server ${String(req.serverName)} is not the plugin server` };
138
+ default:
139
+ return { approve: false, reason: `permission kind ${String(req.kind)} is not granted to sdk workers` };
140
+ }
141
+ }
142
+ /** Built-in tool names a bare `workerDenyTools` kind expands to. */
143
+ const KIND_TOOLS = {
144
+ shell: ['shell', 'powershell', 'bash'],
145
+ write: ['create', 'edit'],
146
+ };
147
+ /**
148
+ * Built-in tools that start or drive other agents. A worker is one agent on
149
+ * one credit cap; these would fan out work (and spend) outside the team's
150
+ * task and claim protocol.
151
+ */
152
+ export const SDK_AGENT_FANOUT_TOOLS = [
153
+ 'task',
154
+ 'run_dynamic_workflow',
155
+ 'dynamic_workflows_manage',
156
+ 'write_agent',
157
+ 'read_agent',
158
+ 'list_agents',
159
+ 'search_code_subagent',
160
+ ];
161
+ /**
162
+ * `excludedTools` for an SDK worker session: the recursion fence (the
163
+ * `<server>-host_smoke` tool and {@link SDK_AGENT_FANOUT_TOOLS}) plus each bare
164
+ * `workerDenyTools` name; `<server>(<tool>)` becomes `<server>-<tool>`, the
165
+ * SDK's MCP tool name. `shell(<prefix>)` entries stay with the handler.
166
+ */
167
+ export function buildSdkExcludedTools(mcpServer, denyTools = []) {
168
+ const out = new Set([`${mcpServer}-host_smoke`, ...SDK_AGENT_FANOUT_TOOLS]);
169
+ for (const raw of denyTools) {
170
+ const entry = raw.trim();
171
+ if (!entry)
172
+ continue;
173
+ const call = /^([A-Za-z0-9_.-]+)\(([^)]*)\)$/.exec(entry);
174
+ if (call) {
175
+ if (call[1].toLowerCase() === 'shell' || call[1].toLowerCase() === 'write')
176
+ continue;
177
+ if (call[2])
178
+ out.add(`${call[1]}-${call[2]}`);
179
+ continue;
180
+ }
181
+ for (const name of KIND_TOOLS[entry.toLowerCase()] ?? [entry])
182
+ out.add(name);
183
+ }
184
+ return [...out];
185
+ }
186
+ //# sourceMappingURL=sdk-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-policy.js","sourceRoot":"","sources":["../../src/team/sdk-policy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsChD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAkD;IACpF,wFAAwF;IACxF,EAAE,EAAE,EAAE,qFAAqF,EAAE,MAAM,EAAE,iCAAiC,EAAE;IACxI,EAAE,EAAE,EAAE,wCAAwC,EAAE,MAAM,EAAE,iCAAiC,EAAE;IAC3F,EAAE,EAAE,EAAE,wDAAwD,EAAE,MAAM,EAAE,2BAA2B,EAAE;IACrG,EAAE,EAAE,EAAE,6CAA6C,EAAE,MAAM,EAAE,qBAAqB,EAAE;IACpF,0GAA0G;IAC1G,EAAE,EAAE,EAAE,oGAAoG,EAAE,MAAM,EAAE,0BAA0B,EAAE;IAChJ,uFAAuF;IACvF,EAAE,EAAE,EAAE,qCAAqC,EAAE,MAAM,EAAE,0BAA0B,EAAE;CAClF,CAAC;AAEF,0GAA0G;AAC1G,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,OAAO,OAAO,CAAC,OAAO,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,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AC;IACpF,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK;YAAE,SAAS;QACrB,MAAM,IAAI,GAAG,gCAAgC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1D,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,IAAI,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,KAAK,OAAO,IAAI,IAAI,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,KAAK,OAAO;gBAAE,SAAS;YACvF,IAAI,IAAI,CAAC,CAAC,CAAC;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9C,SAAS;QACX,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Leader side of the headless SDK team transport (`omg team --transport sdk`).
3
+ *
4
+ * Pane workers are processes a multiplexer owns; SDK workers are sessions a
5
+ * detached `omg team sdk-host` process owns (sdk-host.ts). This module holds
6
+ * what the leader, the monitor, mailbox delivery and shutdown need:
7
+ * - the per-worker file layout under the team state root;
8
+ * - the doorbell (`sdk-doorbell.jsonl`), the only way to reach a session;
9
+ * - the session file (`sdk-session.json`), read instead of a pane capture;
10
+ * - host launch (launch attempt + detached spawn + ack/started handshake)
11
+ * and host stop (doorbell stop, then a bounded wait, then a tree kill).
12
+ *
13
+ * The team target is `sdk:<team>` and each worker's `pane_id` is `sdk:<worker>`:
14
+ * neither names a multiplexer resource, so pane code paths must skip them
15
+ * ({@link isSdkTarget}).
16
+ */
17
+ import { type WorkerLaunchAttempt } from './worker-launch-ack.js';
18
+ export declare const SDK_TARGET_PREFIX = "sdk:";
19
+ /** True for the sdk team target (`sdk:<team>`) and sdk worker ids (`sdk:<worker>`). */
20
+ export declare function isSdkTarget(value: string | null | undefined): boolean;
21
+ export declare function sdkTeamTarget(teamName: string): string;
22
+ export declare function sdkPaneId(workerName: string): string;
23
+ export declare function sdkWorkerFiles(stateRoot: string, workerName: string): {
24
+ dir: string;
25
+ spec: string;
26
+ doorbell: string;
27
+ session: string;
28
+ probe: string;
29
+ events: string;
30
+ log: string;
31
+ home: string;
32
+ bin: string;
33
+ shutdownAck: string;
34
+ };
35
+ export interface SdkHostSpec {
36
+ schema_version: 1;
37
+ leader_cwd: string;
38
+ team_name: string;
39
+ worker_name: string;
40
+ instance_id: string;
41
+ attempt_id: string;
42
+ pane_id: string;
43
+ runtime_cli_path: string;
44
+ worker_cwd: string;
45
+ state_root: string;
46
+ plugin_root: string;
47
+ /** The installed Copilot exe (or its npm package .js), never a .cmd shim. */
48
+ copilot_bin: string;
49
+ model?: string;
50
+ max_credits: number;
51
+ worker_env: Record<string, string>;
52
+ deny_tools: string[];
53
+ deny_urls: string[];
54
+ mcp_server: string;
55
+ /** The leader's `bridge/cli.cjs`; the worker's `omg` shim runs it. */
56
+ omg_cli_path: string;
57
+ node_path: string;
58
+ /** Copilot config dir whose login identity the per-worker home copies. */
59
+ user_config_dir: string;
60
+ }
61
+ export interface SdkDoorbellEntry {
62
+ id: string;
63
+ /** `probe`: zero-model introspection (tools offered, MCP servers) written to `sdk-probe.json`. */
64
+ kind: 'prompt' | 'abort' | 'stop' | 'shutdown' | 'probe';
65
+ text?: string;
66
+ at: string;
67
+ from?: string;
68
+ }
69
+ export type SdkSessionState = 'starting' | 'idle' | 'busy' | 'capped' | 'closing' | 'closed' | 'failed';
70
+ export interface SdkSessionFile {
71
+ schema_version: 1;
72
+ team_name: string;
73
+ worker_name: string;
74
+ attempt_id: string;
75
+ host_pid: number;
76
+ runtime_pid: number | null;
77
+ /** Strict start identity of `runtime_pid`; absent in files written before it existed. */
78
+ runtime_start_identity?: string | null;
79
+ session_id: string | null;
80
+ model: string | null;
81
+ state: SdkSessionState;
82
+ turns: number;
83
+ queued: number;
84
+ /** Doorbell ids sent to the session, in order. */
85
+ delivered: string[];
86
+ last_event_type: string | null;
87
+ last_event_at: string | null;
88
+ updated_at: string;
89
+ usage: {
90
+ credits: number;
91
+ premium_requests: number;
92
+ shutdown_premium_requests: number | null;
93
+ shutdown_credits: number | null;
94
+ };
95
+ hooks: {
96
+ session_end_runs: number;
97
+ failed: number;
98
+ };
99
+ aborts: number;
100
+ permissions: Array<{
101
+ at: string;
102
+ kind: string;
103
+ approve: boolean;
104
+ reason: string;
105
+ detail: string;
106
+ }>;
107
+ last_error: string | null;
108
+ timeline: Partial<Record<'host_started_at' | 'ack_at' | 'accepted_at' | 'client_started_at' | 'session_created_at' | 'first_send_at' | 'first_message_at' | 'closed_at', string>>;
109
+ }
110
+ /** Append one doorbell entry; returns its id. Appends are line-sized and atomic enough for one writer per call. */
111
+ export declare function ringDoorbell(stateRoot: string, workerName: string, entry: Omit<SdkDoorbellEntry, 'id' | 'at'> & {
112
+ id?: string;
113
+ }): string;
114
+ export declare function readSdkSession(stateRoot: string, workerName: string): SdkSessionFile | null;
115
+ export interface SdkLaunchInput {
116
+ leaderCwd: string;
117
+ teamName: string;
118
+ workerName: string;
119
+ instanceId: string;
120
+ workerCwd: string;
121
+ stateRoot: string;
122
+ workerEnv: Record<string, string>;
123
+ copilotBin: string;
124
+ pluginRoot: string;
125
+ userConfigDir: string;
126
+ model?: string;
127
+ maxCredits: number;
128
+ denyTools: string[];
129
+ denyUrls: string[];
130
+ mcpServer?: string;
131
+ /** Test seam for the detached spawn. */
132
+ spawnHost?: (cliPath: string, specPath: string, logPath: string, cwd: string) => number | undefined;
133
+ ackTimeoutMs?: number;
134
+ }
135
+ export type SdkLaunchResult = {
136
+ ok: true;
137
+ attempt: WorkerLaunchAttempt;
138
+ hostPid: number | undefined;
139
+ paneId: string;
140
+ } | {
141
+ ok: false;
142
+ attempt: WorkerLaunchAttempt | null;
143
+ reason: string;
144
+ hostPid?: number;
145
+ };
146
+ /**
147
+ * Create the launch attempt, write the host spec and spawn the detached host,
148
+ * then run the same ack -> accepted -> provider_started handshake a pane
149
+ * bootstrap runs. A failed handshake tree-kills the host it spawned.
150
+ */
151
+ export declare function launchSdkHost(input: SdkLaunchInput): Promise<SdkLaunchResult>;
152
+ /** Floor for a shutdown's host stop budget: lets a host already mid-teardown finish. */
153
+ export declare const SDK_HOST_STOP_FLOOR_MS = 5000;
154
+ /**
155
+ * Ring `stop` (or `shutdown`, which also writes the shutdown ack), wait for the
156
+ * host to report its provider dead, then tree-kill it as the last resort.
157
+ * True once the provider is observed dead.
158
+ */
159
+ export declare function stopSdkHost(attempt: WorkerLaunchAttempt, stateRoot: string, opts?: {
160
+ timeoutMs?: number;
161
+ kind?: 'stop' | 'shutdown';
162
+ pollMs?: number;
163
+ }): Promise<boolean>;
164
+ //# sourceMappingURL=sdk-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-transport.d.ts","sourceRoot":"","sources":["../../src/team/sdk-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,OAAO,EAKL,KAAK,mBAAmB,EACzB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,iBAAiB,SAAS,CAAC;AAExC,uFAAuF;AACvF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAErE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;;;;;;;;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