@leitwerk-dev/worker 0.1.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/LICENSE +13 -0
- package/dist/automatic-turn-executor.d.ts +28 -0
- package/dist/automatic-turn-executor.d.ts.map +1 -0
- package/dist/automatic-turn-executor.js +58 -0
- package/dist/automatic-turn-executor.js.map +1 -0
- package/dist/chunk-N5HLJDWA.js +8124 -0
- package/dist/chunk-N5HLJDWA.js.map +1 -0
- package/dist/diagnostics.d.ts +23 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +51 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/entry-runtime.d.ts +24 -0
- package/dist/entry-runtime.d.ts.map +1 -0
- package/dist/entry-runtime.js +160 -0
- package/dist/entry-runtime.js.map +1 -0
- package/dist/event-translator.d.ts +8 -0
- package/dist/event-translator.d.ts.map +1 -0
- package/dist/event-translator.js +12 -0
- package/dist/event-translator.js.map +1 -0
- package/dist/extension-entry-roots.d.ts +7 -0
- package/dist/extension-entry-roots.d.ts.map +1 -0
- package/dist/extension-entry-roots.js +41 -0
- package/dist/extension-entry-roots.js.map +1 -0
- package/dist/identified-pi-entry.d.ts +56 -0
- package/dist/identified-pi-entry.d.ts.map +1 -0
- package/dist/identified-pi-entry.js +125 -0
- package/dist/identified-pi-entry.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/input-consumer.d.ts +24 -0
- package/dist/input-consumer.d.ts.map +1 -0
- package/dist/input-consumer.js +34 -0
- package/dist/input-consumer.js.map +1 -0
- package/dist/ipc.d.ts +22 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +192 -0
- package/dist/ipc.js.map +1 -0
- package/dist/logical-prompt-runner.d.ts +49 -0
- package/dist/logical-prompt-runner.d.ts.map +1 -0
- package/dist/logical-prompt-runner.js +225 -0
- package/dist/logical-prompt-runner.js.map +1 -0
- package/dist/managed-pi-agent-dir.d.ts +13 -0
- package/dist/managed-pi-agent-dir.d.ts.map +1 -0
- package/dist/managed-pi-agent-dir.js +66 -0
- package/dist/managed-pi-agent-dir.js.map +1 -0
- package/dist/managed-pi-bootstrap.d.ts +24 -0
- package/dist/managed-pi-bootstrap.d.ts.map +1 -0
- package/dist/managed-pi-bootstrap.js +135 -0
- package/dist/managed-pi-bootstrap.js.map +1 -0
- package/dist/missing-tool-recovery-runner.d.ts +23 -0
- package/dist/missing-tool-recovery-runner.d.ts.map +1 -0
- package/dist/missing-tool-recovery-runner.js +73 -0
- package/dist/missing-tool-recovery-runner.js.map +1 -0
- package/dist/pi-adapter.d.ts +134 -0
- package/dist/pi-adapter.d.ts.map +1 -0
- package/dist/pi-adapter.js +1648 -0
- package/dist/pi-adapter.js.map +1 -0
- package/dist/pi-branch-guard.d.ts +39 -0
- package/dist/pi-branch-guard.d.ts.map +1 -0
- package/dist/pi-branch-guard.js +75 -0
- package/dist/pi-branch-guard.js.map +1 -0
- package/dist/pi-event-reporter.d.ts +15 -0
- package/dist/pi-event-reporter.d.ts.map +1 -0
- package/dist/pi-event-reporter.js +136 -0
- package/dist/pi-event-reporter.js.map +1 -0
- package/dist/pi-resource-bundle.d.ts +12 -0
- package/dist/pi-resource-bundle.d.ts.map +1 -0
- package/dist/pi-resource-bundle.js +58 -0
- package/dist/pi-resource-bundle.js.map +1 -0
- package/dist/pre-turn-targeted-inputs.d.ts +44 -0
- package/dist/pre-turn-targeted-inputs.d.ts.map +1 -0
- package/dist/pre-turn-targeted-inputs.js +101 -0
- package/dist/pre-turn-targeted-inputs.js.map +1 -0
- package/dist/prompt-guards.d.ts +52 -0
- package/dist/prompt-guards.d.ts.map +1 -0
- package/dist/prompt-guards.js +318 -0
- package/dist/prompt-guards.js.map +1 -0
- package/dist/question-bridge.d.ts +16 -0
- package/dist/question-bridge.d.ts.map +1 -0
- package/dist/question-bridge.js +55 -0
- package/dist/question-bridge.js.map +1 -0
- package/dist/question-tool.d.ts +14 -0
- package/dist/question-tool.d.ts.map +1 -0
- package/dist/question-tool.js +54 -0
- package/dist/question-tool.js.map +1 -0
- package/dist/resource-loader-factory.d.ts +11 -0
- package/dist/resource-loader-factory.d.ts.map +1 -0
- package/dist/resource-loader-factory.js +87 -0
- package/dist/resource-loader-factory.js.map +1 -0
- package/dist/result-image-upload.d.ts +14 -0
- package/dist/result-image-upload.d.ts.map +1 -0
- package/dist/result-image-upload.js +183 -0
- package/dist/result-image-upload.js.map +1 -0
- package/dist/runtime/adapters.d.ts +48 -0
- package/dist/runtime/adapters.d.ts.map +1 -0
- package/dist/runtime/adapters.js +15 -0
- package/dist/runtime/adapters.js.map +1 -0
- package/dist/runtime/bootstrap-session.d.ts +95 -0
- package/dist/runtime/bootstrap-session.d.ts.map +1 -0
- package/dist/runtime/bootstrap-session.js +198 -0
- package/dist/runtime/bootstrap-session.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +81 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +440 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/failure-policy.d.ts +79 -0
- package/dist/runtime/failure-policy.d.ts.map +1 -0
- package/dist/runtime/failure-policy.js +182 -0
- package/dist/runtime/failure-policy.js.map +1 -0
- package/dist/runtime/index.d.ts +9 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +326 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/lifecycle-reducer.d.ts +328 -0
- package/dist/runtime/lifecycle-reducer.d.ts.map +1 -0
- package/dist/runtime/lifecycle-reducer.js +1100 -0
- package/dist/runtime/lifecycle-reducer.js.map +1 -0
- package/dist/runtime/llm-turn-execution.d.ts +42 -0
- package/dist/runtime/llm-turn-execution.d.ts.map +1 -0
- package/dist/runtime/llm-turn-execution.js +472 -0
- package/dist/runtime/llm-turn-execution.js.map +1 -0
- package/dist/runtime/settings.d.ts +11 -0
- package/dist/runtime/settings.d.ts.map +1 -0
- package/dist/runtime/settings.js +23 -0
- package/dist/runtime/settings.js.map +1 -0
- package/dist/runtime/snapshot-policy.d.ts +11 -0
- package/dist/runtime/snapshot-policy.d.ts.map +1 -0
- package/dist/runtime/snapshot-policy.js +16 -0
- package/dist/runtime/snapshot-policy.js.map +1 -0
- package/dist/runtime/turn-execution.d.ts +49 -0
- package/dist/runtime/turn-execution.d.ts.map +1 -0
- package/dist/runtime/turn-execution.js +120 -0
- package/dist/runtime/turn-execution.js.map +1 -0
- package/dist/session-snapshot-exchange.d.ts +39 -0
- package/dist/session-snapshot-exchange.d.ts.map +1 -0
- package/dist/session-snapshot-exchange.js +102 -0
- package/dist/session-snapshot-exchange.js.map +1 -0
- package/dist/test-helpers/fake-websocket.d.ts +16 -0
- package/dist/test-helpers/fake-websocket.d.ts.map +1 -0
- package/dist/test-helpers/fake-websocket.js +40 -0
- package/dist/test-helpers/fake-websocket.js.map +1 -0
- package/dist/test-helpers/ipc-harness.d.ts +11 -0
- package/dist/test-helpers/ipc-harness.d.ts.map +1 -0
- package/dist/test-helpers/ipc-harness.js +17 -0
- package/dist/test-helpers/ipc-harness.js.map +1 -0
- package/dist/test-helpers/worker-message-builders.d.ts +21 -0
- package/dist/test-helpers/worker-message-builders.d.ts.map +1 -0
- package/dist/test-helpers/worker-message-builders.js +62 -0
- package/dist/test-helpers/worker-message-builders.js.map +1 -0
- package/dist/turn-continuation.d.ts +28 -0
- package/dist/turn-continuation.d.ts.map +1 -0
- package/dist/turn-continuation.js +80 -0
- package/dist/turn-continuation.js.map +1 -0
- package/dist/turn-execution-error.d.ts +39 -0
- package/dist/turn-execution-error.d.ts.map +1 -0
- package/dist/turn-execution-error.js +64 -0
- package/dist/turn-execution-error.js.map +1 -0
- package/dist/turn-execution-result.d.ts +35 -0
- package/dist/turn-execution-result.d.ts.map +1 -0
- package/dist/turn-execution-result.js +21 -0
- package/dist/turn-execution-result.js.map +1 -0
- package/dist/turn-outcome-tool-session.d.ts +50 -0
- package/dist/turn-outcome-tool-session.d.ts.map +1 -0
- package/dist/turn-outcome-tool-session.js +209 -0
- package/dist/turn-outcome-tool-session.js.map +1 -0
- package/dist/turn-record-id.d.ts +3 -0
- package/dist/turn-record-id.d.ts.map +1 -0
- package/dist/turn-record-id.js +10 -0
- package/dist/turn-record-id.js.map +1 -0
- package/dist/turn-result-markdown.d.ts +74 -0
- package/dist/turn-result-markdown.d.ts.map +1 -0
- package/dist/turn-result-markdown.js +263 -0
- package/dist/turn-result-markdown.js.map +1 -0
- package/dist/turn-tree-strategy.d.ts +29 -0
- package/dist/turn-tree-strategy.d.ts.map +1 -0
- package/dist/turn-tree-strategy.js +80 -0
- package/dist/turn-tree-strategy.js.map +1 -0
- package/dist/worker-entry.d.ts +2 -0
- package/dist/worker-entry.d.ts.map +1 -0
- package/dist/worker-entry.js +7 -0
- package/dist/worker-entry.js.map +1 -0
- package/dist/worker-http.d.ts +2 -0
- package/dist/worker-http.d.ts.map +1 -0
- package/dist/worker-http.js +9 -0
- package/dist/worker-http.js.map +1 -0
- package/dist/worker-ipc-reporter.d.ts +29 -0
- package/dist/worker-ipc-reporter.d.ts.map +1 -0
- package/dist/worker-ipc-reporter.js +58 -0
- package/dist/worker-ipc-reporter.js.map +1 -0
- package/dist/worker-payloads.d.ts +10 -0
- package/dist/worker-payloads.d.ts.map +1 -0
- package/dist/worker-payloads.js +66 -0
- package/dist/worker-payloads.js.map +1 -0
- package/dist/worker-start-payload.d.ts +7 -0
- package/dist/worker-start-payload.d.ts.map +1 -0
- package/dist/worker-start-payload.js +5 -0
- package/dist/worker-start-payload.js.map +1 -0
- package/dist/workspace/manifest.d.ts +35 -0
- package/dist/workspace/manifest.d.ts.map +1 -0
- package/dist/workspace/manifest.js +79 -0
- package/dist/workspace/manifest.js.map +1 -0
- package/dist/workspace/node-run-root-git-ops.d.ts +17 -0
- package/dist/workspace/node-run-root-git-ops.d.ts.map +1 -0
- package/dist/workspace/node-run-root-git-ops.js +96 -0
- package/dist/workspace/node-run-root-git-ops.js.map +1 -0
- package/dist/workspace/resource-aggregator.d.ts +15 -0
- package/dist/workspace/resource-aggregator.d.ts.map +1 -0
- package/dist/workspace/resource-aggregator.js +39 -0
- package/dist/workspace/resource-aggregator.js.map +1 -0
- package/dist/workspace/run-root.d.ts +52 -0
- package/dist/workspace/run-root.d.ts.map +1 -0
- package/dist/workspace/run-root.js +209 -0
- package/dist/workspace/run-root.js.map +1 -0
- package/package.json +55 -0
- package/src/automatic-turn-executor.ts +106 -0
- package/src/diagnostics.ts +82 -0
- package/src/entry-runtime.ts +235 -0
- package/src/event-translator.ts +22 -0
- package/src/extension-entry-roots.ts +43 -0
- package/src/identified-pi-entry.ts +188 -0
- package/src/index.ts +54 -0
- package/src/input-consumer.ts +71 -0
- package/src/ipc.ts +250 -0
- package/src/logical-prompt-runner.ts +320 -0
- package/src/managed-pi-agent-dir.ts +86 -0
- package/src/managed-pi-bootstrap.ts +208 -0
- package/src/missing-tool-recovery-runner.ts +112 -0
- package/src/pi-adapter.ts +2197 -0
- package/src/pi-branch-guard.ts +104 -0
- package/src/pi-event-reporter.ts +164 -0
- package/src/pi-resource-bundle.ts +90 -0
- package/src/pre-turn-targeted-inputs.ts +167 -0
- package/src/prompt-guards.ts +385 -0
- package/src/question-bridge.ts +69 -0
- package/src/question-tool.ts +65 -0
- package/src/resource-loader-factory.ts +115 -0
- package/src/result-image-upload.ts +256 -0
- package/src/runtime/adapters.ts +67 -0
- package/src/runtime/bootstrap-session.ts +294 -0
- package/src/runtime/bootstrap.ts +621 -0
- package/src/runtime/failure-policy.ts +274 -0
- package/src/runtime/index.ts +362 -0
- package/src/runtime/lifecycle-reducer.ts +1537 -0
- package/src/runtime/llm-turn-execution.ts +696 -0
- package/src/runtime/settings.ts +41 -0
- package/src/runtime/snapshot-policy.ts +28 -0
- package/src/runtime/turn-execution.ts +203 -0
- package/src/session-snapshot-exchange.ts +155 -0
- package/src/test-helpers/fake-websocket.ts +46 -0
- package/src/test-helpers/ipc-harness.ts +19 -0
- package/src/test-helpers/worker-message-builders.ts +92 -0
- package/src/turn-continuation.ts +147 -0
- package/src/turn-execution-error.ts +102 -0
- package/src/turn-execution-result.ts +48 -0
- package/src/turn-outcome-tool-session.ts +311 -0
- package/src/turn-record-id.ts +17 -0
- package/src/turn-result-markdown.ts +355 -0
- package/src/turn-tree-strategy.ts +141 -0
- package/src/worker-entry.ts +8 -0
- package/src/worker-http.ts +6 -0
- package/src/worker-ipc-reporter.ts +100 -0
- package/src/worker-payloads.ts +94 -0
- package/src/worker-start-payload.ts +10 -0
- package/src/workspace/manifest.ts +126 -0
- package/src/workspace/node-run-root-git-ops.ts +137 -0
- package/src/workspace/resource-aggregator.ts +43 -0
- package/src/workspace/run-root.ts +361 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
detectRepoLocatorKind,
|
|
3
|
+
type ProcessInstance,
|
|
4
|
+
type ProcessProductRefs,
|
|
5
|
+
type ProcessProject,
|
|
6
|
+
type ProcessSemanticEntryRefs,
|
|
7
|
+
parseProcessProductRefs,
|
|
8
|
+
parseSemanticEntryRefsFromStateJsonStrict,
|
|
9
|
+
parseSemanticEntryRefsLenient,
|
|
10
|
+
} from "@leitwerk-dev/domain";
|
|
11
|
+
import type {
|
|
12
|
+
InputDelivery,
|
|
13
|
+
ProcessInstanceSnapshot,
|
|
14
|
+
ProcessProjectSnapshot,
|
|
15
|
+
} from "@leitwerk-dev/worker-protocol";
|
|
16
|
+
import type { InputItem } from "./input-consumer.js";
|
|
17
|
+
|
|
18
|
+
export function inputDeliveryToItem(delivery: InputDelivery): InputItem {
|
|
19
|
+
return {
|
|
20
|
+
inputId: delivery.inputId,
|
|
21
|
+
sequence: delivery.sequence,
|
|
22
|
+
source: delivery.source,
|
|
23
|
+
kind: delivery.kind,
|
|
24
|
+
target: delivery.target,
|
|
25
|
+
bodyMarkdown: delivery.bodyMarkdown,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function projectSnapshotsFromPayload(raw: ProcessProjectSnapshot[]): ProcessProject[] {
|
|
30
|
+
return raw.map((project) => ({
|
|
31
|
+
id: project.id ?? "",
|
|
32
|
+
instanceId: project.instanceId ?? "",
|
|
33
|
+
key: project.key,
|
|
34
|
+
repoLocator: project.repoLocator,
|
|
35
|
+
repoLocatorKind:
|
|
36
|
+
project.repoLocatorKind ?? detectRepoLocatorKind(project.repoLocator) ?? "remote_url",
|
|
37
|
+
baseBranch: project.baseBranch,
|
|
38
|
+
workBranch: project.workBranch ?? "",
|
|
39
|
+
externalId: project.externalId ?? null,
|
|
40
|
+
externalUrl: project.externalUrl ?? null,
|
|
41
|
+
metadata: project.metadata ?? null,
|
|
42
|
+
pipelineStatus: project.pipelineStatus ?? null,
|
|
43
|
+
createdAt: project.createdAt ?? "",
|
|
44
|
+
updatedAt: project.updatedAt ?? "",
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function buildProcessSnapshotSeed(
|
|
49
|
+
processId: string,
|
|
50
|
+
processSnapshot: ProcessInstanceSnapshot,
|
|
51
|
+
): ProcessInstance {
|
|
52
|
+
const resolvedProcessId = processSnapshot.processId ?? processId;
|
|
53
|
+
return {
|
|
54
|
+
id: processSnapshot.id ?? "",
|
|
55
|
+
processId: resolvedProcessId,
|
|
56
|
+
selectedTurnId: processSnapshot.selectedTurnId ?? null,
|
|
57
|
+
lifecycleStatus: processSnapshot.lifecycleStatus ?? "discovered",
|
|
58
|
+
currentExecution: processSnapshot.currentExecution ?? null,
|
|
59
|
+
planRevision: processSnapshot.planRevision ?? 0,
|
|
60
|
+
title: processSnapshot.title ?? null,
|
|
61
|
+
externalId: processSnapshot.externalId ?? null,
|
|
62
|
+
externalUrl: processSnapshot.externalUrl ?? null,
|
|
63
|
+
metadata: processSnapshot.metadata ?? null,
|
|
64
|
+
defaultModelProfileId: processSnapshot.defaultModelProfileId ?? null,
|
|
65
|
+
turnConfigsJson: processSnapshot.turnConfigsJson ?? null,
|
|
66
|
+
selectedTurnModelProfileId: processSnapshot.selectedTurnModelProfileId ?? null,
|
|
67
|
+
paramsJson: processSnapshot.paramsJson ?? null,
|
|
68
|
+
stateJson: processSnapshot.stateJson ?? null,
|
|
69
|
+
createdAt: processSnapshot.createdAt ?? "",
|
|
70
|
+
updatedAt: processSnapshot.updatedAt ?? "",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function readProcessSemanticEntryRefs(state: unknown): ProcessSemanticEntryRefs | null {
|
|
75
|
+
if (typeof state !== "object" || state === null || Array.isArray(state)) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return parseSemanticEntryRefsLenient(
|
|
79
|
+
(state as { semanticEntryRefs?: unknown }).semanticEntryRefs,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function readProcessProductRefs(state: unknown): ProcessProductRefs | null {
|
|
84
|
+
if (typeof state !== "object" || state === null || Array.isArray(state)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return parseProcessProductRefs((state as { productRefs?: unknown }).productRefs);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function parseProcessSemanticEntryRefsFromStateJson(
|
|
91
|
+
stateJson: string | null | undefined,
|
|
92
|
+
): ProcessSemanticEntryRefs {
|
|
93
|
+
return parseSemanticEntryRefsFromStateJsonStrict(stateJson, "process stateJson");
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorkerStartPayload } from "@leitwerk-dev/worker-protocol";
|
|
2
|
+
|
|
3
|
+
export type LlmWorkerStartPayload = Extract<WorkerStartPayload, { configSnapshot: unknown }>;
|
|
4
|
+
|
|
5
|
+
/** Correlates the nested bootstrap discriminant with the containing payload variant. */
|
|
6
|
+
export function isLlmWorkerStartPayload(
|
|
7
|
+
payload: WorkerStartPayload,
|
|
8
|
+
): payload is LlmWorkerStartPayload {
|
|
9
|
+
return payload.bootstrap.kind === "llm";
|
|
10
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
export interface ComponentManifest {
|
|
4
|
+
version: 1;
|
|
5
|
+
instanceId: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
components: ComponentManifestEntry[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ComponentManifestEntry {
|
|
11
|
+
key: string;
|
|
12
|
+
repoLocator: string;
|
|
13
|
+
baseBranch: string;
|
|
14
|
+
workBranch: string;
|
|
15
|
+
clonedAt: string;
|
|
16
|
+
headSha: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ManifestDiff {
|
|
20
|
+
stale: string[];
|
|
21
|
+
missing: string[];
|
|
22
|
+
extra: string[];
|
|
23
|
+
unchanged: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function serializeManifest(manifest: ComponentManifest): string {
|
|
27
|
+
return JSON.stringify(manifest, null, 2);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const jsonObjectSchema = v.custom<Record<string, unknown>>(
|
|
31
|
+
(value): value is Record<string, unknown> =>
|
|
32
|
+
typeof value === "object" && value !== null && !Array.isArray(value),
|
|
33
|
+
"Expected object",
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const componentManifestEntrySchema = v.pipe(
|
|
37
|
+
jsonObjectSchema,
|
|
38
|
+
v.object({
|
|
39
|
+
key: v.string(),
|
|
40
|
+
repoLocator: v.string(),
|
|
41
|
+
baseBranch: v.string(),
|
|
42
|
+
workBranch: v.string(),
|
|
43
|
+
clonedAt: v.string(),
|
|
44
|
+
headSha: v.string(),
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const componentManifestSchema = v.pipe(
|
|
49
|
+
jsonObjectSchema,
|
|
50
|
+
v.object({
|
|
51
|
+
version: v.literal(1),
|
|
52
|
+
instanceId: v.pipe(v.string(), v.minLength(1)),
|
|
53
|
+
createdAt: v.pipe(v.string(), v.minLength(1)),
|
|
54
|
+
components: v.array(componentManifestEntrySchema),
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const componentManifestJsonSchema = v.pipe(v.string(), v.parseJson(), componentManifestSchema);
|
|
59
|
+
|
|
60
|
+
function formatManifestValidationError(issues: readonly v.BaseIssue<unknown>[]): string {
|
|
61
|
+
const issue = issues[0];
|
|
62
|
+
if (issue?.type === "parse_json") return "Invalid JSON";
|
|
63
|
+
const path = issue ? v.getDotPath(issue) : null;
|
|
64
|
+
if (!path) return "Manifest must be a JSON object";
|
|
65
|
+
if (path === "version") return "Unsupported manifest version";
|
|
66
|
+
if (path === "instanceId") return "Invalid instanceId";
|
|
67
|
+
if (path === "createdAt") return "Invalid createdAt";
|
|
68
|
+
if (path === "components") return "components must be an array";
|
|
69
|
+
if (path.match(/^components\.\d+$/)) return "Invalid component entry";
|
|
70
|
+
const componentField = path.match(/^components\.\d+\.([^.]*)$/)?.[1];
|
|
71
|
+
if (componentField) return `Invalid component field: ${componentField}`;
|
|
72
|
+
return issue?.message ? `Invalid manifest: ${issue.message}` : "Invalid manifest";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function deserializeManifest(
|
|
76
|
+
content: string,
|
|
77
|
+
): { ok: true; manifest: ComponentManifest } | { ok: false; error: string } {
|
|
78
|
+
const result = v.safeParse(componentManifestJsonSchema, content, { abortEarly: true });
|
|
79
|
+
if (!result.success) {
|
|
80
|
+
return { ok: false, error: formatManifestValidationError(result.issues) };
|
|
81
|
+
}
|
|
82
|
+
return { ok: true, manifest: result.output };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function diffManifest(
|
|
86
|
+
existing: ComponentManifest,
|
|
87
|
+
serverProjects: Array<{
|
|
88
|
+
key: string;
|
|
89
|
+
repoLocator: string;
|
|
90
|
+
baseBranch: string;
|
|
91
|
+
workBranch: string;
|
|
92
|
+
}>,
|
|
93
|
+
): ManifestDiff {
|
|
94
|
+
const stale: string[] = [];
|
|
95
|
+
const missing: string[] = [];
|
|
96
|
+
const extra: string[] = [];
|
|
97
|
+
const unchanged: string[] = [];
|
|
98
|
+
|
|
99
|
+
const byKey = new Map(existing.components.map((c) => [c.key, c]));
|
|
100
|
+
const serverByKey = new Map(serverProjects.map((p) => [p.key, p]));
|
|
101
|
+
|
|
102
|
+
for (const p of serverProjects) {
|
|
103
|
+
const m = byKey.get(p.key);
|
|
104
|
+
if (!m) {
|
|
105
|
+
missing.push(p.key);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (
|
|
109
|
+
m.repoLocator === p.repoLocator &&
|
|
110
|
+
m.baseBranch === p.baseBranch &&
|
|
111
|
+
m.workBranch === p.workBranch
|
|
112
|
+
) {
|
|
113
|
+
unchanged.push(p.key);
|
|
114
|
+
} else {
|
|
115
|
+
stale.push(p.key);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for (const c of existing.components) {
|
|
120
|
+
if (!serverByKey.has(c.key)) {
|
|
121
|
+
extra.push(c.key);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return { stale, missing, extra, unchanged };
|
|
126
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chmodSync,
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import {
|
|
13
|
+
clearRepositoryGitSshWrappers,
|
|
14
|
+
repositoryGitArgs,
|
|
15
|
+
repositoryGitSubprocessEnv,
|
|
16
|
+
setRepositoryGitSshWrapper,
|
|
17
|
+
} from "@leitwerk-dev/process-sdk";
|
|
18
|
+
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
19
|
+
import type { WorkerGitSshCredential } from "@leitwerk-dev/worker-protocol";
|
|
20
|
+
import { execa } from "execa";
|
|
21
|
+
import fg from "fast-glob";
|
|
22
|
+
import type { RunRootGitOps } from "./run-root.js";
|
|
23
|
+
|
|
24
|
+
function toAbsolute(targetPath: string): string {
|
|
25
|
+
return path.resolve(targetPath);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class NodeRunRootGitOps implements RunRootGitOps {
|
|
29
|
+
#credentialDir: string | null = null;
|
|
30
|
+
|
|
31
|
+
configureRepositoryCredentials(credentials: readonly WorkerGitSshCredential[]): void {
|
|
32
|
+
this.cleanupRepositoryCredentials();
|
|
33
|
+
if (credentials.length === 0) return;
|
|
34
|
+
const root = mkdtempSync(path.join(tmpdir(), "leitwerk-repo-auth-"));
|
|
35
|
+
chmodSync(root, 0o700);
|
|
36
|
+
this.#credentialDir = root;
|
|
37
|
+
for (const credential of credentials) {
|
|
38
|
+
const dir = path.join(root, encodeURIComponent(credential.projectKey));
|
|
39
|
+
mkdirSync(dir, { mode: 0o700 });
|
|
40
|
+
const key = path.join(dir, "identity");
|
|
41
|
+
const hosts = path.join(dir, "known_hosts");
|
|
42
|
+
const wrapper = path.join(dir, "ssh");
|
|
43
|
+
writeFileSync(key, `${credential.privateKey.trim()}\n`, { mode: 0o600 });
|
|
44
|
+
writeFileSync(hosts, `${credential.knownHosts.trim()}\n`, { mode: 0o600 });
|
|
45
|
+
writeFileSync(
|
|
46
|
+
wrapper,
|
|
47
|
+
`#!/bin/sh\nexec ssh -F /dev/null -o IdentitiesOnly=yes -o IdentityFile="${key}" -o UserKnownHostsFile="${hosts}" -o StrictHostKeyChecking=yes -o BatchMode=yes "$@"\n`,
|
|
48
|
+
{ mode: 0o700 },
|
|
49
|
+
);
|
|
50
|
+
setRepositoryGitSshWrapper(credential.projectKey, wrapper);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
cleanupRepositoryCredentials(): void {
|
|
55
|
+
clearRepositoryGitSshWrappers();
|
|
56
|
+
if (this.#credentialDir) rmSync(this.#credentialDir, { recursive: true, force: true });
|
|
57
|
+
this.#credentialDir = null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async runGit(
|
|
61
|
+
args: readonly string[],
|
|
62
|
+
cwd?: string,
|
|
63
|
+
projectKey?: string,
|
|
64
|
+
): Promise<string> {
|
|
65
|
+
const result = await execa(resolveGitBinary(), repositoryGitArgs(args), {
|
|
66
|
+
...(cwd ? { cwd: toAbsolute(cwd) } : {}),
|
|
67
|
+
env: repositoryGitSubprocessEnv(projectKey ?? "", { GIT_TERMINAL_PROMPT: "0" }),
|
|
68
|
+
extendEnv: false,
|
|
69
|
+
stdin: "ignore",
|
|
70
|
+
});
|
|
71
|
+
return result.stdout;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async writeFile(repoDir: string, filePath: string, content: string): Promise<void> {
|
|
75
|
+
const absolutePath = toAbsolute(path.join(repoDir, filePath));
|
|
76
|
+
mkdirSync(path.dirname(absolutePath), { recursive: true });
|
|
77
|
+
writeFileSync(absolutePath, content, "utf8");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async readFile(repoDir: string, filePath: string): Promise<string | null> {
|
|
81
|
+
const absolutePath = toAbsolute(path.join(repoDir, filePath));
|
|
82
|
+
if (!existsSync(absolutePath)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return readFileSync(absolutePath, "utf8");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async clone(repoLocator: string, targetDir: string): Promise<void> {
|
|
89
|
+
const absoluteTargetDir = toAbsolute(targetDir);
|
|
90
|
+
rmSync(absoluteTargetDir, { recursive: true, force: true });
|
|
91
|
+
mkdirSync(path.dirname(absoluteTargetDir), { recursive: true });
|
|
92
|
+
await this.runGit(
|
|
93
|
+
["clone", repoLocator, absoluteTargetDir],
|
|
94
|
+
undefined,
|
|
95
|
+
path.basename(absoluteTargetDir),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async checkout(repoDir: string, branch: string): Promise<void> {
|
|
100
|
+
await this.runGit(["checkout", branch], repoDir);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async createBranch(repoDir: string, branchName: string, startPoint: string): Promise<void> {
|
|
104
|
+
await this.runGit(["branch", branchName, startPoint], repoDir);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async branchExists(repoDir: string, branchName: string): Promise<boolean> {
|
|
108
|
+
try {
|
|
109
|
+
const output = await this.runGit(
|
|
110
|
+
["rev-parse", "--verify", "--quiet", `refs/heads/${branchName}`],
|
|
111
|
+
repoDir,
|
|
112
|
+
);
|
|
113
|
+
return output.trim() !== "";
|
|
114
|
+
} catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async getHeadSha(repoDir: string): Promise<string> {
|
|
120
|
+
return (await this.runGit(["rev-parse", "HEAD"], repoDir)).trim();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async listFiles(repoDir: string, pattern: string): Promise<string[]> {
|
|
124
|
+
const absoluteRoot = toAbsolute(repoDir);
|
|
125
|
+
if (!existsSync(absoluteRoot)) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
return (
|
|
129
|
+
await fg(pattern, {
|
|
130
|
+
cwd: absoluteRoot,
|
|
131
|
+
dot: true,
|
|
132
|
+
onlyFiles: true,
|
|
133
|
+
ignore: ["**/.git/**"],
|
|
134
|
+
})
|
|
135
|
+
).sort((a, b) => a.localeCompare(b));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function formatProvenanceMarker(componentKey: string, filePath: string): string {
|
|
2
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
3
|
+
return `<!-- source: ${componentKey}/${normalizedPath} -->`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function aggregateAgentsMd(
|
|
7
|
+
sources: Array<{ componentKey: string; filePath: string; content: string }>,
|
|
8
|
+
): string {
|
|
9
|
+
const sorted = [...sources].sort((a, b) => a.componentKey.localeCompare(b.componentKey));
|
|
10
|
+
if (sorted.length === 0) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
const parts: string[] = [];
|
|
14
|
+
for (const s of sorted) {
|
|
15
|
+
parts.push(formatProvenanceMarker(s.componentKey, s.filePath));
|
|
16
|
+
parts.push(s.content.trimEnd());
|
|
17
|
+
}
|
|
18
|
+
return `${parts.join("\n\n").trimEnd()}\n`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function collectSkills(
|
|
22
|
+
sources: Array<{ componentKey: string; skillId: string; content: string }>,
|
|
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
|
+
const out = new Map<string, { content: string; source: string }>();
|
|
34
|
+
for (const [skillId, group] of byId) {
|
|
35
|
+
group.sort((a, b) => a.componentKey.localeCompare(b.componentKey));
|
|
36
|
+
const winner = group[0];
|
|
37
|
+
out.set(skillId, {
|
|
38
|
+
content: winner.content,
|
|
39
|
+
source: winner.componentKey,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|