@leitwerk-dev/worker 0.2.0 → 0.3.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/{chunk-Y7S2MZD3.js → chunk-4WNVRNE5.js} +634 -605
- package/dist/chunk-4WNVRNE5.js.map +1 -0
- package/dist/development-tool-environment.d.ts +39 -3
- package/dist/development-tool-environment.d.ts.map +1 -1
- package/dist/entry-runtime.d.ts +20 -0
- package/dist/entry-runtime.d.ts.map +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -37
- package/dist/input-consumer.d.ts +1 -0
- package/dist/input-consumer.d.ts.map +1 -1
- package/dist/ipc.d.ts +9 -0
- package/dist/ipc.d.ts.map +1 -1
- package/dist/managed-pi-agent-dir.d.ts +8 -1
- package/dist/managed-pi-agent-dir.d.ts.map +1 -1
- package/dist/managed-pi-bootstrap.d.ts +1 -0
- package/dist/managed-pi-bootstrap.d.ts.map +1 -1
- package/dist/pi-adapter.d.ts +87 -1
- package/dist/pi-adapter.d.ts.map +1 -1
- package/dist/pi-resource-bundle.d.ts +6 -1
- package/dist/pi-resource-bundle.d.ts.map +1 -1
- package/dist/prompt-guards.d.ts +6 -0
- package/dist/prompt-guards.d.ts.map +1 -1
- package/dist/runtime/adapters.d.ts +38 -0
- package/dist/runtime/adapters.d.ts.map +1 -1
- package/dist/runtime/bootstrap-session.d.ts +1 -0
- package/dist/runtime/bootstrap-session.d.ts.map +1 -1
- package/dist/runtime/bootstrap.d.ts +24 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +4 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/session-snapshot-exchange.d.ts +10 -0
- package/dist/session-snapshot-exchange.d.ts.map +1 -1
- package/dist/worker-entry.js +1 -1
- package/dist/workspace/run-root.d.ts +12 -0
- package/dist/workspace/run-root.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/development-tool-environment.ts +42 -4
- package/src/entry-runtime.ts +27 -1
- package/src/index.ts +1 -50
- package/src/input-consumer.ts +1 -0
- package/src/ipc.ts +14 -1
- package/src/managed-pi-agent-dir.ts +8 -1
- package/src/managed-pi-bootstrap.ts +1 -0
- package/src/pi-adapter.ts +106 -6
- package/src/pi-resource-bundle.ts +10 -2
- package/src/prompt-guards.ts +6 -0
- package/src/runtime/adapters.ts +46 -4
- package/src/runtime/bootstrap-session.ts +1 -0
- package/src/runtime/bootstrap.ts +27 -1
- package/src/runtime/index.ts +12 -3
- package/src/session-snapshot-exchange.ts +23 -4
- package/src/workspace/run-root.ts +12 -0
- package/dist/chunk-Y7S2MZD3.js.map +0 -1
|
@@ -10,9 +10,13 @@ function safeSegment(value: string, name: string): string {
|
|
|
10
10
|
return value;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/** @internal */
|
|
13
14
|
export function resolveManagedPiAgentDir(input: {
|
|
15
|
+
/** @internal */
|
|
14
16
|
agentDirRoot: string;
|
|
17
|
+
/** @internal */
|
|
15
18
|
instanceId: string;
|
|
19
|
+
/** @internal */
|
|
16
20
|
startOrLeaseId: string;
|
|
17
21
|
}): string {
|
|
18
22
|
const root = path.resolve(input.agentDirRoot);
|
|
@@ -51,12 +55,15 @@ async function assertNoSymlinkParents(root: string, target: string): Promise<voi
|
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
|
|
58
|
+
/** @internal */
|
|
54
59
|
export interface DeclaredCredentialFile {
|
|
60
|
+
/** @internal */
|
|
55
61
|
path: string;
|
|
62
|
+
/** @internal */
|
|
56
63
|
content: string | Uint8Array;
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
/** Atomically writes declared credential files inside an existing managed directory. */
|
|
66
|
+
/** Atomically writes declared credential files inside an existing managed directory. @internal */
|
|
60
67
|
export async function writeManagedPiCredentialFiles(
|
|
61
68
|
agentDir: string,
|
|
62
69
|
files: readonly DeclaredCredentialFile[],
|
package/src/pi-adapter.ts
CHANGED
|
@@ -52,7 +52,6 @@ export type {
|
|
|
52
52
|
PiRunDetails,
|
|
53
53
|
PiSessionDiagnostic,
|
|
54
54
|
PiSessionDiagnosticHandler,
|
|
55
|
-
PiSessionDiagnosticLevel,
|
|
56
55
|
PiTreeEntry,
|
|
57
56
|
PiTreeHandle,
|
|
58
57
|
PiTreeNode,
|
|
@@ -60,53 +59,110 @@ export type {
|
|
|
60
59
|
} from "@leitwerk-dev/process-sdk";
|
|
61
60
|
export { isPiBranchDriftError, PiBranchDriftError } from "./pi-branch-guard.js";
|
|
62
61
|
|
|
62
|
+
/** @public */
|
|
63
63
|
export interface PiTreeHandleOptions {
|
|
64
|
+
/** @internal */
|
|
64
65
|
instanceId: string;
|
|
66
|
+
/** @internal */
|
|
65
67
|
treeFile: string;
|
|
68
|
+
/** @public */
|
|
66
69
|
workspaceRoot: string;
|
|
70
|
+
/** @public */
|
|
67
71
|
sessionCwd?: string;
|
|
72
|
+
/** @internal */
|
|
68
73
|
resume: boolean;
|
|
74
|
+
/** @internal */
|
|
69
75
|
agentDir?: string;
|
|
76
|
+
/** @internal */
|
|
70
77
|
configSnapshot?: ConfigSnapshot;
|
|
78
|
+
/** @internal */
|
|
71
79
|
modelProfileId?: string | null;
|
|
80
|
+
/** @internal */
|
|
72
81
|
piConfig?: {
|
|
82
|
+
/** @internal */
|
|
73
83
|
systemPrompt?: string;
|
|
84
|
+
/** @internal */
|
|
74
85
|
appendSystemPrompt?: string;
|
|
86
|
+
/** @internal */
|
|
75
87
|
availableToolNames: string[];
|
|
76
88
|
};
|
|
77
89
|
}
|
|
78
90
|
|
|
91
|
+
/** @internal */
|
|
79
92
|
export interface PiManagedBootstrapOptions {
|
|
93
|
+
/** @internal */
|
|
80
94
|
agentDir: string;
|
|
95
|
+
/** @internal */
|
|
81
96
|
workspaceRoot: string;
|
|
97
|
+
/** @internal */
|
|
82
98
|
sessionCwd: string;
|
|
99
|
+
/** @internal */
|
|
83
100
|
configSnapshot: ConfigSnapshot;
|
|
101
|
+
/** @internal */
|
|
84
102
|
piConfig: PiTreeHandleOptions["piConfig"];
|
|
103
|
+
/** @internal */
|
|
85
104
|
manifest: ManagedPiResourceManifest;
|
|
86
|
-
|
|
105
|
+
/** @internal */
|
|
106
|
+
expectedModel: {
|
|
107
|
+
/** @internal */
|
|
108
|
+
providerId: string;
|
|
109
|
+
/** @internal */
|
|
110
|
+
modelId: string;
|
|
111
|
+
};
|
|
87
112
|
}
|
|
88
113
|
|
|
114
|
+
/** @internal */
|
|
89
115
|
export interface PiManagedBootstrapResult {
|
|
116
|
+
/** @internal */
|
|
90
117
|
loadedResourceIds: string[];
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
118
|
+
/** @internal */
|
|
119
|
+
loadedAgentsFiles: Array<{
|
|
120
|
+
/** @internal */
|
|
121
|
+
path: string;
|
|
122
|
+
/** @internal */
|
|
123
|
+
sizeBytes: number;
|
|
124
|
+
}>;
|
|
125
|
+
/** @internal */
|
|
126
|
+
loadedSkillFiles: Array<{
|
|
127
|
+
/** @internal */
|
|
128
|
+
name: string;
|
|
129
|
+
/** @internal */
|
|
130
|
+
path: string;
|
|
131
|
+
}>;
|
|
132
|
+
/** @internal */
|
|
133
|
+
resolvedModel: {
|
|
134
|
+
/** @internal */
|
|
135
|
+
providerId: string;
|
|
136
|
+
/** @internal */
|
|
137
|
+
modelId: string;
|
|
138
|
+
};
|
|
139
|
+
/** @internal */
|
|
94
140
|
diagnostics: string[];
|
|
95
141
|
}
|
|
96
142
|
|
|
143
|
+
/** @public */
|
|
97
144
|
export interface PiTreeHandleFactory {
|
|
145
|
+
/** @internal */
|
|
98
146
|
prepareManagedBootstrap(opts: PiManagedBootstrapOptions): Promise<PiManagedBootstrapResult>;
|
|
147
|
+
/** @internal */
|
|
99
148
|
inspectPrimaryTree(opts: PiTreePlanningOptions): Promise<PiTreePlanningSnapshot>;
|
|
149
|
+
/** @internal */
|
|
100
150
|
createPrimaryTreeHandle(opts: PiTreeHandleOptions): Promise<PiTreeHandle>;
|
|
101
151
|
}
|
|
102
152
|
|
|
153
|
+
/** @internal */
|
|
103
154
|
export interface PiTreePlanningOptions {
|
|
155
|
+
/** @internal */
|
|
104
156
|
treeFile: string;
|
|
157
|
+
/** @internal */
|
|
105
158
|
sessionCwd: string;
|
|
106
159
|
}
|
|
107
160
|
|
|
161
|
+
/** @internal */
|
|
108
162
|
export interface PiTreePlanningSnapshot {
|
|
163
|
+
/** @internal */
|
|
109
164
|
currentLeafId: string | null;
|
|
165
|
+
/** @internal */
|
|
110
166
|
entries: readonly Pick<PiTreeEntry, "id" | "parentId">[];
|
|
111
167
|
}
|
|
112
168
|
|
|
@@ -684,8 +740,11 @@ function describeRetryEnd(input: {
|
|
|
684
740
|
: `Retry sequence failed after ${attemptLabel}`;
|
|
685
741
|
}
|
|
686
742
|
|
|
743
|
+
/** @internal */
|
|
687
744
|
export interface AgentSessionEventTranslation {
|
|
745
|
+
/** @internal */
|
|
688
746
|
piEvents: PiEvent[];
|
|
747
|
+
/** @internal */
|
|
689
748
|
diagnostics: PiSessionDiagnostic[];
|
|
690
749
|
}
|
|
691
750
|
|
|
@@ -705,6 +764,7 @@ const INACTIVITY_RESET_EVENT_TYPES = new Set<PiEventType>([
|
|
|
705
764
|
"retry.end",
|
|
706
765
|
]);
|
|
707
766
|
|
|
767
|
+
/** @internal */
|
|
708
768
|
export function doesPiEventResetInactivity(event: PiEvent): boolean {
|
|
709
769
|
return INACTIVITY_RESET_EVENT_TYPES.has(event.type);
|
|
710
770
|
}
|
|
@@ -883,9 +943,15 @@ function buildUnknownAssistantEventDiagnostic(input: {
|
|
|
883
943
|
});
|
|
884
944
|
}
|
|
885
945
|
|
|
946
|
+
/** @internal */
|
|
886
947
|
export function translateAgentSessionEventEnvelope(
|
|
887
948
|
event: AgentSessionEvent,
|
|
888
|
-
state: {
|
|
949
|
+
state: {
|
|
950
|
+
/** @internal */
|
|
951
|
+
currentTurnId: string | null;
|
|
952
|
+
/** @internal */
|
|
953
|
+
turnSequence: number;
|
|
954
|
+
},
|
|
889
955
|
): AgentSessionEventTranslation {
|
|
890
956
|
const runtimeEventType = (event as unknown as { type?: unknown }).type;
|
|
891
957
|
if (runtimeEventType === "session_info_changed") {
|
|
@@ -1267,9 +1333,13 @@ export function translateAgentSessionEventEnvelope(
|
|
|
1267
1333
|
}
|
|
1268
1334
|
}
|
|
1269
1335
|
|
|
1336
|
+
/** @internal */
|
|
1270
1337
|
export class SdkPiTreeHandle implements PiTreeHandle {
|
|
1338
|
+
/** @internal */
|
|
1271
1339
|
readonly sessionId: string;
|
|
1340
|
+
/** @internal */
|
|
1272
1341
|
readonly treeFile: string;
|
|
1342
|
+
/** @internal */
|
|
1273
1343
|
readonly isResumed: boolean;
|
|
1274
1344
|
|
|
1275
1345
|
private readonly eventState = { currentTurnId: null as string | null, turnSequence: 0 };
|
|
@@ -1280,12 +1350,17 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1280
1350
|
private readonly availableToolNames: string[];
|
|
1281
1351
|
private readonly runDetails: PiRunDetails;
|
|
1282
1352
|
|
|
1353
|
+
/** @internal */
|
|
1283
1354
|
constructor(
|
|
1284
1355
|
private readonly session: AgentSession,
|
|
1285
1356
|
options: {
|
|
1357
|
+
/** @internal */
|
|
1286
1358
|
treeFile: string;
|
|
1359
|
+
/** @internal */
|
|
1287
1360
|
isResumed: boolean;
|
|
1361
|
+
/** @internal */
|
|
1288
1362
|
availableToolNames: string[];
|
|
1363
|
+
/** @internal */
|
|
1289
1364
|
runDetails: PiRunDetails;
|
|
1290
1365
|
},
|
|
1291
1366
|
) {
|
|
@@ -1300,6 +1375,7 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1300
1375
|
};
|
|
1301
1376
|
}
|
|
1302
1377
|
|
|
1378
|
+
/** @internal */
|
|
1303
1379
|
getRunDetails(): PiRunDetails {
|
|
1304
1380
|
return {
|
|
1305
1381
|
loadedAgentsFiles: this.runDetails.loadedAgentsFiles.map((file) => ({ ...file })),
|
|
@@ -1308,40 +1384,49 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1308
1384
|
};
|
|
1309
1385
|
}
|
|
1310
1386
|
|
|
1387
|
+
/** @internal */
|
|
1311
1388
|
getLeafId(): string | null {
|
|
1312
1389
|
return this.session.sessionManager.getLeafId();
|
|
1313
1390
|
}
|
|
1314
1391
|
|
|
1392
|
+
/** @internal */
|
|
1315
1393
|
getEntry(id: string): PiTreeEntry | undefined {
|
|
1316
1394
|
return this.session.sessionManager.getEntry(id) as PiTreeEntry | undefined;
|
|
1317
1395
|
}
|
|
1318
1396
|
|
|
1397
|
+
/** @internal */
|
|
1319
1398
|
getBranch(fromId?: string): PiTreeEntry[] {
|
|
1320
1399
|
return this.session.sessionManager.getBranch(fromId) as PiTreeEntry[];
|
|
1321
1400
|
}
|
|
1322
1401
|
|
|
1402
|
+
/** @internal */
|
|
1323
1403
|
getChildren(parentId: string): PiTreeEntry[] {
|
|
1324
1404
|
return this.session.sessionManager.getChildren(parentId) as PiTreeEntry[];
|
|
1325
1405
|
}
|
|
1326
1406
|
|
|
1407
|
+
/** @internal */
|
|
1327
1408
|
getTree(): PiTreeNode[] {
|
|
1328
1409
|
return this.session.sessionManager.getTree() as unknown as PiTreeNode[];
|
|
1329
1410
|
}
|
|
1330
1411
|
|
|
1412
|
+
/** @internal */
|
|
1331
1413
|
async branch(entryId: string): Promise<void> {
|
|
1332
1414
|
this.session.sessionManager.branch(entryId);
|
|
1333
1415
|
updateAgentMessagesForCurrentLeaf(this.session);
|
|
1334
1416
|
}
|
|
1335
1417
|
|
|
1418
|
+
/** @internal */
|
|
1336
1419
|
async branchFromRoot(): Promise<void> {
|
|
1337
1420
|
this.session.sessionManager.resetLeaf();
|
|
1338
1421
|
updateAgentMessagesForCurrentLeaf(this.session);
|
|
1339
1422
|
}
|
|
1340
1423
|
|
|
1424
|
+
/** @internal */
|
|
1341
1425
|
async resetLeaf(): Promise<void> {
|
|
1342
1426
|
await this.branchFromRoot();
|
|
1343
1427
|
}
|
|
1344
1428
|
|
|
1429
|
+
/** @internal */
|
|
1345
1430
|
async compact(customInstructions?: string, details?: unknown): Promise<unknown> {
|
|
1346
1431
|
if (details === undefined) {
|
|
1347
1432
|
const result = await this.session.compact(customInstructions);
|
|
@@ -1637,14 +1722,17 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1637
1722
|
);
|
|
1638
1723
|
}
|
|
1639
1724
|
|
|
1725
|
+
/** @internal */
|
|
1640
1726
|
async prompt(text: string, options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {
|
|
1641
1727
|
return await this.executePrompt(options, () => this.session.prompt(text));
|
|
1642
1728
|
}
|
|
1643
1729
|
|
|
1730
|
+
/** @internal */
|
|
1644
1731
|
async promptLiteral(text: string, options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {
|
|
1645
1732
|
return await this.executePrompt(options, () => this.session.sendUserMessage(text));
|
|
1646
1733
|
}
|
|
1647
1734
|
|
|
1735
|
+
/** @internal */
|
|
1648
1736
|
async promptCustom(
|
|
1649
1737
|
input: PiCustomMessageInput,
|
|
1650
1738
|
options: PiPromptOptions = {},
|
|
@@ -1657,6 +1745,7 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1657
1745
|
);
|
|
1658
1746
|
}
|
|
1659
1747
|
|
|
1748
|
+
/** @internal */
|
|
1660
1749
|
async continueTurn(options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {
|
|
1661
1750
|
updateAgentMessagesForCurrentLeaf(this.session);
|
|
1662
1751
|
return await this.captureTurnExecutionResult(
|
|
@@ -1667,6 +1756,7 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1667
1756
|
);
|
|
1668
1757
|
}
|
|
1669
1758
|
|
|
1759
|
+
/** @internal */
|
|
1670
1760
|
async appendCustomMessage(input: PiCustomMessageInput): Promise<string> {
|
|
1671
1761
|
const branch = this.createExecutionBranchSnapshot();
|
|
1672
1762
|
const sessionManager = this.session
|
|
@@ -1693,15 +1783,18 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1693
1783
|
return entryId;
|
|
1694
1784
|
}
|
|
1695
1785
|
|
|
1786
|
+
/** @internal */
|
|
1696
1787
|
async steer(text: string): Promise<void> {
|
|
1697
1788
|
await this.session.steer(text);
|
|
1698
1789
|
}
|
|
1699
1790
|
|
|
1791
|
+
/** @internal */
|
|
1700
1792
|
async abortTurn(): Promise<void> {
|
|
1701
1793
|
this.continuationRetryAbortController?.abort(new Error("Retry cancelled"));
|
|
1702
1794
|
await this.session.abort();
|
|
1703
1795
|
}
|
|
1704
1796
|
|
|
1797
|
+
/** @internal */
|
|
1705
1798
|
subscribe(handler: PiEventHandler): () => void {
|
|
1706
1799
|
this.eventHandlers.add(handler);
|
|
1707
1800
|
this.ensureSessionSubscription();
|
|
@@ -1711,6 +1804,7 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1711
1804
|
};
|
|
1712
1805
|
}
|
|
1713
1806
|
|
|
1807
|
+
/** @internal */
|
|
1714
1808
|
subscribeDiagnostics(handler: PiSessionDiagnosticHandler): () => void {
|
|
1715
1809
|
this.diagnosticHandlers.add(handler);
|
|
1716
1810
|
this.ensureSessionSubscription();
|
|
@@ -1766,6 +1860,7 @@ export class SdkPiTreeHandle implements PiTreeHandle {
|
|
|
1766
1860
|
}
|
|
1767
1861
|
}
|
|
1768
1862
|
|
|
1863
|
+
/** @internal */
|
|
1769
1864
|
async close(): Promise<void> {
|
|
1770
1865
|
if (this.sessionUnsubscribe) {
|
|
1771
1866
|
this.sessionUnsubscribe();
|
|
@@ -2030,15 +2125,18 @@ function managedServicesKey(agentDir: string, sessionCwd: string): string {
|
|
|
2030
2125
|
return `${path.resolve(agentDir)}\0${path.resolve(sessionCwd)}`;
|
|
2031
2126
|
}
|
|
2032
2127
|
|
|
2128
|
+
/** @internal */
|
|
2033
2129
|
export class SdkPiTreeHandleFactory implements PiTreeHandleFactory {
|
|
2034
2130
|
private readonly preparedServices = new Map<string, AgentSessionServices>();
|
|
2035
2131
|
|
|
2132
|
+
/** @internal */
|
|
2036
2133
|
constructor() {
|
|
2037
2134
|
// Module loading can overlap IPC connection and workspace materialization.
|
|
2038
2135
|
// Bootstrap awaits the same module and reports any import failure.
|
|
2039
2136
|
void import("@earendil-works/pi-coding-agent").catch(() => undefined);
|
|
2040
2137
|
}
|
|
2041
2138
|
|
|
2139
|
+
/** @internal */
|
|
2042
2140
|
async prepareManagedBootstrap(
|
|
2043
2141
|
opts: PiManagedBootstrapOptions,
|
|
2044
2142
|
): Promise<PiManagedBootstrapResult> {
|
|
@@ -2091,10 +2189,12 @@ export class SdkPiTreeHandleFactory implements PiTreeHandleFactory {
|
|
|
2091
2189
|
};
|
|
2092
2190
|
}
|
|
2093
2191
|
|
|
2192
|
+
/** @internal */
|
|
2094
2193
|
async inspectPrimaryTree(opts: PiTreePlanningOptions): Promise<PiTreePlanningSnapshot> {
|
|
2095
2194
|
return inspectPiTreeForPlanning(opts);
|
|
2096
2195
|
}
|
|
2097
2196
|
|
|
2197
|
+
/** @internal */
|
|
2098
2198
|
async createPrimaryTreeHandle(opts: PiTreeHandleOptions): Promise<PiTreeHandle> {
|
|
2099
2199
|
const { CURRENT_SESSION_VERSION, createAgentSessionFromServices, SessionManager } =
|
|
2100
2200
|
await import("@earendil-works/pi-coding-agent");
|
|
@@ -108,12 +108,20 @@ async function writeExtractedFiles(
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
/** Extracts a verified bundle into an empty staging directory, then atomically publishes it. */
|
|
111
|
+
/** Extracts a verified bundle into an empty staging directory, then atomically publishes it. @internal */
|
|
112
112
|
export async function materializeCanonicalPiResourceBundle(input: {
|
|
113
|
+
/** @internal */
|
|
113
114
|
bundle: Uint8Array;
|
|
115
|
+
/** @internal */
|
|
114
116
|
digest: string;
|
|
117
|
+
/** @internal */
|
|
115
118
|
targetDir: string;
|
|
116
|
-
}): Promise<{
|
|
119
|
+
}): Promise<{
|
|
120
|
+
/** @internal */
|
|
121
|
+
targetDir: string;
|
|
122
|
+
/** @internal */
|
|
123
|
+
reused: boolean;
|
|
124
|
+
}> {
|
|
117
125
|
const files = verifyCanonicalPiResourceBundle(input.bundle, input.digest);
|
|
118
126
|
const targetDir = path.resolve(input.targetDir);
|
|
119
127
|
const parent = path.dirname(targetDir);
|
package/src/prompt-guards.ts
CHANGED
|
@@ -7,12 +7,18 @@ import {
|
|
|
7
7
|
} from "./pi-adapter.js";
|
|
8
8
|
import { toErrorMessage } from "./turn-execution-error.js";
|
|
9
9
|
|
|
10
|
+
/** @internal */
|
|
10
11
|
export type PromptGuardTimer = ReturnType<typeof setTimeout>;
|
|
11
12
|
|
|
13
|
+
/** @internal */
|
|
12
14
|
export interface PromptGuardScheduler {
|
|
15
|
+
/** @internal */
|
|
13
16
|
setTimeout(handler: () => void, delayMs: number): PromptGuardTimer;
|
|
17
|
+
/** @internal */
|
|
14
18
|
clearTimeout(timer: PromptGuardTimer): void;
|
|
19
|
+
/** @internal */
|
|
15
20
|
sleep(delayMs: number): Promise<void>;
|
|
21
|
+
/** @internal */
|
|
16
22
|
now(): Date;
|
|
17
23
|
}
|
|
18
24
|
|
package/src/runtime/adapters.ts
CHANGED
|
@@ -10,11 +10,15 @@ import type { CredentialRefreshDescriptor } from "./bootstrap-session.js";
|
|
|
10
10
|
|
|
11
11
|
export type WorkerRuntimeTimer = PromptGuardTimer;
|
|
12
12
|
|
|
13
|
+
/** @internal */
|
|
13
14
|
export interface WorkerRuntimeScheduler extends PromptGuardScheduler {
|
|
15
|
+
/** @internal */
|
|
14
16
|
sleep(delayMs: number): Promise<void>;
|
|
17
|
+
/** @internal */
|
|
15
18
|
now(): Date;
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
/** @internal */
|
|
18
22
|
export const nodeWorkerRuntimeScheduler: WorkerRuntimeScheduler = {
|
|
19
23
|
setTimeout(handler, delayMs) {
|
|
20
24
|
return setTimeout(handler, delayMs);
|
|
@@ -30,44 +34,82 @@ export const nodeWorkerRuntimeScheduler: WorkerRuntimeScheduler = {
|
|
|
30
34
|
},
|
|
31
35
|
};
|
|
32
36
|
|
|
37
|
+
/** @internal */
|
|
33
38
|
export interface WorkerRuntimeConfig {
|
|
39
|
+
/** @internal */
|
|
34
40
|
instanceId: string;
|
|
41
|
+
/** @internal */
|
|
35
42
|
workerId: string;
|
|
43
|
+
/** @internal */
|
|
36
44
|
heartbeatIntervalMs?: number;
|
|
45
|
+
/** @internal */
|
|
37
46
|
turnMaxDurationMs?: number;
|
|
47
|
+
/** @internal */
|
|
38
48
|
turnInactivityTimeoutMs?: number;
|
|
49
|
+
/** @internal */
|
|
39
50
|
turnAbortGracePeriodMs?: number;
|
|
40
51
|
}
|
|
41
52
|
|
|
53
|
+
/** @internal */
|
|
42
54
|
export interface ResultImageToolFactory {
|
|
55
|
+
/** @internal */
|
|
43
56
|
create(input: {
|
|
57
|
+
/** @internal */
|
|
44
58
|
workspaceRoot?: string;
|
|
59
|
+
/** @internal */
|
|
45
60
|
instanceId: string;
|
|
61
|
+
/** @internal */
|
|
46
62
|
turnRecordId: string;
|
|
47
63
|
}): PiCustomTool | null;
|
|
48
64
|
}
|
|
49
65
|
|
|
66
|
+
/** @internal */
|
|
50
67
|
export interface WorkerRuntimeAdapters {
|
|
68
|
+
/** @internal */
|
|
51
69
|
transport: WorkerIpc;
|
|
70
|
+
/** @internal */
|
|
52
71
|
sessionSnapshots: WorkerSessionSnapshotExchange;
|
|
72
|
+
/** @internal */
|
|
53
73
|
resultImageTools: ResultImageToolFactory;
|
|
74
|
+
/** @internal */
|
|
54
75
|
piFactory: PiTreeHandleFactory;
|
|
76
|
+
/** @internal */
|
|
55
77
|
gitOps: RunRootGitOps;
|
|
78
|
+
/** @internal */
|
|
56
79
|
developmentTools?: DevelopmentToolEnvironment;
|
|
80
|
+
/** @internal */
|
|
57
81
|
scheduler: WorkerRuntimeScheduler;
|
|
82
|
+
/** @internal */
|
|
58
83
|
exit(code: number): void;
|
|
84
|
+
/** Internal test seam; pauses before bootstrap and worker acceptance. @internal */
|
|
85
|
+
beforeTurnBootstrap?(turnId: string): Promise<void>;
|
|
86
|
+
/** @internal */
|
|
59
87
|
stderr?: NodeJS.WritableStream;
|
|
88
|
+
/** @internal */
|
|
60
89
|
extensionEvents?: EventBus;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
/** @internal */
|
|
91
|
+
sampleCredentials?: (descriptor: CredentialRefreshDescriptor) => Promise<{
|
|
92
|
+
/** @internal */
|
|
93
|
+
values: Record<string, string>;
|
|
94
|
+
/** @internal */
|
|
95
|
+
fingerprint: string;
|
|
96
|
+
}>;
|
|
97
|
+
/** @internal */
|
|
64
98
|
resolveWorkerProcess?: (
|
|
65
99
|
processId: string,
|
|
66
|
-
opts?: {
|
|
100
|
+
opts?: {
|
|
101
|
+
/** @internal */
|
|
102
|
+
paramsJson?: string | null;
|
|
103
|
+
/** @internal */
|
|
104
|
+
stateJson?: string | null;
|
|
105
|
+
},
|
|
67
106
|
) => Promise<ResolvedWorkerProcess | undefined> | ResolvedWorkerProcess | undefined;
|
|
68
107
|
}
|
|
69
108
|
|
|
109
|
+
/** @internal */
|
|
70
110
|
export interface WorkerRuntimeOptions {
|
|
111
|
+
/** @internal */
|
|
71
112
|
config: WorkerRuntimeConfig;
|
|
113
|
+
/** @internal */
|
|
72
114
|
adapters: WorkerRuntimeAdapters;
|
|
73
115
|
}
|
|
@@ -59,6 +59,7 @@ export interface PreparedLlmSession extends PreparedSessionBase {
|
|
|
59
59
|
|
|
60
60
|
export type PreparedWorkerSession = PreparedAutomaticSession | PreparedLlmSession;
|
|
61
61
|
|
|
62
|
+
/** @internal */
|
|
62
63
|
export interface CredentialRefreshDescriptor
|
|
63
64
|
extends NonNullable<BootstrapWorkerRuntimeResult["credentialRefresh"]> {}
|
|
64
65
|
|
package/src/runtime/bootstrap.ts
CHANGED
|
@@ -84,30 +84,56 @@ export interface AcceptedStartActivationResult {
|
|
|
84
84
|
diagnostics: string[];
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/** @internal */
|
|
87
88
|
export interface PreparedStartActivation {
|
|
89
|
+
/** @internal */
|
|
88
90
|
startPayload: WorkerStartPayload;
|
|
91
|
+
/** @internal */
|
|
89
92
|
managedAgentDir: string | null;
|
|
93
|
+
/** @internal */
|
|
90
94
|
managedModelProfileId: string | null;
|
|
95
|
+
/** @internal */
|
|
91
96
|
workspaceRoot: string;
|
|
97
|
+
/** @internal */
|
|
92
98
|
sessionCwd: string;
|
|
99
|
+
/** @internal */
|
|
93
100
|
processSnapshot: ProcessInstance;
|
|
101
|
+
/** @internal */
|
|
94
102
|
resolvedPiConfig: ResolvedProcessPiConfig;
|
|
95
103
|
}
|
|
96
104
|
|
|
105
|
+
/** @internal */
|
|
97
106
|
export interface BootstrapWorkerRuntimeResult {
|
|
107
|
+
/** @internal */
|
|
98
108
|
startPayload: WorkerStartPayload;
|
|
109
|
+
/** @internal */
|
|
99
110
|
resolvedWorkerProcess?: ResolvedWorkerProcess;
|
|
111
|
+
/** @internal */
|
|
100
112
|
projectSnapshots: ProcessProject[];
|
|
113
|
+
/** @internal */
|
|
101
114
|
processSnapshot: ProcessInstance;
|
|
115
|
+
/** @internal */
|
|
102
116
|
activation: PreparedStartActivation;
|
|
117
|
+
/** @internal */
|
|
103
118
|
resolvedPiConfig: ResolvedProcessPiConfig;
|
|
119
|
+
/** @internal */
|
|
104
120
|
diagnostics: string[];
|
|
105
|
-
|
|
121
|
+
/** @internal */
|
|
122
|
+
readyPayload: WorkerReadyPayload & {
|
|
123
|
+
/** @internal */
|
|
124
|
+
rootEntryId: string | null;
|
|
125
|
+
};
|
|
126
|
+
/** @internal */
|
|
106
127
|
pendingInputs: InputItem[];
|
|
128
|
+
/** @internal */
|
|
107
129
|
credentialRefresh?: {
|
|
130
|
+
/** @internal */
|
|
108
131
|
agentDir: string;
|
|
132
|
+
/** @internal */
|
|
109
133
|
declaredCredentialPaths: readonly string[];
|
|
134
|
+
/** @internal */
|
|
110
135
|
providerId: string;
|
|
136
|
+
/** @internal */
|
|
111
137
|
revision: number;
|
|
112
138
|
};
|
|
113
139
|
}
|
package/src/runtime/index.ts
CHANGED
|
@@ -31,12 +31,15 @@ export {
|
|
|
31
31
|
type WorkerRuntimeScheduler,
|
|
32
32
|
} from "./adapters.js";
|
|
33
33
|
|
|
34
|
+
/** @internal */
|
|
34
35
|
export interface WorkerRuntime {
|
|
36
|
+
/** @internal */
|
|
35
37
|
start(): Promise<void>;
|
|
38
|
+
/** @internal */
|
|
36
39
|
stop(reason: string): Promise<void>;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
/** One non-reentrant driver around the pure runtime reducer. */
|
|
42
|
+
/** One non-reentrant driver around the pure runtime reducer. @internal */
|
|
40
43
|
export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntime {
|
|
41
44
|
const { config, adapters } = options;
|
|
42
45
|
const sampleCredentials = adapters.sampleCredentials ?? sampleCredentialFiles;
|
|
@@ -140,8 +143,14 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
140
143
|
adapters.exit(command.code);
|
|
141
144
|
return;
|
|
142
145
|
case "bootstrap":
|
|
143
|
-
void
|
|
144
|
-
.
|
|
146
|
+
void Promise.resolve()
|
|
147
|
+
.then(() => adapters.beforeTurnBootstrap?.(command.payload.turnStart.turnId))
|
|
148
|
+
.then(() =>
|
|
149
|
+
resources.bootstrap(
|
|
150
|
+
command.payload,
|
|
151
|
+
resolveWorkerRuntimeSettings(config, command.payload),
|
|
152
|
+
),
|
|
153
|
+
)
|
|
145
154
|
.then((completion) =>
|
|
146
155
|
complete({
|
|
147
156
|
kind: "bootstrap_succeeded",
|
|
@@ -11,17 +11,36 @@ import {
|
|
|
11
11
|
} from "@leitwerk-dev/worker-protocol";
|
|
12
12
|
import { resolveWorkerHttpUrl } from "./worker-http.js";
|
|
13
13
|
|
|
14
|
+
/** @internal */
|
|
14
15
|
export type SessionSnapshotUploadResult =
|
|
15
|
-
| {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
| {
|
|
17
|
+
/** @internal */
|
|
18
|
+
kind: "disabled";
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
/** @internal */
|
|
22
|
+
kind: "missing";
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
/** @internal */
|
|
26
|
+
kind: "empty";
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
/** @internal */
|
|
30
|
+
kind: "uploaded";
|
|
31
|
+
/** @internal */
|
|
32
|
+
bytes: number;
|
|
33
|
+
};
|
|
19
34
|
|
|
35
|
+
/** @internal */
|
|
20
36
|
export interface WorkerSessionSnapshotUploadMetadata {
|
|
37
|
+
/** @internal */
|
|
21
38
|
turnRecordId?: string | null;
|
|
22
39
|
}
|
|
23
40
|
|
|
41
|
+
/** @internal */
|
|
24
42
|
export interface WorkerSessionSnapshotExchange {
|
|
43
|
+
/** @internal */
|
|
25
44
|
uploadSnapshot(
|
|
26
45
|
treeFile: string,
|
|
27
46
|
reason: string,
|