@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.
- package/README.md +18 -12
- package/README.zh-CN.md +18 -12
- package/package.json +8 -1
- package/src/core/AGENTS.md +3 -1
- package/src/core/apply.ts +110 -117
- package/src/core/character-set.ts +2 -3
- package/src/core/copy-span.ts +15 -0
- package/src/core/errors.ts +24 -9
- package/src/core/lines.ts +71 -17
- package/src/core/ranges.ts +5 -4
- package/src/core/replace-schema.ts +3 -1
- package/src/core/replace.ts +50 -29
- package/src/core/search-analysis.ts +21 -22
- package/src/core/search.ts +15 -32
- package/src/core/types.ts +3 -0
- package/src/index.ts +47 -39
- package/src/pi/AGENTS.md +30 -19
- package/src/pi/action-fusion.ts +284 -211
- package/src/pi/argument-diagnostics.ts +50 -37
- package/src/pi/argument-error.ts +2 -2
- package/src/pi/argument-validation.ts +163 -66
- package/src/pi/budgets.ts +12 -0
- package/src/pi/diagnostic-buffer.ts +12 -11
- package/src/pi/edit-tool.ts +138 -115
- package/src/pi/error-text.ts +10 -2
- package/src/pi/failure-context.ts +24 -37
- package/src/pi/file-commit.ts +131 -164
- package/src/pi/file-read.ts +122 -31
- package/src/pi/fusion-arguments.ts +214 -0
- package/src/pi/fusion-card.ts +102 -60
- package/src/pi/grep-candidates.ts +35 -22
- package/src/pi/grep-output.ts +197 -190
- package/src/pi/grep-render.ts +22 -13
- package/src/pi/grep-reread.ts +7 -6
- package/src/pi/grep-scope.ts +31 -16
- package/src/pi/grep-search.ts +56 -47
- package/src/pi/grep-tool.ts +35 -33
- package/src/pi/grep-worker.ts +3 -4
- package/src/pi/mutation-diff.ts +238 -0
- package/src/pi/mutation-result.ts +102 -79
- package/src/pi/mutation-runner.ts +107 -84
- package/src/pi/native-bash.ts +41 -0
- package/src/pi/path.ts +59 -6
- package/src/pi/read-tool.ts +173 -138
- package/src/pi/regex-worker.ts +14 -8
- package/src/pi/render.ts +101 -54
- package/src/pi/replace-regex.ts +1 -1
- package/src/pi/replace-tool.ts +14 -7
- package/src/pi/report-cause.ts +34 -17
- package/src/pi/report-schema.ts +184 -85
- package/src/pi/report.ts +133 -64
- package/src/pi/rg-process.ts +68 -48
- package/src/pi/schema.ts +4 -0
- package/src/pi/text-stream.ts +81 -87
- package/src/pi/workspace-cwd.js +2 -0
- package/src/pi/workspace.ts +46 -0
- package/src/pi/write-tool.ts +19 -13
- package/src/core/apply.test.ts +0 -644
- package/src/core/case-fold.test.ts +0 -35
- package/src/core/character-set.test.ts +0 -97
- package/src/core/errors.test.ts +0 -39
- package/src/core/hash.test.ts +0 -64
- package/src/core/lines.test.ts +0 -63
- package/src/core/ranges.test.ts +0 -123
- package/src/core/replace.test.ts +0 -187
- package/src/core/search-analysis.test.ts +0 -210
- package/src/core/search-matrix.test.ts +0 -64
- package/src/core/search-matrix.testing.ts +0 -171
- package/src/core/search.test.ts +0 -132
- package/src/core/text.test.ts +0 -52
- package/src/integration/config-registration.test.ts +0 -291
- package/src/integration/fusion-dispatch.test.ts +0 -320
- package/src/integration/grep-errors.test.ts +0 -81
- package/src/integration/grep-flags.test.ts +0 -76
- package/src/integration/grep-js-completeness.test.ts +0 -278
- package/src/integration/grep-line-candidates.test.ts +0 -201
- package/src/integration/grep-matrix.test.ts +0 -118
- package/src/integration/grep-order.test.ts +0 -78
- package/src/integration/grep-path-matrix.test.ts +0 -128
- package/src/integration/grep-prefilter-coverage.test.ts +0 -204
- package/src/integration/grep-process-limits.test.ts +0 -122
- package/src/integration/grep-regex.test.ts +0 -412
- package/src/integration/grep-rg.test.ts +0 -1659
- package/src/integration/grep-scan-budget.test.ts +0 -111
- package/src/integration/grep-translation.test.ts +0 -199
- package/src/integration/large-text.test.ts +0 -70
- package/src/integration/model-budget-lifecycle.test.ts +0 -186
- package/src/integration/mutation-file-types.test.ts +0 -30
- package/src/integration/mutation-file-types.testing.ts +0 -33
- package/src/integration/npm-package.test.ts +0 -19
- package/src/integration/npm-package.testing.ts +0 -243
- package/src/integration/publication-read-changes.test.ts +0 -454
- package/src/integration/read-changes.test.ts +0 -98
- package/src/integration/replace-package.test.ts +0 -22
- package/src/integration/replace-package.testing.ts +0 -36
- package/src/integration/replace-worker-boundary.test.ts +0 -127
- package/src/integration/report-replay.test.ts +0 -91
- package/src/integration/utf8-errors.test.ts +0 -46
- package/src/pi/action-fusion.test.ts +0 -659
- package/src/pi/action-fusion.testing.ts +0 -38
- package/src/pi/anchor-format.test.ts +0 -124
- package/src/pi/argument-error.testing.ts +0 -46
- package/src/pi/argument-format.test.ts +0 -196
- package/src/pi/argument-validation.test.ts +0 -1007
- package/src/pi/codemode.test.ts +0 -101
- package/src/pi/config.test.ts +0 -204
- package/src/pi/diagnostic-buffer.test.ts +0 -115
- package/src/pi/directory-sync.test.ts +0 -57
- package/src/pi/execute.test.ts +0 -1257
- package/src/pi/extension-loading.test.ts +0 -14
- package/src/pi/extension-loading.testing.ts +0 -3
- package/src/pi/failure-context.test.ts +0 -370
- package/src/pi/failure-path.test.ts +0 -289
- package/src/pi/file-commit.test.ts +0 -628
- package/src/pi/file-read.test.ts +0 -29
- package/src/pi/file-snapshot.test.ts +0 -22
- package/src/pi/fusion-card-interaction.test.ts +0 -143
- package/src/pi/fusion-card.test.ts +0 -353
- package/src/pi/grep-candidates.test.ts +0 -26
- package/src/pi/grep-matrix.test.ts +0 -68
- package/src/pi/grep-order.test.ts +0 -447
- package/src/pi/grep-output.testing.ts +0 -24
- package/src/pi/grep-rg.testing.ts +0 -73
- package/src/pi/grep.test.ts +0 -1670
- package/src/pi/model-budgets.test.ts +0 -96
- package/src/pi/mutation-outcome.testing.ts +0 -20
- package/src/pi/mutation-result.test.ts +0 -96
- package/src/pi/output-budgets.test.ts +0 -221
- package/src/pi/pi.test.ts +0 -158
- package/src/pi/read-delegation.test.ts +0 -119
- package/src/pi/read.test.ts +0 -735
- package/src/pi/regex-worker.test.ts +0 -42
- package/src/pi/registration.test.ts +0 -549
- package/src/pi/render.test.ts +0 -841
- package/src/pi/replace.test.ts +0 -634
- package/src/pi/report-failure.testing.ts +0 -27
- package/src/pi/report.test.ts +0 -533
- package/src/pi/result-safety.test.ts +0 -597
- package/src/pi/rg-process.test.ts +0 -133
- package/src/pi/rg-regex.test.ts +0 -40
- package/src/pi/text-stream.test.ts +0 -281
- package/src/pi/tool-call.testing.ts +0 -61
- package/src/pi/tool-factories.testing.ts +0 -59
- package/src/pi/write.test.ts +0 -256
- package/src/testing/extension-loader.testing.ts +0 -24
- package/src/testing/installation.testing.ts +0 -77
- package/src/testing/process.testing.ts +0 -33
- package/src/testing/regex-host.testing.ts +0 -20
- package/src/testing/regex-translation-corpus.ts +0 -267
- package/src/testing/rg-line-listing.fixture.mjs +0 -7
- package/src/testing/run-tests.ts +0 -47
- package/src/testing/session.testing.ts +0 -127
package/src/testing/run-tests.ts
DELETED
|
@@ -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
|
-
}
|