@ricsam/r5d-worker 0.0.107 → 0.0.109
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 +1 -1
- package/dist/cjs/main.cjs +431 -145
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/plan-lint.cjs +165 -0
- package/dist/cjs/plan-parser.cjs +127 -0
- package/dist/cjs/plan-paths.cjs +53 -0
- package/dist/cjs/recovery-output-window.cjs +77 -0
- package/dist/cjs/recovery-protocol.cjs +31 -0
- package/dist/cjs/recovery-store.cjs +229 -0
- package/dist/cjs/supervisor.cjs +11 -4
- package/dist/mjs/main.mjs +433 -144
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/plan-lint.mjs +129 -0
- package/dist/mjs/plan-parser.mjs +94 -0
- package/dist/mjs/plan-paths.mjs +25 -0
- package/dist/mjs/recovery-output-window.mjs +53 -0
- package/dist/mjs/recovery-protocol.mjs +6 -0
- package/dist/mjs/recovery-store.mjs +194 -0
- package/dist/mjs/supervisor.mjs +10 -4
- package/dist/types/main.d.ts +49 -3
- package/dist/types/plan-lint.d.ts +16 -0
- package/dist/types/plan-parser.d.ts +38 -0
- package/dist/types/plan-paths.d.ts +36 -0
- package/dist/types/recovery-output-window.d.ts +19 -0
- package/dist/types/recovery-protocol.d.ts +59 -0
- package/dist/types/recovery-store.d.ts +38 -0
- package/dist/types/supervisor.d.ts +2 -1
- package/package.json +3 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface PlanLintError {
|
|
2
|
+
planId: string;
|
|
3
|
+
message: string;
|
|
4
|
+
severity: "warning" | "error";
|
|
5
|
+
line?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PlanLintResult {
|
|
8
|
+
type: "plan_lint";
|
|
9
|
+
errors: PlanLintError[];
|
|
10
|
+
errorCount: number;
|
|
11
|
+
warningCount: number;
|
|
12
|
+
lintedPlanCount: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function lintPlanContent(planId: string, content: string): PlanLintError[];
|
|
15
|
+
export declare function lintPlans(plansDir: string, glob?: string): Promise<PlanLintResult>;
|
|
16
|
+
export declare function formatPlanLintErrors(errors: PlanLintError[]): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown plan parser.
|
|
3
|
+
*
|
|
4
|
+
* Plans are plain Markdown files. The only structured region is the first
|
|
5
|
+
* "## Tasks" section, which contains checkbox task lines.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PLAN_TASK_ID_REGEX: RegExp;
|
|
8
|
+
export declare const PLAN_TASK_LINE_REGEX: RegExp;
|
|
9
|
+
export declare const PLAN_TASKS_HEADING_REGEX: RegExp;
|
|
10
|
+
export interface PlanTask {
|
|
11
|
+
id: string;
|
|
12
|
+
description: string;
|
|
13
|
+
checked: boolean;
|
|
14
|
+
lineNumber: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ParsedPlan {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
content: string;
|
|
20
|
+
tasks: PlanTask[];
|
|
21
|
+
currentTask: PlanTask | null;
|
|
22
|
+
complete: boolean;
|
|
23
|
+
tasksStartLine: number | null;
|
|
24
|
+
tasksEndLine: number | null;
|
|
25
|
+
}
|
|
26
|
+
export type ParsedMarkdownPlan = ParsedPlan;
|
|
27
|
+
export declare function getPlanMetadata(content: string): {
|
|
28
|
+
title: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function getTasksSectionRange(content: string): {
|
|
31
|
+
startIndex: number;
|
|
32
|
+
endIndex: number;
|
|
33
|
+
} | null;
|
|
34
|
+
export declare function parseMarkdownPlan(content: string, planId: string): ParsedPlan;
|
|
35
|
+
export declare const parsePlan: typeof parseMarkdownPlan;
|
|
36
|
+
export declare function createPlanMarkdown(planId: string, title?: string): string;
|
|
37
|
+
export declare function updateTaskCheckbox(content: string, taskId: string, checked: boolean): string;
|
|
38
|
+
export declare function formatPlanTitle(planId: string): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type PlanTarget = {
|
|
2
|
+
type: "project";
|
|
3
|
+
} | {
|
|
4
|
+
type: "workspace";
|
|
5
|
+
rootProfile: "visible_projects" | "canonical_sync";
|
|
6
|
+
};
|
|
7
|
+
export declare const PLAN_EXTENSION = ".plan.md";
|
|
8
|
+
export declare function validatePlanId(planId: string): void;
|
|
9
|
+
export declare function assertPlanTarget(target: PlanTarget): void;
|
|
10
|
+
export declare function getWorkerPlansPath(target: PlanTarget): string;
|
|
11
|
+
/** The same worker path is used in prompts, injected reads, and file tools. */
|
|
12
|
+
export declare function getWorkerPlanPath(target: PlanTarget, planId: string): string;
|
|
13
|
+
export type WorkerReadPlanInput = {
|
|
14
|
+
planId: string;
|
|
15
|
+
createIfMissing: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type WorkerLintPlansInput = {
|
|
18
|
+
glob?: string;
|
|
19
|
+
};
|
|
20
|
+
export type WorkerUpdatePlanTaskInput = {
|
|
21
|
+
planId: string;
|
|
22
|
+
taskId: string;
|
|
23
|
+
checked: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type WorkerLintPlansResult = {
|
|
26
|
+
type: "lint_plans";
|
|
27
|
+
content: string;
|
|
28
|
+
};
|
|
29
|
+
export type WorkerUpdatePlanTaskResult = {
|
|
30
|
+
type: "update_task_status";
|
|
31
|
+
planId: string;
|
|
32
|
+
taskId: string;
|
|
33
|
+
checked: boolean;
|
|
34
|
+
message: string;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WorkerOutputOffsets } from "./recovery-protocol";
|
|
2
|
+
export type WorkerOutputFrame = {
|
|
3
|
+
type: "exec_output";
|
|
4
|
+
runId: string;
|
|
5
|
+
stream: "stdout" | "stderr";
|
|
6
|
+
offset: number;
|
|
7
|
+
data: string;
|
|
8
|
+
};
|
|
9
|
+
/** Bound outstanding application bytes, including data already buffered by the server's socket. */
|
|
10
|
+
export declare class WorkerOutputWindow {
|
|
11
|
+
private readonly windowBytes;
|
|
12
|
+
private sent;
|
|
13
|
+
private acknowledged;
|
|
14
|
+
private outstanding;
|
|
15
|
+
constructor(windowBytes?: number);
|
|
16
|
+
reset(cursors: WorkerOutputOffsets[]): void;
|
|
17
|
+
send(frame: WorkerOutputFrame, send: (frame: WorkerOutputFrame) => boolean, bufferedAmount?: number): boolean;
|
|
18
|
+
acknowledge(runId: string, stream: "stdout" | "stderr", offset: number): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** The application protocol survives replacement of its WebSocket transport. */
|
|
2
|
+
export declare const WORKER_RESUMABLE_PROTOCOL: 1;
|
|
3
|
+
export declare const WORKER_RECOVERY_TIMEOUT_MS: number;
|
|
4
|
+
export type WorkerOperationRecovery = {
|
|
5
|
+
requestId: string;
|
|
6
|
+
runId?: string;
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
requestType?: string;
|
|
9
|
+
state: "accepted" | "preparing" | "running" | "completed" | "unknown";
|
|
10
|
+
};
|
|
11
|
+
export type WorkerOutputOffsets = {
|
|
12
|
+
runId: string;
|
|
13
|
+
stdoutBytes: number;
|
|
14
|
+
stderrBytes: number;
|
|
15
|
+
};
|
|
16
|
+
export type WorkerRecoveryServerMessage = {
|
|
17
|
+
type: "recovery_request";
|
|
18
|
+
recoveryId: string;
|
|
19
|
+
requests: string[];
|
|
20
|
+
outputOffsets: WorkerOutputOffsets[];
|
|
21
|
+
} | {
|
|
22
|
+
type: "recovery_ready";
|
|
23
|
+
recoveryId: string;
|
|
24
|
+
leaseMs: number;
|
|
25
|
+
} | {
|
|
26
|
+
type: "operation_result_ack";
|
|
27
|
+
requestId: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: "exec_output_ack";
|
|
30
|
+
runId: string;
|
|
31
|
+
stream: "stdout" | "stderr";
|
|
32
|
+
nextOffset: number;
|
|
33
|
+
} | {
|
|
34
|
+
type: "worker_execution_lease";
|
|
35
|
+
leaseMs: number;
|
|
36
|
+
} | {
|
|
37
|
+
type: "cancel_session";
|
|
38
|
+
sessionId: string;
|
|
39
|
+
cancellationId: string;
|
|
40
|
+
};
|
|
41
|
+
export type WorkerRecoveryClientMessage = {
|
|
42
|
+
type: "recovery_state";
|
|
43
|
+
recoveryId: string;
|
|
44
|
+
runtimeId: string;
|
|
45
|
+
ledgerId: string;
|
|
46
|
+
operations: WorkerOperationRecovery[];
|
|
47
|
+
} | {
|
|
48
|
+
type: "recovery_complete";
|
|
49
|
+
recoveryId: string;
|
|
50
|
+
} | {
|
|
51
|
+
type: "operation_received";
|
|
52
|
+
requestId: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: "operation_completed";
|
|
55
|
+
requestId: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: "cancel_session_ack";
|
|
58
|
+
cancellationId: string;
|
|
59
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { WorkerOperationRecovery, WorkerOutputOffsets } from "./recovery-protocol";
|
|
2
|
+
type Message = {
|
|
3
|
+
type: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
/** Stable semantic identity, independent of JSON key order and transport request aliases. */
|
|
7
|
+
export declare function workerOperationDigest(message: Message): string;
|
|
8
|
+
/** The receipt is committed before a handler can mutate anything. Unknown crash outcomes never replay effects. */
|
|
9
|
+
export declare class WorkerRecoveryStore {
|
|
10
|
+
private readonly db;
|
|
11
|
+
readonly ledgerId: string;
|
|
12
|
+
constructor(filename: string);
|
|
13
|
+
close(): void;
|
|
14
|
+
private row;
|
|
15
|
+
admit(message: Message & {
|
|
16
|
+
requestId: string;
|
|
17
|
+
}): "new" | "duplicate" | "unknown" | "conflict";
|
|
18
|
+
isUnknown(requestId: string): boolean;
|
|
19
|
+
unknown(requestId: string): void;
|
|
20
|
+
unknownRun(runId: string): void;
|
|
21
|
+
record(message: Message): Message;
|
|
22
|
+
operations(): WorkerOperationRecovery[];
|
|
23
|
+
response(requestId: string): Message | undefined;
|
|
24
|
+
responses(requestIds: string[]): Message[];
|
|
25
|
+
lengths(runId: string): {
|
|
26
|
+
stdoutBytes: number;
|
|
27
|
+
stderrBytes: number;
|
|
28
|
+
};
|
|
29
|
+
outputCursors(): WorkerOutputOffsets[];
|
|
30
|
+
output(offsets?: WorkerOutputOffsets[]): Generator<Message>;
|
|
31
|
+
terminals(): Message[];
|
|
32
|
+
acknowledgeOutput(runId: string, stream: "stdout" | "stderr", offset: number): void;
|
|
33
|
+
acknowledgeResult(requestId: string): void;
|
|
34
|
+
acknowledgeTerminal(runId: string): void;
|
|
35
|
+
cancelSession(sessionId: string): void;
|
|
36
|
+
isRequestCancelled(requestId: string): boolean;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -5,6 +5,7 @@ export declare const WORKER_RECONNECT_EXIT_CODE = 76;
|
|
|
5
5
|
export declare const WORKER_CREDENTIAL_RESTART_EXIT_CODE = 77;
|
|
6
6
|
export declare const WORKER_RECONNECT_DELAY_MS = 2000;
|
|
7
7
|
export declare const WORKER_RECONNECT_JITTER_MS = 3000;
|
|
8
|
+
export declare const WORKER_RECONNECT_MAX_DELAY_MS = 30000;
|
|
8
9
|
type RuntimeProcess = KillableSubprocess;
|
|
9
10
|
export type RuntimeSpawner = (argv: string[], options: {
|
|
10
11
|
stdin: "inherit";
|
|
@@ -16,7 +17,7 @@ export type RuntimeSpawner = (argv: string[], options: {
|
|
|
16
17
|
export type RuntimeDelay = (delayMs: number) => Promise<void>;
|
|
17
18
|
export type RuntimeReaper = (runtime: RuntimeProcess) => Promise<void>;
|
|
18
19
|
export type RuntimeReconnectDelay = () => number;
|
|
19
|
-
export declare function workerReconnectDelayMs(random?: () => number): number;
|
|
20
|
+
export declare function workerReconnectDelayMs(random?: () => number, attempt?: number): number;
|
|
20
21
|
export declare function isRetryableWorkerServerStatus(status: number): boolean;
|
|
21
22
|
export declare function superviseWorkerRuntime(argv: string[], env?: Record<string, string | undefined>, spawnRuntime?: RuntimeSpawner, waitBeforeReconnect?: RuntimeDelay, reapCredentialRuntime?: RuntimeReaper, reconnectDelay?: RuntimeReconnectDelay): Promise<number>;
|
|
22
23
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/r5d-worker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.109",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/cjs/main.cjs",
|
|
6
6
|
"module": "./dist/mjs/main.mjs",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"r5d-worker": "dist/cjs/main.cjs"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"node-pty": "^1.1.0"
|
|
24
|
+
"node-pty": "^1.1.0",
|
|
25
|
+
"picomatch": "^4.0.3"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"dist",
|