@te-river/opencode-team-mode 1.6.0 → 1.6.2

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 (150) hide show
  1. package/README.md +80 -15
  2. package/README.zh-CN.md +67 -18
  3. package/dist/host/note.d.ts +7 -0
  4. package/dist/host/note.d.ts.map +1 -0
  5. package/dist/host/note.js +31 -0
  6. package/dist/host/note.js.map +1 -0
  7. package/dist/host/v1.d.ts +14 -0
  8. package/dist/host/v1.d.ts.map +1 -0
  9. package/dist/host/v1.js +340 -0
  10. package/dist/host/v1.js.map +1 -0
  11. package/dist/host/v2-browser-gate.d.ts +45 -0
  12. package/dist/host/v2-browser-gate.d.ts.map +1 -0
  13. package/dist/host/v2-browser-gate.js +319 -0
  14. package/dist/host/v2-browser-gate.js.map +1 -0
  15. package/dist/host/v2-capabilities.d.ts +78 -0
  16. package/dist/host/v2-capabilities.d.ts.map +1 -0
  17. package/dist/host/v2-capabilities.js +173 -0
  18. package/dist/host/v2-capabilities.js.map +1 -0
  19. package/dist/host/v2-client.d.ts +53 -0
  20. package/dist/host/v2-client.d.ts.map +1 -0
  21. package/dist/host/v2-client.js +193 -0
  22. package/dist/host/v2-client.js.map +1 -0
  23. package/dist/host/v2-events.d.ts +56 -0
  24. package/dist/host/v2-events.d.ts.map +1 -0
  25. package/dist/host/v2-events.js +158 -0
  26. package/dist/host/v2-events.js.map +1 -0
  27. package/dist/host/v2-guard.d.ts +101 -0
  28. package/dist/host/v2-guard.d.ts.map +1 -0
  29. package/dist/host/v2-guard.js +199 -0
  30. package/dist/host/v2-guard.js.map +1 -0
  31. package/dist/host/v2-offload.d.ts +148 -0
  32. package/dist/host/v2-offload.d.ts.map +1 -0
  33. package/dist/host/v2-offload.js +288 -0
  34. package/dist/host/v2-offload.js.map +1 -0
  35. package/dist/host/v2-permissions.d.ts +123 -0
  36. package/dist/host/v2-permissions.d.ts.map +1 -0
  37. package/dist/host/v2-permissions.js +190 -0
  38. package/dist/host/v2-permissions.js.map +1 -0
  39. package/dist/host/v2-probe.d.ts +85 -0
  40. package/dist/host/v2-probe.d.ts.map +1 -0
  41. package/dist/host/v2-probe.js +268 -0
  42. package/dist/host/v2-probe.js.map +1 -0
  43. package/dist/host/v2-scope.d.ts +51 -0
  44. package/dist/host/v2-scope.d.ts.map +1 -0
  45. package/dist/host/v2-scope.js +58 -0
  46. package/dist/host/v2-scope.js.map +1 -0
  47. package/dist/host/v2-session-client.d.ts +105 -0
  48. package/dist/host/v2-session-client.d.ts.map +1 -0
  49. package/dist/host/v2-session-client.js +390 -0
  50. package/dist/host/v2-session-client.js.map +1 -0
  51. package/dist/host/v2-session.d.ts +85 -0
  52. package/dist/host/v2-session.d.ts.map +1 -0
  53. package/dist/host/v2-session.js +171 -0
  54. package/dist/host/v2-session.js.map +1 -0
  55. package/dist/host/v2-subagent.d.ts +157 -0
  56. package/dist/host/v2-subagent.d.ts.map +1 -0
  57. package/dist/host/v2-subagent.js +286 -0
  58. package/dist/host/v2-subagent.js.map +1 -0
  59. package/dist/host/v2-tool.d.ts +67 -0
  60. package/dist/host/v2-tool.d.ts.map +1 -0
  61. package/dist/host/v2-tool.js +209 -0
  62. package/dist/host/v2-tool.js.map +1 -0
  63. package/dist/host/v2-transcript.d.ts +73 -0
  64. package/dist/host/v2-transcript.d.ts.map +1 -0
  65. package/dist/host/v2-transcript.js +151 -0
  66. package/dist/host/v2-transcript.js.map +1 -0
  67. package/dist/host/v2-types.d.ts +229 -0
  68. package/dist/host/v2-types.d.ts.map +1 -0
  69. package/dist/host/v2-types.js +17 -0
  70. package/dist/host/v2-types.js.map +1 -0
  71. package/dist/host/v2.d.ts +42 -0
  72. package/dist/host/v2.d.ts.map +1 -0
  73. package/dist/host/v2.js +853 -0
  74. package/dist/host/v2.js.map +1 -0
  75. package/dist/index.d.ts +23 -17
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +29 -366
  78. package/dist/index.js.map +1 -1
  79. package/dist/prompts/lead.d.ts +1 -1
  80. package/dist/prompts/lead.d.ts.map +1 -1
  81. package/dist/prompts/lead.js +456 -426
  82. package/dist/prompts/lead.js.map +1 -1
  83. package/dist/prompts/shared.d.ts +2 -2
  84. package/dist/prompts/shared.d.ts.map +1 -1
  85. package/dist/prompts/shared.js +38 -11
  86. package/dist/prompts/shared.js.map +1 -1
  87. package/dist/prompts/specialists.d.ts +2 -2
  88. package/dist/prompts/specialists.d.ts.map +1 -1
  89. package/dist/prompts/specialists.js +7 -6
  90. package/dist/prompts/specialists.js.map +1 -1
  91. package/dist/task-offload.d.ts +16 -0
  92. package/dist/task-offload.d.ts.map +1 -1
  93. package/dist/task-offload.js +51 -0
  94. package/dist/task-offload.js.map +1 -1
  95. package/dist/tm/browser.d.ts.map +1 -1
  96. package/dist/tm/browser.js +41 -10
  97. package/dist/tm/browser.js.map +1 -1
  98. package/dist/tm/dispatch.d.ts +86 -1
  99. package/dist/tm/dispatch.d.ts.map +1 -1
  100. package/dist/tm/dispatch.js +360 -39
  101. package/dist/tm/dispatch.js.map +1 -1
  102. package/dist/tm/dupe-guard.d.ts +16 -3
  103. package/dist/tm/dupe-guard.d.ts.map +1 -1
  104. package/dist/tm/dupe-guard.js +27 -7
  105. package/dist/tm/dupe-guard.js.map +1 -1
  106. package/dist/tm/index.d.ts +40 -1
  107. package/dist/tm/index.d.ts.map +1 -1
  108. package/dist/tm/index.js +40 -11
  109. package/dist/tm/index.js.map +1 -1
  110. package/dist/tm/ledger.d.ts +114 -0
  111. package/dist/tm/ledger.d.ts.map +1 -0
  112. package/dist/tm/ledger.js +308 -0
  113. package/dist/tm/ledger.js.map +1 -0
  114. package/dist/tm/perm-ask.d.ts +1 -3
  115. package/dist/tm/perm-ask.d.ts.map +1 -1
  116. package/dist/tm/perm-ask.js +10 -1
  117. package/dist/tm/perm-ask.js.map +1 -1
  118. package/dist/tm/preview.d.ts +55 -0
  119. package/dist/tm/preview.d.ts.map +1 -1
  120. package/dist/tm/preview.js +225 -0
  121. package/dist/tm/preview.js.map +1 -1
  122. package/dist/tm/search.d.ts.map +1 -1
  123. package/dist/tm/search.js +40 -10
  124. package/dist/tm/search.js.map +1 -1
  125. package/dist/tm/serp-loop.d.ts +45 -0
  126. package/dist/tm/serp-loop.d.ts.map +1 -0
  127. package/dist/tm/serp-loop.js +80 -0
  128. package/dist/tm/serp-loop.js.map +1 -0
  129. package/dist/tm/stats.d.ts +29 -0
  130. package/dist/tm/stats.d.ts.map +1 -1
  131. package/dist/tm/stats.js +278 -4
  132. package/dist/tm/stats.js.map +1 -1
  133. package/dist/tm/webfetch.d.ts +4 -0
  134. package/dist/tm/webfetch.d.ts.map +1 -1
  135. package/dist/tm/webfetch.js +75 -8
  136. package/dist/tm/webfetch.js.map +1 -1
  137. package/docs/installation-v2.md +445 -0
  138. package/docs/installation.md +12 -0
  139. package/docs/research/agent-data-exchange.md +117 -0
  140. package/docs/research/browser-pane.md +89 -0
  141. package/docs/research/host-http-api.md +132 -0
  142. package/docs/research/host-subagent-injection.md +187 -0
  143. package/docs/research/plugin-loader-contract.md +261 -0
  144. package/docs/research/v2-builtin-tools.md +447 -0
  145. package/docs/v2-port-notes.md +413 -0
  146. package/index.js +7 -0
  147. package/package.json +64 -61
  148. package/scripts/gen-v2-config.mjs +304 -0
  149. package/scripts/lib/config-surgery.cjs +239 -0
  150. package/scripts/lib/fake-ctx.mjs +169 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2-offload.js","sourceRoot":"","sources":["../../src/host/v2-offload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,oBAAoB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACzH,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH;;;;;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CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpD,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAAE,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;QAC/D,CAAC;QACD,MAAM,CAAC,SAAS,EAAE,CAAA;QAClB,MAAM,CAAC,WAAW,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAA;QAC1E,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAA;IACjC,CAAC,CAAC,CAAA;IACF,OAAO,EAAE,aAAa,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,CAAA;AACvD,CAAC"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * v1's flat permission map -> v2's ordered `{action, resource, effect}` rules.
