@criogaid/pi-hashline-edit 0.13.0 → 0.15.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 (152) hide show
  1. package/README.md +18 -12
  2. package/README.zh-CN.md +18 -12
  3. package/package.json +8 -1
  4. package/src/core/AGENTS.md +3 -1
  5. package/src/core/apply.ts +110 -117
  6. package/src/core/character-set.ts +2 -3
  7. package/src/core/copy-span.ts +15 -0
  8. package/src/core/errors.ts +24 -9
  9. package/src/core/lines.ts +71 -17
  10. package/src/core/ranges.ts +5 -4
  11. package/src/core/replace-schema.ts +3 -1
  12. package/src/core/replace.ts +50 -29
  13. package/src/core/search-analysis.ts +21 -22
  14. package/src/core/search.ts +15 -32
  15. package/src/core/types.ts +3 -0
  16. package/src/index.ts +47 -39
  17. package/src/pi/AGENTS.md +30 -19
  18. package/src/pi/action-fusion.ts +284 -211
  19. package/src/pi/argument-diagnostics.ts +50 -37
  20. package/src/pi/argument-error.ts +2 -2
  21. package/src/pi/argument-validation.ts +163 -66
  22. package/src/pi/budgets.ts +12 -0
  23. package/src/pi/diagnostic-buffer.ts +12 -11
  24. package/src/pi/edit-tool.ts +138 -115
  25. package/src/pi/error-text.ts +10 -2
  26. package/src/pi/failure-context.ts +24 -37
  27. package/src/pi/file-commit.ts +131 -164
  28. package/src/pi/file-read.ts +122 -31
  29. package/src/pi/fusion-arguments.ts +214 -0
  30. package/src/pi/fusion-card.ts +102 -60
  31. package/src/pi/grep-candidates.ts +35 -22
  32. package/src/pi/grep-output.ts +197 -190
  33. package/src/pi/grep-render.ts +22 -13
  34. package/src/pi/grep-reread.ts +7 -6
  35. package/src/pi/grep-scope.ts +31 -16
  36. package/src/pi/grep-search.ts +56 -47
  37. package/src/pi/grep-tool.ts +35 -33
  38. package/src/pi/grep-worker.ts +3 -4
  39. package/src/pi/mutation-diff.ts +238 -0
  40. package/src/pi/mutation-result.ts +102 -79
  41. package/src/pi/mutation-runner.ts +107 -84
  42. package/src/pi/native-bash.ts +41 -0
  43. package/src/pi/path.ts +59 -6
  44. package/src/pi/read-tool.ts +173 -138
  45. package/src/pi/regex-worker.ts +14 -8
  46. package/src/pi/render.ts +101 -54
  47. package/src/pi/replace-regex.ts +1 -1
  48. package/src/pi/replace-tool.ts +14 -7
  49. package/src/pi/report-cause.ts +34 -17
  50. package/src/pi/report-schema.ts +184 -85
  51. package/src/pi/report.ts +133 -64
  52. package/src/pi/rg-process.ts +68 -48
  53. package/src/pi/schema.ts +4 -0
  54. package/src/pi/text-stream.ts +81 -87
  55. package/src/pi/workspace-cwd.js +2 -0
  56. package/src/pi/workspace.ts +46 -0
  57. package/src/pi/write-tool.ts +19 -13
  58. package/src/core/apply.test.ts +0 -644
  59. package/src/core/case-fold.test.ts +0 -35
  60. package/src/core/character-set.test.ts +0 -97
  61. package/src/core/errors.test.ts +0 -39
  62. package/src/core/hash.test.ts +0 -64
  63. package/src/core/lines.test.ts +0 -63
  64. package/src/core/ranges.test.ts +0 -123
  65. package/src/core/replace.test.ts +0 -187
  66. package/src/core/search-analysis.test.ts +0 -210
  67. package/src/core/search-matrix.test.ts +0 -64
  68. package/src/core/search-matrix.testing.ts +0 -171
  69. package/src/core/search.test.ts +0 -132
  70. package/src/core/text.test.ts +0 -52
  71. package/src/integration/config-registration.test.ts +0 -291
  72. package/src/integration/fusion-dispatch.test.ts +0 -320
  73. package/src/integration/grep-errors.test.ts +0 -81
  74. package/src/integration/grep-flags.test.ts +0 -76
  75. package/src/integration/grep-js-completeness.test.ts +0 -278
  76. package/src/integration/grep-line-candidates.test.ts +0 -201
  77. package/src/integration/grep-matrix.test.ts +0 -118
  78. package/src/integration/grep-order.test.ts +0 -78
  79. package/src/integration/grep-path-matrix.test.ts +0 -128
  80. package/src/integration/grep-prefilter-coverage.test.ts +0 -204
  81. package/src/integration/grep-process-limits.test.ts +0 -122
  82. package/src/integration/grep-regex.test.ts +0 -412
  83. package/src/integration/grep-rg.test.ts +0 -1659
  84. package/src/integration/grep-scan-budget.test.ts +0 -111
  85. package/src/integration/grep-translation.test.ts +0 -199
  86. package/src/integration/large-text.test.ts +0 -70
  87. package/src/integration/model-budget-lifecycle.test.ts +0 -186
  88. package/src/integration/mutation-file-types.test.ts +0 -30
  89. package/src/integration/mutation-file-types.testing.ts +0 -33
  90. package/src/integration/npm-package.test.ts +0 -19
  91. package/src/integration/npm-package.testing.ts +0 -243
  92. package/src/integration/publication-read-changes.test.ts +0 -454
  93. package/src/integration/read-changes.test.ts +0 -98
  94. package/src/integration/replace-package.test.ts +0 -22
  95. package/src/integration/replace-package.testing.ts +0 -36
  96. package/src/integration/replace-worker-boundary.test.ts +0 -127
  97. package/src/integration/report-replay.test.ts +0 -91
  98. package/src/integration/utf8-errors.test.ts +0 -46
  99. package/src/pi/action-fusion.test.ts +0 -659
  100. package/src/pi/action-fusion.testing.ts +0 -38
  101. package/src/pi/anchor-format.test.ts +0 -124
  102. package/src/pi/argument-error.testing.ts +0 -46
  103. package/src/pi/argument-format.test.ts +0 -196
  104. package/src/pi/argument-validation.test.ts +0 -1007
  105. package/src/pi/codemode.test.ts +0 -101
  106. package/src/pi/config.test.ts +0 -204
  107. package/src/pi/diagnostic-buffer.test.ts +0 -115
  108. package/src/pi/directory-sync.test.ts +0 -57
  109. package/src/pi/execute.test.ts +0 -1257
  110. package/src/pi/extension-loading.test.ts +0 -14
  111. package/src/pi/extension-loading.testing.ts +0 -3
  112. package/src/pi/failure-context.test.ts +0 -370
  113. package/src/pi/failure-path.test.ts +0 -289
  114. package/src/pi/file-commit.test.ts +0 -628
  115. package/src/pi/file-read.test.ts +0 -29
  116. package/src/pi/file-snapshot.test.ts +0 -22
  117. package/src/pi/fusion-card-interaction.test.ts +0 -143
  118. package/src/pi/fusion-card.test.ts +0 -353
  119. package/src/pi/grep-candidates.test.ts +0 -26
  120. package/src/pi/grep-matrix.test.ts +0 -68
  121. package/src/pi/grep-order.test.ts +0 -447
  122. package/src/pi/grep-output.testing.ts +0 -24
  123. package/src/pi/grep-rg.testing.ts +0 -73
  124. package/src/pi/grep.test.ts +0 -1670
  125. package/src/pi/model-budgets.test.ts +0 -96
  126. package/src/pi/mutation-outcome.testing.ts +0 -20
  127. package/src/pi/mutation-result.test.ts +0 -96
  128. package/src/pi/output-budgets.test.ts +0 -221
  129. package/src/pi/pi.test.ts +0 -158
  130. package/src/pi/read-delegation.test.ts +0 -119
  131. package/src/pi/read.test.ts +0 -735
  132. package/src/pi/regex-worker.test.ts +0 -42
  133. package/src/pi/registration.test.ts +0 -549
  134. package/src/pi/render.test.ts +0 -841
  135. package/src/pi/replace.test.ts +0 -634
  136. package/src/pi/report-failure.testing.ts +0 -27
  137. package/src/pi/report.test.ts +0 -533
  138. package/src/pi/result-safety.test.ts +0 -597
  139. package/src/pi/rg-process.test.ts +0 -133
  140. package/src/pi/rg-regex.test.ts +0 -40
  141. package/src/pi/text-stream.test.ts +0 -281
  142. package/src/pi/tool-call.testing.ts +0 -61
  143. package/src/pi/tool-factories.testing.ts +0 -59
  144. package/src/pi/write.test.ts +0 -256
  145. package/src/testing/extension-loader.testing.ts +0 -24
  146. package/src/testing/installation.testing.ts +0 -77
  147. package/src/testing/process.testing.ts +0 -33
  148. package/src/testing/regex-host.testing.ts +0 -20
  149. package/src/testing/regex-translation-corpus.ts +0 -267
  150. package/src/testing/rg-line-listing.fixture.mjs +0 -7
  151. package/src/testing/run-tests.ts +0 -47
  152. package/src/testing/session.testing.ts +0 -127
