@roodriigoooo/pi-docket 0.4.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/CHANGELOG.md +132 -0
- package/LICENSE +21 -0
- package/README.md +241 -0
- package/assets/docket_logo.jpeg +0 -0
- package/docs/adr/0001-bundle-first-checkpoints.md +21 -0
- package/docs/adr/0002-rename-to-docket.md +44 -0
- package/docs/architecture.md +101 -0
- package/docs/bundle-guidelines.md +39 -0
- package/docs/configuration.md +191 -0
- package/docs/releases/0.4.0.md +93 -0
- package/extensions/artifact-catalog.ts +467 -0
- package/extensions/background-work.ts +510 -0
- package/extensions/checkpoint-commands.ts +147 -0
- package/extensions/checkpoint-lifecycle.ts +195 -0
- package/extensions/checkpoint-selector.ts +162 -0
- package/extensions/checkpoint-store.ts +230 -0
- package/extensions/checkpoint-summarizer.ts +141 -0
- package/extensions/docket-command-grammar.ts +319 -0
- package/extensions/docket-command-router.ts +626 -0
- package/extensions/docket-config.ts +88 -0
- package/extensions/docket-extension-surface.ts +43 -0
- package/extensions/docket-navigator.ts +585 -0
- package/extensions/docket.README.md +46 -0
- package/extensions/docket.ts +2965 -0
- package/extensions/event-log.ts +121 -0
- package/extensions/git-context.ts +44 -0
- package/extensions/loaded-artifact-context.ts +228 -0
- package/extensions/search-index.ts +140 -0
- package/extensions/types.ts +40 -0
- package/extensions/worker-activity.ts +402 -0
- package/extensions/worker-changes.ts +180 -0
- package/extensions/worker-commands.ts +251 -0
- package/extensions/worker-dock-cache.ts +147 -0
- package/extensions/worker-events.ts +87 -0
- package/extensions/worker-eviction.ts +55 -0
- package/extensions/worker-guardrails.md +125 -0
- package/extensions/worker-kinds/patcher.md +23 -0
- package/extensions/worker-kinds/scout.md +17 -0
- package/extensions/worker-kinds.ts +280 -0
- package/extensions/worker-result.ts +193 -0
- package/extensions/worker-store.ts +621 -0
- package/extensions/worker-summary-embed.ts +98 -0
- package/package.json +53 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { getAgentDir } from "@mariozechner/pi-coding-agent";
|
|
5
|
+
import type { CheckpointSummarizerConfig } from "./checkpoint-summarizer.js";
|
|
6
|
+
|
|
7
|
+
export type DocketWorkerConfig = {
|
|
8
|
+
guardrailsPath?: string;
|
|
9
|
+
/** Hide ended workers from the dock once they go untouched for this many minutes. Set 0 to keep them visible. */
|
|
10
|
+
dockIdleHideMinutes?: number;
|
|
11
|
+
/** Auto-prune ended worker dirs once they go untouched for this many hours. Set 0 to disable. */
|
|
12
|
+
pruneAfterHours?: number;
|
|
13
|
+
/** Max simultaneously active workers (across the whole tmux session). Excess /docket spawn calls are rejected. */
|
|
14
|
+
maxActive?: number;
|
|
15
|
+
/** Max child-spawn depth. Top-level parent is depth 0; its children are depth 1; etc. */
|
|
16
|
+
maxSpawnDepth?: number;
|
|
17
|
+
/** Project-default kind picked when /docket spawn is invoked without --as. */
|
|
18
|
+
defaultKind?: string;
|
|
19
|
+
/** When true, dock writes a compact worker line to tmux status-right so attached panes still see fleet state. */
|
|
20
|
+
tmuxStatusLine?: boolean;
|
|
21
|
+
/** When true, every spawned worker also runs tmux pipe-pane to <worker-dir>/pane.log for post-hoc debug. */
|
|
22
|
+
captureTerminal?: boolean;
|
|
23
|
+
/** When true, /docket offers to re-window orphan workers when the shared tmux session is gone but their dirs are still live. */
|
|
24
|
+
autoRespawn?: boolean;
|
|
25
|
+
/** When true (default), a short summary message is appended to the parent session when a worker reaches ready. Set false to keep the parent JSONL fully manual. */
|
|
26
|
+
autoEmbedSummary?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type DocketConfig = {
|
|
30
|
+
maxArtifacts: number;
|
|
31
|
+
maxBodyChars: number;
|
|
32
|
+
checkpointArtifacts: number;
|
|
33
|
+
consumedRetentionDays: number;
|
|
34
|
+
summarizer: CheckpointSummarizerConfig;
|
|
35
|
+
worker?: DocketWorkerConfig;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const DEFAULT_CONFIG: DocketConfig = {
|
|
39
|
+
maxArtifacts: 300,
|
|
40
|
+
maxBodyChars: 6000,
|
|
41
|
+
checkpointArtifacts: 24,
|
|
42
|
+
consumedRetentionDays: 7,
|
|
43
|
+
summarizer: {
|
|
44
|
+
enabled: true,
|
|
45
|
+
maxOutputTokens: 1200,
|
|
46
|
+
maxInputChars: 36000,
|
|
47
|
+
timeoutMs: 120000,
|
|
48
|
+
},
|
|
49
|
+
worker: {
|
|
50
|
+
dockIdleHideMinutes: 30,
|
|
51
|
+
pruneAfterHours: 24,
|
|
52
|
+
maxActive: 8,
|
|
53
|
+
maxSpawnDepth: 2,
|
|
54
|
+
tmuxStatusLine: false,
|
|
55
|
+
captureTerminal: false,
|
|
56
|
+
autoRespawn: false,
|
|
57
|
+
autoEmbedSummary: true,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
async function readJsonFile<T>(file: string, fallback: T): Promise<T> {
|
|
62
|
+
try {
|
|
63
|
+
if (!existsSync(file)) return fallback;
|
|
64
|
+
return JSON.parse(await fs.readFile(file, "utf8")) as T;
|
|
65
|
+
} catch {
|
|
66
|
+
return fallback;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function loadConfig(cwd: string): Promise<DocketConfig> {
|
|
71
|
+
const globalConfig = await readJsonFile<Partial<DocketConfig>>(path.join(getAgentDir(), "docket.json"), {});
|
|
72
|
+
const projectConfig = await readJsonFile<Partial<DocketConfig>>(path.join(cwd, ".pi", "docket.json"), {});
|
|
73
|
+
return {
|
|
74
|
+
...DEFAULT_CONFIG,
|
|
75
|
+
...globalConfig,
|
|
76
|
+
...projectConfig,
|
|
77
|
+
summarizer: {
|
|
78
|
+
...DEFAULT_CONFIG.summarizer,
|
|
79
|
+
...(globalConfig.summarizer ?? {}),
|
|
80
|
+
...(projectConfig.summarizer ?? {}),
|
|
81
|
+
},
|
|
82
|
+
worker: {
|
|
83
|
+
...DEFAULT_CONFIG.worker,
|
|
84
|
+
...(globalConfig.worker ?? {}),
|
|
85
|
+
...(projectConfig.worker ?? {}),
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { WorkerEvent } from "./worker-events.js";
|
|
2
|
+
import type { WorkerKind, WorkerKindRegistry } from "./worker-kinds.js";
|
|
3
|
+
|
|
4
|
+
export type DocketExtensionSurface = {
|
|
5
|
+
registerWorkerKind(kind: Omit<WorkerKind, "source"> & { source?: WorkerKind["source"] }): () => void;
|
|
6
|
+
listWorkerKinds(): WorkerKind[];
|
|
7
|
+
onWorkerEvent(handler: (event: { workerId: string; event: WorkerEvent }) => void): () => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const SURFACE_KEY = "__docket";
|
|
11
|
+
|
|
12
|
+
type EventHandler = (event: { workerId: string; event: WorkerEvent }) => void;
|
|
13
|
+
|
|
14
|
+
export type DocketExtensionSurfaceInternals = DocketExtensionSurface & {
|
|
15
|
+
emitWorkerEvent(workerId: string, event: WorkerEvent): void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function installDocketExtensionSurface(registry: WorkerKindRegistry): DocketExtensionSurfaceInternals {
|
|
19
|
+
const handlers = new Set<EventHandler>();
|
|
20
|
+
const surface: DocketExtensionSurfaceInternals = {
|
|
21
|
+
registerWorkerKind(kind) {
|
|
22
|
+
return registry.register({ ...kind, source: kind.source ?? "runtime" });
|
|
23
|
+
},
|
|
24
|
+
listWorkerKinds() {
|
|
25
|
+
return registry.list();
|
|
26
|
+
},
|
|
27
|
+
onWorkerEvent(handler) {
|
|
28
|
+
handlers.add(handler);
|
|
29
|
+
return () => handlers.delete(handler);
|
|
30
|
+
},
|
|
31
|
+
emitWorkerEvent(workerId, event) {
|
|
32
|
+
for (const handler of handlers) {
|
|
33
|
+
try { handler({ workerId, event }); } catch { /* never let a subscriber break docket */ }
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
(globalThis as Record<string, unknown>)[SURFACE_KEY] = surface;
|
|
38
|
+
return surface;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getDocketExtensionSurface(): DocketExtensionSurfaceInternals | undefined {
|
|
42
|
+
return (globalThis as Record<string, unknown>)[SURFACE_KEY] as DocketExtensionSurfaceInternals | undefined;
|
|
43
|
+
}
|