@gotgenes/pi-permission-system 18.1.1 → 18.2.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 (133) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/docs/configuration.md +11 -0
  3. package/package.json +1 -2
  4. package/src/access-intent/access-path.ts +29 -4
  5. package/src/access-intent/bash/bash-path-resolver.ts +39 -18
  6. package/src/access-intent/bash/msys-bash-tokens.ts +64 -0
  7. package/src/extension-config.ts +7 -0
  8. package/src/forwarded-permissions/permission-forwarder.ts +6 -3
  9. package/src/handlers/gates/helpers.ts +1 -1
  10. package/src/handlers/gates/runner.ts +22 -0
  11. package/src/index.ts +10 -6
  12. package/src/path-normalizer.ts +105 -2
  13. package/src/permission-manager.ts +21 -1
  14. package/src/permission-prompter.ts +10 -16
  15. package/src/prompting-gateway.ts +13 -17
  16. package/src/rule.ts +21 -1
  17. package/src/status.ts +1 -1
  18. package/src/yolo-mode.ts +0 -30
  19. package/test/access-intent/access-path.test.ts +0 -277
  20. package/test/access-intent/bash/node-text.test.ts +0 -148
  21. package/test/access-intent/bash/parser.test.ts +0 -19
  22. package/test/access-intent/bash/program.test.ts +0 -673
  23. package/test/access-intent/bash/token-classification.test.ts +0 -363
  24. package/test/access-intent/bash/token-collection.test.ts +0 -300
  25. package/test/active-agent.test.ts +0 -155
  26. package/test/async-cache.test.ts +0 -48
  27. package/test/bash-arity.test.ts +0 -144
  28. package/test/bash-external-directory.test.ts +0 -1022
  29. package/test/builtin-tool-input-formatters.test.ts +0 -109
  30. package/test/canonicalize-path.test.ts +0 -119
  31. package/test/composition-root.test.ts +0 -698
  32. package/test/config-loader.test.ts +0 -740
  33. package/test/config-modal.test.ts +0 -320
  34. package/test/config-paths.test.ts +0 -83
  35. package/test/config-pipeline.test.ts +0 -90
  36. package/test/config-reporter.test.ts +0 -147
  37. package/test/config-store.test.ts +0 -466
  38. package/test/decision-audit.test.ts +0 -72
  39. package/test/decision-reporter.test.ts +0 -112
  40. package/test/denial-messages.test.ts +0 -714
  41. package/test/detect-permissive-bash-fallback.test.ts +0 -56
  42. package/test/expand-home.test.ts +0 -93
  43. package/test/extension-config.test.ts +0 -129
  44. package/test/extension-paths.test.ts +0 -108
  45. package/test/forwarded-permissions/io.test.ts +0 -251
  46. package/test/forwarding-manager.test.ts +0 -200
  47. package/test/handlers/before-agent-start.test.ts +0 -314
  48. package/test/handlers/external-directory-integration.test.ts +0 -515
  49. package/test/handlers/external-directory-session-dedup.test.ts +0 -175
  50. package/test/handlers/external-directory-symlink-acceptance.test.ts +0 -167
  51. package/test/handlers/gates/bash-command-metamorphic.test.ts +0 -88
  52. package/test/handlers/gates/bash-command.test.ts +0 -257
  53. package/test/handlers/gates/bash-external-directory.test.ts +0 -268
  54. package/test/handlers/gates/bash-path.test.ts +0 -346
  55. package/test/handlers/gates/candidate-check.test.ts +0 -52
  56. package/test/handlers/gates/external-directory-messages.test.ts +0 -85
  57. package/test/handlers/gates/external-directory-policy.test.ts +0 -134
  58. package/test/handlers/gates/external-directory.test.ts +0 -267
  59. package/test/handlers/gates/helpers.test.ts +0 -165
  60. package/test/handlers/gates/path.test.ts +0 -369
  61. package/test/handlers/gates/runner.test.ts +0 -408
  62. package/test/handlers/gates/skill-input-gate-pipeline.test.ts +0 -176
  63. package/test/handlers/gates/skill-input.test.ts +0 -128
  64. package/test/handlers/gates/skill-read.test.ts +0 -161
  65. package/test/handlers/gates/tool-call-gate-pipeline.test.ts +0 -356
  66. package/test/handlers/gates/tool.test.ts +0 -244
  67. package/test/handlers/input-events.test.ts +0 -168
  68. package/test/handlers/input.test.ts +0 -199
  69. package/test/handlers/lifecycle.test.ts +0 -221
  70. package/test/handlers/tool-call-boundary.test.ts +0 -145
  71. package/test/handlers/tool-call-events.test.ts +0 -277
  72. package/test/handlers/tool-call.test.ts +0 -395
  73. package/test/handlers/validate-requested-tool.test.ts +0 -92
  74. package/test/helpers/external-directory-fixtures.ts +0 -269
  75. package/test/helpers/gate-fixtures.ts +0 -316
  76. package/test/helpers/handler-fixtures.ts +0 -335
  77. package/test/helpers/make-fake-pi.ts +0 -100
  78. package/test/helpers/manager-harness.ts +0 -112
  79. package/test/helpers/session-fixtures.ts +0 -199
  80. package/test/input-normalizer.test.ts +0 -325
  81. package/test/logging.test.ts +0 -51
  82. package/test/mcp-targets.test.ts +0 -233
  83. package/test/node-modules-discovery.test.ts +0 -97
  84. package/test/normalize.test.ts +0 -247
  85. package/test/path-containment.test.ts +0 -161
  86. package/test/path-normalization.test.ts +0 -233
  87. package/test/path-normalizer.test.ts +0 -196
  88. package/test/path-surfaces.test.ts +0 -55
  89. package/test/pattern-suggest.test.ts +0 -248
  90. package/test/permission-dialog.test.ts +0 -205
  91. package/test/permission-event-rpc.test.ts +0 -560
  92. package/test/permission-events.test.ts +0 -400
  93. package/test/permission-forwarder.test.ts +0 -370
  94. package/test/permission-forwarding.test.ts +0 -315
  95. package/test/permission-gate.test.ts +0 -269
  96. package/test/permission-manager-unified.test.ts +0 -3714
  97. package/test/permission-merge.test.ts +0 -61
  98. package/test/permission-prompter.test.ts +0 -518
  99. package/test/permission-prompts.test.ts +0 -363
  100. package/test/permission-resolver.test.ts +0 -277
  101. package/test/permission-session.test.ts +0 -404
  102. package/test/permission-ui-prompt.test.ts +0 -146
  103. package/test/permissions-service.test.ts +0 -192
  104. package/test/pi-infrastructure-read.test.ts +0 -432
  105. package/test/policy-loader.test.ts +0 -561
  106. package/test/prompting-gateway.test.ts +0 -231
  107. package/test/rule.test.ts +0 -650
  108. package/test/safe-system-paths.test.ts +0 -46
  109. package/test/scope-merge.test.ts +0 -116
  110. package/test/service-lifecycle.test.ts +0 -163
  111. package/test/service.test.ts +0 -261
  112. package/test/session-approval.test.ts +0 -75
  113. package/test/session-logger.test.ts +0 -200
  114. package/test/session-rules.test.ts +0 -321
  115. package/test/session-start.test.ts +0 -112
  116. package/test/skill-prompt-sanitizer.test.ts +0 -418
  117. package/test/status.test.ts +0 -10
  118. package/test/subagent-context.test.ts +0 -372
  119. package/test/subagent-lifecycle-events.test.ts +0 -132
  120. package/test/subagent-registry.test.ts +0 -145
  121. package/test/synthesize.test.ts +0 -302
  122. package/test/system-prompt-sanitizer.test.ts +0 -382
  123. package/test/tool-access-extractor-registry.test.ts +0 -77
  124. package/test/tool-input-formatter-registry.test.ts +0 -75
  125. package/test/tool-input-path.test.ts +0 -84
  126. package/test/tool-input-preview.test.ts +0 -129
  127. package/test/tool-input-prompt-formatters.test.ts +0 -115
  128. package/test/tool-preview-formatter.test.ts +0 -458
  129. package/test/tool-registry.test.ts +0 -197
  130. package/test/value-guards.test.ts +0 -193
  131. package/test/wildcard-matcher.test.ts +0 -424
  132. package/test/yaml-frontmatter.test.ts +0 -91
  133. package/test/yolo-mode.test.ts +0 -188