@@ -1,47 +0,0 @@
1
- /** Keep npm's test entry points independent of personal Pi settings and Node loaders. */
2
- import { spawnSync } from "node:child_process";
3
- import { mkdtempSync, rmSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
- import { fileURLToPath } from "node:url";
7
- import { testEnvironment } from "./process.testing.ts";
8
-
9
- const unit = ["src/core/*.test.ts", "src/pi/*.test.ts"];
10
- const integration = ["src/integration/*.test.ts"];
11
- // Cartesian matrices take minutes per test; unit and integration skip them, `cartesian` runs only them.
12
- const CARTESIAN = "^Cartesian ";
13
- const suites = {
14
- unit: { files: unit, filter: `--test-skip-pattern=${CARTESIAN}`, timeoutMs: 10 * 60 * 1000 },
15
- integration: {
16
- files: integration,
17
- filter: `--test-skip-pattern=${CARTESIAN}`,
18
- timeoutMs: 10 * 60 * 1000,
19
- },
20
- cartesian: {
21
- files: [...unit, ...integration],
22
- filter: `--test-name-pattern=${CARTESIAN}`,
23
- timeoutMs: 60 * 60 * 1000,
24
- },
25
- };
26
- const suite = process.argv[2];
27
- if (suite !== "unit" && suite !== "integration" && suite !== "cartesian")
28
- throw new Error("Expected unit, integration, or cartesian suite");
29
- const { files, filter, timeoutMs } = suites[suite];
30
- const agentDir = mkdtempSync(join(tmpdir(), "hashline-test-agent-"));
31
- try {
32
- const result = spawnSync(
33
- process.execPath,
34
- ["--experimental-test-module-mocks", "--test", filter, ...process.argv.slice(3), ...files],
35
- {
36
- cwd: fileURLToPath(new URL("../../", import.meta.url)),
37
- env: testEnvironment(agentDir),
38
- stdio: "inherit",
39
- timeout: timeoutMs,
40
- },
41
- );
42
- if (result.error) throw result.error;
43
- if (result.signal) throw new Error(`Test suite stopped by ${result.signal}`);
44
- process.exitCode = result.status ?? 1;
45
- } finally {
46
- rmSync(agentDir, { recursive: true, force: true });
47
- }
@@ -1,127 +0,0 @@
1
- /** Real Pi sessions with local model responses and no personal resources or provider traffic. */
2
- import assert from "node:assert/strict";
3
- import { mkdtemp, rm } from "node:fs/promises";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
- import type { TestContext } from "node:test";
7
- import type { AssistantMessage } from "@earendil-works/pi-ai";
8
- import { AssistantMessageEventStream } from "@earendil-works/pi-ai/utils/event-stream";
9
- import {
10
- createAgentSession,
11
- DefaultResourceLoader,
12
- type ExtensionAPI,
13
- ModelRuntime,
14
- SessionManager,
15
- SettingsManager,
16
- } from "@earendil-works/pi-coding-agent";
17
-
18
- const TEST_PROVIDER = "hashline-test";
19
- const TEST_CONTEXT_TOKENS = 100_000;
20
- const TEST_OUTPUT_TOKENS = 1000;
21
- export const SESSION_TIMEOUT_MS = 30_000;
22
- export type TestResponse = Pick<AssistantMessage, "content" | "stopReason">;
23
- type TestModel = NonNullable<ReturnType<ModelRuntime["getModel"]>>;
24
-
25
- export function responseStream(model: TestModel, response: TestResponse) {
26
- const message: AssistantMessage = {
27
- role: "assistant",
28
- ...response,
29
- api: model.api,
30
- provider: model.provider,
31
- model: model.id,
32
- timestamp: Date.now(),
33
- usage: {
34
- input: 0,
35
- output: 0,
36
- cacheRead: 0,
37
- cacheWrite: 0,
38
- totalTokens: 0,
39
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
40
- },
41
- };
42
- const stream = new AssistantMessageEventStream();
43
- stream.push({ type: "start", partial: message });
44
- assert.ok(message.stopReason !== "pending");
45
- if (message.stopReason === "error" || message.stopReason === "aborted") {
46
- stream.push({ type: "error", reason: message.stopReason, error: message });
47
- } else {
48
- stream.push({ type: "done", reason: message.stopReason, message });
49
- }
50
- return stream;
51
- }
52
-
53
- export async function openTestSession(
54
- t: TestContext,
55
- options: {
56
- readonly cwd?: string;
57
- readonly tools: readonly string[];
58
- readonly configure?: (pi: ExtensionAPI, cwd: string) => void | Promise<void>;
59
- },
60
- ) {
61
- const cwd = options.cwd ?? (await mkdtemp(join(tmpdir(), "hashline-session-")));
62
- let dispose: (() => void) | undefined;
63
- t.after(async () => {
64
- dispose?.();
65
- if (options.cwd === undefined) await rm(cwd, { recursive: true, force: true });
66
- });
67
- const modelRuntime = await ModelRuntime.create({
68
- authPath: join(cwd, "auth.json"),
69
- modelsPath: null,
70
- modelsStorePath: join(cwd, "models.json"),
71
- refreshOnCreate: false,
72
- allowModelNetwork: false,
73
- });
74
- modelRuntime.registerProvider(TEST_PROVIDER, {
75
- api: "openai-completions",
76
- baseUrl: "https://unused.invalid",
77
- apiKey: "local-test-placeholder",
78
- models: [
79
- {
80
- id: "test",
81
- name: "Test",
82
- input: ["text", "image"],
83
- reasoning: false,
84
- contextWindow: TEST_CONTEXT_TOKENS,
85
- maxTokens: TEST_OUTPUT_TOKENS,
86
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
87
- },
88
- ],
89
- });
90
- const model = modelRuntime.getModel(TEST_PROVIDER, "test");
91
- assert.ok(model);
92
- const settingsManager = SettingsManager.inMemory({
93
- compaction: { enabled: false },
94
- retry: { enabled: false },
95
- });
96
- const configure = options.configure;
97
- const loader = new DefaultResourceLoader({
98
- cwd,
99
- agentDir: cwd,
100
- settingsManager,
101
- noExtensions: true,
102
- noSkills: true,
103
- noPromptTemplates: true,
104
- noThemes: true,
105
- noContextFiles: true,
106
- extensionFactories: configure ? [(pi) => configure(pi, cwd)] : [],
107
- });
108
- await loader.reload();
109
- const sessionManager = SessionManager.inMemory(cwd);
110
- const { session, extensionsResult } = await createAgentSession({
111
- cwd,
112
- agentDir: cwd,
113
- modelRuntime,
114
- model,
115
- settingsManager,
116
- resourceLoader: loader,
117
- sessionManager,
118
- tools: [...options.tools],
119
- });
120
- dispose = () => session.dispose();
121
- assert.deepEqual(extensionsResult.errors, []);
122
- session.agent.streamFunction = () => {
123
- throw new Error("Install a scripted response before prompting");
124
- };
125
- await session.bindExtensions({});
126
- return { cwd, session, model, sessionManager };
127
- }