@akagilnc/pi-workflow-roles 0.1.1751
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/LICENSE +202 -0
- package/README.md +104 -0
- package/README.zh-CN.md +133 -0
- package/THIRD_PARTY_NOTICES.md +60 -0
- package/dist/activation-ledger-git.js +68 -0
- package/dist/activation-ledger-session.js +120 -0
- package/dist/activation-ledger-topology.js +239 -0
- package/dist/activation-reconciliation.js +61 -0
- package/dist/audit-escalation.js +108 -0
- package/dist/auditor-dossier-tool.js +35 -0
- package/dist/canonical-json.js +78 -0
- package/dist/compliance-transport.js +77 -0
- package/dist/doctor-contracts.js +172 -0
- package/dist/dossier-resolution.js +103 -0
- package/dist/evidence-child-executor.js +661 -0
- package/dist/exact-utf8.js +12 -0
- package/dist/git-object-id.js +7 -0
- package/dist/in-process-session.js +50 -0
- package/dist/merger-contracts.js +76 -0
- package/dist/navigator-attendance.js +995 -0
- package/dist/navigator-invocation-identity.js +220 -0
- package/dist/open-tool-schema.js +39 -0
- package/dist/package-contracts/collector-output.js +50 -0
- package/dist/package-contracts/fixer-output.js +72 -0
- package/dist/package-contracts/fixer-packet.js +77 -0
- package/dist/package-contracts/judge-output.js +17 -0
- package/dist/package-contracts/reviewer-output.js +82 -0
- package/dist/package-contracts/terminating-tools.js +173 -0
- package/dist/package-contracts/worker-output.js +13 -0
- package/dist/package-owned-tool-idle.js +104 -0
- package/dist/packaged-role-registry.js +34 -0
- package/dist/public-cli/main.js +23867 -0
- package/dist/public-command-renderer.js +20 -0
- package/dist/reviewer-agent.js +93 -0
- package/dist/reviewer-child-executor.js +23 -0
- package/dist/reviewer-construction.js +95 -0
- package/dist/reviewer-dispatch.js +77 -0
- package/dist/reviewer-execution-ledger.js +160 -0
- package/dist/reviewer-failure-diagnostic.js +17 -0
- package/dist/reviewer-git-snapshot.js +38 -0
- package/dist/reviewer-pinned-git.js +146 -0
- package/dist/reviewer-preflight-error.js +15 -0
- package/dist/reviewer-prompt-identity.js +10 -0
- package/dist/reviewer-scope-prompt.js +21 -0
- package/dist/reviewer-workspace.js +151 -0
- package/dist/sha256.js +5 -0
- package/dist/sitian-record-entry.js +33 -0
- package/dist/stderr-jsonl.js +26 -0
- package/dist/stream-idle-guard.js +75 -0
- package/dist/tool-execution-observation.js +141 -0
- package/dist/uuidv7.js +21 -0
- package/dist/work-subject-identity.js +53 -0
- package/extensions/role-runtime.ts +303 -0
- package/package.json +69 -0
- package/packets/fixer-prerequisites.json +6 -0
- package/packets/fixer-repair.md +5 -0
- package/packets/judge-apply.md +77 -0
- package/packets/judge-authority.md +64 -0
- package/packets/judge-plan.md +55 -0
- package/packets/judge-review.md +49 -0
- package/packets/judge-submission.md +34 -0
- package/resources/methods/code-review/SKILL.md +92 -0
- package/resources/methods/code-review/agents/openai.yaml +3 -0
- package/resources/methods/code-review/provenance.json +26 -0
- package/resources/methods/diagnosing-bugs/SKILL.md +134 -0
- package/resources/methods/diagnosing-bugs/agents/openai.yaml +3 -0
- package/resources/methods/diagnosing-bugs/provenance.json +31 -0
- package/resources/methods/diagnosing-bugs/scripts/hitl-loop.template.sh +41 -0
- package/resources/methods/resolving-merge-conflicts/SKILL.md +14 -0
- package/resources/methods/resolving-merge-conflicts/agents/openai.yaml +3 -0
- package/resources/methods/resolving-merge-conflicts/provenance.json +26 -0
- package/resources/methods/tdd/SKILL.md +38 -0
- package/resources/methods/tdd/agents/openai.yaml +3 -0
- package/resources/methods/tdd/mocking.md +59 -0
- package/resources/methods/tdd/provenance.json +36 -0
- package/resources/methods/tdd/tests.md +77 -0
- package/resources/navigator-route-playbook.md +32 -0
- package/schemas/tool-execution-observation.schema.json +107 -0
- package/scripts/build-package.mjs +65 -0
- package/scripts/generate-tool-execution-observation-schema.ts +7 -0
- package/souls/coder.md +10 -0
- package/souls/collector.md +11 -0
- package/souls/doctor-auditor.md +23 -0
- package/souls/doctor.md +8 -0
- package/souls/fixer-auditor.md +33 -0
- package/souls/fixer.md +13 -0
- package/souls/judge-auditor.md +33 -0
- package/souls/judge.md +74 -0
- package/souls/merger.md +5 -0
- package/souls/navigator.md +5 -0
- package/souls/reviewer-auditor.md +25 -0
- package/souls/reviewer.md +11 -0
- package/src/activation-ledger-git.ts +96 -0
- package/src/activation-ledger-session.ts +188 -0
- package/src/activation-ledger-topology.ts +301 -0
- package/src/activation-ledger.ts +240 -0
- package/src/activation-reconciliation.ts +163 -0
- package/src/activation-trace.ts +38 -0
- package/src/audit-escalation.ts +177 -0
- package/src/auditor-dossier-tool.ts +48 -0
- package/src/auditor-soul.ts +28 -0
- package/src/canonical-json.ts +74 -0
- package/src/canonical-skill-binding.ts +107 -0
- package/src/collector-config.ts +89 -0
- package/src/collector-evidence.ts +461 -0
- package/src/collector-github.ts +656 -0
- package/src/collector-identity.ts +161 -0
- package/src/collector-ledger.ts +827 -0
- package/src/collector-receipt.ts +87 -0
- package/src/collector-role.ts +592 -0
- package/src/collector-tool-schemas.ts +19 -0
- package/src/compliance-transport.ts +130 -0
- package/src/doctor-auditor.ts +53 -0
- package/src/doctor-contracts.ts +166 -0
- package/src/doctor-evidence.ts +47 -0
- package/src/doctor-role.ts +18 -0
- package/src/dossier-resolution.ts +137 -0
- package/src/evidence-child-executor.ts +775 -0
- package/src/exact-utf8.ts +9 -0
- package/src/factory-board.ts +1822 -0
- package/src/git-object-id.ts +11 -0
- package/src/human-format.ts +65 -0
- package/src/in-process-session.ts +78 -0
- package/src/judge-auditor.ts +55 -0
- package/src/judge-recording-anti-forge.ts +53 -0
- package/src/judge-role.ts +160 -0
- package/src/merger-contracts.ts +71 -0
- package/src/merger-git-state.ts +76 -0
- package/src/merger-role.ts +60 -0
- package/src/navigator-attendance.ts +1254 -0
- package/src/navigator-invocation-identity.ts +446 -0
- package/src/open-tool-schema.ts +46 -0
- package/src/package-contracts/collector-output.ts +109 -0
- package/src/package-contracts/fixer-output.ts +81 -0
- package/src/package-contracts/fixer-packet.ts +93 -0
- package/src/package-contracts/judge-output.ts +39 -0
- package/src/package-contracts/reviewer-output.ts +115 -0
- package/src/package-contracts/terminating-tools.ts +259 -0
- package/src/package-contracts/worker-output.ts +36 -0
- package/src/package-owned-tool-idle.ts +134 -0
- package/src/package-resources/method-skill-binding.ts +87 -0
- package/src/package-resources/method-skill.ts +358 -0
- package/src/packaged-role-registry.ts +36 -0
- package/src/public-cli/cli-errors.ts +11 -0
- package/src/public-cli/cli-io.ts +4 -0
- package/src/public-cli/cli.ts +912 -0
- package/src/public-cli/coder-run.ts +575 -0
- package/src/public-cli/collector-run.ts +375 -0
- package/src/public-cli/command-renderer.ts +8 -0
- package/src/public-cli/config.ts +346 -0
- package/src/public-cli/doctor-run.ts +355 -0
- package/src/public-cli/explicit-internal.ts +274 -0
- package/src/public-cli/fixer-run.ts +587 -0
- package/src/public-cli/host-pi-runtime.ts +112 -0
- package/src/public-cli/invocation.ts +1958 -0
- package/src/public-cli/judge-run.ts +507 -0
- package/src/public-cli/main.ts +15 -0
- package/src/public-cli/merger-run.ts +681 -0
- package/src/public-cli/public-run-credentials.ts +71 -0
- package/src/public-cli/registry.ts +153 -0
- package/src/public-cli/reviewer-run.ts +561 -0
- package/src/public-cli/run-lifecycle.ts +884 -0
- package/src/public-cli/settlement.ts +3765 -0
- package/src/public-cli/terminal.ts +325 -0
- package/src/public-command-renderer.ts +43 -0
- package/src/reviewer-agent.ts +94 -0
- package/src/reviewer-auditor.ts +53 -0
- package/src/reviewer-child-executor.ts +31 -0
- package/src/reviewer-construction.ts +137 -0
- package/src/reviewer-dispatch.ts +94 -0
- package/src/reviewer-execution-ledger.ts +206 -0
- package/src/reviewer-failure-diagnostic.ts +18 -0
- package/src/reviewer-git-snapshot.ts +53 -0
- package/src/reviewer-pinned-git.ts +144 -0
- package/src/reviewer-preflight-error.ts +14 -0
- package/src/reviewer-prompt-identity.ts +17 -0
- package/src/reviewer-role.ts +193 -0
- package/src/reviewer-scope-prompt.ts +24 -0
- package/src/reviewer-settlement.ts +63 -0
- package/src/reviewer-workspace.ts +111 -0
- package/src/role-runtime.ts +884 -0
- package/src/sha256.ts +6 -0
- package/src/sitian-record-entry.ts +57 -0
- package/src/stderr-jsonl.ts +28 -0
- package/src/stream-idle-guard.ts +98 -0
- package/src/ticket-snapshot.ts +662 -0
- package/src/ticket-trajectory.ts +1000 -0
- package/src/tool-execution-observation.ts +168 -0
- package/src/uuidv7.ts +1 -0
- package/src/work-subject-identity.ts +94 -0
- package/src/worker-role.ts +434 -0
- package/src/worker-submission-gates.ts +225 -0
package/src/sha256.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 司天台唯一 Pi session 记录落盘入口(ADR 0065)。
|
|
3
|
+
* 调用方只声明自己是谁的什么;落点由候簿拓扑算出,签名不含任何落点/路径参数。
|
|
4
|
+
* 「谁调了谁」复用 Pi parentSession + ADR 0047 correlation,不新增 caller 字段。
|
|
5
|
+
*/
|
|
6
|
+
import { dirname, resolve, join } from "node:path";
|
|
7
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
|
|
9
|
+
import { resolveBookKeyFromGit } from "./activation-ledger-git.ts";
|
|
10
|
+
import {
|
|
11
|
+
activationBookDirectory,
|
|
12
|
+
ensureRealDirectoryTree,
|
|
13
|
+
physicallyContainedIn,
|
|
14
|
+
resolveActivationLedgerHome,
|
|
15
|
+
} from "./activation-ledger-topology.ts";
|
|
16
|
+
|
|
17
|
+
/** Parent session surface needed to link and (when already under home) nest the record. */
|
|
18
|
+
export type RecordSessionParent = {
|
|
19
|
+
getSessionFile(): string | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type CreateRecordSessionOptions = {
|
|
23
|
+
/** Role working directory — used for git book-key discovery when the parent is not already under home. Not a record destination. */
|
|
24
|
+
readonly cwd: string;
|
|
25
|
+
/** What kind of record this is (e.g. "auditor-roles"). Single path segment; not a destination path. */
|
|
26
|
+
readonly kind: string;
|
|
27
|
+
/** Optional parent session — supplies parentSession link; nest under parent only when that parent already lives under the ledger home. */
|
|
28
|
+
readonly parent?: RecordSessionParent;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sole package entry that constructs a durable Pi session record (ADR 0065).
|
|
33
|
+
* No destination/path parameters — location is computed from ledger topology only.
|
|
34
|
+
*/
|
|
35
|
+
export function createRecordSession(options: CreateRecordSessionOptions): SessionManager {
|
|
36
|
+
const cwd = options.cwd;
|
|
37
|
+
const parentFile = options.parent?.getSessionFile();
|
|
38
|
+
if (parentFile === undefined || parentFile.length === 0) {
|
|
39
|
+
// No durable parent principal — preserve prior in-memory child behavior.
|
|
40
|
+
return SessionManager.inMemory(cwd);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ledgerHome = resolveActivationLedgerHome();
|
|
44
|
+
const parentResolved = resolve(parentFile);
|
|
45
|
+
|
|
46
|
+
// Nest under parent only when the parent record already lives under the package home.
|
|
47
|
+
// Nest base is dirname(parent file) — the durable principal's directory — never a
|
|
48
|
+
// separate getSessionDir() that can diverge (empty in-memory dir + durable file).
|
|
49
|
+
// Otherwise the book is resolved from cwd (ADR 0048) and the kind sits under that book —
|
|
50
|
+
// workspace / foreign parents cannot drag records out of home.
|
|
51
|
+
const sessionDir = physicallyContainedIn(ledgerHome, parentResolved)
|
|
52
|
+
? join(dirname(parentResolved), options.kind)
|
|
53
|
+
: join(activationBookDirectory(ledgerHome, resolveBookKeyFromGit(cwd)), options.kind);
|
|
54
|
+
|
|
55
|
+
ensureRealDirectoryTree(ledgerHome, sessionDir);
|
|
56
|
+
return SessionManager.create(cwd, sessionDir, { parentSession: parentFile });
|
|
57
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { writeSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
const STDERR_JSONL_WRITE_RETRY_LIMIT = 100;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Write one complete JSONL record to fd 2.
|
|
7
|
+
* Retries EAGAIN/EINTR and short writes; never writes stdout.
|
|
8
|
+
*/
|
|
9
|
+
export function writeStderrJsonlRecord(
|
|
10
|
+
record: unknown,
|
|
11
|
+
write: typeof writeSync = writeSync,
|
|
12
|
+
): void {
|
|
13
|
+
const bytes = Buffer.from(`${JSON.stringify(record)}\n`);
|
|
14
|
+
let offset = 0;
|
|
15
|
+
let retries = 0;
|
|
16
|
+
while (offset < bytes.length) {
|
|
17
|
+
try {
|
|
18
|
+
const written = write(2, bytes, offset, bytes.length - offset);
|
|
19
|
+
if (written <= 0) throw new Error("stderr JSONL write made no progress");
|
|
20
|
+
offset += written;
|
|
21
|
+
retries = 0;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
24
|
+
if ((code === "EAGAIN" || code === "EINTR") && retries++ < STDERR_JSONL_WRITE_RETRY_LIMIT) continue;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream idle backstop (#102 / #155 a): first-wait + between-event silence only.
|
|
3
|
+
* Not a total wall-clock for long thinking turns.
|
|
4
|
+
*
|
|
5
|
+
* Default silence budget is owner-final 183s (#102 2026-08-04),
|
|
6
|
+
* same numeric value as header timeoutMs but a distinct body-idle clock.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 183_000;
|
|
10
|
+
export const STREAM_IDLE_TIMEOUT_CODE = "AK_STREAM_IDLE_TIMEOUT" as const;
|
|
11
|
+
|
|
12
|
+
export class StreamIdleTimeoutError extends Error {
|
|
13
|
+
readonly code = STREAM_IDLE_TIMEOUT_CODE;
|
|
14
|
+
readonly idleTimeoutMs: number;
|
|
15
|
+
|
|
16
|
+
constructor(idleTimeoutMs: number, options?: ErrorOptions) {
|
|
17
|
+
super(`stream idle timeout after ${idleTimeoutMs}ms`, options);
|
|
18
|
+
this.name = "StreamIdleTimeoutError";
|
|
19
|
+
this.idleTimeoutMs = idleTimeoutMs;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isStreamIdleTimeoutError(value: unknown): value is StreamIdleTimeoutError {
|
|
24
|
+
return value instanceof StreamIdleTimeoutError
|
|
25
|
+
|| (
|
|
26
|
+
typeof value === "object"
|
|
27
|
+
&& value !== null
|
|
28
|
+
&& (value as { name?: unknown }).name === "StreamIdleTimeoutError"
|
|
29
|
+
&& (value as { code?: unknown }).code === STREAM_IDLE_TIMEOUT_CODE
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type StreamIdleGuardOptions = {
|
|
34
|
+
idleTimeoutMs?: number;
|
|
35
|
+
parentSignal?: AbortSignal;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type StreamIdleGuard = {
|
|
39
|
+
readonly signal: AbortSignal;
|
|
40
|
+
poke(): void;
|
|
41
|
+
dispose(): void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export function createStreamIdleGuard(
|
|
45
|
+
options: StreamIdleGuardOptions = {},
|
|
46
|
+
): StreamIdleGuard {
|
|
47
|
+
const idleTimeoutMs = options.idleTimeoutMs ?? DEFAULT_STREAM_IDLE_TIMEOUT_MS;
|
|
48
|
+
const parentSignal = options.parentSignal;
|
|
49
|
+
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
52
|
+
let disposed = false;
|
|
53
|
+
|
|
54
|
+
const clear = (): void => {
|
|
55
|
+
if (timer !== undefined) {
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
timer = undefined;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const arm = (): void => {
|
|
62
|
+
if (disposed || controller.signal.aborted || idleTimeoutMs <= 0) return;
|
|
63
|
+
clear();
|
|
64
|
+
timer = setTimeout(() => {
|
|
65
|
+
timer = undefined;
|
|
66
|
+
if (disposed || controller.signal.aborted) return;
|
|
67
|
+
controller.abort(new StreamIdleTimeoutError(idleTimeoutMs));
|
|
68
|
+
}, idleTimeoutMs);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const onParentAbort = (): void => {
|
|
72
|
+
if (controller.signal.aborted) return;
|
|
73
|
+
clear();
|
|
74
|
+
controller.abort(parentSignal?.reason);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (parentSignal !== undefined) {
|
|
78
|
+
if (parentSignal.aborted) {
|
|
79
|
+
controller.abort(parentSignal.reason);
|
|
80
|
+
} else {
|
|
81
|
+
parentSignal.addEventListener("abort", onParentAbort);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
arm();
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
signal: controller.signal,
|
|
89
|
+
poke(): void {
|
|
90
|
+
arm();
|
|
91
|
+
},
|
|
92
|
+
dispose(): void {
|
|
93
|
+
disposed = true;
|
|
94
|
+
clear();
|
|
95
|
+
parentSignal?.removeEventListener("abort", onParentAbort);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|