3
+ *
4
+ * v1 expressed an agent's whitelist as an object keyed by tool name, with two
5
+ * tricks the v2 schema cannot hold: a value may be an OBJECT of
6
+ * pattern->effect (the bash escalation that made the host's official dialog
7
+ * fire for the R6/R2 faces), and `"tm_*"` was a literal wildcard KEY that
8
+ * matched our whole tool family. v2 takes only flat triples, so:
9
+ *
10
+ * - a plain `tool: "allow"|"deny"|"ask"` becomes `{action: tool, resource:"*", effect}`;
11
+ * - an escalation object becomes ONE `ask` triple for that action — the object
12
+ * existed only to force a dialog, and `ask` is the effect that does it. The
13
+ * per-pattern precision comes back in #94, where the `evaluate` hook can
14
+ * classify the actual command line (probed: `action:"shell"` carries the
15
+ * whole command in `resources[0]`).
16
+ *
17
+ * Anything whose effect is not one of the host's three literals is DROPPED
18
+ * rather than guessed at: a rule the host cannot parse is worse than no rule,
19
+ * because it may fail closed on the whole agent.
20
+ */
21
+ export type PermissionEffect = "allow" | "deny" | "ask";
22
+ export interface PermissionTriple {
23
+ action: string;
24
+ resource: string;
25
+ effect: PermissionEffect;
26
+ }
27
+ /**
28
+ * v1 named its built-in tools differently. Measured against the live v2
29
+ * surface (probed `session.context.tools`: edit glob grep question read shell
30
+ * skill subagent webfetch websearch write, plus patch/browser_*):
31
+ *
32
+ * bash → shell · task → subagent · apply_patch → patch
33
+ *
34
+ * A name with no v2 counterpart (`list`, `todowrite`, `lsp`) is NOT emitted as
35
+ * a phantom rule — the caller gets it back in `unmapped` so the boot log can
36
+ * say "this part of the whitelist has no v2 equivalent yet", which is a
37
+ * reportable fact, unlike a rule the host will never match.
38
+ */
39
+ export declare const V2_ACTION_NAMES: Readonly<Record<string, string>>;
40
+ /**
41
+ * Tools the v1 personality registers and the v2 one does NOT — the host's own
42
+ * `execute` (Code Mode) already covers `tm_ptc_run` on v2 (proved against a live
43
+ * session: parallel governed calls, results still offloaded through handles).
44
+ *
45
+ * This is the single source for that fact: `v2.ts` skips them when registering,
46
+ * and `scripts/gen-v2-config.mjs` drops their permission triples, because an
47
+ * `allow` for an action the host has never heard of claims a capability that
48
+ * does not exist.
49
+ */
50
+ /**
51
+ * Tools v1 keeps and v2 does not register.
52
+ *
53
+ * `tm_ptc_run` left because the host's own Code Mode does the job. The other
54
+ * three left for the opposite reason: on v2 the NATIVE read/grep/shell are the
55
+ * better tools (paged reads, image/PDF attachment, background shell, and — since
56
+ * 1.7.0's offload layer — they are now governed too, measured at 12,902 tokens
57
+ * arriving as a 78-token preview). Retiring them is only safe in that order,
58
+ * which is why the governance moved to `execute.after` FIRST and this list is the
59
+ * step that follows it, not the one that precedes it.
60
+ *
61
+ * v1 keeps all three: its `tool.execute.before` can rewrite arguments but not
62
+ * results, so deleting them there would delete offload itself.
63
+ */
64
+ export declare const V1_ONLY_TOOLS: ReadonlySet<string>;
65
+ /**
66
+ * The v2 file/shell ladder runs through the host's own tools, so the triples that
67
+ * DENY them must not be projected: v2-session.ts deletes every literal-`deny`
68
+ * action from the request, and denying `read` while `tm_read` is unregistered
69
+ * would leave a role with no way to open a file at all. This is a translation
70
+ * decision, not an edit to src/agents.ts — v1's matrix keeps its denies and the
71
+ * two personalities' ladders genuinely differ now.
72
+ *
73
+ * Both halves have to agree, so the SAME set is consulted by `toolsToRemove()` in
74
+ * v2-session.ts; this constant is the one source. Letting the native file tools
75
+ * back in does not lower a red line: v1's P2 scope ("stay inside the project +
76
+ * the store dirs") is the host's own `external_directory` permission action on v2,
77
+ * observed live answering `effect:"ask"` with a `permission.asked` behind it — a
78
+ * real dialog where our code used to hard-throw. The two red lines the host does
79
+ * NOT know about (the address policy under `webfetch`, R6 under `shell`) are the
80
+ * ones `v2-guard.ts` puts into `permission.hook("evaluate")`, and that happened
81
+ * BEFORE this fork, which is the ordering AGENTS.md requires.
82
+ */
83
+ export declare const V2_LADDER_ACTIONS: ReadonlySet<string>;
84
+ export interface TranslateOptions {
85
+ /**
86
+ * With R6 on, v1 escalated `bash` to a pattern object so the host's OFFICIAL
87
+ * dialog fired. A plugin cannot raise a dialog on v2 (probed) — but the host
88
+ * does honor an `ask` EFFECT it evaluates itself, so escalating the mapped
89
+ * `shell` action to `ask` is the closest honest equivalent: the human is
90
+ * asked, just per command rather than per pattern. #94 refines the
91
+ * per-pattern half through `permission.hook("evaluate")`.
92
+ */
93
+ escalateShellAsk?: boolean;
94
+ /**
95
+ * Which role these triples are for. Needed for the ONE tool that exists only on this
96
+ * personality: `tm_ledger` is not in the v1 permission map (v1 has the host's
97
+ * `todowrite`), so nothing would ever name it, and an unruled action is the host's
98
+ * default rather than our stated rule. The lead's list is the lead's: `allow` for it,
99
+ * `deny` for the five specialists, which also makes the runtime gate
100
+ * (`onlyAgent: "team"`) visible in the config the user can read.
101
+ */
102
+ agentName?: string;
103
+ }
104
+ /** The v1 `permission` block, as loosely as the host hands it to us. */
105
+ export declare function triplesFromAgentPermission(permission: Record<string, unknown> | undefined | null, options?: TranslateOptions): {
106
+ triples: PermissionTriple[];
107
+ unmapped: string[];
108
+ };
109
+ /**
110
+ * Union that keeps the user's unrelated rules and lets OUR matrix decide OUR
111
+ * actions (the matrix is the whitelist — that is the product's tool-surface
112
+ * promise, and it must not be silently widened by a config edit half-applying
113
+ * it). Idempotent: running it twice changes nothing.
114
+ *
115
+ * `drop` is the reclaim path for an upgrade: a rule naming an action this
116
+ * personality never registers (a v1-only tool) can only have come from us, and
117
+ * leaving it behind would keep claiming a capability the host does not have.
118
+ */
119
+ export declare function mergeTriples(existing: ReadonlyArray<PermissionTriple> | undefined | null, ours: ReadonlyArray<PermissionTriple>, drop?: ReadonlySet<string>): {
120
+ triples: PermissionTriple[];
121
+ changed: boolean;
122
+ };
123
+ //# sourceMappingURL=v2-permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2-permissions.d.ts","sourceRoot":"","sources":["../../src/host/v2-permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAA;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,gBAAgB,CAAA;CACzB;AAID;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAI5D,CAAA;AAED;;;;;;;;;GASG;AACH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,MAAM,CAe5C,CAAA;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAqC,CAAA;AAQvF,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wEAAwE;AACxE,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,EACtD,OAAO,GAAE,gBAAqB,GAC7B;IAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CA0DrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,SAAS,GAAG,IAAI,EAC5D,IAAI,EAAE,aAAa,CAAC,gBAAgB,CAAC,EACrC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACzB;IAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAcnD"}
@@ -0,0 +1,190 @@
1
+ /**
2
+ * v1's flat permission map -> v2's ordered `{action, resource, effect}` rules.
3
+ *
4
+ * v1 expressed an agent's whitelist as an object keyed by tool name, with two
5
+ * tricks the v2 schema cannot hold: a value may be an OBJECT of
6
+ * pattern->effect (the bash escalation that made the host's official dialog
7
+ * fire for the R6/R2 faces), and `"tm_*"` was a literal wildcard KEY that
8
+ * matched our whole tool family. v2 takes only flat triples, so:
9
+ *
10
+ * - a plain `tool: "allow"|"deny"|"ask"` becomes `{action: tool, resource:"*", effect}`;
11
+ * - an escalation object becomes ONE `ask` triple for that action — the object
12
+ * existed only to force a dialog, and `ask` is the effect that does it. The
13
+ * per-pattern precision comes back in #94, where the `evaluate` hook can
14
+ * classify the actual command line (probed: `action:"shell"` carries the
15
+ * whole command in `resources[0]`).
16
+ *
17
+ * Anything whose effect is not one of the host's three literals is DROPPED
18
+ * rather than guessed at: a rule the host cannot parse is worse than no rule,
19
+ * because it may fail closed on the whole agent.
20
+ */
21
+ const EFFECTS = new Set(["allow", "deny", "ask"]);
22
+ /**
23
+ * v1 named its built-in tools differently. Measured against the live v2
24
+ * surface (probed `session.context.tools`: edit glob grep question read shell
25
+ * skill subagent webfetch websearch write, plus patch/browser_*):
26
+ *
27
+ * bash → shell · task → subagent · apply_patch → patch
28
+ *
29
+ * A name with no v2 counterpart (`list`, `todowrite`, `lsp`) is NOT emitted as
30
+ * a phantom rule — the caller gets it back in `unmapped` so the boot log can
31
+ * say "this part of the whitelist has no v2 equivalent yet", which is a
32
+ * reportable fact, unlike a rule the host will never match.
33
+ */
34
+ export const V2_ACTION_NAMES = {
35
+ bash: "shell",
36
+ task: "subagent",
37
+ apply_patch: "patch",
38
+ };
39
+ /**
40
+ * Tools the v1 personality registers and the v2 one does NOT — the host's own
41
+ * `execute` (Code Mode) already covers `tm_ptc_run` on v2 (proved against a live
42
+ * session: parallel governed calls, results still offloaded through handles).
43
+ *
44
+ * This is the single source for that fact: `v2.ts` skips them when registering,
45
+ * and `scripts/gen-v2-config.mjs` drops their permission triples, because an
46
+ * `allow` for an action the host has never heard of claims a capability that
47
+ * does not exist.
48
+ */
49
+ /**
50
+ * Tools v1 keeps and v2 does not register.
51
+ *
52
+ * `tm_ptc_run` left because the host's own Code Mode does the job. The other
53
+ * three left for the opposite reason: on v2 the NATIVE read/grep/shell are the
54
+ * better tools (paged reads, image/PDF attachment, background shell, and — since
55
+ * 1.7.0's offload layer — they are now governed too, measured at 12,902 tokens
56
+ * arriving as a 78-token preview). Retiring them is only safe in that order,
57
+ * which is why the governance moved to `execute.after` FIRST and this list is the
58
+ * step that follows it, not the one that precedes it.
59
+ *
60
+ * v1 keeps all three: its `tool.execute.before` can rewrite arguments but not
61
+ * results, so deleting them there would delete offload itself.
62
+ */
63
+ export const V1_ONLY_TOOLS = new Set([
64
+ "tm_ptc_run",
65
+ "tm_read",
66
+ "tm_grep",
67
+ "tm_bash",
68
+ /*
69
+ * `tm_pty` executes on the host's OWN terminal sessions through `client.pty.*`,
70
+ * and the v2 plugin context has no pty domain at all — so registering it meant
71
+ * shipping a tool whose every start answers "宿主 pty 接口不可用". A tool that
72
+ * cannot work is the overstated claim, not the fallback. v1 keeps it.
73
+ * Revisit only when #28 measures the native `shell` background round-trip
74
+ (what returns, how output is retrieved, how it is cancelled); if the host's own
75
+ * background shell covers it, this stays retired and the prompt says `shell`.
76
+ */
77
+ "tm_pty",
78
+ ]);
79
+ /**
80
+ * The v2 file/shell ladder runs through the host's own tools, so the triples that
81
+ * DENY them must not be projected: v2-session.ts deletes every literal-`deny`
82
+ * action from the request, and denying `read` while `tm_read` is unregistered
83
+ * would leave a role with no way to open a file at all. This is a translation
84
+ * decision, not an edit to src/agents.ts — v1's matrix keeps its denies and the
85
+ * two personalities' ladders genuinely differ now.
86
+ *
87
+ * Both halves have to agree, so the SAME set is consulted by `toolsToRemove()` in
88
+ * v2-session.ts; this constant is the one source. Letting the native file tools
89
+ * back in does not lower a red line: v1's P2 scope ("stay inside the project +
90
+ * the store dirs") is the host's own `external_directory` permission action on v2,
91
+ * observed live answering `effect:"ask"` with a `permission.asked` behind it — a
92
+ * real dialog where our code used to hard-throw. The two red lines the host does
93
+ * NOT know about (the address policy under `webfetch`, R6 under `shell`) are the
94
+ * ones `v2-guard.ts` puts into `permission.hook("evaluate")`, and that happened
95
+ * BEFORE this fork, which is the ordering AGENTS.md requires.
96
+ */
97
+ export const V2_LADDER_ACTIONS = new Set(["read", "grep", "glob"]);
98
+ const V2_ONLY_ACTIONS = new Set(["list", "todowrite", "lsp"]);
99
+ function normalizeEffect(value) {
100
+ return typeof value === "string" && EFFECTS.has(value) ? value : null;
101
+ }
102
+ /** The v1 `permission` block, as loosely as the host hands it to us. */
103
+ export function triplesFromAgentPermission(permission, options = {}) {
104
+ const triples = [];
105
+ const unmapped = [];
106
+ if (!permission || typeof permission !== "object")
107
+ return { triples, unmapped };
108
+ for (const [v1Action, value] of Object.entries(permission)) {
109
+ if (!v1Action)
110
+ continue;
111
+ if (V2_ONLY_ACTIONS.has(v1Action)) {
112
+ unmapped.push(v1Action);
113
+ continue;
114
+ }
115
+ const action = V2_ACTION_NAMES[v1Action] ?? v1Action;
116
+ // A rule for an action v2 never registers claims a capability that does not
117
+ // exist, and `permission.evaluate` cannot even see it to enforce it. One
118
+ // source for the decision: this is the same set v2.ts skips when registering
119
+ // and gen-v2-config.mjs uses for the markdown frontmatter.
120
+ if (V1_ONLY_TOOLS.has(action))
121
+ continue;
122
+ const direct = normalizeEffect(value);
123
+ if (direct) {
124
+ // The v2 file ladder IS the native read/grep/glob, so a `deny` on them may
125
+ // not be projected: v2-session.ts deletes every literal-deny action from the
126
+ // request, and deleting them while tm_read/tm_grep are unregistered would
127
+ // leave a role with no way to open a file. An explicit allow still rides.
128
+ if (V2_LADDER_ACTIONS.has(action) && direct === "deny")
129
+ continue;
130
+ const effect = options.escalateShellAsk && action === "shell" && direct === "allow" ? "ask" : direct;
131
+ triples.push({ action, resource: "*", effect });
132
+ // The host's 45 `browser_*` tools share ONE permission action named `browser`
133
+ // (read from the binary), and they are NOT in the direct tool surface — so
134
+ // deleting `browser_*` from `event.tools` at the request layer removes a
135
+ // catalog the assembled request never contained, while a role that is denied
136
+ // `tm_browser` can still reach every one of them from inside `execute`.
137
+ // Projecting the deny is the only lever that speaks their language.
138
+ if (action === "tm_browser" && direct === "deny") {
139
+ triples.push({ action: "browser", resource: "*", effect: "deny" });
140
+ }
141
+ continue;
142
+ }
143
+ if (value && typeof value === "object" && !Array.isArray(value)) {
144
+ // pattern -> effect map: one dialog-forcing rule, and `ask` wins over
145
+ // `allow` because that is what the object was for.
146
+ const effects = Object.values(value)
147
+ .map(normalizeEffect)
148
+ .filter((e) => e !== null);
149
+ const effect = effects.includes("ask")
150
+ ? "ask"
151
+ : effects.includes("deny")
152
+ ? "deny"
153
+ : effects[0] ?? "ask";
154
+ triples.push({ action, resource: "*", effect });
155
+ }
156
+ }
157
+ if (options.agentName) {
158
+ const ledgerEffect = options.agentName === "team" ? "allow" : "deny";
159
+ if (!triples.some((x) => x.action === "tm_ledger")) {
160
+ triples.push({ action: "tm_ledger", resource: "*", effect: ledgerEffect });
161
+ }
162
+ }
163
+ return { triples, unmapped };
164
+ }
165
+ /**
166
+ * Union that keeps the user's unrelated rules and lets OUR matrix decide OUR
167
+ * actions (the matrix is the whitelist — that is the product's tool-surface
168
+ * promise, and it must not be silently widened by a config edit half-applying
169
+ * it). Idempotent: running it twice changes nothing.
170
+ *
171
+ * `drop` is the reclaim path for an upgrade: a rule naming an action this
172
+ * personality never registers (a v1-only tool) can only have come from us, and
173
+ * leaving it behind would keep claiming a capability the host does not have.
174
+ */
175
+ export function mergeTriples(existing, ours, drop) {
176
+ const base = Array.isArray(existing) ? existing : [];
177
+ const ourActions = new Set(ours.map((t) => t.action));
178
+ const kept = base.filter((t) => {
179
+ if (!t || typeof t !== "object")
180
+ return false;
181
+ const action = String(t.action);
182
+ return !ourActions.has(action) && !drop?.has(action);
183
+ });
184
+ const keptClean = kept.filter((t) => t && typeof t.action === "string" && EFFECTS.has(String(t.effect)));
185
+ const triples = [...keptClean.map((t) => ({ ...t, resource: typeof t.resource === "string" && t.resource ? t.resource : "*" })), ...ours];
186
+ const changed = triples.length !== base.length ||
187
+ JSON.stringify(triples) !== JSON.stringify(base);
188
+ return { triples, changed };
189
+ }
190
+ //# sourceMappingURL=v2-permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2-permissions.js","sourceRoot":"","sources":["../../src/host/v2-permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAUH,MAAM,OAAO,GAAG,IAAI,GAAG,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,eAAe,GAAqC;IAC/D,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,UAAU;IAChB,WAAW,EAAE,OAAO;CACrB,CAAA;AAED;;;;;;;;;GASG;AACH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC;IACxD,YAA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MAAM,CAAC,CAAA;QAC/B,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;IACF,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACxG,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IACzI,MAAM,OAAO,GACX,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAC9B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,85 @@
1
+ import type { V2Registration } from "./v2-types.js";
2
+ /**
3
+ * The v2 host's real tool surface — observed, not assumed.
4
+ *
5
+ * Why this exists: every decision on the v2 line is currently being made against
6
+ * a DESCRIPTION of the host (does `permission.evaluate` fire for `shell`? what are
7
+ * the native browser tools named, and do their calls reach our hooks at all? is
8
+ * the native `read` output reachable from `execute.after`?), and the type package
9
+ * this repo has installed is 1.18.25 while the host that runs is 2.0.16. Reading
10
+ * node_modules cannot answer a question about a different build.
11
+ *
12
+ * So this module asks the running host and writes down what it says. It registers
13
+ * the same hooks the guards register, mutates NOTHING, and reports only NAMES:
14
+ * tool ids, agent ids, action ids, the key names of an input object, the COUNT of
15
+ * resources plus whether any of them parses as a URL. It never records a resource
16
+ * VALUE, a command line, a path or an env face — the same privacy red line the R6
17
+ * audit log holds itself to (tool name + category + verdict, never content). A
18
+ * diagnostic that leaked the user's command lines into a probe file would be a
19
+ * worse bug than the one it was written to answer.
20
+ *
21
+ * The file dump is off unless `TM_V2_PROBE` names one. The name sets fill either
22
+ * way and a compact snapshot rides the trajectory, because that is what lets
23
+ * `tm_stats` answer "which half of the plugin is running, and what did it see"
24
+ * from inside a session — and the snapshot is written WHILE THE PROCESS LIVES, not
25
+ * only from its cleanup: a first live run proved a hard exit never reaches
26
+ * `dispose`, so counters that only land at teardown are counters that do not exist.
27
+ */
28
+ export interface V2ProbeReport {
29
+ /** agent ids seen in a session context */
30
+ agentsSeen: string[];
31
+ toolNames: string[];
32
+ /** ids reaching tool.execute.before / after */
33
+ executed: string[];
34
+ executedAfter: string[];
35
+ /** actions reaching permission.evaluate */
36
+ actions: string[];
37
+ /** shape facts about the message list a request carries: how many messages, how
38
+ * many look like the host's injected `<task id=… state="completed">` envelope,
39
+ * and how long the biggest one is. LENGTHS ONLY — the body of a sub-agent reply
40
+ * is the most private payload in the product, which is exactly why Plan B keeps
41
+ * it off disk. This is what decides whether the v2 offload has anything to hook
42
+ * onto, and it must not be guessed from the v1 shape. */
43
+ messages: number;
44
+ taskEnvelopes: number;
45
+ maxEnvelopeChars: number;
46
+ /** key names of the first messages the context hook carried (shape, not text) */
47
+ messageShapes: Array<Record<string, unknown>>;
48
+ /** which host envelope spellings were seen — "v1-task" vs "v2-subagent" */
49
+ envelopeForms: Set<string>;
50
+ /** permission evaluations whose resources carried a URL (count, never the URL) */
51
+ urlResources: number;
52
+ evaluations: number;
53
+ /** hook points the ctx did not expose — a missing entry is a host fact */
54
+ hooksMissing: string[];
55
+ /** the ctx domains the host actually handed us. This is what decides whether an
56
+ * event-driven rebuild is even possible: a plugin cannot subscribe to a channel
57
+ * that was never given, and "we should rebuild tm_join on ctx.event" is only a
58
+ * plan if ctx.event exists. */
59
+ ctxDomains: string[];
60
+ /** whether TM_V2_PROBE reached THIS process. Without this line, "no browser
61
+ * tools were seen" and "nobody was listening" are the same answer. */
62
+ probeTarget: string;
63
+ lines: number;
64
+ }
65
+ export interface V2Probe {
66
+ readonly enabled: boolean;
67
+ readonly report: V2ProbeReport;
68
+ readonly registrations: V2Registration[];
69
+ /** Push the current counters to `onSummary`. Throttled unless `force` — this is
70
+ * called from the session context hook, which fires before EVERY model request. */
71
+ flush: (force?: boolean) => void;
72
+ }
73
+ interface ProbeOptions {
74
+ env?: Record<string, string | undefined>;
75
+ /** safety valve: a pathological session must not fill a disk */
76
+ maxLines?: number;
77
+ /** where a throttled snapshot goes (the trajectory) */
78
+ onSummary?: (summary: Record<string, unknown>) => void;
79
+ flushMs?: number;
80
+ }
81
+ export declare function applyV2Probe(ctx: unknown, opts?: ProbeOptions): Promise<V2Probe>;
82
+ /** Compact form for the trajectory — names are safe, values never are. */
83
+ export declare function probeSummary(report: V2ProbeReport): Record<string, unknown>;
84
+ export {};
85
+ //# sourceMappingURL=v2-probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2-probe.d.ts","sourceRoot":"","sources":["../../src/host/v2-probe.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,2CAA2C;IAC3C,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB;;;;;8DAK0D;IAC1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