@gotgenes/pi-permission-system 18.1.0 → 18.1.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 (132) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/docs/assets/logo.png +0 -0
  3. package/docs/assets/logo.svg +213 -0
  4. package/docs/configuration.md +700 -0
  5. package/docs/cross-extension-api.md +525 -0
  6. package/docs/guides/permission-frontmatter-for-subagent-extensions.md +201 -0
  7. package/docs/guides/upstream-issue-template.md +113 -0
  8. package/docs/migration/legacy-to-flat.md +365 -0
  9. package/docs/opencode-compatibility.md +213 -0
  10. package/docs/session-approvals.md +68 -0
  11. package/docs/subagent-integration.md +102 -0
  12. package/docs/troubleshooting.md +53 -0
  13. package/package.json +5 -2
  14. package/src/access-intent/access-path.ts +29 -4
  15. package/src/access-intent/bash/bash-path-resolver.ts +39 -18
  16. package/src/access-intent/bash/msys-bash-tokens.ts +64 -0
  17. package/src/path-normalizer.ts +105 -2
  18. package/test/access-intent/access-path.test.ts +0 -277
  19. package/test/access-intent/bash/node-text.test.ts +0 -148
  20. package/test/access-intent/bash/parser.test.ts +0 -19
  21. package/test/access-intent/bash/program.test.ts +0 -673
  22. package/test/access-intent/bash/token-classification.test.ts +0 -363
  23. package/test/access-intent/bash/token-collection.test.ts +0 -300
  24. package/test/active-agent.test.ts +0 -155
  25. package/test/async-cache.test.ts +0 -48
  26. package/test/bash-arity.test.ts +0 -144
  27. package/test/bash-external-directory.test.ts +0 -1022
  28. package/test/builtin-tool-input-formatters.test.ts +0 -109
  29. package/test/canonicalize-path.test.ts +0 -119
  30. package/test/composition-root.test.ts +0 -698
  31. package/test/config-loader.test.ts +0 -740
  32. package/test/config-modal.test.ts +0 -320
  33. package/test/config-paths.test.ts +0 -83
  34. package/test/config-pipeline.test.ts +0 -90
  35. package/test/config-reporter.test.ts +0 -147
  36. package/test/config-store.test.ts +0 -466
  37. package/test/decision-audit.test.ts +0 -72
  38. package/test/decision-reporter.test.ts +0 -112
  39. package/test/denial-messages.test.ts +0 -714
  40. package/test/detect-permissive-bash-fallback.test.ts +0 -56
  41. package/test/expand-home.test.ts +0 -93
  42. package/test/extension-config.test.ts +0 -129
  43. package/test/extension-paths.test.ts +0 -108
  44. package/test/forwarded-permissions/io.test.ts +0 -251
  45. package/test/forwarding-manager.test.ts +0 -200
  46. package/test/handlers/before-agent-start.test.ts +0 -314
  47. package/test/handlers/external-directory-integration.test.ts +0 -515
  48. package/test/handlers/external-directory-session-dedup.test.ts +0 -175
  49. package/test/handlers/external-directory-symlink-acceptance.test.ts +0 -167
  50. package/test/handlers/gates/bash-command-metamorphic.test.ts +0 -88
  51. package/test/handlers/gates/bash-command.test.ts +0 -257
  52. package/test/handlers/gates/bash-external-directory.test.ts +0 -268
  53. package/test/handlers/gates/bash-path.test.ts +0 -346
  54. package/test/handlers/gates/candidate-check.test.ts +0 -52
  55. package/test/handlers/gates/external-directory-messages.test.ts +0 -85
  56. package/test/handlers/gates/external-directory-policy.test.ts +0 -134
  57. package/test/handlers/gates/external-directory.test.ts +0 -267
  58. package/test/handlers/gates/helpers.test.ts +0 -165
  59. package/test/handlers/gates/path.test.ts +0 -369
  60. package/test/handlers/gates/runner.test.ts +0 -408
  61. package/test/handlers/gates/skill-input-gate-pipeline.test.ts +0 -176
  62. package/test/handlers/gates/skill-input.test.ts +0 -128
  63. package/test/handlers/gates/skill-read.test.ts +0 -161
  64. package/test/handlers/gates/tool-call-gate-pipeline.test.ts +0 -356
  65. package/test/handlers/gates/tool.test.ts +0 -244
  66. package/test/handlers/input-events.test.ts +0 -168
  67. package/test/handlers/input.test.ts +0 -199
  68. package/test/handlers/lifecycle.test.ts +0 -221
  69. package/test/handlers/tool-call-boundary.test.ts +0 -145
  70. package/test/handlers/tool-call-events.test.ts +0 -277
  71. package/test/handlers/tool-call.test.ts +0 -395
  72. package/test/handlers/validate-requested-tool.test.ts +0 -92
  73. package/test/helpers/external-directory-fixtures.ts +0 -269
  74. package/test/helpers/gate-fixtures.ts +0 -316
  75. package/test/helpers/handler-fixtures.ts +0 -335
  76. package/test/helpers/make-fake-pi.ts +0 -100
  77. package/test/helpers/manager-harness.ts +0 -112
  78. package/test/helpers/session-fixtures.ts +0 -199
  79. package/test/input-normalizer.test.ts +0 -325
  80. package/test/logging.test.ts +0 -51
  81. package/test/mcp-targets.test.ts +0 -233
  82. package/test/node-modules-discovery.test.ts +0 -97
  83. package/test/normalize.test.ts +0 -247
  84. package/test/path-containment.test.ts +0 -161
  85. package/test/path-normalization.test.ts +0 -233
  86. package/test/path-normalizer.test.ts +0 -196
  87. package/test/path-surfaces.test.ts +0 -55
  88. package/test/pattern-suggest.test.ts +0 -248
  89. package/test/permission-dialog.test.ts +0 -205
  90. package/test/permission-event-rpc.test.ts +0 -560
  91. package/test/permission-events.test.ts +0 -400
  92. package/test/permission-forwarder.test.ts +0 -370
  93. package/test/permission-forwarding.test.ts +0 -315
  94. package/test/permission-gate.test.ts +0 -269
  95. package/test/permission-manager-unified.test.ts +0 -3714
  96. package/test/permission-merge.test.ts +0 -61
  97. package/test/permission-prompter.test.ts +0 -518
  98. package/test/permission-prompts.test.ts +0 -363
  99. package/test/permission-resolver.test.ts +0 -277
  100. package/test/permission-session.test.ts +0 -404
  101. package/test/permission-ui-prompt.test.ts +0 -146
  102. package/test/permissions-service.test.ts +0 -192
  103. package/test/pi-infrastructure-read.test.ts +0 -432
  104. package/test/policy-loader.test.ts +0 -561
  105. package/test/prompting-gateway.test.ts +0 -231
  106. package/test/rule.test.ts +0 -650
  107. package/test/safe-system-paths.test.ts +0 -46
  108. package/test/scope-merge.test.ts +0 -116
  109. package/test/service-lifecycle.test.ts +0 -163
  110. package/test/service.test.ts +0 -261
  111. package/test/session-approval.test.ts +0 -75
  112. package/test/session-logger.test.ts +0 -200
  113. package/test/session-rules.test.ts +0 -321
  114. package/test/session-start.test.ts +0 -112
  115. package/test/skill-prompt-sanitizer.test.ts +0 -418
  116. package/test/status.test.ts +0 -10
  117. package/test/subagent-context.test.ts +0 -372
  118. package/test/subagent-lifecycle-events.test.ts +0 -132
  119. package/test/subagent-registry.test.ts +0 -145
  120. package/test/synthesize.test.ts +0 -302
  121. package/test/system-prompt-sanitizer.test.ts +0 -382
  122. package/test/tool-access-extractor-registry.test.ts +0 -77
  123. package/test/tool-input-formatter-registry.test.ts +0 -75
  124. package/test/tool-input-path.test.ts +0 -84
  125. package/test/tool-input-preview.test.ts +0 -129
  126. package/test/tool-input-prompt-formatters.test.ts +0 -115
  127. package/test/tool-preview-formatter.test.ts +0 -458
  128. package/test/tool-registry.test.ts +0 -197
  129. package/test/value-guards.test.ts +0 -193
  130. package/test/wildcard-matcher.test.ts +0 -424
  131. package/test/yaml-frontmatter.test.ts +0 -91
  132. package/test/yolo-mode.test.ts +0 -188
