@cleocode/core 2026.6.19 → 2026.7.2
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/docs/export-document.js +1160 -329
- package/dist/docs/export-document.js.map +3 -3
- package/dist/llm/plugin-facade.js +1211 -383
- package/dist/llm/plugin-facade.js.map +3 -3
- package/dist/memory/brain-writer-handlers.d.ts.map +1 -1
- package/dist/memory/brain-writer-handlers.js +39 -0
- package/dist/memory/brain-writer-handlers.js.map +1 -1
- package/dist/orchestrate/admission.d.ts +65 -0
- package/dist/orchestrate/admission.d.ts.map +1 -0
- package/dist/orchestrate/admission.js +54 -0
- package/dist/orchestrate/admission.js.map +1 -0
- package/dist/orchestrate/query-ops.d.ts.map +1 -1
- package/dist/orchestrate/query-ops.js +37 -8
- package/dist/orchestrate/query-ops.js.map +1 -1
- package/dist/orchestrate/spawn-ops.d.ts.map +1 -1
- package/dist/orchestrate/spawn-ops.js +24 -0
- package/dist/orchestrate/spawn-ops.js.map +1 -1
- package/dist/resources/governor.d.ts +133 -0
- package/dist/resources/governor.d.ts.map +1 -0
- package/dist/resources/governor.js +377 -0
- package/dist/resources/governor.js.map +1 -0
- package/dist/resources/supervisor-admit.d.ts +42 -0
- package/dist/resources/supervisor-admit.d.ts.map +1 -0
- package/dist/resources/supervisor-admit.js +136 -0
- package/dist/resources/supervisor-admit.js.map +1 -0
- package/dist/selfimprove/draft-pr.d.ts +93 -9
- package/dist/selfimprove/draft-pr.d.ts.map +1 -1
- package/dist/selfimprove/draft-pr.js +164 -23
- package/dist/selfimprove/draft-pr.js.map +1 -1
- package/dist/selfimprove/fix-gen.js +1209 -381
- package/dist/selfimprove/fix-gen.js.map +3 -3
- package/dist/selfimprove/run-loop.d.ts +9 -1
- package/dist/selfimprove/run-loop.d.ts.map +1 -1
- package/dist/selfimprove/run-loop.js +7 -1
- package/dist/selfimprove/run-loop.js.map +1 -1
- package/dist/sentient/tick.d.ts.map +1 -1
- package/dist/sentient/tick.js +29 -0
- package/dist/sentient/tick.js.map +1 -1
- package/dist/store/agent-registry-store.d.ts.map +1 -1
- package/dist/store/agent-registry-store.js +17 -2
- package/dist/store/agent-registry-store.js.map +1 -1
- package/dist/store/dual-scope-db.d.ts.map +1 -1
- package/dist/store/dual-scope-db.js +35 -0
- package/dist/store/dual-scope-db.js.map +1 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +15 -0
- package/dist/store/sqlite.js.map +1 -1
- package/dist/tasks/tool-semaphore.d.ts +25 -0
- package/dist/tasks/tool-semaphore.d.ts.map +1 -1
- package/dist/tasks/tool-semaphore.js +68 -1
- package/dist/tasks/tool-semaphore.js.map +1 -1
- package/package.json +12 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"governor.js","sourceRoot":"","sources":["../../src/resources/governor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAEL,+BAA+B,GAKhC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B,IAAI,IAAI,GAAwC,IAAI,CAAC;AACrD,SAAS,GAAG;IACV,IAAI,IAAI,KAAK,IAAI;QAAE,IAAI,GAAG,SAAS,CAAC,mB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a,CAAC,GAAkB;IAC9C,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC7F,CAAC;AAED,uCAAuC;AACvC,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supervisor-mode resource admission client (T12001 · Epic T11992).
|
|
3
|
+
*
|
|
4
|
+
* The `supervisor`-mode counterpart of the {@link ResourceGovernor}'s local slot
|
|
5
|
+
* engine. Where local mode arbitrates heavy-op concurrency through cross-process
|
|
6
|
+
* lockfiles, supervisor mode routes the `resource_admit` / `resource_release`
|
|
7
|
+
* lease-ipc verbs to the Rust `cleo-supervisor` so a single in-memory counter is
|
|
8
|
+
* the machine-wide source of truth.
|
|
9
|
+
*
|
|
10
|
+
* A dead/absent supervisor must NEVER deadlock work: every send degrades to
|
|
11
|
+
* `{ unavailable }` on any transport error, and the governor falls back to the
|
|
12
|
+
* local slot engine. Mirrors the `llm-queue-admit.ts` transport (core cannot
|
|
13
|
+
* import `@cleocode/runtime` — a cycle — so it speaks the NDJSON codec directly
|
|
14
|
+
* through the shared `@cleocode/contracts` lease-ipc Zod schemas).
|
|
15
|
+
*
|
|
16
|
+
* @task T12001
|
|
17
|
+
* @epic T11992
|
|
18
|
+
*/
|
|
19
|
+
import { type ResourceAdmitResultResponse, type ResourceReleaseResultResponse } from '@cleocode/contracts';
|
|
20
|
+
/** A transport-unavailable sentinel — the caller degrades to the local engine. */
|
|
21
|
+
export interface SupervisorUnavailable {
|
|
22
|
+
readonly unavailable: true;
|
|
23
|
+
readonly reason: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the supervisor socket path: `$CLEO_SUPERVISOR_SOCKET` overrides,
|
|
27
|
+
* otherwise `<cleoHome>/cleo-supervisor.sock`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveSupervisorSocketPath(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Admit (or defer) a heavy op of `cls` for `holderId` against `budget` through
|
|
32
|
+
* the supervisor's central arbiter. Resolves the `resource_admit_result` reply,
|
|
33
|
+
* or `{ unavailable }` when the supervisor cannot arbitrate (degrade to local).
|
|
34
|
+
*/
|
|
35
|
+
export declare function sendResourceAdmit(socketPath: string, cls: string, holderId: string, budget: number): Promise<ResourceAdmitResultResponse | SupervisorUnavailable>;
|
|
36
|
+
/**
|
|
37
|
+
* Release a previously-admitted slot of `cls` for `holderId`. Resolves the
|
|
38
|
+
* `resource_release_result` reply, or `{ unavailable }` on transport failure
|
|
39
|
+
* (the slot self-heals via the arbiter's process-death reclaim / stale recovery).
|
|
40
|
+
*/
|
|
41
|
+
export declare function sendResourceRelease(socketPath: string, cls: string, holderId: string): Promise<ResourceReleaseResultResponse | SupervisorUnavailable>;
|
|
42
|
+
//# sourceMappingURL=supervisor-admit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-admit.d.ts","sourceRoot":"","sources":["../../src/resources/supervisor-admit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,EAKL,KAAK,2BAA2B,EAChC,KAAK,6BAA6B,EACnC,MAAM,qBAAqB,CAAC;AAY7B,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,2BAA2B,GAAG,qBAAqB,CAAC,CAS9D;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,6BAA6B,GAAG,qBAAqB,CAAC,CAShE"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supervisor-mode resource admission client (T12001 · Epic T11992).
|
|
3
|
+
*
|
|
4
|
+
* The `supervisor`-mode counterpart of the {@link ResourceGovernor}'s local slot
|
|
5
|
+
* engine. Where local mode arbitrates heavy-op concurrency through cross-process
|
|
6
|
+
* lockfiles, supervisor mode routes the `resource_admit` / `resource_release`
|
|
7
|
+
* lease-ipc verbs to the Rust `cleo-supervisor` so a single in-memory counter is
|
|
8
|
+
* the machine-wide source of truth.
|
|
9
|
+
*
|
|
10
|
+
* A dead/absent supervisor must NEVER deadlock work: every send degrades to
|
|
11
|
+
* `{ unavailable }` on any transport error, and the governor falls back to the
|
|
12
|
+
* local slot engine. Mirrors the `llm-queue-admit.ts` transport (core cannot
|
|
13
|
+
* import `@cleocode/runtime` — a cycle — so it speaks the NDJSON codec directly
|
|
14
|
+
* through the shared `@cleocode/contracts` lease-ipc Zod schemas).
|
|
15
|
+
*
|
|
16
|
+
* @task T12001
|
|
17
|
+
* @epic T11992
|
|
18
|
+
*/
|
|
19
|
+
import { connect } from 'node:net';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { LEASE_IPC_PROTOCOL_VERSION, LeaseIpcRequestEnvelopeSchema, LeaseIpcResponseEnvelopeSchema, } from '@cleocode/contracts';
|
|
22
|
+
import { getCleoHome } from '@cleocode/paths';
|
|
23
|
+
/** The supervisor IPC socket filename — MUST equal `SOCKET_NAME` in `crates/cleo-supervisor/src/paths.rs`. */
|
|
24
|
+
const SUPERVISOR_SOCKET_NAME = 'cleo-supervisor.sock';
|
|
25
|
+
/** Connect timeout (ms). A slow/absent socket degrades fast — never a deadlock. */
|
|
26
|
+
const CONNECT_TIMEOUT_MS = 250;
|
|
27
|
+
/** Per-request read timeout for a result frame (ms). */
|
|
28
|
+
const REQUEST_TIMEOUT_MS = 2_000;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the supervisor socket path: `$CLEO_SUPERVISOR_SOCKET` overrides,
|
|
31
|
+
* otherwise `<cleoHome>/cleo-supervisor.sock`.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveSupervisorSocketPath() {
|
|
34
|
+
return process.env.CLEO_SUPERVISOR_SOCKET ?? join(getCleoHome(), SUPERVISOR_SOCKET_NAME);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Admit (or defer) a heavy op of `cls` for `holderId` against `budget` through
|
|
38
|
+
* the supervisor's central arbiter. Resolves the `resource_admit_result` reply,
|
|
39
|
+
* or `{ unavailable }` when the supervisor cannot arbitrate (degrade to local).
|
|
40
|
+
*/
|
|
41
|
+
export async function sendResourceAdmit(socketPath, cls, holderId, budget) {
|
|
42
|
+
const result = await sendLeaseRequest(socketPath, { kind: 'resource_admit', class: cls, holder_id: holderId, budget }, 'resource_admit_result');
|
|
43
|
+
if ('unavailable' in result)
|
|
44
|
+
return result;
|
|
45
|
+
if (result.kind === 'resource_admit_result')
|
|
46
|
+
return result;
|
|
47
|
+
return { unavailable: true, reason: `unexpected response kind: ${result.kind}` };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Release a previously-admitted slot of `cls` for `holderId`. Resolves the
|
|
51
|
+
* `resource_release_result` reply, or `{ unavailable }` on transport failure
|
|
52
|
+
* (the slot self-heals via the arbiter's process-death reclaim / stale recovery).
|
|
53
|
+
*/
|
|
54
|
+
export async function sendResourceRelease(socketPath, cls, holderId) {
|
|
55
|
+
const result = await sendLeaseRequest(socketPath, { kind: 'resource_release', class: cls, holder_id: holderId }, 'resource_release_result');
|
|
56
|
+
if ('unavailable' in result)
|
|
57
|
+
return result;
|
|
58
|
+
if (result.kind === 'resource_release_result')
|
|
59
|
+
return result;
|
|
60
|
+
return { unavailable: true, reason: `unexpected response kind: ${result.kind}` };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* One-shot NDJSON lease-ipc round-trip over a fresh Unix socket. Connection per
|
|
64
|
+
* request (the verbs are stateless); the socket is closed before resolution.
|
|
65
|
+
* Any transport error resolves to `{ unavailable }` — never throws, never
|
|
66
|
+
* deadlocks. `expectedKind` is the result `kind` the caller correlates.
|
|
67
|
+
*/
|
|
68
|
+
function sendLeaseRequest(socketPath, request, expectedKind) {
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
const id = `ra-${process.pid}-${request.kind}`;
|
|
71
|
+
const envelope = LeaseIpcRequestEnvelopeSchema.parse({
|
|
72
|
+
protocol_version: LEASE_IPC_PROTOCOL_VERSION,
|
|
73
|
+
id,
|
|
74
|
+
direction: 'request',
|
|
75
|
+
request,
|
|
76
|
+
});
|
|
77
|
+
const line = `${JSON.stringify(envelope)}\n`;
|
|
78
|
+
let settled = false;
|
|
79
|
+
let buffer = '';
|
|
80
|
+
const socket = connect(socketPath);
|
|
81
|
+
const done = (value) => {
|
|
82
|
+
if (settled)
|
|
83
|
+
return;
|
|
84
|
+
settled = true;
|
|
85
|
+
socket.removeAllListeners();
|
|
86
|
+
socket.destroy();
|
|
87
|
+
resolve(value);
|
|
88
|
+
};
|
|
89
|
+
const degrade = (reason) => done({ unavailable: true, reason });
|
|
90
|
+
socket.setTimeout(REQUEST_TIMEOUT_MS);
|
|
91
|
+
const connectTimer = setTimeout(() => degrade('supervisor connect timeout'), CONNECT_TIMEOUT_MS);
|
|
92
|
+
socket.on('connect', () => {
|
|
93
|
+
clearTimeout(connectTimer);
|
|
94
|
+
socket.write(line);
|
|
95
|
+
});
|
|
96
|
+
socket.on('timeout', () => degrade('supervisor request timeout'));
|
|
97
|
+
socket.on('error', (err) => {
|
|
98
|
+
clearTimeout(connectTimer);
|
|
99
|
+
degrade(err.message);
|
|
100
|
+
});
|
|
101
|
+
socket.on('close', () => {
|
|
102
|
+
if (!settled)
|
|
103
|
+
degrade('supervisor closed the connection before responding');
|
|
104
|
+
});
|
|
105
|
+
socket.on('data', (chunk) => {
|
|
106
|
+
buffer += chunk.toString('utf8');
|
|
107
|
+
const nl = buffer.indexOf('\n');
|
|
108
|
+
if (nl < 0)
|
|
109
|
+
return; // wait for a full NDJSON line
|
|
110
|
+
let json;
|
|
111
|
+
try {
|
|
112
|
+
json = JSON.parse(buffer.slice(0, nl));
|
|
113
|
+
}
|
|
114
|
+
catch (cause) {
|
|
115
|
+
degrade(`malformed lease-ipc frame: ${cause instanceof Error ? cause.message : cause}`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const parsed = LeaseIpcResponseEnvelopeSchema.safeParse(json);
|
|
119
|
+
if (!parsed.success) {
|
|
120
|
+
degrade(`off-contract lease-ipc response: ${parsed.error.message}`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const { response } = parsed.data;
|
|
124
|
+
if (response.kind === expectedKind) {
|
|
125
|
+
done(response);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (response.kind === 'error') {
|
|
129
|
+
degrade(`${response.code}: ${response.message}`);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
degrade(`unexpected lease-ipc response kind for ${request.kind}: ${response.kind}`);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=supervisor-admit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-admit.js","sourceRoot":"","sources":["../../src/resources/supervisor-admit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAi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,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;gBACxF,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAG,8BAA8B,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,CAAC,oCAAoC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACpE,OAAO;YACT,CAAC;YACD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;YACjC,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBACnC,IAAI,CAAC,QAAuE,CAAC,CAAC;gBAC9E,OAAO;YACT,CAAC;YACD,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC9B,OAAO,CAAC,GAAG,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;gBACjD,OAAO;YACT,CAAC;YACD,OAAO,CAAC,0CAA0C,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QACtF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* PR against the cleocode repo (ADR-065 — PRs target `main` via the Merge Queue;
|
|
6
6
|
* NEVER a direct push to `main`, NEVER an auto-merge, NEVER a publish). This module
|
|
7
7
|
* is the egress primitive, modeled on `propose-patch.ts` (the closest "agent
|
|
8
|
-
* proposes a fix PR" exemplar) with
|
|
8
|
+
* proposes a fix PR" exemplar) with four self-dogfooding hardenings:
|
|
9
9
|
*
|
|
10
10
|
* 1. **`--draft` is ALWAYS appended** to `gh pr create` — the PR is never
|
|
11
11
|
* ready-for-merge; a human reviews and undrafts it.
|
|
@@ -14,6 +14,13 @@
|
|
|
14
14
|
* side-effect-free at egress by default.
|
|
15
15
|
* 3. **Branch `feat/T11889-selfimprove-<scenario>-<ts>`** — a feature branch
|
|
16
16
|
* (ADR-065); no main mutation path exists in this module.
|
|
17
|
+
* 4. **Workspace isolation (T12007).** The patch is applied inside an
|
|
18
|
+
* *ephemeral transient worktree* cut fresh off `origin/main` — NEVER the
|
|
19
|
+
* invoking checkout — and ONLY the paths the patch names are staged
|
|
20
|
+
* (`git add -- <paths>`, never `git add -A`). This closes a P1 data-safety
|
|
21
|
+
* defect where the egress swept the orchestrator's entire dirty working
|
|
22
|
+
* tree (untracked owner scratch notes, uncommitted edits) into the public
|
|
23
|
+
* branch and deleted them locally. The invoking repo is never mutated.
|
|
17
24
|
*
|
|
18
25
|
* The live path wraps the git/gh shell-out in
|
|
19
26
|
* {@link "../sentient/skill-provenance.js".withProvenance}`('pr-generator', …)`
|
|
@@ -26,21 +33,56 @@
|
|
|
26
33
|
* @module @cleocode/core/selfimprove/draft-pr
|
|
27
34
|
* @epic T11889
|
|
28
35
|
* @task T11913
|
|
36
|
+
* @task T12007
|
|
29
37
|
*/
|
|
30
38
|
/**
|
|
31
39
|
* Pluggable command runner. Returns stdout as UTF-8 text or throws on non-zero
|
|
32
40
|
* exit. Production default wraps `child_process.execFileSync` with piped stdio.
|
|
41
|
+
*
|
|
42
|
+
* The optional `cwd` is REQUIRED for workspace isolation (T12007): every git
|
|
43
|
+
* mutation runs inside the ephemeral worktree, never `process.cwd()` (which
|
|
44
|
+
* would be the invoking checkout). The default runner threads it into
|
|
45
|
+
* `execFileSync`; test doubles capture it to assert the isolation boundary.
|
|
46
|
+
*/
|
|
47
|
+
export type CommandRunner = (file: string, args: readonly string[], cwd?: string) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Provision arguments for the isolated worktree hook (T12007).
|
|
50
|
+
*
|
|
51
|
+
* @see {@link WorktreeProvisioner}
|
|
52
|
+
*/
|
|
53
|
+
export interface ProvisionWorktreeArgs {
|
|
54
|
+
/** Absolute invoking project root the worktree is registered against. */
|
|
55
|
+
readonly projectRoot: string;
|
|
56
|
+
/** Absolute path where the ephemeral worktree directory is created (tmpdir). */
|
|
57
|
+
readonly worktreePath: string;
|
|
58
|
+
/** The feature branch created inside the worktree. */
|
|
59
|
+
readonly branch: string;
|
|
60
|
+
/** The base ref the worktree (and its branch) is cut from — `origin/main`. */
|
|
61
|
+
readonly baseRef: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Inject hook that provisions the ephemeral isolation worktree. Production
|
|
65
|
+
* leaves it undefined and the module routes through `@cleocode/worktree`'s
|
|
66
|
+
* `addTransientWorktree` (the sanctioned escape hatch for tmpdir worktrees —
|
|
67
|
+
* keeps the raw `git worktree` shell-out out of `packages/core/` per the
|
|
68
|
+
* T9984 lint gate). Tests inject a double to avoid a real git remote.
|
|
33
69
|
*/
|
|
34
|
-
export type
|
|
70
|
+
export type WorktreeProvisioner = (args: ProvisionWorktreeArgs) => Promise<void> | void;
|
|
71
|
+
/**
|
|
72
|
+
* Inject hook that removes the ephemeral isolation worktree. Production leaves
|
|
73
|
+
* it undefined and the module routes through `@cleocode/worktree`'s
|
|
74
|
+
* `removeTransientWorktree`.
|
|
75
|
+
*/
|
|
76
|
+
export type WorktreeRemover = (projectRoot: string, worktreePath: string) => Promise<void> | void;
|
|
35
77
|
/** Failure codes from {@link openDraftPr}. */
|
|
36
78
|
export type DraftPrErrorCode =
|
|
37
79
|
/** Patch file does not exist on disk. */
|
|
38
80
|
'E_NOT_FOUND'
|
|
39
|
-
/** Patch file exists but is empty. */
|
|
81
|
+
/** Patch file exists but is empty (or names no files). */
|
|
40
82
|
| 'E_PATCH_EMPTY'
|
|
41
83
|
/** `gh` CLI missing / not authenticated. */
|
|
42
84
|
| 'E_GH_UNAVAILABLE'
|
|
43
|
-
/** Shell-out failure during the live PR cut. */
|
|
85
|
+
/** Shell-out failure during the live PR cut (incl. worktree provisioning). */
|
|
44
86
|
| 'E_DRAFT_PR_FAILED';
|
|
45
87
|
/** Args for {@link openDraftPr}. */
|
|
46
88
|
export interface OpenDraftPrArgs {
|
|
@@ -60,12 +102,25 @@ export interface OpenDraftPrArgs {
|
|
|
60
102
|
* @defaultValue false
|
|
61
103
|
*/
|
|
62
104
|
readonly execute?: boolean;
|
|
63
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* The INVOKING checkout / project root. Used to (a) resolve {@link diffPath}
|
|
107
|
+
* and (b) register the ephemeral worktree against — it is NEVER mutated
|
|
108
|
+
* (T12007). Defaults to {@link process.cwd}.
|
|
109
|
+
*/
|
|
64
110
|
readonly cwd?: string;
|
|
65
111
|
/** Injectable command runner (tests capture the shell-out). Defaults to {@link execFileSync}. */
|
|
66
112
|
readonly run?: CommandRunner;
|
|
67
113
|
/** Injectable timestamp source for the branch suffix (tests pin it). Defaults to now. */
|
|
68
114
|
readonly timestamp?: () => string;
|
|
115
|
+
/**
|
|
116
|
+
* Explicit path for the ephemeral isolation worktree (T12007). Defaults to a
|
|
117
|
+
* unique `os.tmpdir()` directory. Overridable for deterministic tests.
|
|
118
|
+
*/
|
|
119
|
+
readonly worktreeDir?: string;
|
|
120
|
+
/** Injectable worktree provisioner (tests avoid a real remote). Defaults to `addTransientWorktree`. */
|
|
121
|
+
readonly provisionWorktree?: WorktreeProvisioner;
|
|
122
|
+
/** Injectable worktree remover. Defaults to `removeTransientWorktree`. */
|
|
123
|
+
readonly removeWorktree?: WorktreeRemover;
|
|
69
124
|
}
|
|
70
125
|
/** Dry-run result — the planned steps, no side effects. */
|
|
71
126
|
export interface DraftPrDryRun {
|
|
@@ -74,6 +129,8 @@ export interface DraftPrDryRun {
|
|
|
74
129
|
readonly branchName: string;
|
|
75
130
|
/** The planned shell steps; the `gh pr create` step includes `--draft`. */
|
|
76
131
|
readonly steps: readonly string[];
|
|
132
|
+
/** The repo-relative paths the patch touches — the ONLY paths that will be staged. */
|
|
133
|
+
readonly patchPaths: readonly string[];
|
|
77
134
|
}
|
|
78
135
|
/** Live result — the opened draft PR. */
|
|
79
136
|
export interface DraftPrOk {
|
|
@@ -82,6 +139,8 @@ export interface DraftPrOk {
|
|
|
82
139
|
readonly branchName: string;
|
|
83
140
|
/** The draft PR URL emitted by `gh pr create --draft`. */
|
|
84
141
|
readonly prUrl: string;
|
|
142
|
+
/** The repo-relative paths the patch touched (the PR's complete file set). */
|
|
143
|
+
readonly patchPaths: readonly string[];
|
|
85
144
|
}
|
|
86
145
|
/** Failure result. */
|
|
87
146
|
export interface DraftPrFailure {
|
|
@@ -101,15 +160,40 @@ export type DraftPrResult = DraftPrDryRun | DraftPrOk | DraftPrFailure;
|
|
|
101
160
|
* @returns The branch name.
|
|
102
161
|
*/
|
|
103
162
|
export declare function draftPrBranchName(scenario: string, ts: string): string;
|
|
163
|
+
/**
|
|
164
|
+
* Extract the set of repo-relative paths a unified diff touches — the SSoT for
|
|
165
|
+
* "which paths may be staged" (T12007).
|
|
166
|
+
*
|
|
167
|
+
* Parses the `diff --git a/<old> b/<new>` header (the authoritative per-file
|
|
168
|
+
* boundary in a git-format diff), collecting BOTH the pre-image (`a/`) and
|
|
169
|
+
* post-image (`b/`) paths so renames stage their old path too and deletions
|
|
170
|
+
* stage the removed path. `/dev/null` sentinels (pure add / pure delete) are
|
|
171
|
+
* skipped. Also parses bare `--- ` / `+++ ` headers as a fallback for
|
|
172
|
+
* non-`diff --git` unified diffs. The result is de-duplicated and stable
|
|
173
|
+
* ordered by first appearance.
|
|
174
|
+
*
|
|
175
|
+
* The egress stages ONLY these paths (`git add -- <paths>`), so the isolated
|
|
176
|
+
* worktree can never sweep anything the patch did not name.
|
|
177
|
+
*
|
|
178
|
+
* @param diffText - The unified-diff text.
|
|
179
|
+
* @returns The de-duplicated repo-relative paths the diff touches.
|
|
180
|
+
*/
|
|
181
|
+
export declare function parseUnifiedDiffPaths(diffText: string): string[];
|
|
104
182
|
/**
|
|
105
183
|
* Open ONE DRAFT PR carrying a proposed self-improvement fix.
|
|
106
184
|
*
|
|
107
185
|
* DRY-RUN by default ({@link OpenDraftPrArgs.execute} falsey): returns the planned
|
|
108
186
|
* `steps[]` (the `gh pr create` step ALWAYS carries `--draft`) WITHOUT touching
|
|
109
187
|
* git/gh — so the loop is egress-side-effect-free unless `--execute` is threaded
|
|
110
|
-
* through.
|
|
111
|
-
*
|
|
112
|
-
*
|
|
188
|
+
* through.
|
|
189
|
+
*
|
|
190
|
+
* The live path (`execute: true`) never mutates the invoking checkout (T12007).
|
|
191
|
+
* It cuts an EPHEMERAL transient worktree fresh off `origin/main`, applies the
|
|
192
|
+
* diff there, stages ONLY the paths the patch names (`git add -- <paths>` — NEVER
|
|
193
|
+
* `git add -A`), commits, pushes the FEATURE branch (NEVER `main`), runs
|
|
194
|
+
* `gh pr create --base main --head <branch> --draft`, and tears the worktree
|
|
195
|
+
* down in a `finally`. The orchestrator's untracked/uncommitted files are never
|
|
196
|
+
* staged, pushed, or deleted.
|
|
113
197
|
*
|
|
114
198
|
* NEVER pushes `main`, NEVER auto-merges, NEVER publishes — the only egress is a
|
|
115
199
|
* draft PR against a feature branch.
|
|
@@ -121,7 +205,7 @@ export declare function draftPrBranchName(scenario: string, ts: string): string;
|
|
|
121
205
|
* ```ts
|
|
122
206
|
* // dry-run (default): no side effects, steps include `--draft`
|
|
123
207
|
* const plan = await openDraftPr({ scenario: 'x', diffPath: 'fix.patch', title, body });
|
|
124
|
-
* // live: cuts
|
|
208
|
+
* // live: cuts an isolated worktree + opens draft PR (invoking repo untouched)
|
|
125
209
|
* const res = await openDraftPr({ scenario: 'x', diffPath: 'fix.patch', title, body, execute: true });
|
|
126
210
|
* ```
|
|
127
211
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-pr.d.ts","sourceRoot":"","sources":["../../src/selfimprove/draft-pr.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"draft-pr.d.ts","sourceRoot":"","sources":["../../src/selfimprove/draft-pr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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