@leitwerk-dev/worker 0.1.9 → 0.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.
- package/dist/automatic-turn-executor.d.ts +1 -0
- package/dist/automatic-turn-executor.d.ts.map +1 -1
- package/dist/{chunk-O6332GRG.js → chunk-Y7S2MZD3.js} +1349 -932
- package/dist/chunk-Y7S2MZD3.js.map +1 -0
- package/dist/connection-diagnostics.d.ts +5 -0
- package/dist/connection-diagnostics.d.ts.map +1 -0
- package/dist/container-entry-main.d.ts +2 -0
- package/dist/container-entry-main.d.ts.map +1 -0
- package/dist/container-entry-main.js +232 -0
- package/dist/container-entry-main.js.map +1 -0
- package/dist/container-entry.d.ts +14 -0
- package/dist/container-entry.d.ts.map +1 -0
- package/dist/development-tool-environment.d.ts +48 -0
- package/dist/development-tool-environment.d.ts.map +1 -0
- package/dist/diagnostics.d.ts +4 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/docker-registry-credentials.d.ts +8 -0
- package/dist/docker-registry-credentials.d.ts.map +1 -0
- package/dist/entry-runtime.d.ts +1 -0
- package/dist/entry-runtime.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -5
- package/dist/index.js.map +1 -1
- package/dist/input-consumer.d.ts +6 -11
- package/dist/input-consumer.d.ts.map +1 -1
- package/dist/ipc.d.ts +1 -0
- package/dist/ipc.d.ts.map +1 -1
- package/dist/logical-prompt-runner.d.ts.map +1 -1
- package/dist/managed-pi-bootstrap.d.ts.map +1 -1
- package/dist/missing-tool-recovery-runner.d.ts +4 -3
- package/dist/missing-tool-recovery-runner.d.ts.map +1 -1
- package/dist/pi-adapter.d.ts +1 -0
- package/dist/pi-adapter.d.ts.map +1 -1
- package/dist/pi-event-reporter.d.ts.map +1 -1
- package/dist/pi-resource-bundle.d.ts +11 -0
- package/dist/pi-resource-bundle.d.ts.map +1 -1
- package/dist/pre-turn-targeted-inputs.d.ts +8 -7
- package/dist/pre-turn-targeted-inputs.d.ts.map +1 -1
- package/dist/prompt-guards.d.ts.map +1 -1
- package/dist/repository-bash-tool.d.ts +4 -0
- package/dist/repository-bash-tool.d.ts.map +1 -0
- package/dist/resource-loader-factory.d.ts +1 -2
- package/dist/resource-loader-factory.d.ts.map +1 -1
- package/dist/result-image-upload.d.ts.map +1 -1
- package/dist/runtime/adapters.d.ts +2 -0
- package/dist/runtime/adapters.d.ts.map +1 -1
- package/dist/runtime/bootstrap-session.d.ts +8 -5
- package/dist/runtime/bootstrap-session.d.ts.map +1 -1
- package/dist/runtime/bootstrap.d.ts +14 -18
- package/dist/runtime/bootstrap.d.ts.map +1 -1
- package/dist/runtime/failure-policy.d.ts +1 -0
- package/dist/runtime/failure-policy.d.ts.map +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/lifecycle-reducer.d.ts.map +1 -1
- package/dist/runtime/llm-turn-execution.d.ts +3 -8
- package/dist/runtime/llm-turn-execution.d.ts.map +1 -1
- package/dist/runtime/turn-execution.d.ts +2 -9
- package/dist/runtime/turn-execution.d.ts.map +1 -1
- package/dist/session-snapshot-exchange.d.ts +0 -4
- package/dist/session-snapshot-exchange.d.ts.map +1 -1
- package/dist/turn-continuation.d.ts.map +1 -1
- package/dist/turn-execution-error.d.ts +1 -1
- package/dist/turn-execution-error.d.ts.map +1 -1
- package/dist/turn-execution-result.d.ts +1 -0
- package/dist/turn-execution-result.d.ts.map +1 -1
- package/dist/turn-outcome-tool-session.d.ts +0 -2
- package/dist/turn-outcome-tool-session.d.ts.map +1 -1
- package/dist/turn-result-markdown.d.ts +2 -1
- package/dist/turn-result-markdown.d.ts.map +1 -1
- package/dist/turn-tree-strategy.d.ts +0 -1
- package/dist/turn-tree-strategy.d.ts.map +1 -1
- package/dist/worker-entry.js +16 -4
- package/dist/worker-entry.js.map +1 -1
- package/dist/worker-ipc-reporter.d.ts.map +1 -1
- package/dist/workspace/manifest.d.ts +4 -7
- package/dist/workspace/manifest.d.ts.map +1 -1
- package/dist/workspace/node-run-root-git-ops.d.ts +2 -2
- package/dist/workspace/node-run-root-git-ops.d.ts.map +1 -1
- package/dist/workspace/resource-aggregator.d.ts.map +1 -1
- package/dist/workspace/run-root.d.ts +9 -20
- package/dist/workspace/run-root.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/automatic-turn-executor.ts +2 -0
- package/src/connection-diagnostics.ts +27 -0
- package/src/container-entry-main.ts +24 -0
- package/src/container-entry.ts +246 -0
- package/src/development-tool-environment.ts +452 -0
- package/src/diagnostics.ts +1 -0
- package/src/docker-registry-credentials.ts +65 -0
- package/src/entry-runtime.ts +5 -4
- package/src/index.ts +11 -0
- package/src/input-consumer.ts +7 -29
- package/src/ipc.ts +37 -2
- package/src/logical-prompt-runner.ts +23 -29
- package/src/managed-pi-bootstrap.ts +3 -3
- package/src/missing-tool-recovery-runner.ts +4 -18
- package/src/pi-adapter.ts +19 -50
- package/src/pi-event-reporter.ts +16 -38
- package/src/pi-resource-bundle.ts +67 -1
- package/src/pre-turn-targeted-inputs.ts +9 -11
- package/src/prompt-guards.ts +44 -75
- package/src/repository-bash-tool.ts +15 -0
- package/src/resource-loader-factory.ts +1 -18
- package/src/result-image-upload.ts +16 -27
- package/src/runtime/adapters.ts +2 -0
- package/src/runtime/bootstrap-session.ts +69 -39
- package/src/runtime/bootstrap.ts +160 -103
- package/src/runtime/failure-policy.ts +36 -42
- package/src/runtime/index.ts +43 -14
- package/src/runtime/lifecycle-reducer.ts +71 -173
- package/src/runtime/llm-turn-execution.ts +13 -30
- package/src/runtime/turn-execution.ts +78 -31
- package/src/session-snapshot-exchange.ts +23 -64
- package/src/turn-continuation.ts +9 -17
- package/src/turn-execution-error.ts +3 -11
- package/src/turn-execution-result.ts +1 -0
- package/src/turn-outcome-tool-session.ts +25 -21
- package/src/turn-result-markdown.ts +31 -34
- package/src/turn-tree-strategy.ts +6 -19
- package/src/worker-entry.ts +8 -0
- package/src/worker-ipc-reporter.ts +8 -16
- package/src/workspace/manifest.ts +5 -7
- package/src/workspace/node-run-root-git-ops.ts +65 -25
- package/src/workspace/resource-aggregator.ts +5 -16
- package/src/workspace/run-root.ts +38 -89
- package/dist/automatic-turn-executor.js +0 -58
- package/dist/automatic-turn-executor.js.map +0 -1
- package/dist/chunk-O6332GRG.js.map +0 -1
- package/dist/diagnostics.js +0 -51
- package/dist/diagnostics.js.map +0 -1
- package/dist/entry-runtime.js +0 -160
- package/dist/entry-runtime.js.map +0 -1
- package/dist/event-translator.js +0 -12
- package/dist/event-translator.js.map +0 -1
- package/dist/extension-entry-roots.js +0 -41
- package/dist/extension-entry-roots.js.map +0 -1
- package/dist/identified-pi-entry.js +0 -125
- package/dist/identified-pi-entry.js.map +0 -1
- package/dist/input-consumer.js +0 -34
- package/dist/input-consumer.js.map +0 -1
- package/dist/integration-tool-bridge.js +0 -53
- package/dist/integration-tool-bridge.js.map +0 -1
- package/dist/ipc.js +0 -192
- package/dist/ipc.js.map +0 -1
- package/dist/logical-prompt-runner.js +0 -225
- package/dist/logical-prompt-runner.js.map +0 -1
- package/dist/managed-pi-agent-dir.js +0 -66
- package/dist/managed-pi-agent-dir.js.map +0 -1
- package/dist/managed-pi-bootstrap.js +0 -135
- package/dist/managed-pi-bootstrap.js.map +0 -1
- package/dist/missing-tool-recovery-runner.js +0 -73
- package/dist/missing-tool-recovery-runner.js.map +0 -1
- package/dist/pi-adapter.js +0 -1648
- package/dist/pi-adapter.js.map +0 -1
- package/dist/pi-branch-guard.js +0 -75
- package/dist/pi-branch-guard.js.map +0 -1
- package/dist/pi-event-reporter.js +0 -136
- package/dist/pi-event-reporter.js.map +0 -1
- package/dist/pi-resource-bundle.js +0 -58
- package/dist/pi-resource-bundle.js.map +0 -1
- package/dist/pre-turn-targeted-inputs.js +0 -101
- package/dist/pre-turn-targeted-inputs.js.map +0 -1
- package/dist/prompt-guards.js +0 -318
- package/dist/prompt-guards.js.map +0 -1
- package/dist/question-bridge.js +0 -24
- package/dist/question-bridge.js.map +0 -1
- package/dist/question-tool.js +0 -54
- package/dist/question-tool.js.map +0 -1
- package/dist/replaying-request-bridge.js +0 -71
- package/dist/replaying-request-bridge.js.map +0 -1
- package/dist/resource-loader-factory.js +0 -87
- package/dist/resource-loader-factory.js.map +0 -1
- package/dist/result-image-upload.js +0 -183
- package/dist/result-image-upload.js.map +0 -1
- package/dist/runtime/adapters.js +0 -15
- package/dist/runtime/adapters.js.map +0 -1
- package/dist/runtime/bootstrap-session.js +0 -199
- package/dist/runtime/bootstrap-session.js.map +0 -1
- package/dist/runtime/bootstrap.js +0 -440
- package/dist/runtime/bootstrap.js.map +0 -1
- package/dist/runtime/failure-policy.js +0 -182
- package/dist/runtime/failure-policy.js.map +0 -1
- package/dist/runtime/index.js +0 -339
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/lifecycle-reducer.js +0 -1142
- package/dist/runtime/lifecycle-reducer.js.map +0 -1
- package/dist/runtime/llm-turn-execution.js +0 -494
- package/dist/runtime/llm-turn-execution.js.map +0 -1
- package/dist/runtime/settings.js +0 -24
- package/dist/runtime/settings.js.map +0 -1
- package/dist/runtime/snapshot-policy.js +0 -16
- package/dist/runtime/snapshot-policy.js.map +0 -1
- package/dist/runtime/turn-execution.js +0 -151
- package/dist/runtime/turn-execution.js.map +0 -1
- package/dist/session-snapshot-exchange.js +0 -102
- package/dist/session-snapshot-exchange.js.map +0 -1
- package/dist/test-helpers/fake-websocket.js +0 -40
- package/dist/test-helpers/fake-websocket.js.map +0 -1
- package/dist/test-helpers/ipc-harness.d.ts +0 -11
- package/dist/test-helpers/ipc-harness.d.ts.map +0 -1
- package/dist/test-helpers/ipc-harness.js +0 -17
- package/dist/test-helpers/ipc-harness.js.map +0 -1
- package/dist/turn-continuation.js +0 -80
- package/dist/turn-continuation.js.map +0 -1
- package/dist/turn-execution-error.js +0 -64
- package/dist/turn-execution-error.js.map +0 -1
- package/dist/turn-execution-result.js +0 -21
- package/dist/turn-execution-result.js.map +0 -1
- package/dist/turn-outcome-tool-session.js +0 -210
- package/dist/turn-outcome-tool-session.js.map +0 -1
- package/dist/turn-record-id.js +0 -10
- package/dist/turn-record-id.js.map +0 -1
- package/dist/turn-result-markdown.js +0 -263
- package/dist/turn-result-markdown.js.map +0 -1
- package/dist/turn-tree-strategy.js +0 -80
- package/dist/turn-tree-strategy.js.map +0 -1
- package/dist/worker-http.js +0 -9
- package/dist/worker-http.js.map +0 -1
- package/dist/worker-ipc-reporter.js +0 -58
- package/dist/worker-ipc-reporter.js.map +0 -1
- package/dist/worker-payloads.js +0 -66
- package/dist/worker-payloads.js.map +0 -1
- package/dist/worker-start-payload.js +0 -5
- package/dist/worker-start-payload.js.map +0 -1
- package/dist/workspace/manifest.js +0 -79
- package/dist/workspace/manifest.js.map +0 -1
- package/dist/workspace/node-run-root-git-ops.js +0 -96
- package/dist/workspace/node-run-root-git-ops.js.map +0 -1
- package/dist/workspace/resource-aggregator.js +0 -39
- package/dist/workspace/resource-aggregator.js.map +0 -1
- package/dist/workspace/run-root.js +0 -209
- package/dist/workspace/run-root.js.map +0 -1
- package/src/test-helpers/ipc-harness.ts +0 -19
|
@@ -10,49 +10,71 @@ import {
|
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import {
|
|
13
|
+
clearRepositoryGitHttpsHelpers,
|
|
13
14
|
clearRepositoryGitSshWrappers,
|
|
14
15
|
repositoryGitArgs,
|
|
15
16
|
repositoryGitSubprocessEnv,
|
|
17
|
+
repositoryHttpsUrl,
|
|
18
|
+
setRepositoryGitHttpsHelper,
|
|
16
19
|
setRepositoryGitSshWrapper,
|
|
17
20
|
} from "@leitwerk-dev/process-sdk";
|
|
18
21
|
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
19
|
-
import type {
|
|
22
|
+
import type { WorkerRepositoryCredential } from "@leitwerk-dev/worker-protocol";
|
|
20
23
|
import { execa } from "execa";
|
|
21
24
|
import fg from "fast-glob";
|
|
22
25
|
import type { RunRootGitOps } from "./run-root.js";
|
|
23
26
|
|
|
24
|
-
function toAbsolute(targetPath: string): string {
|
|
25
|
-
return path.resolve(targetPath);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
27
|
export class NodeRunRootGitOps implements RunRootGitOps {
|
|
29
28
|
#credentialDir: string | null = null;
|
|
30
29
|
|
|
31
|
-
configureRepositoryCredentials(credentials: readonly
|
|
30
|
+
configureRepositoryCredentials(credentials: readonly WorkerRepositoryCredential[]): void {
|
|
32
31
|
this.cleanupRepositoryCredentials();
|
|
33
32
|
if (credentials.length === 0) return;
|
|
34
33
|
const root = mkdtempSync(path.join(tmpdir(), "leitwerk-repo-auth-"));
|
|
35
34
|
chmodSync(root, 0o700);
|
|
36
35
|
this.#credentialDir = root;
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
try {
|
|
37
|
+
for (const credential of credentials) {
|
|
38
|
+
const dir = path.join(root, encodeURIComponent(credential.projectKey));
|
|
39
|
+
mkdirSync(dir, { mode: 0o700 });
|
|
40
|
+
if (credential.kind === "git_https") {
|
|
41
|
+
const url = repositoryHttpsUrl(credential.repositoryUrl);
|
|
42
|
+
writeFileSync(
|
|
43
|
+
path.join(dir, "credential.json"),
|
|
44
|
+
JSON.stringify({
|
|
45
|
+
host: url.host,
|
|
46
|
+
path: url.pathname.slice(1),
|
|
47
|
+
username: credential.username,
|
|
48
|
+
password: credential.password,
|
|
49
|
+
}),
|
|
50
|
+
{ mode: 0o600 },
|
|
51
|
+
);
|
|
52
|
+
const helper = path.join(dir, "credential.cjs");
|
|
53
|
+
writeFileSync(helper, HTTPS_CREDENTIAL_HELPER, { mode: 0o700 });
|
|
54
|
+
setRepositoryGitHttpsHelper(credential.projectKey, helper);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const key = path.join(dir, "identity");
|
|
58
|
+
const hosts = path.join(dir, "known_hosts");
|
|
59
|
+
const wrapper = path.join(dir, "ssh");
|
|
60
|
+
writeFileSync(key, `${credential.privateKey.trim()}\n`, { mode: 0o600 });
|
|
61
|
+
writeFileSync(hosts, `${credential.knownHosts.trim()}\n`, { mode: 0o600 });
|
|
62
|
+
writeFileSync(
|
|
63
|
+
wrapper,
|
|
64
|
+
`#!/bin/sh\nexec ssh -F /dev/null -o IdentitiesOnly=yes -o IdentityFile="${key}" -o UserKnownHostsFile="${hosts}" -o StrictHostKeyChecking=yes -o BatchMode=yes "$@"\n`,
|
|
65
|
+
{ mode: 0o700 },
|
|
66
|
+
);
|
|
67
|
+
setRepositoryGitSshWrapper(credential.projectKey, wrapper);
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
this.cleanupRepositoryCredentials();
|
|
71
|
+
throw error;
|
|
51
72
|
}
|
|
52
73
|
}
|
|
53
74
|
|
|
54
75
|
cleanupRepositoryCredentials(): void {
|
|
55
76
|
clearRepositoryGitSshWrappers();
|
|
77
|
+
clearRepositoryGitHttpsHelpers();
|
|
56
78
|
if (this.#credentialDir) rmSync(this.#credentialDir, { recursive: true, force: true });
|
|
57
79
|
this.#credentialDir = null;
|
|
58
80
|
}
|
|
@@ -63,7 +85,7 @@ export class NodeRunRootGitOps implements RunRootGitOps {
|
|
|
63
85
|
projectKey?: string,
|
|
64
86
|
): Promise<string> {
|
|
65
87
|
const result = await execa(resolveGitBinary(), repositoryGitArgs(args), {
|
|
66
|
-
...(cwd ? { cwd:
|
|
88
|
+
...(cwd ? { cwd: path.resolve(cwd) } : {}),
|
|
67
89
|
env: repositoryGitSubprocessEnv(projectKey ?? "", { GIT_TERMINAL_PROMPT: "0" }),
|
|
68
90
|
extendEnv: false,
|
|
69
91
|
stdin: "ignore",
|
|
@@ -72,13 +94,13 @@ export class NodeRunRootGitOps implements RunRootGitOps {
|
|
|
72
94
|
}
|
|
73
95
|
|
|
74
96
|
async writeFile(repoDir: string, filePath: string, content: string): Promise<void> {
|
|
75
|
-
const absolutePath =
|
|
97
|
+
const absolutePath = path.resolve(path.join(repoDir, filePath));
|
|
76
98
|
mkdirSync(path.dirname(absolutePath), { recursive: true });
|
|
77
99
|
writeFileSync(absolutePath, content, "utf8");
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
async readFile(repoDir: string, filePath: string): Promise<string | null> {
|
|
81
|
-
const absolutePath =
|
|
103
|
+
const absolutePath = path.resolve(path.join(repoDir, filePath));
|
|
82
104
|
if (!existsSync(absolutePath)) {
|
|
83
105
|
return null;
|
|
84
106
|
}
|
|
@@ -86,7 +108,7 @@ export class NodeRunRootGitOps implements RunRootGitOps {
|
|
|
86
108
|
}
|
|
87
109
|
|
|
88
110
|
async clone(repoLocator: string, targetDir: string): Promise<void> {
|
|
89
|
-
const absoluteTargetDir =
|
|
111
|
+
const absoluteTargetDir = path.resolve(targetDir);
|
|
90
112
|
rmSync(absoluteTargetDir, { recursive: true, force: true });
|
|
91
113
|
mkdirSync(path.dirname(absoluteTargetDir), { recursive: true });
|
|
92
114
|
await this.runGit(
|
|
@@ -121,7 +143,7 @@ export class NodeRunRootGitOps implements RunRootGitOps {
|
|
|
121
143
|
}
|
|
122
144
|
|
|
123
145
|
async listFiles(repoDir: string, pattern: string): Promise<string[]> {
|
|
124
|
-
const absoluteRoot =
|
|
146
|
+
const absoluteRoot = path.resolve(repoDir);
|
|
125
147
|
if (!existsSync(absoluteRoot)) {
|
|
126
148
|
return [];
|
|
127
149
|
}
|
|
@@ -135,3 +157,21 @@ export class NodeRunRootGitOps implements RunRootGitOps {
|
|
|
135
157
|
).sort((a, b) => a.localeCompare(b));
|
|
136
158
|
}
|
|
137
159
|
}
|
|
160
|
+
|
|
161
|
+
// The secret is read only by this short-lived helper, never embedded in its source or argv.
|
|
162
|
+
const HTTPS_CREDENTIAL_HELPER = `const fs = require('node:fs');
|
|
163
|
+
if (process.argv[2] !== 'get') process.exit(0);
|
|
164
|
+
const input = fs.readFileSync(0, 'utf8');
|
|
165
|
+
const fields = Object.create(null);
|
|
166
|
+
for (const line of input.split('\\n')) {
|
|
167
|
+
const i = line.indexOf('=');
|
|
168
|
+
if (i < 0) continue;
|
|
169
|
+
const key = line.slice(0, i);
|
|
170
|
+
if (Object.hasOwn(fields, key)) process.exit(0);
|
|
171
|
+
fields[key] = line.slice(i + 1);
|
|
172
|
+
}
|
|
173
|
+
const c = JSON.parse(fs.readFileSync(require('node:path').join(__dirname, 'credential.json'), 'utf8'));
|
|
174
|
+
if (fields.protocol !== 'https' || fields.host !== c.host || fields.path !== c.path ||
|
|
175
|
+
(fields.username && fields.username !== c.username)) process.exit(0);
|
|
176
|
+
process.stdout.write('username=' + c.username + '\\npassword=' + c.password + '\\n\\n');
|
|
177
|
+
`;
|
|
@@ -21,23 +21,12 @@ export function aggregateAgentsMd(
|
|
|
21
21
|
export function collectSkills(
|
|
22
22
|
sources: Array<{ componentKey: string; skillId: string; content: string }>,
|
|
23
23
|
): Map<string, { content: string; source: string }> {
|
|
24
|
-
const byId = new Map<string, Array<{ componentKey: string; skillId: string; content: string }>>();
|
|
25
|
-
for (const s of sources) {
|
|
26
|
-
const list = byId.get(s.skillId);
|
|
27
|
-
if (list) {
|
|
28
|
-
list.push(s);
|
|
29
|
-
} else {
|
|
30
|
-
byId.set(s.skillId, [s]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
24
|
const out = new Map<string, { content: string; source: string }>();
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
source: winner.componentKey,
|
|
40
|
-
});
|
|
25
|
+
for (const { skillId, componentKey, content } of sources) {
|
|
26
|
+
const winner = out.get(skillId);
|
|
27
|
+
if (!winner || componentKey.localeCompare(winner.source) < 0) {
|
|
28
|
+
out.set(skillId, { content, source: componentKey });
|
|
29
|
+
}
|
|
41
30
|
}
|
|
42
31
|
return out;
|
|
43
32
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { isPathInside } from "@leitwerk-dev/process-sdk";
|
|
2
3
|
import {
|
|
4
|
+
type ComponentCheckoutPlan,
|
|
3
5
|
type ComponentManifest,
|
|
4
6
|
type ComponentManifestEntry,
|
|
5
7
|
deserializeManifest,
|
|
@@ -22,7 +24,7 @@ export interface GitOps {
|
|
|
22
24
|
export type RunRootGitOps = GitOps & {
|
|
23
25
|
writeFile(repoDir: string, filePath: string, content: string): Promise<void>;
|
|
24
26
|
configureRepositoryCredentials?(
|
|
25
|
-
credentials: readonly import("@leitwerk-dev/worker-protocol").
|
|
27
|
+
credentials: readonly import("@leitwerk-dev/worker-protocol").WorkerRepositoryCredential[],
|
|
26
28
|
): void;
|
|
27
29
|
cleanupRepositoryCredentials?(): void;
|
|
28
30
|
};
|
|
@@ -30,12 +32,7 @@ export type RunRootGitOps = GitOps & {
|
|
|
30
32
|
export interface RunRootPlan {
|
|
31
33
|
workspaceRoot: string;
|
|
32
34
|
instanceId: string;
|
|
33
|
-
components:
|
|
34
|
-
key: string;
|
|
35
|
-
repoLocator: string;
|
|
36
|
-
baseBranch: string;
|
|
37
|
-
workBranch: string;
|
|
38
|
-
}>;
|
|
35
|
+
components: ComponentCheckoutPlan[];
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
export interface MaterializeResult {
|
|
@@ -52,6 +49,16 @@ export interface ValidationResult {
|
|
|
52
49
|
existingManifest: ComponentManifest | null;
|
|
53
50
|
}
|
|
54
51
|
|
|
52
|
+
export class RunRootPreparationError extends Error {
|
|
53
|
+
readonly errors: readonly string[];
|
|
54
|
+
|
|
55
|
+
constructor(errors: readonly string[]) {
|
|
56
|
+
super(`Workspace preparation failed: ${errors.join("; ")}`);
|
|
57
|
+
this.name = "RunRootPreparationError";
|
|
58
|
+
this.errors = [...errors];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
55
62
|
const MANIFEST_REL = path.join(".leitwerk", "components.json");
|
|
56
63
|
const AGGREGATED_AGENTS_REL = "AGENTS.md";
|
|
57
64
|
const SKILLS_DIR_REL = path.join(".leitwerk", "skills");
|
|
@@ -59,17 +66,7 @@ const SKILLS_DIR_REL = path.join(".leitwerk", "skills");
|
|
|
59
66
|
const SKILL_GLOB = "**/.cursor/skills/**/SKILL.md";
|
|
60
67
|
const AGENTS_GLOB = "**/AGENTS.md";
|
|
61
68
|
|
|
62
|
-
function
|
|
63
|
-
const relative = path.relative(parent, child);
|
|
64
|
-
return (
|
|
65
|
-
relative !== "" &&
|
|
66
|
-
relative !== ".." &&
|
|
67
|
-
!relative.startsWith(`..${path.sep}`) &&
|
|
68
|
-
!path.isAbsolute(relative)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function safeJoinInsideWorkspace(workspaceRoot: string, childPath: string): string {
|
|
69
|
+
function componentDir(workspaceRoot: string, childPath: string): string {
|
|
73
70
|
const root = path.resolve(workspaceRoot);
|
|
74
71
|
const target = path.resolve(root, childPath);
|
|
75
72
|
if (!isPathInside(root, target)) {
|
|
@@ -78,10 +75,6 @@ function safeJoinInsideWorkspace(workspaceRoot: string, childPath: string): stri
|
|
|
78
75
|
return target;
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
function componentDir(workspaceRoot: string, key: string): string {
|
|
82
|
-
return safeJoinInsideWorkspace(workspaceRoot, key);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
78
|
function skillIdFromSkillPath(filePath: string): string | null {
|
|
86
79
|
const normalized = filePath.replace(/\\/g, "/");
|
|
87
80
|
const m = normalized.match(/\.cursor\/skills\/([^/]+)\/SKILL\.md$/);
|
|
@@ -91,12 +84,7 @@ function skillIdFromSkillPath(filePath: string): string | null {
|
|
|
91
84
|
export function planRunRoot(
|
|
92
85
|
workspaceRoot: string,
|
|
93
86
|
instanceId: string,
|
|
94
|
-
projectSnapshots:
|
|
95
|
-
key: string;
|
|
96
|
-
repoLocator: string;
|
|
97
|
-
baseBranch: string;
|
|
98
|
-
workBranch: string;
|
|
99
|
-
}>,
|
|
87
|
+
projectSnapshots: ComponentCheckoutPlan[],
|
|
100
88
|
): RunRootPlan {
|
|
101
89
|
return {
|
|
102
90
|
workspaceRoot,
|
|
@@ -113,12 +101,10 @@ async function materializeComponentEntry(
|
|
|
113
101
|
const dir = componentDir(plan.workspaceRoot, comp.key);
|
|
114
102
|
await git.clone(comp.repoLocator, dir);
|
|
115
103
|
await git.checkout(dir, comp.baseBranch);
|
|
116
|
-
if (await git.branchExists(dir, comp.workBranch)) {
|
|
117
|
-
await git.checkout(dir, comp.workBranch);
|
|
118
|
-
} else {
|
|
104
|
+
if (!(await git.branchExists(dir, comp.workBranch))) {
|
|
119
105
|
await git.createBranch(dir, comp.workBranch, comp.baseBranch);
|
|
120
|
-
await git.checkout(dir, comp.workBranch);
|
|
121
106
|
}
|
|
107
|
+
await git.checkout(dir, comp.workBranch);
|
|
122
108
|
return {
|
|
123
109
|
key: comp.key,
|
|
124
110
|
repoLocator: comp.repoLocator,
|
|
@@ -232,7 +218,7 @@ async function finalizeRunRoot(
|
|
|
232
218
|
git: RunRootGitOps,
|
|
233
219
|
entries: ComponentManifestEntry[],
|
|
234
220
|
errors: string[],
|
|
235
|
-
) {
|
|
221
|
+
): Promise<MaterializeResult> {
|
|
236
222
|
const manifest: ComponentManifest = {
|
|
237
223
|
version: 1,
|
|
238
224
|
instanceId: plan.instanceId,
|
|
@@ -249,7 +235,20 @@ async function finalizeRunRoot(
|
|
|
249
235
|
errors.push(`write: ${e instanceof Error ? e.message : String(e)}`);
|
|
250
236
|
}
|
|
251
237
|
|
|
252
|
-
|
|
238
|
+
const expectedKeys = new Set(plan.components.map((component) => component.key));
|
|
239
|
+
const hasAllExpectedEntries =
|
|
240
|
+
entries.length === expectedKeys.size &&
|
|
241
|
+
[...expectedKeys].every((key) => entries.some((entry) => entry.key === key));
|
|
242
|
+
if (errors.length > 0 || !hasAllExpectedEntries) {
|
|
243
|
+
throw new RunRootPreparationError(errors);
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
ok: true,
|
|
247
|
+
manifest,
|
|
248
|
+
aggregatedAgentsMdSources,
|
|
249
|
+
loadedSkills,
|
|
250
|
+
errors,
|
|
251
|
+
};
|
|
253
252
|
}
|
|
254
253
|
|
|
255
254
|
export async function materializeRunRoot(
|
|
@@ -258,48 +257,17 @@ export async function materializeRunRoot(
|
|
|
258
257
|
): Promise<MaterializeResult> {
|
|
259
258
|
const errors: string[] = [];
|
|
260
259
|
const entries = await collectMaterializedEntries(plan, git, errors);
|
|
261
|
-
|
|
262
|
-
plan,
|
|
263
|
-
git,
|
|
264
|
-
entries,
|
|
265
|
-
errors,
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
const ok = errors.length === 0 && plan.components.length === entries.length;
|
|
269
|
-
return {
|
|
270
|
-
ok,
|
|
271
|
-
manifest,
|
|
272
|
-
aggregatedAgentsMdSources,
|
|
273
|
-
loadedSkills,
|
|
274
|
-
errors,
|
|
275
|
-
};
|
|
260
|
+
return finalizeRunRoot(plan, git, entries, errors);
|
|
276
261
|
}
|
|
277
262
|
|
|
278
263
|
export async function validateRunRoot(
|
|
279
264
|
workspaceRoot: string,
|
|
280
|
-
serverProjects:
|
|
281
|
-
key: string;
|
|
282
|
-
repoLocator: string;
|
|
283
|
-
baseBranch: string;
|
|
284
|
-
workBranch: string;
|
|
285
|
-
}>,
|
|
265
|
+
serverProjects: ComponentCheckoutPlan[],
|
|
286
266
|
git: GitOps,
|
|
287
267
|
): Promise<ValidationResult> {
|
|
288
268
|
const raw = await git.readFile(workspaceRoot, MANIFEST_REL);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
valid: false,
|
|
292
|
-
diff: {
|
|
293
|
-
stale: [],
|
|
294
|
-
missing: serverProjects.map((p) => p.key),
|
|
295
|
-
extra: [],
|
|
296
|
-
unchanged: [],
|
|
297
|
-
},
|
|
298
|
-
existingManifest: null,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
const parsed = deserializeManifest(raw);
|
|
302
|
-
if (!parsed.ok) {
|
|
269
|
+
const parsed = raw === null ? null : deserializeManifest(raw);
|
|
270
|
+
if (!parsed?.ok) {
|
|
303
271
|
return {
|
|
304
272
|
valid: false,
|
|
305
273
|
diff: {
|
|
@@ -338,24 +306,5 @@ export async function repairRunRoot(
|
|
|
338
306
|
null,
|
|
339
307
|
);
|
|
340
308
|
|
|
341
|
-
|
|
342
|
-
plan,
|
|
343
|
-
git,
|
|
344
|
-
manifestEntries,
|
|
345
|
-
errors,
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
const expectedKeys = new Set(plan.components.map((c) => c.key));
|
|
349
|
-
const ok =
|
|
350
|
-
errors.length === 0 &&
|
|
351
|
-
manifestEntries.length === plan.components.length &&
|
|
352
|
-
[...expectedKeys].every((k) => manifestEntries.some((e) => e.key === k));
|
|
353
|
-
|
|
354
|
-
return {
|
|
355
|
-
ok,
|
|
356
|
-
manifest,
|
|
357
|
-
aggregatedAgentsMdSources,
|
|
358
|
-
loadedSkills,
|
|
359
|
-
errors,
|
|
360
|
-
};
|
|
309
|
+
return finalizeRunRoot(plan, git, manifestEntries, errors);
|
|
361
310
|
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { classifyRuntimeError, TurnExecutionError } from "./turn-execution-error.js";
|
|
2
|
-
import { TurnExecutionFailure } from "./turn-execution-result.js";
|
|
3
|
-
import { resolveTurnRecordIdForExecution } from "./turn-record-id.js";
|
|
4
|
-
import { resolveRootEntryIdFromHandle } from "./turn-tree-strategy.js";
|
|
5
|
-
import { readProcessSemanticEntryRefs } from "./worker-payloads.js";
|
|
6
|
-
export function createAutomaticTurnExecutor(input) {
|
|
7
|
-
const turnType = "automatic";
|
|
8
|
-
const pathType = "primary";
|
|
9
|
-
const turnRecordId = resolveTurnRecordIdForExecution(input.processSnapshot, input.currentTurnId, input.acceptedTurnRecordId);
|
|
10
|
-
let result = null;
|
|
11
|
-
const failure = (error) => {
|
|
12
|
-
const classified = classifyRuntimeError(error);
|
|
13
|
-
const turnError = error instanceof TurnExecutionError
|
|
14
|
-
? error
|
|
15
|
-
: new TurnExecutionError(input.currentTurnId, classified.errorClass, classified.message);
|
|
16
|
-
return new TurnExecutionFailure({
|
|
17
|
-
turnRecordId,
|
|
18
|
-
turnId: input.currentTurnId,
|
|
19
|
-
turnType,
|
|
20
|
-
pathType,
|
|
21
|
-
failure: turnError,
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
turnRecordId,
|
|
26
|
-
get result() {
|
|
27
|
-
return result;
|
|
28
|
-
},
|
|
29
|
-
async complete(completeInput) {
|
|
30
|
-
if (result) {
|
|
31
|
-
throw new TurnExecutionError(input.currentTurnId, "protocol_error", `Automatic turn '${input.currentTurnId}' completed more than once`);
|
|
32
|
-
}
|
|
33
|
-
result = {
|
|
34
|
-
turnId: input.currentTurnId,
|
|
35
|
-
outcome: completeInput.outcome,
|
|
36
|
-
params: completeInput.params ?? {},
|
|
37
|
-
meta: {
|
|
38
|
-
turnRecordId,
|
|
39
|
-
turnType,
|
|
40
|
-
pathType,
|
|
41
|
-
forkPiEntryId: null,
|
|
42
|
-
resultPiEntryId: null,
|
|
43
|
-
turnResultMarkdown: completeInput.markdown ?? null,
|
|
44
|
-
rootEntryId: input.piHandle
|
|
45
|
-
? resolveRootEntryIdFromHandle(input.piHandle)
|
|
46
|
-
: (readProcessSemanticEntryRefs(input.state)?.rootEntry?.entryId ?? null),
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
failure,
|
|
51
|
-
assertCompletedUnlessParked(parked) {
|
|
52
|
-
if (!result && !parked) {
|
|
53
|
-
throw failure(new TurnExecutionError(input.currentTurnId, "protocol_error", `Automatic turn '${input.currentTurnId}' returned without calling run.complete()`));
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=automatic-turn-executor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"automatic-turn-executor.js","sourceRoot":"","sources":["../src/automatic-turn-executor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAA0B,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAqBpE,MAAM,UAAU,2BAA2B,CAAC,KAM3C;IACA,MAAM,QAAQ,GAAoB,WAAW,CAAC;IAC9C,MAAM,QAAQ,GAA8B,SAAS,CAAC;IACtD,MAAM,YAAY,GAAG,+BAA+B,CACnD,KAAK,CAAC,eAAe,EACrB,KAAK,CAAC,aAAa,EACnB,KAAK,CAAC,oBAAoB,CAC1B,CAAC;IACF,IAAI,MAAM,GAA+B,IAAI,CAAC;IAE9C,MAAM,OAAO,GAAG,CAAC,KAAc,EAAwB,EAAE;QACxD,MAAM,UAAU,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAC/C,MAAM,SAAS,GACd,KAAK,YAAY,kBAAkB;YAClC,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAC,aAAa,EAAE,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QAC3F,OAAO,IAAI,oBAAoB,CAAC;YAC/B,YAAY;YACZ,MAAM,EAAE,KAAK,CAAC,aAAa;YAC3B,QAAQ;YACR,QAAQ;YACR,OAAO,EAAE,SAAS;SAClB,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACN,YAAY;QACZ,IAAI,MAAM;YACT,OAAO,MAAM,CAAC;QACf,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,aAAa;YAC3B,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,kBAAkB,CAC3B,KAAK,CAAC,aAAa,EACnB,gBAAgB,EAChB,mBAAmB,KAAK,CAAC,aAAa,4BAA4B,CAClE,CAAC;YACH,CAAC;YACD,MAAM,GAAG;gBACR,MAAM,EAAE,KAAK,CAAC,aAAa;gBAC3B,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,MAAM,EAAE,aAAa,CAAC,MAAM,IAAI,EAAE;gBAClC,IAAI,EAAE;oBACL,YAAY;oBACZ,QAAQ;oBACR,QAAQ;oBACR,aAAa,EAAE,IAAI;oBACnB,eAAe,EAAE,IAAI;oBACrB,kBAAkB,EAAE,aAAa,CAAC,QAAQ,IAAI,IAAI;oBAClD,WAAW,EAAE,KAAK,CAAC,QAAQ;wBAC1B,CAAC,CAAC,4BAA4B,CAAC,KAAK,CAAC,QAAQ,CAAC;wBAC9C,CAAC,CAAC,CAAC,4BAA4B,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,OAAO,IAAI,IAAI,CAAC;iBAC1E;aACD,CAAC;QACH,CAAC;QACD,OAAO;QACP,2BAA2B,CAAC,MAAM;YACjC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;gBACxB,MAAM,OAAO,CACZ,IAAI,kBAAkB,CACrB,KAAK,CAAC,aAAa,EACnB,gBAAgB,EAChB,mBAAmB,KAAK,CAAC,aAAa,2CAA2C,CACjF,CACD,CAAC;YACH,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC"}
|