@@ -1,404 +0,0 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
-
4
- // ── Module mocks (hoisted) ─────────────────────────────────────────────────
5
-
6
- const { mockGetActiveAgentName, mockGetActiveAgentNameFromSystemPrompt } =
7
- vi.hoisted(() => ({
8
- mockGetActiveAgentName: vi.fn<(ctx: ExtensionContext) => string | null>(),
9
- mockGetActiveAgentNameFromSystemPrompt:
10
- vi.fn<(systemPrompt?: string) => string | null>(),
11
- }));
12
-
13
- vi.mock("../src/active-agent", () => ({
14
- getActiveAgentName: mockGetActiveAgentName,
15
- getActiveAgentNameFromSystemPrompt: mockGetActiveAgentNameFromSystemPrompt,
16
- }));
17
-
18
- // ── Test helpers ───────────────────────────────────────────────────────────
19
-
20
- import type { DEFAULT_EXTENSION_CONFIG } from "#src/extension-config";
21
- import { SessionApproval } from "#src/session-approval";
22
- import type { SkillPromptEntry } from "#src/skill-prompt-sanitizer";
23
- import { makeCtx } from "#test/helpers/handler-fixtures";
24
- import {
25
- makeConfigStore,
26
- makeFakePermissionManager,
27
- makeRealSession,
28
- } from "#test/helpers/session-fixtures";
29
-
30
- // Alias so the existing tests read naturally.
31
- const createSession = makeRealSession;
32
- const makePermissionManager = makeFakePermissionManager;
33
-
34
- function makeSkillEntry(
35
- name: string,
36
- overrides: Partial<SkillPromptEntry> = {},
37
- ): SkillPromptEntry {
38
- return {
39
- name,
40
- description: `${name} skill`,
41
- location: `/${name}/SKILL.md`,
42
- state: "allow",
43
- normalizedLocation: `/${name}/SKILL.md`,
44
- normalizedBaseDir: `/${name}`,
45
- ...overrides,
46
- };
47
- }
48
-
49
- // ── Tests ──────────────────────────────────────────────────────────────────
50
-
51
- beforeEach(() => {
52
- mockGetActiveAgentName.mockReset();
53
- mockGetActiveAgentNameFromSystemPrompt.mockReset();
54
- mockGetActiveAgentName.mockReturnValue(null);
55
- mockGetActiveAgentNameFromSystemPrompt.mockReturnValue(null);
56
- });
57
-
58
- describe("PermissionSession", () => {
59
- describe("activate and deactivate", () => {
60
- it("stores the context on activate", () => {
61
- const { session, forwarding } = createSession();
62
- const ctx = makeCtx();
63
-
64
- session.activate(ctx);
65
-
66
- expect(forwarding.start).toHaveBeenCalledWith(ctx);
67
- });
68
-
69
- it("clears context on deactivate", () => {
70
- const { session, forwarding } = createSession();
71
- session.activate(makeCtx());
72
- session.deactivate();
73
-
74
- expect(forwarding.stop).toHaveBeenCalled();
75
- });
76
-
77
- it("forwards activate to the gateway", () => {
78
- const { session, gateway } = createSession();
79
- const ctx = makeCtx();
80
-
81
- session.activate(ctx);
82
-
83
- expect(gateway.activate).toHaveBeenCalledWith(ctx);
84
- });
85
-
86
- it("forwards deactivate to the gateway", () => {
87
- const { session, gateway } = createSession();
88
- session.activate(makeCtx());
89
- session.deactivate();
90
-
91
- expect(gateway.deactivate).toHaveBeenCalled();
92
- });
93
- });
94
-
95
- describe("resetForNewSession", () => {
96
- it("configures the injected PermissionManager for the context cwd", () => {
97
- const pm = makePermissionManager();
98
- const { session } = createSession({ permissionManager: pm });
99
- const ctx = makeCtx({ cwd: "/new/project" });
100
-
101
- session.resetForNewSession(ctx);
102
-
103
- expect(pm.configureForCwd).toHaveBeenCalledWith("/new/project");
104
- });
105
-
106
- it("clears skill entries", () => {
107
- const { session } = createSession();
108
- session.setActiveSkillEntries([makeSkillEntry("test")]);
109
- expect(session.getActiveSkillEntries()).toHaveLength(1);
110
-
111
- session.resetForNewSession(makeCtx());
112
-
113
- expect(session.getActiveSkillEntries()).toEqual([]);
114
- });
115
-
116
- it("starts forwarding with the new context", () => {
117
- const { session, forwarding } = createSession();
118
- const ctx = makeCtx();
119
-
120
- session.resetForNewSession(ctx);
121
-
122
- expect(forwarding.start).toHaveBeenCalledWith(ctx);
123
- });
124
-
125
- it("activates the new context", () => {
126
- const { session } = createSession();
127
- const ctx = makeCtx();
128
-
129
- session.resetForNewSession(ctx);
130
-
131
- // Verify context is stored by calling resolveAgentName which needs it
132
- mockGetActiveAgentName.mockReturnValue("test-agent");
133
- const name = session.resolveAgentName(ctx);
134
- expect(name).toBe("test-agent");
135
- });
136
- });
137
-
138
- describe("getPathNormalizer", () => {
139
- it("returns a normalizer bound to the reset session cwd", () => {
140
- const { session } = createSession();
141
- session.resetForNewSession(makeCtx({ cwd: "/projects/app" }));
142
-
143
- const ap = session.getPathNormalizer().forPath("src/foo.ts");
144
-
145
- expect(ap.value()).toBe("/projects/app/src/foo.ts");
146
- });
147
-
148
- it("rebinds the normalizer cwd on a subsequent reset", () => {
149
- const { session } = createSession();
150
- session.resetForNewSession(makeCtx({ cwd: "/projects/app" }));
151
- session.resetForNewSession(makeCtx({ cwd: "/projects/other" }));
152
-
153
- expect(session.getPathNormalizer().forPath("a.ts").value()).toBe(
154
- "/projects/other/a.ts",
155
- );
156
- });
157
-
158
- it("binds the normalizer on activate, before any reset (no fail-open)", () => {
159
- const { session } = createSession();
160
- // A tool call can activate the session before session_start resets it;
161
- // the normalizer must still track the active ctx cwd.
162
- session.activate(makeCtx({ cwd: "/projects/activated" }));
163
-
164
- expect(session.getPathNormalizer().forPath("a.ts").value()).toBe(
165
- "/projects/activated/a.ts",
166
- );
167
- });
168
-
169
- it("builds a win32 normalizer when constructed with the win32 platform", () => {
170
- const { session } = createSession({ platform: "win32" });
171
- session.resetForNewSession(makeCtx({ cwd: "C:\\Projects\\App" }));
172
-
173
- expect(session.getPathNormalizer().forPath("src\\foo.ts").value()).toBe(
174
- "c:\\projects\\app\\src\\foo.ts",
175
- );
176
- });
177
- });
178
-
179
- describe("shutdown", () => {
180
- it("clears session rules", () => {
181
- const { session, sessionRules } = createSession();
182
- sessionRules.recordSessionApproval(SessionApproval.single("bash", "*"));
183
- expect(sessionRules.getRuleset()).toHaveLength(1);
184
-
185
- session.shutdown();
186
-
187
- expect(sessionRules.getRuleset()).toEqual([]);
188
- });
189
-
190
- it("clears skill entries", () => {
191
- const { session } = createSession();
192
- session.setActiveSkillEntries([makeSkillEntry("s")]);
193
-
194
- session.shutdown();
195
-
196
- expect(session.getActiveSkillEntries()).toEqual([]);
197
- });
198
-
199
- it("stops forwarding and deactivates context", () => {
200
- const { session, forwarding } = createSession();
201
- session.activate(makeCtx());
202
-
203
- session.shutdown();
204
-
205
- expect(forwarding.stop).toHaveBeenCalled();
206
- });
207
- });
208
-
209
- describe("skill entries", () => {
210
- it("get/set skill entries", () => {
211
- const { session } = createSession();
212
- const entries = [makeSkillEntry("a"), makeSkillEntry("b")];
213
- session.setActiveSkillEntries(entries);
214
- expect(session.getActiveSkillEntries()).toEqual(entries);
215
- });
216
- });
217
-
218
- describe("resolveAgentName", () => {
219
- it("returns name from session context", () => {
220
- mockGetActiveAgentName.mockReturnValue("ctx-agent");
221
- const { session } = createSession();
222
- const ctx = makeCtx();
223
-
224
- expect(session.resolveAgentName(ctx)).toBe("ctx-agent");
225
- });
226
-
227
- it("falls back to system prompt", () => {
228
- mockGetActiveAgentName.mockReturnValue(null);
229
- mockGetActiveAgentNameFromSystemPrompt.mockReturnValue("prompt-agent");
230
- const { session } = createSession();
231
- const ctx = makeCtx();
232
-
233
- expect(session.resolveAgentName(ctx, "system prompt")).toBe(
234
- "prompt-agent",
235
- );
236
- });
237
-
238
- it("falls back to last known name", () => {
239
- const { session } = createSession();
240
- const ctx = makeCtx();
241
-
242
- // First call sets name
243
- mockGetActiveAgentName.mockReturnValue("first-agent");
244
- session.resolveAgentName(ctx);
245
-
246
- // Second call with no name resolves to last known
247
- mockGetActiveAgentName.mockReturnValue(null);
248
- mockGetActiveAgentNameFromSystemPrompt.mockReturnValue(null);
249
- expect(session.resolveAgentName(ctx)).toBe("first-agent");
250
- });
251
-
252
- it("exposes lastKnownActiveAgentName", () => {
253
- const { session } = createSession();
254
- expect(session.lastKnownActiveAgentName).toBeNull();
255
-
256
- mockGetActiveAgentName.mockReturnValue("named");
257
- session.resolveAgentName(makeCtx());
258
- expect(session.lastKnownActiveAgentName).toBe("named");
259
- });
260
- });
261
-
262
- describe("infrastructure paths", () => {
263
- it("getInfrastructureReadDirs combines piInfrastructureDirs and piInfrastructureReadPaths", () => {
264
- const configStore = makeConfigStore({
265
- current: vi.fn().mockReturnValue({
266
- piInfrastructureReadPaths: ["/extra/path"],
267
- }),
268
- });
269
- const { session } = createSession({ configStore });
270
- expect(session.getInfrastructureReadDirs()).toEqual([
271
- "/test/agent",
272
- "/test/agent/git",
273
- "/extra/path",
274
- ]);
275
- });
276
-
277
- it("getInfrastructureReadDirs returns only piInfrastructureDirs when config omits the field", () => {
278
- const { session } = createSession();
279
- expect(session.getInfrastructureReadDirs()).toEqual([
280
- "/test/agent",
281
- "/test/agent/git",
282
- ]);
283
- });
284
- });
285
-
286
- describe("config delegation", () => {
287
- it("refreshConfig delegates to configStore.refresh", () => {
288
- const { session, configStore } = createSession();
289
- const ctx = makeCtx();
290
- session.refreshConfig(ctx);
291
- expect(configStore.refresh).toHaveBeenCalledWith(ctx);
292
- });
293
-
294
- it("logResolvedConfigPaths delegates to configStore.logResolvedPaths", () => {
295
- const { session, configStore } = createSession();
296
- session.logResolvedConfigPaths();
297
- expect(configStore.logResolvedPaths).toHaveBeenCalled();
298
- });
299
-
300
- it("config getter delegates to configStore.current()", () => {
301
- const fakeConfig = { debugLog: true } as typeof DEFAULT_EXTENSION_CONFIG;
302
- const configStore = makeConfigStore({
303
- current: vi.fn().mockReturnValue(fakeConfig),
304
- });
305
- const { session } = createSession({ configStore });
306
- expect(session.config).toBe(fakeConfig);
307
- });
308
-
309
- it("getToolPreviewLimits returns resolved preview limits from config", () => {
310
- const configStore = makeConfigStore({
311
- current: vi.fn().mockReturnValue({
312
- toolInputPreviewMaxLength: 400,
313
- toolTextSummaryMaxLength: 120,
314
- }),
315
- });
316
- const { session } = createSession({ configStore });
317
- const limits = session.getToolPreviewLimits();
318
- expect(limits.toolInputPreviewMaxLength).toBe(400);
319
- expect(limits.toolTextSummaryMaxLength).toBe(120);
320
- });
321
-
322
- it("getToolPreviewLimits falls back to built-in defaults when config omits fields", () => {
323
- const { session } = createSession();
324
- const limits = session.getToolPreviewLimits();
325
- expect(limits.toolInputPreviewMaxLength).toBeGreaterThan(0);
326
- expect(limits.toolTextSummaryMaxLength).toBeGreaterThan(0);
327
- expect(limits.toolInputLogPreviewMaxLength).toBeGreaterThan(0);
328
- });
329
- });
330
-
331
- describe("reload", () => {
332
- it("configures PermissionManager for current context cwd", () => {
333
- const pm = makePermissionManager();
334
- const { session } = createSession({ permissionManager: pm });
335
- const ctx = makeCtx({ cwd: "/project" });
336
- session.activate(ctx);
337
-
338
- session.reload();
339
-
340
- expect(pm.configureForCwd).toHaveBeenCalledWith("/project");
341
- });
342
-
343
- it("clears skill entries", () => {
344
- const { session } = createSession();
345
- session.setActiveSkillEntries([makeSkillEntry("s")]);
346
-
347
- session.reload();
348
-
349
- expect(session.getActiveSkillEntries()).toEqual([]);
350
- });
351
- });
352
-
353
- describe("getRuntimeContext", () => {
354
- it("returns null before activation", () => {
355
- const { session } = createSession();
356
- expect(session.getRuntimeContext()).toBeNull();
357
- });
358
-
359
- it("returns context after activation", () => {
360
- const { session } = createSession();
361
- const ctx = makeCtx();
362
- session.activate(ctx);
363
- expect(session.getRuntimeContext()).toBe(ctx);
364
- });
365
-
366
- it("returns null after deactivation", () => {
367
- const { session } = createSession();
368
- session.activate(makeCtx());
369
- session.deactivate();
370
- expect(session.getRuntimeContext()).toBeNull();
371
- });
372
- });
373
-
374
- describe("notify", () => {
375
- it("forwards the message to ctx.ui.notify with 'warning' severity after activation", () => {
376
- const { session } = createSession();
377
- const ctx = makeCtx();
378
- session.activate(ctx);
379
-
380
- session.notify("something went wrong");
381
-
382
- expect(ctx.ui.notify).toHaveBeenCalledOnce();
383
- expect(ctx.ui.notify).toHaveBeenCalledWith(
384
- "something went wrong",
385
- "warning",
386
- );
387
- });
388
-
389
- it("is a no-op and does not throw before activation", () => {
390
- const { session } = createSession();
391
-
392
- expect(() => session.notify("msg")).not.toThrow();
393
- });
394
-
395
- it("is a no-op and does not throw after deactivation", () => {
396
- const { session } = createSession();
397
- const ctx = makeCtx();
398
- session.activate(ctx);
399
- session.deactivate();
400
-
401
- expect(() => session.notify("msg")).not.toThrow();
402
- });
403
- });
404
- });
@@ -1,146 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import {
4
- buildDirectUiPrompt,
5
- buildForwardedUiPrompt,
6
- buildRpcUiPrompt,
7
- } from "#src/permission-ui-prompt";
8
-
9
- describe("buildDirectUiPrompt", () => {
10
- it("maps a tool_call prompt to the tool surface and command value", () => {
11
- expect(
12
- buildDirectUiPrompt({
13
- requestId: "req-1",
14
- source: "tool_call",
15
- agentName: "Explore",
16
- message: "Allow git push?",
17
- toolName: "bash",
18
- command: "git push",
19
- }),
20
- ).toEqual({
21
- requestId: "req-1",
22
- source: "tool_call",
23
- surface: "bash",
24
- value: "git push",
25
- agentName: "Explore",
26
- message: "Allow git push?",
27
- forwarding: null,
28
- });
29
- });
30
-
31
- it("normalizes a skill prompt to the skill surface and skill-name value", () => {
32
- expect(
33
- buildDirectUiPrompt({
34
- requestId: "req-2",
35
- source: "skill_input",
36
- agentName: null,
37
- message: "Allow skill?",
38
- skillName: "deploy-helper",
39
- }),
40
- ).toEqual({
41
- requestId: "req-2",
42
- source: "skill_input",
43
- surface: "skill",
44
- value: "deploy-helper",
45
- agentName: null,
46
- message: "Allow skill?",
47
- forwarding: null,
48
- });
49
- });
50
-
51
- it("derives value with command > path > target > skillName > toolName precedence", () => {
52
- expect(
53
- buildDirectUiPrompt({
54
- requestId: "req-3",
55
- source: "tool_call",
56
- agentName: null,
57
- message: "m",
58
- toolName: "read",
59
- path: "/etc/hosts",
60
- target: "ignored",
61
- }).value,
62
- ).toBe("/etc/hosts");
63
- });
64
- });
65
-
66
- describe("buildRpcUiPrompt", () => {
67
- it("maps an RPC prompt to the rpc_prompt source with passthrough surface/value", () => {
68
- expect(
69
- buildRpcUiPrompt({
70
- requestId: "req-rpc",
71
- surface: "bash",
72
- value: "git push",
73
- agentName: "Worker",
74
- message: "Allow git push?",
75
- }),
76
- ).toEqual({
77
- requestId: "req-rpc",
78
- source: "rpc_prompt",
79
- surface: "bash",
80
- value: "git push",
81
- agentName: "Worker",
82
- message: "Allow git push?",
83
- forwarding: null,
84
- });
85
- });
86
-
87
- it("defaults missing surface, value, and agentName to null", () => {
88
- expect(
89
- buildRpcUiPrompt({ requestId: "req-rpc-2", message: "Allow?" }),
90
- ).toEqual({
91
- requestId: "req-rpc-2",
92
- source: "rpc_prompt",
93
- surface: null,
94
- value: null,
95
- agentName: null,
96
- message: "Allow?",
97
- forwarding: null,
98
- });
99
- });
100
- });
101
-
102
- describe("buildForwardedUiPrompt", () => {
103
- it("populates forwarding context and carries the original source/surface/value", () => {
104
- expect(
105
- buildForwardedUiPrompt({
106
- requestId: "req-fwd",
107
- message: "Subagent 'Explore' requested permission.\n\nAllow git push?",
108
- requesterAgentName: "Explore",
109
- requesterSessionId: "child-session",
110
- source: "tool_call",
111
- surface: "bash",
112
- value: "git push",
113
- }),
114
- ).toEqual({
115
- requestId: "req-fwd",
116
- source: "tool_call",
117
- surface: "bash",
118
- value: "git push",
119
- agentName: "Explore",
120
- message: "Subagent 'Explore' requested permission.\n\nAllow git push?",
121
- forwarding: {
122
- requesterAgentName: "Explore",
123
- requesterSessionId: "child-session",
124
- },
125
- });
126
- });
127
-
128
- it("falls back to source tool_call with null surface/value when the request omits them", () => {
129
- expect(
130
- buildForwardedUiPrompt({
131
- requestId: "req-fwd-old",
132
- message: "Allow?",
133
- requesterAgentName: null,
134
- requesterSessionId: null,
135
- }),
136
- ).toEqual({
137
- requestId: "req-fwd-old",
138
- source: "tool_call",
139
- surface: null,
140
- value: null,
141
- agentName: null,
142
- message: "Allow?",
143
- forwarding: { requesterAgentName: null, requesterSessionId: null },
144
- });
145
- });
146
- });