@@ -1,77 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
-
3
- import {
4
- type ToolAccessExtractor,
5
- ToolAccessExtractorRegistry,
6
- } from "#src/tool-access-extractor-registry";
7
-
8
- const noopExtractor: ToolAccessExtractor = () => "/tmp/x";
9
-
10
- describe("ToolAccessExtractorRegistry", () => {
11
- describe("register", () => {
12
- test("stores an extractor so get() returns it", () => {
13
- const registry = new ToolAccessExtractorRegistry();
14
- registry.register("my-tool", noopExtractor);
15
- expect(registry.get("my-tool")).toBe(noopExtractor);
16
- });
17
-
18
- test("returns a disposer that removes the extractor", () => {
19
- const registry = new ToolAccessExtractorRegistry();
20
- const dispose = registry.register("my-tool", noopExtractor);
21
- dispose();
22
- expect(registry.get("my-tool")).toBeUndefined();
23
- });
24
-
25
- test("throws when an extractor is already registered for the same tool name", () => {
26
- const registry = new ToolAccessExtractorRegistry();
27
- registry.register("my-tool", noopExtractor);
28
- expect(() => registry.register("my-tool", () => undefined)).toThrow(
29
- "my-tool",
30
- );
31
- });
32
-
33
- test("allows registering different tool names independently", () => {
34
- const registry = new ToolAccessExtractorRegistry();
35
- const extractorA: ToolAccessExtractor = () => "/a";
36
- const extractorB: ToolAccessExtractor = () => "/b";
37
- registry.register("tool-a", extractorA);
38
- registry.register("tool-b", extractorB);
39
- expect(registry.get("tool-a")).toBe(extractorA);
40
- expect(registry.get("tool-b")).toBe(extractorB);
41
- });
42
- });
43
-
44
- describe("disposer identity guard", () => {
45
- test("stale disposer does not evict a later registration", () => {
46
- const registry = new ToolAccessExtractorRegistry();
47
- const first: ToolAccessExtractor = () => "/first";
48
- const second: ToolAccessExtractor = () => "/second";
49
-
50
- const disposeFirst = registry.register("my-tool", first);
51
- disposeFirst(); // removes first
52
-
53
- registry.register("my-tool", second); // second registration is now valid
54
- disposeFirst(); // calling stale disposer again — must not remove second
55
-
56
- expect(registry.get("my-tool")).toBe(second);
57
- });
58
- });
59
-
60
- describe("get", () => {
61
- test("returns undefined for an unregistered tool name", () => {
62
- const registry = new ToolAccessExtractorRegistry();
63
- expect(registry.get("unknown")).toBeUndefined();
64
- });
65
-
66
- test("the registered extractor is callable and returns its path", () => {
67
- const registry = new ToolAccessExtractorRegistry();
68
- const extractor: ToolAccessExtractor = (input) =>
69
- typeof input.target === "string" ? input.target : undefined;
70
- registry.register("ffgrep", extractor);
71
- expect(registry.get("ffgrep")?.({ target: "/etc/hosts" })).toBe(
72
- "/etc/hosts",
73
- );
74
- expect(registry.get("ffgrep")?.({ other: true })).toBeUndefined();
75
- });
76
- });
77
- });
@@ -1,75 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
-
3
- import {
4
- type ToolInputFormatter,
5
- ToolInputFormatterRegistry,
6
- } from "#src/tool-input-formatter-registry";
7
-
8
- const noopFormatter: ToolInputFormatter = () => "preview";
9
-
10
- describe("ToolInputFormatterRegistry", () => {
11
- describe("register", () => {
12
- test("stores a formatter so get() returns it", () => {
13
- const registry = new ToolInputFormatterRegistry();
14
- registry.register("my-tool", noopFormatter);
15
- expect(registry.get("my-tool")).toBe(noopFormatter);
16
- });
17
-
18
- test("returns a disposer that removes the formatter", () => {
19
- const registry = new ToolInputFormatterRegistry();
20
- const dispose = registry.register("my-tool", noopFormatter);
21
- dispose();
22
- expect(registry.get("my-tool")).toBeUndefined();
23
- });
24
-
25
- test("throws when a formatter is already registered for the same tool name", () => {
26
- const registry = new ToolInputFormatterRegistry();
27
- registry.register("my-tool", noopFormatter);
28
- expect(() => registry.register("my-tool", () => undefined)).toThrow(
29
- "my-tool",
30
- );
31
- });
32
-
33
- test("allows registering different tool names independently", () => {
34
- const registry = new ToolInputFormatterRegistry();
35
- const formatterA: ToolInputFormatter = () => "a";
36
- const formatterB: ToolInputFormatter = () => "b";
37
- registry.register("tool-a", formatterA);
38
- registry.register("tool-b", formatterB);
39
- expect(registry.get("tool-a")).toBe(formatterA);
40
- expect(registry.get("tool-b")).toBe(formatterB);
41
- });
42
- });
43
-
44
- describe("disposer identity guard", () => {
45
- test("stale disposer does not evict a later registration", () => {
46
- const registry = new ToolInputFormatterRegistry();
47
- const first: ToolInputFormatter = () => "first";
48
- const second: ToolInputFormatter = () => "second";
49
-
50
- const disposeFirst = registry.register("my-tool", first);
51
- disposeFirst(); // removes first
52
-
53
- registry.register("my-tool", second); // second registration is now valid
54
- disposeFirst(); // calling stale disposer again — must not remove second
55
-
56
- expect(registry.get("my-tool")).toBe(second);
57
- });
58
- });
59
-
60
- describe("get", () => {
61
- test("returns undefined for an unregistered tool name", () => {
62
- const registry = new ToolInputFormatterRegistry();
63
- expect(registry.get("unknown")).toBeUndefined();
64
- });
65
-
66
- test("the registered formatter is callable and returns its result", () => {
67
- const registry = new ToolInputFormatterRegistry();
68
- const fmt: ToolInputFormatter = (input) =>
69
- typeof input.cmd === "string" ? `runs ${input.cmd}` : undefined;
70
- registry.register("run", fmt);
71
- expect(registry.get("run")?.({ cmd: "ls" })).toBe("runs ls");
72
- expect(registry.get("run")?.({ other: true })).toBeUndefined();
73
- });
74
- });
75
- });
@@ -1,84 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import type { ToolAccessExtractorLookup } from "#src/tool-access-extractor-registry";
3
- import { getPathBearingToolPath, getToolInputPath } from "#src/tool-input-path";
4
-
5
- describe("getPathBearingToolPath", () => {
6
- test("returns path for a path-bearing tool", () => {
7
- expect(getPathBearingToolPath("read", { path: "/src/foo.ts" })).toBe(
8
- "/src/foo.ts",
9
- );
10
- });
11
-
12
- test("returns null for a non-path-bearing tool", () => {
13
- expect(getPathBearingToolPath("bash", { path: "/src/foo.ts" })).toBeNull();
14
- expect(getPathBearingToolPath("mcp", { path: "/src/foo.ts" })).toBeNull();
15
- expect(getPathBearingToolPath("task", { path: "/src/foo.ts" })).toBeNull();
16
- });
17
-
18
- test("returns null when input has no path", () => {
19
- expect(getPathBearingToolPath("read", {})).toBeNull();
20
- expect(getPathBearingToolPath("read", { path: "" })).toBeNull();
21
- expect(getPathBearingToolPath("read", null)).toBeNull();
22
- });
23
- });
24
-
25
- describe("getToolInputPath", () => {
26
- function lookupOf(
27
- toolName: string,
28
- extractor: (input: Record<string, unknown>) => string | undefined,
29
- ): ToolAccessExtractorLookup {
30
- return {
31
- get: (name) => (name === toolName ? extractor : undefined),
32
- };
33
- }
34
-
35
- test("returns input.path for a built-in path-bearing tool", () => {
36
- expect(getToolInputPath("read", { path: "/src/foo.ts" })).toBe(
37
- "/src/foo.ts",
38
- );
39
- expect(getToolInputPath("write", { path: "/src/bar.ts" })).toBe(
40
- "/src/bar.ts",
41
- );
42
- });
43
-
44
- test("returns null for bash", () => {
45
- expect(getToolInputPath("bash", { path: "/src/foo.ts" })).toBeNull();
46
- });
47
-
48
- test("returns the MCP arguments.path for an mcp call", () => {
49
- expect(getToolInputPath("mcp", { arguments: { path: "/etc/hosts" } })).toBe(
50
- "/etc/hosts",
51
- );
52
- });
53
-
54
- test("returns null for an mcp call without an arguments.path", () => {
55
- expect(getToolInputPath("mcp", { arguments: { query: "x" } })).toBeNull();
56
- expect(getToolInputPath("mcp", {})).toBeNull();
57
- });
58
-
59
- test("defaults to input.path for an unregistered extension tool", () => {
60
- expect(getToolInputPath("my-ext", { path: "/work/file.txt" })).toBe(
61
- "/work/file.txt",
62
- );
63
- });
64
-
65
- test("returns null for an extension tool without a path", () => {
66
- expect(getToolInputPath("my-ext", { other: true })).toBeNull();
67
- expect(getToolInputPath("my-ext", { path: "" })).toBeNull();
68
- expect(getToolInputPath("my-ext", null)).toBeNull();
69
- });
70
-
71
- test("uses a registered extractor's path over the default convention", () => {
72
- const extractors = lookupOf("ffgrep", (input) =>
73
- typeof input.target === "string" ? input.target : undefined,
74
- );
75
- expect(
76
- getToolInputPath("ffgrep", { target: "/etc/passwd" }, extractors),
77
- ).toBe("/etc/passwd");
78
- });
79
-
80
- test("returns null when a registered extractor declines", () => {
81
- const extractors = lookupOf("ffgrep", () => undefined);
82
- expect(getToolInputPath("ffgrep", { target: "x" }, extractors)).toBeNull();
83
- });
84
- });
@@ -1,129 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
-
3
- // Mock logging collaborator before importing the module under test.
4
- vi.mock("../src/logging.js", () => ({
5
- safeJsonStringify: vi.fn((value: unknown) => JSON.stringify(value)),
6
- }));
7
-
8
- import { safeJsonStringify } from "#src/logging";
9
- import {
10
- countTextLines,
11
- formatCount,
12
- serializeToolInputPreview,
13
- TOOL_INPUT_LOG_PREVIEW_MAX_LENGTH,
14
- TOOL_INPUT_PREVIEW_MAX_LENGTH,
15
- TOOL_TEXT_SUMMARY_MAX_LENGTH,
16
- truncateInlineText,
17
- } from "#src/tool-input-preview";
18
-
19
- const mockedStringify = vi.mocked(safeJsonStringify);
20
-
21
- beforeEach(() => {
22
- mockedStringify.mockReset();
23
- });
24
-
25
- afterEach(() => {
26
- vi.restoreAllMocks();
27
- });
28
-
29
- describe("constants", () => {
30
- test("TOOL_INPUT_PREVIEW_MAX_LENGTH is 200", () => {
31
- expect(TOOL_INPUT_PREVIEW_MAX_LENGTH).toBe(200);
32
- });
33
-
34
- test("TOOL_INPUT_LOG_PREVIEW_MAX_LENGTH is 1000", () => {
35
- expect(TOOL_INPUT_LOG_PREVIEW_MAX_LENGTH).toBe(1000);
36
- });
37
-
38
- test("TOOL_TEXT_SUMMARY_MAX_LENGTH is 80", () => {
39
- expect(TOOL_TEXT_SUMMARY_MAX_LENGTH).toBe(80);
40
- });
41
- });
42
-
43
- describe("truncateInlineText", () => {
44
- test("returns text unchanged when within maxLength", () => {
45
- expect(truncateInlineText("hello", 10)).toBe("hello");
46
- });
47
-
48
- test("does not truncate when length equals maxLength", () => {
49
- const text = "a".repeat(200);
50
- expect(truncateInlineText(text, 200)).toBe(text);
51
- });
52
-
53
- test("truncates and appends ellipsis when length exceeds maxLength", () => {
54
- const text = "a".repeat(201);
55
- const result = truncateInlineText(text, 200);
56
- expect(result).toBe(`${"a".repeat(200)}…`);
57
- });
58
-
59
- test("truncates long text and appends ellipsis", () => {
60
- const result = truncateInlineText("abcdef", 3);
61
- expect(result).toBe("abc…");
62
- });
63
- });
64
-
65
- describe("countTextLines", () => {
66
- test("returns 0 for empty string", () => {
67
- expect(countTextLines("")).toBe(0);
68
- });
69
-
70
- test("returns 1 for a single line with no newline", () => {
71
- expect(countTextLines("hello")).toBe(1);
72
- });
73
-
74
- test("counts LF-separated lines", () => {
75
- expect(countTextLines("line1\nline2\nline3")).toBe(3);
76
- });
77
-
78
- test("counts CRLF-separated lines", () => {
79
- expect(countTextLines("line1\r\nline2")).toBe(2);
80
- });
81
-
82
- test("counts CR-separated lines", () => {
83
- expect(countTextLines("line1\rline2")).toBe(2);
84
- });
85
- });
86
-
87
- describe("formatCount", () => {
88
- test("uses singular form for 1", () => {
89
- expect(formatCount(1, "line", "lines")).toBe("1 line");
90
- });
91
-
92
- test("uses plural form for 0", () => {
93
- expect(formatCount(0, "line", "lines")).toBe("0 lines");
94
- });
95
-
96
- test("uses plural form for 2+", () => {
97
- expect(formatCount(3, "line", "lines")).toBe("3 lines");
98
- });
99
- });
100
-
101
- describe("serializeToolInputPreview", () => {
102
- test("delegates serialization to safeJsonStringify", () => {
103
- mockedStringify.mockReturnValue('{"key":"value"}');
104
- const result = serializeToolInputPreview({ key: "value" });
105
- expect(mockedStringify).toHaveBeenCalledWith({ key: "value" });
106
- expect(result).toBe('{"key":"value"}');
107
- });
108
-
109
- test("returns empty string when safeJsonStringify returns undefined", () => {
110
- mockedStringify.mockReturnValue(undefined);
111
- expect(serializeToolInputPreview({})).toBe("");
112
- });
113
-
114
- test("returns empty string when serialized value is '{}'", () => {
115
- mockedStringify.mockReturnValue("{}");
116
- expect(serializeToolInputPreview({})).toBe("");
117
- });
118
-
119
- test("returns empty string when serialized value is 'null'", () => {
120
- mockedStringify.mockReturnValue("null");
121
- expect(serializeToolInputPreview(null)).toBe("");
122
- });
123
-
124
- test("collapses whitespace in serialized output", () => {
125
- mockedStringify.mockReturnValue('{\n "key": "val"\n}');
126
- const result = serializeToolInputPreview({});
127
- expect(result).toBe('{ "key": "val" }');
128
- });
129
- });
@@ -1,115 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
-
3
- import {
4
- formatEditInputForPrompt,
5
- formatReadInputForPrompt,
6
- formatWriteInputForPrompt,
7
- getPromptPath,
8
- } from "#src/tool-input-prompt-formatters";
9
-
10
- describe("getPromptPath", () => {
11
- test("returns path from 'path' key", () => {
12
- expect(getPromptPath({ path: "/foo/bar" })).toBe("/foo/bar");
13
- });
14
-
15
- test("falls back to 'file_path' key", () => {
16
- expect(getPromptPath({ file_path: "/baz" })).toBe("/baz");
17
- });
18
-
19
- test("returns null when neither key is present", () => {
20
- expect(getPromptPath({})).toBeNull();
21
- });
22
-
23
- test("returns null when path is empty string", () => {
24
- expect(getPromptPath({ path: "" })).toBeNull();
25
- });
26
- });
27
-
28
- describe("formatEditInputForPrompt", () => {
29
- test("returns path-only description when no edits provided", () => {
30
- const result = formatEditInputForPrompt({ path: "/foo.ts" });
31
- expect(result).toBe("for '/foo.ts' with edit input");
32
- });
33
-
34
- test("formats single replacement with line counts", () => {
35
- const result = formatEditInputForPrompt({
36
- path: "/foo.ts",
37
- edits: [{ oldText: "line1\nline2", newText: "replaced" }],
38
- });
39
- expect(result).toContain("for '/foo.ts'");
40
- expect(result).toContain("1 replacement");
41
- expect(result).toContain("2 lines");
42
- expect(result).toContain("1 line");
43
- });
44
-
45
- test("formats multiple replacements mentioning additional edits", () => {
46
- const result = formatEditInputForPrompt({
47
- path: "/foo.ts",
48
- edits: [
49
- { oldText: "a", newText: "b" },
50
- { oldText: "c", newText: "d" },
51
- { oldText: "e", newText: "f" },
52
- ],
53
- });
54
- expect(result).toContain("3 replacements");
55
- expect(result).toContain("2 additional edits");
56
- });
57
-
58
- test("falls back to oldText/newText when no edits array", () => {
59
- const result = formatEditInputForPrompt({
60
- path: "/bar.ts",
61
- oldText: "old",
62
- newText: "new",
63
- });
64
- expect(result).toContain("for '/bar.ts'");
65
- expect(result).toContain("1 replacement");
66
- });
67
-
68
- test("works without a path", () => {
69
- const result = formatEditInputForPrompt({
70
- edits: [{ oldText: "x", newText: "y" }],
71
- });
72
- expect(result).not.toContain("for '");
73
- expect(result).toContain("1 replacement");
74
- });
75
- });
76
-
77
- describe("formatWriteInputForPrompt", () => {
78
- test("includes path, line count, and character count", () => {
79
- const result = formatWriteInputForPrompt({
80
- path: "/out.ts",
81
- content: "line1\nline2",
82
- });
83
- expect(result).toContain("for '/out.ts'");
84
- expect(result).toContain("2 lines");
85
- expect(result).toContain("11 characters");
86
- });
87
-
88
- test("handles missing content as empty", () => {
89
- const result = formatWriteInputForPrompt({ path: "/out.ts" });
90
- expect(result).toContain("0 lines");
91
- expect(result).toContain("0 characters");
92
- });
93
- });
94
-
95
- describe("formatReadInputForPrompt", () => {
96
- test("includes path", () => {
97
- expect(formatReadInputForPrompt({ path: "/src/foo.ts" })).toBe(
98
- "for path '/src/foo.ts'",
99
- );
100
- });
101
-
102
- test("includes offset and limit when present", () => {
103
- const result = formatReadInputForPrompt({
104
- path: "/x",
105
- offset: 10,
106
- limit: 50,
107
- });
108
- expect(result).toContain("offset 10");
109
- expect(result).toContain("limit 50");
110
- });
111
-
112
- test("returns empty string when no path and no options", () => {
113
- expect(formatReadInputForPrompt({})).toBe("");
114
- });
115
- });