harnessed 4.48.0 → 4.49.1
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-en.md +1 -0
- package/README.md +1 -0
- package/bin/harnessed-check-docs.mjs +452 -0
- package/bin/harnessed-inject-state.mjs +72 -16
- package/bin/harnessed-stop-hook.mjs +51 -10
- package/dist/cli.mjs +858 -243
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/messages/en.json +2 -0
- package/messages/zh-Hans.json +2 -0
- package/package.json +2 -1
package/dist/cli.mjs
CHANGED
|
@@ -6,12 +6,12 @@ import { Type } from '@sinclair/typebox';
|
|
|
6
6
|
import { readFile, readdir, stat, rm, unlink, writeFile, cp, mkdir, access, rename, appendFile, copyFile, chmod, mkdtemp } from 'fs/promises';
|
|
7
7
|
import { Value } from '@sinclair/typebox/value';
|
|
8
8
|
import lockfile from 'proper-lockfile';
|
|
9
|
+
import { createHash, verify, createPublicKey } from 'crypto';
|
|
9
10
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
10
11
|
import { LineCounter, parseDocument, parse, isSeq, isScalar, stringify } from 'yaml';
|
|
11
12
|
import { Ajv } from 'ajv';
|
|
12
13
|
import * as ajvFormatsNs from 'ajv-formats';
|
|
13
14
|
import { execFileSync, spawnSync, spawn, execFile, exec } from 'child_process';
|
|
14
|
-
import { createHash, verify, createPublicKey } from 'crypto';
|
|
15
15
|
import { promisify } from 'util';
|
|
16
16
|
import * as p from '@clack/prompts';
|
|
17
17
|
import { createPatch } from 'diff';
|
|
@@ -38,7 +38,7 @@ var init_package = __esm({
|
|
|
38
38
|
"package.json"() {
|
|
39
39
|
package_default = {
|
|
40
40
|
name: "harnessed",
|
|
41
|
-
version: "4.
|
|
41
|
+
version: "4.49.1",
|
|
42
42
|
description: "AI coding harness package manager + composition orchestrator",
|
|
43
43
|
type: "module",
|
|
44
44
|
license: "Apache-2.0",
|
|
@@ -124,6 +124,7 @@ var init_package = __esm({
|
|
|
124
124
|
"expr-eval": "^2.0.2",
|
|
125
125
|
picocolors: "^1.1.1",
|
|
126
126
|
"proper-lockfile": "^4.1.2",
|
|
127
|
+
undici: "^8.12.1",
|
|
127
128
|
yaml: "^2.9.0"
|
|
128
129
|
},
|
|
129
130
|
devDependencies: {
|
|
@@ -148,15 +149,19 @@ var init_package = __esm({
|
|
|
148
149
|
// src/platform/platform.ts
|
|
149
150
|
var platform_exports = {};
|
|
150
151
|
__export(platform_exports, {
|
|
152
|
+
HOST_IDS: () => HOST_IDS,
|
|
151
153
|
claudeDescriptor: () => claudeDescriptor,
|
|
152
154
|
codexDescriptor: () => codexDescriptor,
|
|
155
|
+
descriptorFor: () => descriptorFor,
|
|
153
156
|
detectPlatform: () => detectPlatform,
|
|
154
157
|
getCommandsDir: () => getCommandsDir,
|
|
155
158
|
getMcpConfigPath: () => getMcpConfigPath,
|
|
156
159
|
getPluginsRegistry: () => getPluginsRegistry,
|
|
157
160
|
getSettingsPath: () => getSettingsPath,
|
|
158
161
|
getSkillsDir: () => getSkillsDir,
|
|
159
|
-
harnessSkillsDirs: () => harnessSkillsDirs
|
|
162
|
+
harnessSkillsDirs: () => harnessSkillsDirs,
|
|
163
|
+
isHostId: () => isHostId,
|
|
164
|
+
resolveHostWithReason: () => resolveHostWithReason
|
|
160
165
|
});
|
|
161
166
|
function claudeDescriptor(home = homedir()) {
|
|
162
167
|
const claudeHome = join(home, ".claude");
|
|
@@ -195,10 +200,14 @@ function codexDescriptor(home = homedir()) {
|
|
|
195
200
|
sessionIdEnv: "CODEX_SESSION_ID"
|
|
196
201
|
};
|
|
197
202
|
}
|
|
203
|
+
function isHostId(id) {
|
|
204
|
+
return HOST_IDS.includes(id);
|
|
205
|
+
}
|
|
206
|
+
function descriptorFor(id, home = homedir()) {
|
|
207
|
+
return id === "codex" ? codexDescriptor(home) : claudeDescriptor(home);
|
|
208
|
+
}
|
|
198
209
|
function descriptorById(id, home) {
|
|
199
|
-
|
|
200
|
-
if (id === "codex") return codexDescriptor(home);
|
|
201
|
-
return void 0;
|
|
210
|
+
return isHostId(id) ? descriptorFor(id, home) : void 0;
|
|
202
211
|
}
|
|
203
212
|
function detectPlatform(home = homedir()) {
|
|
204
213
|
const resolved = resolveHost(home);
|
|
@@ -207,29 +216,65 @@ function detectPlatform(home = homedir()) {
|
|
|
207
216
|
return resolved;
|
|
208
217
|
}
|
|
209
218
|
function resolveHost(home) {
|
|
219
|
+
return resolveHostWithReason(home).descriptor;
|
|
220
|
+
}
|
|
221
|
+
function resolveHostWithReason(home = homedir()) {
|
|
210
222
|
const base = claudeDescriptor(home);
|
|
223
|
+
const skipped = [];
|
|
211
224
|
const envPlatform = process.env.HARNESSED_PLATFORM;
|
|
212
225
|
if (envPlatform !== void 0 && envPlatform !== "") {
|
|
213
226
|
const d = descriptorById(envPlatform, home);
|
|
214
|
-
if (d)
|
|
227
|
+
if (d) {
|
|
228
|
+
return {
|
|
229
|
+
descriptor: d,
|
|
230
|
+
reason: { kind: "env-platform", envVar: "HARNESSED_PLATFORM", value: envPlatform },
|
|
231
|
+
skipped
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
skipped.push({ kind: "env-platform-unknown", envVar: "HARNESSED_PLATFORM", value: envPlatform });
|
|
215
235
|
}
|
|
216
236
|
const inClaude = Boolean(process.env.CLAUDE_CODE_SESSION_ID?.trim());
|
|
217
237
|
const inCodex = Boolean(process.env.CODEX_SESSION_ID?.trim());
|
|
218
|
-
if (inClaude !== inCodex)
|
|
238
|
+
if (inClaude !== inCodex) {
|
|
239
|
+
return {
|
|
240
|
+
descriptor: inClaude ? base : codexDescriptor(home),
|
|
241
|
+
reason: {
|
|
242
|
+
kind: "host-session-env",
|
|
243
|
+
envVar: inClaude ? "CLAUDE_CODE_SESSION_ID" : "CODEX_SESSION_ID"
|
|
244
|
+
},
|
|
245
|
+
skipped
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (inClaude && inCodex) skipped.push({ kind: "host-session-env-ambiguous" });
|
|
219
249
|
for (const pinRoot of [codexDescriptor(home).stateRoot, base.stateRoot]) {
|
|
250
|
+
const pinPath = join(pinRoot, ".platform");
|
|
220
251
|
try {
|
|
221
|
-
const
|
|
222
|
-
|
|
252
|
+
const value = readFileSync(pinPath, "utf8").trim();
|
|
253
|
+
const d = descriptorById(value, home);
|
|
254
|
+
if (d) return { descriptor: d, reason: { kind: "platform-pin", pinPath, value }, skipped };
|
|
255
|
+
skipped.push({ kind: "platform-pin-unknown", pinPath, value });
|
|
223
256
|
} catch {
|
|
224
257
|
}
|
|
225
258
|
}
|
|
226
259
|
try {
|
|
227
|
-
if (existsSync(base.homeDir))
|
|
260
|
+
if (existsSync(base.homeDir)) {
|
|
261
|
+
return {
|
|
262
|
+
descriptor: base,
|
|
263
|
+
reason: { kind: "directory-probe", probedDir: base.homeDir },
|
|
264
|
+
skipped
|
|
265
|
+
};
|
|
266
|
+
}
|
|
228
267
|
const codex = codexDescriptor(home);
|
|
229
|
-
if (existsSync(codex.homeDir))
|
|
268
|
+
if (existsSync(codex.homeDir)) {
|
|
269
|
+
return {
|
|
270
|
+
descriptor: codex,
|
|
271
|
+
reason: { kind: "directory-probe", probedDir: codex.homeDir },
|
|
272
|
+
skipped
|
|
273
|
+
};
|
|
274
|
+
}
|
|
230
275
|
} catch {
|
|
231
276
|
}
|
|
232
|
-
return base;
|
|
277
|
+
return { descriptor: base, reason: { kind: "fallback" }, skipped };
|
|
233
278
|
}
|
|
234
279
|
function getSettingsPath(home) {
|
|
235
280
|
return detectPlatform(home).settingsPath;
|
|
@@ -251,8 +296,10 @@ function harnessSkillsDirs(home) {
|
|
|
251
296
|
const dirs = [claudeDescriptor(home).skillsDir, codex.skillsDir, join(codex.homeDir, "skills")];
|
|
252
297
|
return [...new Set(dirs)];
|
|
253
298
|
}
|
|
299
|
+
var HOST_IDS;
|
|
254
300
|
var init_platform = __esm({
|
|
255
301
|
"src/platform/platform.ts"() {
|
|
302
|
+
HOST_IDS = ["claude", "codex"];
|
|
256
303
|
}
|
|
257
304
|
});
|
|
258
305
|
function getHarnessedRoot() {
|
|
@@ -416,37 +463,6 @@ var init_atomicWrite = __esm({
|
|
|
416
463
|
isTransient = (e) => TRANSIENT_RENAME.has(e?.code ?? "");
|
|
417
464
|
}
|
|
418
465
|
});
|
|
419
|
-
var CheckpointStatus, CheckpointV1;
|
|
420
|
-
var init_checkpoint_v1 = __esm({
|
|
421
|
-
"src/checkpoint/schema/checkpoint.v1.ts"() {
|
|
422
|
-
init_schemaVersion();
|
|
423
|
-
CheckpointStatus = Type.Union([
|
|
424
|
-
Type.Literal("active"),
|
|
425
|
-
Type.Literal("paused"),
|
|
426
|
-
Type.Literal("complete")
|
|
427
|
-
]);
|
|
428
|
-
CheckpointV1 = Type.Object(
|
|
429
|
-
{
|
|
430
|
-
schemaVersion: Type.Literal(SCHEMA_VERSIONS.checkpoint),
|
|
431
|
-
phase: Type.String({ minLength: 1 }),
|
|
432
|
-
status: CheckpointStatus,
|
|
433
|
-
last_task: Type.String(),
|
|
434
|
-
key_decisions: Type.Array(Type.String()),
|
|
435
|
-
canonical_refs: Type.Array(Type.String()),
|
|
436
|
-
/** D-04 WIRE-IN: optional SDK session_id captured via `sdkSpawn`
|
|
437
|
-
* `onSessionId` callback (CD-4 closure-ready) for future `--resume`. */
|
|
438
|
-
session_id: Type.Optional(Type.String()),
|
|
439
|
-
/** RESEARCH § 1.3 critical constraint — SDK session resume requires cwd
|
|
440
|
-
* match; we capture and validate at restore time. */
|
|
441
|
-
cwd: Type.String({ minLength: 1 }),
|
|
442
|
-
timestamp: Type.String({ minLength: 1 }),
|
|
443
|
-
// ISO-8601 by convention (TypeBox `format` requires Ajv-style format registry; we keep shape-check only — drift caught in writeCheckpoint path)
|
|
444
|
-
archive_path: Type.String({ minLength: 1 })
|
|
445
|
-
},
|
|
446
|
-
{ additionalProperties: false }
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
466
|
|
|
451
467
|
// src/workflow/lib/spawnFailure.ts
|
|
452
468
|
var spawnFailure_exports = {};
|
|
@@ -644,6 +660,37 @@ var init_currentWorkflow_v1 = __esm({
|
|
|
644
660
|
);
|
|
645
661
|
}
|
|
646
662
|
});
|
|
663
|
+
var CheckpointStatus, CheckpointV1;
|
|
664
|
+
var init_checkpoint_v1 = __esm({
|
|
665
|
+
"src/checkpoint/schema/checkpoint.v1.ts"() {
|
|
666
|
+
init_schemaVersion();
|
|
667
|
+
CheckpointStatus = Type.Union([
|
|
668
|
+
Type.Literal("active"),
|
|
669
|
+
Type.Literal("paused"),
|
|
670
|
+
Type.Literal("complete")
|
|
671
|
+
]);
|
|
672
|
+
CheckpointV1 = Type.Object(
|
|
673
|
+
{
|
|
674
|
+
schemaVersion: Type.Literal(SCHEMA_VERSIONS.checkpoint),
|
|
675
|
+
phase: Type.String({ minLength: 1 }),
|
|
676
|
+
status: CheckpointStatus,
|
|
677
|
+
last_task: Type.String(),
|
|
678
|
+
key_decisions: Type.Array(Type.String()),
|
|
679
|
+
canonical_refs: Type.Array(Type.String()),
|
|
680
|
+
/** D-04 WIRE-IN: optional SDK session_id captured via `sdkSpawn`
|
|
681
|
+
* `onSessionId` callback (CD-4 closure-ready) for future `--resume`. */
|
|
682
|
+
session_id: Type.Optional(Type.String()),
|
|
683
|
+
/** RESEARCH § 1.3 critical constraint — SDK session resume requires cwd
|
|
684
|
+
* match; we capture and validate at restore time. */
|
|
685
|
+
cwd: Type.String({ minLength: 1 }),
|
|
686
|
+
timestamp: Type.String({ minLength: 1 }),
|
|
687
|
+
// ISO-8601 by convention (TypeBox `format` requires Ajv-style format registry; we keep shape-check only — drift caught in writeCheckpoint path)
|
|
688
|
+
archive_path: Type.String({ minLength: 1 })
|
|
689
|
+
},
|
|
690
|
+
{ additionalProperties: false }
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
647
694
|
|
|
648
695
|
// src/checkpoint/schema/index.ts
|
|
649
696
|
var init_schema = __esm({
|
|
@@ -653,113 +700,6 @@ var init_schema = __esm({
|
|
|
653
700
|
}
|
|
654
701
|
});
|
|
655
702
|
|
|
656
|
-
// src/checkpoint/workflowStore.ts
|
|
657
|
-
var workflowStore_exports = {};
|
|
658
|
-
__export(workflowStore_exports, {
|
|
659
|
-
IntentEntry: () => IntentEntry,
|
|
660
|
-
RetroMetaEntry: () => RetroMetaEntry,
|
|
661
|
-
WorkflowStoreV1: () => WorkflowStoreV1,
|
|
662
|
-
activeKey: () => activeKey,
|
|
663
|
-
listWorkflows: () => listWorkflows,
|
|
664
|
-
readIntent: () => readIntent,
|
|
665
|
-
readStoreRaw: () => readStoreRaw,
|
|
666
|
-
repoKey: () => repoKey,
|
|
667
|
-
writeStoreRaw: () => writeStoreRaw
|
|
668
|
-
});
|
|
669
|
-
function storePath() {
|
|
670
|
-
return harnessedFile("workflows.json");
|
|
671
|
-
}
|
|
672
|
-
function emptyStore() {
|
|
673
|
-
return { schemaVersion: SCHEMA_VERSIONS.workflowStore, workflows: {} };
|
|
674
|
-
}
|
|
675
|
-
function repoKey(cwd = process.cwd()) {
|
|
676
|
-
let dir = resolve(cwd);
|
|
677
|
-
for (; ; ) {
|
|
678
|
-
if (existsSync(join(dir, ".git"))) return dir;
|
|
679
|
-
const parent = dirname(dir);
|
|
680
|
-
if (parent === dir) break;
|
|
681
|
-
dir = parent;
|
|
682
|
-
}
|
|
683
|
-
return resolve(cwd);
|
|
684
|
-
}
|
|
685
|
-
function activeKey(cwd = process.cwd()) {
|
|
686
|
-
const base = repoKey(cwd);
|
|
687
|
-
const envName = detectPlatform().sessionIdEnv;
|
|
688
|
-
const sid = envName ? process.env[envName]?.trim() : void 0;
|
|
689
|
-
return sid ? `${base}::${sid}` : base;
|
|
690
|
-
}
|
|
691
|
-
async function readStoreRaw() {
|
|
692
|
-
try {
|
|
693
|
-
const parsed = JSON.parse(await readFile(storePath(), "utf8"));
|
|
694
|
-
if (Value.Check(WorkflowStoreV1, parsed)) return parsed;
|
|
695
|
-
} catch {
|
|
696
|
-
}
|
|
697
|
-
return emptyStore();
|
|
698
|
-
}
|
|
699
|
-
async function writeStoreRaw(store) {
|
|
700
|
-
if (!Value.Check(WorkflowStoreV1, store)) {
|
|
701
|
-
const errs = [...Value.Errors(WorkflowStoreV1, store)].map((e) => e.message).join("; ");
|
|
702
|
-
throw new Error(`workflow-store schema validation failed: ${errs}`);
|
|
703
|
-
}
|
|
704
|
-
const p8 = storePath();
|
|
705
|
-
await mkdir(dirname(p8), { recursive: true });
|
|
706
|
-
await writeFileAtomic(p8, JSON.stringify(store, null, 2));
|
|
707
|
-
}
|
|
708
|
-
async function readIntent(cwd = process.cwd()) {
|
|
709
|
-
const store = await readStoreRaw();
|
|
710
|
-
return store.intents?.[activeKey(cwd)] ?? store.intents?.[repoKey(cwd)] ?? null;
|
|
711
|
-
}
|
|
712
|
-
async function listWorkflows() {
|
|
713
|
-
const store = await readStoreRaw();
|
|
714
|
-
return Object.entries(store.workflows).map(([key, wf]) => ({
|
|
715
|
-
key,
|
|
716
|
-
phase: wf.phase,
|
|
717
|
-
status: wf.status
|
|
718
|
-
}));
|
|
719
|
-
}
|
|
720
|
-
var RetroMetaEntry, IntentEntry, WorkflowStoreV1;
|
|
721
|
-
var init_workflowStore = __esm({
|
|
722
|
-
"src/checkpoint/workflowStore.ts"() {
|
|
723
|
-
init_harnessedRoot();
|
|
724
|
-
init_platform();
|
|
725
|
-
init_schemaVersion();
|
|
726
|
-
init_atomicWrite();
|
|
727
|
-
init_currentWorkflow_v1();
|
|
728
|
-
RetroMetaEntry = Type.Object(
|
|
729
|
-
{
|
|
730
|
-
phases_since_retro: Type.Integer({ minimum: 0 }),
|
|
731
|
-
last_retro_at: Type.Optional(Type.String({ minLength: 1 }))
|
|
732
|
-
},
|
|
733
|
-
{ additionalProperties: false }
|
|
734
|
-
);
|
|
735
|
-
IntentEntry = Type.Object(
|
|
736
|
-
{
|
|
737
|
-
// Invoked command name (master OR leaf sub — field name kept for 765cbc9
|
|
738
|
-
// store back-compat; kind carries the distinction).
|
|
739
|
-
master: Type.String({ minLength: 1 }),
|
|
740
|
-
ts: Type.String({ minLength: 1 }),
|
|
741
|
-
// 4.22.0 T6 — additive-optional: absent = 'master' (765cbc9 only ever wrote
|
|
742
|
-
// master intents). 'leaf' switches banner/nag to the leaf SOP wording
|
|
743
|
-
// (prompt → spawn → checkpoint complete) and the absorb trigger to that
|
|
744
|
-
// sub's complete/fail instead of `checkpoint start`.
|
|
745
|
-
kind: Type.Optional(Type.Union([Type.Literal("master"), Type.Literal("leaf")]))
|
|
746
|
-
},
|
|
747
|
-
{ additionalProperties: false }
|
|
748
|
-
);
|
|
749
|
-
WorkflowStoreV1 = Type.Object(
|
|
750
|
-
{
|
|
751
|
-
schemaVersion: Type.Literal(SCHEMA_VERSIONS.workflowStore),
|
|
752
|
-
workflows: Type.Record(Type.String(), CurrentWorkflowV1),
|
|
753
|
-
// Additive-optional (no schemaVersion bump — old stores Value.Check-pass).
|
|
754
|
-
retro_meta: Type.Optional(Type.Record(Type.String(), RetroMetaEntry)),
|
|
755
|
-
// 4.22.0 — additive-optional, same rationale.
|
|
756
|
-
intents: Type.Optional(Type.Record(Type.String(), IntentEntry))
|
|
757
|
-
},
|
|
758
|
-
{ additionalProperties: false }
|
|
759
|
-
);
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
|
|
763
703
|
// src/checkpoint/state.ts
|
|
764
704
|
var state_exports = {};
|
|
765
705
|
__export(state_exports, {
|
|
@@ -887,6 +827,195 @@ var init_state = __esm({
|
|
|
887
827
|
}
|
|
888
828
|
});
|
|
889
829
|
|
|
830
|
+
// src/checkpoint/workflowStore.ts
|
|
831
|
+
var workflowStore_exports = {};
|
|
832
|
+
__export(workflowStore_exports, {
|
|
833
|
+
IntentEntry: () => IntentEntry,
|
|
834
|
+
RetroMetaEntry: () => RetroMetaEntry,
|
|
835
|
+
WorkflowStoreV1: () => WorkflowStoreV1,
|
|
836
|
+
activeKey: () => activeKey,
|
|
837
|
+
listWorkflows: () => listWorkflows,
|
|
838
|
+
migrateRepoKeyCase: () => migrateRepoKeyCase,
|
|
839
|
+
normalizeRepoKey: () => normalizeRepoKey,
|
|
840
|
+
readIntent: () => readIntent,
|
|
841
|
+
readStoreAt: () => readStoreAt,
|
|
842
|
+
readStoreRaw: () => readStoreRaw,
|
|
843
|
+
repoKey: () => repoKey,
|
|
844
|
+
writeStoreRaw: () => writeStoreRaw
|
|
845
|
+
});
|
|
846
|
+
function storePath() {
|
|
847
|
+
return harnessedFile("workflows.json");
|
|
848
|
+
}
|
|
849
|
+
function emptyStore() {
|
|
850
|
+
return { schemaVersion: SCHEMA_VERSIONS.workflowStore, workflows: {} };
|
|
851
|
+
}
|
|
852
|
+
function normalizeRepoKey(key, platform = process.platform) {
|
|
853
|
+
return platform === "win32" ? key.toLowerCase() : key;
|
|
854
|
+
}
|
|
855
|
+
function repoKey(cwd = process.cwd()) {
|
|
856
|
+
let dir = resolve(cwd);
|
|
857
|
+
for (; ; ) {
|
|
858
|
+
if (existsSync(join(dir, ".git"))) return normalizeRepoKey(dir);
|
|
859
|
+
const parent = dirname(dir);
|
|
860
|
+
if (parent === dir) break;
|
|
861
|
+
dir = parent;
|
|
862
|
+
}
|
|
863
|
+
return normalizeRepoKey(resolve(cwd));
|
|
864
|
+
}
|
|
865
|
+
function activeKey(cwd = process.cwd()) {
|
|
866
|
+
const base = repoKey(cwd);
|
|
867
|
+
const envName = detectPlatform().sessionIdEnv;
|
|
868
|
+
const sid = envName ? process.env[envName]?.trim() : void 0;
|
|
869
|
+
return sid ? `${base}::${sid}` : base;
|
|
870
|
+
}
|
|
871
|
+
async function readStoreRaw() {
|
|
872
|
+
return readStoreAt(getHarnessedRoot());
|
|
873
|
+
}
|
|
874
|
+
async function readStoreAt(root) {
|
|
875
|
+
try {
|
|
876
|
+
const parsed = JSON.parse(await readFile(join(root, "workflows.json"), "utf8"));
|
|
877
|
+
if (Value.Check(WorkflowStoreV1, parsed)) return parsed;
|
|
878
|
+
} catch {
|
|
879
|
+
}
|
|
880
|
+
return emptyStore();
|
|
881
|
+
}
|
|
882
|
+
async function writeStoreRaw(store) {
|
|
883
|
+
if (!Value.Check(WorkflowStoreV1, store)) {
|
|
884
|
+
const errs = [...Value.Errors(WorkflowStoreV1, store)].map((e) => e.message).join("; ");
|
|
885
|
+
throw new Error(`workflow-store schema validation failed: ${errs}`);
|
|
886
|
+
}
|
|
887
|
+
const p8 = storePath();
|
|
888
|
+
await mkdir(dirname(p8), { recursive: true });
|
|
889
|
+
await writeFileAtomic(p8, JSON.stringify(store, null, 2));
|
|
890
|
+
}
|
|
891
|
+
async function readIntent(cwd = process.cwd()) {
|
|
892
|
+
const store = await readStoreRaw();
|
|
893
|
+
return store.intents?.[activeKey(cwd)] ?? store.intents?.[repoKey(cwd)] ?? null;
|
|
894
|
+
}
|
|
895
|
+
async function listWorkflows() {
|
|
896
|
+
const store = await readStoreRaw();
|
|
897
|
+
return Object.entries(store.workflows).map(([key, wf]) => ({
|
|
898
|
+
key,
|
|
899
|
+
phase: wf.phase,
|
|
900
|
+
status: wf.status
|
|
901
|
+
}));
|
|
902
|
+
}
|
|
903
|
+
function shortHash(key) {
|
|
904
|
+
return createHash("sha256").update(key).digest("hex").slice(0, 6);
|
|
905
|
+
}
|
|
906
|
+
function foldStoreKey(key, platform) {
|
|
907
|
+
const i = key.indexOf("::");
|
|
908
|
+
return i === -1 ? normalizeRepoKey(key, platform) : normalizeRepoKey(key.slice(0, i), platform) + key.slice(i);
|
|
909
|
+
}
|
|
910
|
+
function needsFold(store, platform) {
|
|
911
|
+
for (const map of [store.workflows, store.retro_meta, store.intents]) {
|
|
912
|
+
if (!map) continue;
|
|
913
|
+
for (const k of Object.keys(map)) if (foldStoreKey(k, platform) !== k) return true;
|
|
914
|
+
}
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
917
|
+
function foldMap(map, newer, platform) {
|
|
918
|
+
const groups = /* @__PURE__ */ new Map();
|
|
919
|
+
let folded = 0;
|
|
920
|
+
for (const [key, value] of Object.entries(map)) {
|
|
921
|
+
const k = foldStoreKey(key, platform);
|
|
922
|
+
if (k !== key) folded++;
|
|
923
|
+
const g = groups.get(k);
|
|
924
|
+
if (g) g.push({ key, value });
|
|
925
|
+
else groups.set(k, [{ key, value }]);
|
|
926
|
+
}
|
|
927
|
+
const next = {};
|
|
928
|
+
let archived = 0;
|
|
929
|
+
for (const [k, entries] of groups) {
|
|
930
|
+
let win = entries[0];
|
|
931
|
+
for (const e of entries) if (e !== win && newer(e.value, win.value)) win = e;
|
|
932
|
+
next[k] = win.value;
|
|
933
|
+
for (const e of entries) {
|
|
934
|
+
if (e === win) continue;
|
|
935
|
+
next[`${k}${PREMIGRATE}${shortHash(e.key)}`] = e.value;
|
|
936
|
+
archived++;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return { next, folded, archived };
|
|
940
|
+
}
|
|
941
|
+
async function migrateRepoKeyCase(platform = process.platform) {
|
|
942
|
+
const noop = { folded: 0, archived: 0 };
|
|
943
|
+
if (platform !== "win32") return noop;
|
|
944
|
+
if (!needsFold(await readStoreRaw(), platform)) return noop;
|
|
945
|
+
let result = noop;
|
|
946
|
+
const { mutateStore: mutateStore2 } = await Promise.resolve().then(() => (init_state(), state_exports));
|
|
947
|
+
await mutateStore2((store) => {
|
|
948
|
+
const w = foldMap(
|
|
949
|
+
store.workflows,
|
|
950
|
+
(a, b) => (a.updated_at ?? "") > (b.updated_at ?? ""),
|
|
951
|
+
platform
|
|
952
|
+
);
|
|
953
|
+
const r = store.retro_meta ? foldMap(
|
|
954
|
+
store.retro_meta,
|
|
955
|
+
(a, b) => a.phases_since_retro !== b.phases_since_retro ? a.phases_since_retro > b.phases_since_retro : (a.last_retro_at ?? "") > (b.last_retro_at ?? ""),
|
|
956
|
+
platform
|
|
957
|
+
) : void 0;
|
|
958
|
+
const i = store.intents ? foldMap(store.intents, (a, b) => a.ts > b.ts, platform) : void 0;
|
|
959
|
+
result = {
|
|
960
|
+
folded: w.folded + (r?.folded ?? 0) + (i?.folded ?? 0),
|
|
961
|
+
archived: w.archived + (r?.archived ?? 0) + (i?.archived ?? 0)
|
|
962
|
+
};
|
|
963
|
+
const next = { ...store, workflows: w.next };
|
|
964
|
+
if (r) next.retro_meta = r.next;
|
|
965
|
+
if (i) next.intents = i.next;
|
|
966
|
+
return next;
|
|
967
|
+
});
|
|
968
|
+
if (result.folded > 0 || result.archived > 0) {
|
|
969
|
+
console.error(
|
|
970
|
+
`[harnessed] folded ${result.folded} ledger key(s) to canonical case (Windows paths are case-insensitive; differently-cased spellings of one repo held separate workflow slots)` + (result.archived > 0 ? ` \u2014 ${result.archived} colliding entr${result.archived === 1 ? "y" : "ies"} preserved under ${PREMIGRATE}* (archive only; nothing dropped)` : "")
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
return result;
|
|
974
|
+
}
|
|
975
|
+
var RetroMetaEntry, IntentEntry, WorkflowStoreV1, PREMIGRATE;
|
|
976
|
+
var init_workflowStore = __esm({
|
|
977
|
+
"src/checkpoint/workflowStore.ts"() {
|
|
978
|
+
init_harnessedRoot();
|
|
979
|
+
init_platform();
|
|
980
|
+
init_schemaVersion();
|
|
981
|
+
init_atomicWrite();
|
|
982
|
+
init_currentWorkflow_v1();
|
|
983
|
+
RetroMetaEntry = Type.Object(
|
|
984
|
+
{
|
|
985
|
+
phases_since_retro: Type.Integer({ minimum: 0 }),
|
|
986
|
+
last_retro_at: Type.Optional(Type.String({ minLength: 1 }))
|
|
987
|
+
},
|
|
988
|
+
{ additionalProperties: false }
|
|
989
|
+
);
|
|
990
|
+
IntentEntry = Type.Object(
|
|
991
|
+
{
|
|
992
|
+
// Invoked command name (master OR leaf sub — field name kept for 765cbc9
|
|
993
|
+
// store back-compat; kind carries the distinction).
|
|
994
|
+
master: Type.String({ minLength: 1 }),
|
|
995
|
+
ts: Type.String({ minLength: 1 }),
|
|
996
|
+
// 4.22.0 T6 — additive-optional: absent = 'master' (765cbc9 only ever wrote
|
|
997
|
+
// master intents). 'leaf' switches banner/nag to the leaf SOP wording
|
|
998
|
+
// (prompt → spawn → checkpoint complete) and the absorb trigger to that
|
|
999
|
+
// sub's complete/fail instead of `checkpoint start`.
|
|
1000
|
+
kind: Type.Optional(Type.Union([Type.Literal("master"), Type.Literal("leaf")]))
|
|
1001
|
+
},
|
|
1002
|
+
{ additionalProperties: false }
|
|
1003
|
+
);
|
|
1004
|
+
WorkflowStoreV1 = Type.Object(
|
|
1005
|
+
{
|
|
1006
|
+
schemaVersion: Type.Literal(SCHEMA_VERSIONS.workflowStore),
|
|
1007
|
+
workflows: Type.Record(Type.String(), CurrentWorkflowV1),
|
|
1008
|
+
// Additive-optional (no schemaVersion bump — old stores Value.Check-pass).
|
|
1009
|
+
retro_meta: Type.Optional(Type.Record(Type.String(), RetroMetaEntry)),
|
|
1010
|
+
// 4.22.0 — additive-optional, same rationale.
|
|
1011
|
+
intents: Type.Optional(Type.Record(Type.String(), IntentEntry))
|
|
1012
|
+
},
|
|
1013
|
+
{ additionalProperties: false }
|
|
1014
|
+
);
|
|
1015
|
+
PREMIGRATE = "::premigrate-";
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
|
|
890
1019
|
// src/checkpoint/planningScan.ts
|
|
891
1020
|
var planningScan_exports = {};
|
|
892
1021
|
__export(planningScan_exports, {
|
|
@@ -1303,6 +1432,8 @@ var init_en = __esm({
|
|
|
1303
1432
|
"gc.summary_will_delete": "would delete {{count}} snapshot(s), ~{{sizeKb}} KB total:",
|
|
1304
1433
|
"gc.summary_deleting": "deleting {{count}} snapshot(s), ~{{sizeKb}} KB total:",
|
|
1305
1434
|
"gc.dry_run_rerun_hint": "\n(dry-run \u2014 re-run without --dry-run to actually delete)",
|
|
1435
|
+
"gc.ledger_will_prune": "would prune {{count}} stale workflow slot(s) from the ledger (kept {{kept}}):",
|
|
1436
|
+
"gc.ledger_pruned": "pruned {{count}} stale workflow slot(s) from the ledger (kept {{kept}}):",
|
|
1306
1437
|
"doctor.summary.fail": "\nsome checks failed (see fix hints above)",
|
|
1307
1438
|
"doctor.summary.warn": "\nall checks ok (with warnings \u2014 see hints above)",
|
|
1308
1439
|
"doctor.summary.pass": "\nall checks passed",
|
|
@@ -1830,8 +1961,8 @@ function insertAgentsMdSection(body, section) {
|
|
|
1830
1961
|
return `${base}${sep3}${section}`;
|
|
1831
1962
|
}
|
|
1832
1963
|
async function resolveCommandNames(workflowsDir) {
|
|
1833
|
-
const { readdir:
|
|
1834
|
-
const entries = await
|
|
1964
|
+
const { readdir: readdir20 } = await import('fs/promises');
|
|
1965
|
+
const entries = await readdir20(workflowsDir);
|
|
1835
1966
|
const { workflows } = await scanWorkflowsNested(workflowsDir, entries);
|
|
1836
1967
|
const prompts = await loadRolePrompts(workflowsDir);
|
|
1837
1968
|
return workflows.map((w) => w.name).filter((n) => prompts[n] !== void 0).sort();
|
|
@@ -4515,6 +4646,287 @@ var init_breakLoop = __esm({
|
|
|
4515
4646
|
}
|
|
4516
4647
|
});
|
|
4517
4648
|
|
|
4649
|
+
// src/checkpoint/pruneSlots.ts
|
|
4650
|
+
function classifyKey(key) {
|
|
4651
|
+
const i = key.indexOf("::");
|
|
4652
|
+
if (i === -1) return "bare";
|
|
4653
|
+
const segment = key.slice(i + 2);
|
|
4654
|
+
if (segment === "" || segment.includes("::")) return "other";
|
|
4655
|
+
return ARCHIVE_SEGMENT_PREFIXES.some((p8) => segment.startsWith(p8)) ? "archive" : "session";
|
|
4656
|
+
}
|
|
4657
|
+
function slotTimeMs(slot) {
|
|
4658
|
+
const raw = slot.updated_at ?? slot.completed_at ?? slot.started_at;
|
|
4659
|
+
const ms = Date.parse(raw);
|
|
4660
|
+
return Number.isNaN(ms) ? void 0 : ms;
|
|
4661
|
+
}
|
|
4662
|
+
function isOlder(slot, nowMs, olderThanMs) {
|
|
4663
|
+
const t2 = slotTimeMs(slot);
|
|
4664
|
+
return t2 !== void 0 && nowMs - t2 >= olderThanMs;
|
|
4665
|
+
}
|
|
4666
|
+
function isStaleSessionSlot(key, slot, nowMs, olderThanMs) {
|
|
4667
|
+
return classifyKey(key) === "session" && slot.status === "complete" && isOlder(slot, nowMs, olderThanMs);
|
|
4668
|
+
}
|
|
4669
|
+
function planPrune(store, nowMs, olderThanMs, protectedKeys) {
|
|
4670
|
+
const out = [];
|
|
4671
|
+
for (const [key, slot] of Object.entries(store.workflows)) {
|
|
4672
|
+
if (protectedKeys.has(key)) continue;
|
|
4673
|
+
const kind = classifyKey(key);
|
|
4674
|
+
if (kind === "archive" ? isOlder(slot, nowMs, olderThanMs) : isStaleSessionSlot(key, slot, nowMs, olderThanMs)) {
|
|
4675
|
+
out.push(key);
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
return out;
|
|
4679
|
+
}
|
|
4680
|
+
function dropKeys(map, gone) {
|
|
4681
|
+
if (!map) return { next: map, dropped: 0 };
|
|
4682
|
+
const kept = Object.entries(map).filter(([k]) => !gone.has(k));
|
|
4683
|
+
const dropped = Object.keys(map).length - kept.length;
|
|
4684
|
+
return dropped === 0 ? { next: map, dropped: 0 } : { next: Object.fromEntries(kept), dropped };
|
|
4685
|
+
}
|
|
4686
|
+
function applyPrune(store, keys) {
|
|
4687
|
+
const gone = new Set(keys);
|
|
4688
|
+
const workflows = Object.fromEntries(
|
|
4689
|
+
Object.entries(store.workflows).filter(([k]) => !gone.has(k))
|
|
4690
|
+
);
|
|
4691
|
+
const next = { ...store, workflows };
|
|
4692
|
+
const r = dropKeys(store.retro_meta, gone);
|
|
4693
|
+
const i = dropKeys(store.intents, gone);
|
|
4694
|
+
if (r.next) next.retro_meta = r.next;
|
|
4695
|
+
if (i.next) next.intents = i.next;
|
|
4696
|
+
return { store: next, cascaded: r.dropped + i.dropped };
|
|
4697
|
+
}
|
|
4698
|
+
async function pruneSlots(options = {}) {
|
|
4699
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
4700
|
+
const olderThanMs = options.olderThanMs ?? DEFAULT_STALE_MS;
|
|
4701
|
+
const dryRun = options.dryRun === true;
|
|
4702
|
+
const protectedKeys = /* @__PURE__ */ new Set([activeKey(options.cwd)]);
|
|
4703
|
+
const snapshot = await readStoreRaw();
|
|
4704
|
+
const plan = planPrune(snapshot, nowMs, olderThanMs, protectedKeys);
|
|
4705
|
+
if (plan.length === 0) {
|
|
4706
|
+
return { pruned: [], keptCount: Object.keys(snapshot.workflows).length, cascaded: 0, dryRun };
|
|
4707
|
+
}
|
|
4708
|
+
if (dryRun) {
|
|
4709
|
+
const { cascaded } = applyPrune(snapshot, plan);
|
|
4710
|
+
return {
|
|
4711
|
+
pruned: plan,
|
|
4712
|
+
keptCount: Object.keys(snapshot.workflows).length - plan.length,
|
|
4713
|
+
cascaded,
|
|
4714
|
+
dryRun
|
|
4715
|
+
};
|
|
4716
|
+
}
|
|
4717
|
+
await options.onPlanned?.(plan);
|
|
4718
|
+
let result = { pruned: [], keptCount: 0, cascaded: 0, dryRun };
|
|
4719
|
+
await mutateStore((store) => {
|
|
4720
|
+
const locked = planPrune(store, nowMs, olderThanMs, protectedKeys);
|
|
4721
|
+
const applied = applyPrune(store, locked);
|
|
4722
|
+
result = {
|
|
4723
|
+
pruned: locked,
|
|
4724
|
+
keptCount: Object.keys(applied.store.workflows).length,
|
|
4725
|
+
cascaded: applied.cascaded,
|
|
4726
|
+
dryRun
|
|
4727
|
+
};
|
|
4728
|
+
return applied.store;
|
|
4729
|
+
});
|
|
4730
|
+
return result;
|
|
4731
|
+
}
|
|
4732
|
+
var DEFAULT_STALE_MS, ARCHIVE_SEGMENT_PREFIXES;
|
|
4733
|
+
var init_pruneSlots = __esm({
|
|
4734
|
+
"src/checkpoint/pruneSlots.ts"() {
|
|
4735
|
+
init_state();
|
|
4736
|
+
init_workflowStore();
|
|
4737
|
+
DEFAULT_STALE_MS = 30 * 864e5;
|
|
4738
|
+
ARCHIVE_SEGMENT_PREFIXES = ["displaced-", "premigrate-"];
|
|
4739
|
+
}
|
|
4740
|
+
});
|
|
4741
|
+
|
|
4742
|
+
// src/checkpoint/adoptSlot.ts
|
|
4743
|
+
var adoptSlot_exports = {};
|
|
4744
|
+
__export(adoptSlot_exports, {
|
|
4745
|
+
adoptSlot: () => adoptSlot
|
|
4746
|
+
});
|
|
4747
|
+
async function destIsSetUp(commandsDir) {
|
|
4748
|
+
let names;
|
|
4749
|
+
try {
|
|
4750
|
+
names = (await readdir(commandsDir)).filter((n) => n.endsWith(".md"));
|
|
4751
|
+
} catch {
|
|
4752
|
+
return false;
|
|
4753
|
+
}
|
|
4754
|
+
for (const n of names) {
|
|
4755
|
+
try {
|
|
4756
|
+
if ((await readFile(join(commandsDir, n), "utf8")).includes(GENERATED_COMMAND_MARKER)) {
|
|
4757
|
+
return true;
|
|
4758
|
+
}
|
|
4759
|
+
} catch {
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
return false;
|
|
4763
|
+
}
|
|
4764
|
+
function findCandidateKeys(workflows, key, nowMs = Date.now()) {
|
|
4765
|
+
const prefix = `${key}::`;
|
|
4766
|
+
return Object.keys(workflows).filter((k) => {
|
|
4767
|
+
if (k === key) return true;
|
|
4768
|
+
if (!k.startsWith(prefix)) return false;
|
|
4769
|
+
const segment = k.slice(prefix.length);
|
|
4770
|
+
if (segment === "" || segment.includes("::")) return false;
|
|
4771
|
+
if (ARCHIVE_SEGMENT_PREFIXES2.some((p8) => segment.startsWith(p8))) return false;
|
|
4772
|
+
return !isStaleSessionSlot(k, workflows[k], nowMs, DEFAULT_STALE_MS);
|
|
4773
|
+
});
|
|
4774
|
+
}
|
|
4775
|
+
function mergeRetroMeta(src, dest) {
|
|
4776
|
+
const last = [src.last_retro_at, dest?.last_retro_at].filter((v) => v !== void 0);
|
|
4777
|
+
const newest = last.length > 0 ? last.reduce((a, b) => a > b ? a : b) : void 0;
|
|
4778
|
+
return {
|
|
4779
|
+
phases_since_retro: Math.max(src.phases_since_retro, dest?.phases_since_retro ?? 0),
|
|
4780
|
+
...newest !== void 0 ? { last_retro_at: newest } : {}
|
|
4781
|
+
};
|
|
4782
|
+
}
|
|
4783
|
+
function ledgerShape(slot) {
|
|
4784
|
+
const entries = slot.sub_progress ?? [];
|
|
4785
|
+
return { done: entries.filter((e) => e.status === "done").length, total: entries.length };
|
|
4786
|
+
}
|
|
4787
|
+
function selfDescribesEmptyLedger(raw) {
|
|
4788
|
+
try {
|
|
4789
|
+
const parsed = JSON.parse(raw);
|
|
4790
|
+
if (typeof parsed !== "object" || parsed === null) return false;
|
|
4791
|
+
const wf = parsed.workflows;
|
|
4792
|
+
return typeof wf === "object" && wf !== null && Object.keys(wf).length === 0;
|
|
4793
|
+
} catch {
|
|
4794
|
+
return false;
|
|
4795
|
+
}
|
|
4796
|
+
}
|
|
4797
|
+
function isVacuous(store) {
|
|
4798
|
+
return Object.keys(store.workflows).length === 0 && store.retro_meta === void 0 && store.intents === void 0;
|
|
4799
|
+
}
|
|
4800
|
+
async function adoptSlot(options = {}) {
|
|
4801
|
+
const home = options.home ?? homedir();
|
|
4802
|
+
const cwd = options.cwd ?? process.cwd();
|
|
4803
|
+
const me = resolveHostWithReason(home);
|
|
4804
|
+
const destHost = me.descriptor.id;
|
|
4805
|
+
let from;
|
|
4806
|
+
if (options.from !== void 0) {
|
|
4807
|
+
if (!isHostId(options.from)) {
|
|
4808
|
+
return refuse({ kind: "unknown-from", value: options.from, known: HOST_IDS });
|
|
4809
|
+
}
|
|
4810
|
+
from = options.from;
|
|
4811
|
+
} else {
|
|
4812
|
+
const others = HOST_IDS.filter((id) => id !== destHost);
|
|
4813
|
+
const inferred = others.length === 1 ? others[0] : void 0;
|
|
4814
|
+
if (inferred === void 0) {
|
|
4815
|
+
return refuse({ kind: "from-required", host: destHost, known: HOST_IDS });
|
|
4816
|
+
}
|
|
4817
|
+
from = inferred;
|
|
4818
|
+
}
|
|
4819
|
+
if (from === destHost) {
|
|
4820
|
+
const other = HOST_IDS.find((id) => id !== destHost) ?? destHost;
|
|
4821
|
+
return refuse({ kind: "same-host", host: from, other, reason: me.reason, skipped: me.skipped });
|
|
4822
|
+
}
|
|
4823
|
+
if (!await destIsSetUp(me.descriptor.commandsDir)) {
|
|
4824
|
+
return refuse({
|
|
4825
|
+
kind: "dest-not-set-up",
|
|
4826
|
+
host: destHost,
|
|
4827
|
+
commandsDir: me.descriptor.commandsDir
|
|
4828
|
+
});
|
|
4829
|
+
}
|
|
4830
|
+
const sourceRoot = descriptorFor(from, home).stateRoot;
|
|
4831
|
+
const sourcePath = join(sourceRoot, "workflows.json");
|
|
4832
|
+
if (!existsSync(sourcePath)) {
|
|
4833
|
+
return refuse({ kind: "no-source-ledger", from, path: sourcePath });
|
|
4834
|
+
}
|
|
4835
|
+
const source = await readStoreAt(sourceRoot);
|
|
4836
|
+
if (isVacuous(source)) {
|
|
4837
|
+
let raw;
|
|
4838
|
+
try {
|
|
4839
|
+
raw = await readFile(sourcePath, "utf8");
|
|
4840
|
+
} catch {
|
|
4841
|
+
raw = void 0;
|
|
4842
|
+
}
|
|
4843
|
+
if (raw === void 0 || !selfDescribesEmptyLedger(raw)) {
|
|
4844
|
+
return refuse({ kind: "source-ledger-unreadable", from, path: sourcePath });
|
|
4845
|
+
}
|
|
4846
|
+
}
|
|
4847
|
+
const key = repoKey(cwd);
|
|
4848
|
+
const sourceKeys = Object.keys(source.workflows);
|
|
4849
|
+
const candidates = findCandidateKeys(source.workflows, key);
|
|
4850
|
+
if (candidates.length === 0) {
|
|
4851
|
+
return refuse({ kind: "no-candidate", from, repoKey: key, sourceKeys });
|
|
4852
|
+
}
|
|
4853
|
+
if (candidates.length > 1) {
|
|
4854
|
+
return refuse({ kind: "ambiguous", from, candidates });
|
|
4855
|
+
}
|
|
4856
|
+
const sourceKey = candidates[0];
|
|
4857
|
+
const slot = source.workflows[sourceKey];
|
|
4858
|
+
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4859
|
+
let archivedKey;
|
|
4860
|
+
let retroMeta;
|
|
4861
|
+
try {
|
|
4862
|
+
await mutateStore((store) => {
|
|
4863
|
+
const occupant = store.workflows[key];
|
|
4864
|
+
if (occupant?.status === "active") {
|
|
4865
|
+
throw new AdoptRefused({
|
|
4866
|
+
kind: "dest-occupied",
|
|
4867
|
+
from,
|
|
4868
|
+
mine: { phase: occupant.phase, status: occupant.status, ...ledgerShape(occupant) },
|
|
4869
|
+
theirs: { phase: slot.phase }
|
|
4870
|
+
});
|
|
4871
|
+
}
|
|
4872
|
+
const workflows = { ...store.workflows };
|
|
4873
|
+
if (occupant?.status === "paused") {
|
|
4874
|
+
archivedKey = `${key}${DISPLACED}${updatedAt}`;
|
|
4875
|
+
workflows[archivedKey] = occupant;
|
|
4876
|
+
}
|
|
4877
|
+
workflows[key] = { ...slot, updated_at: updatedAt };
|
|
4878
|
+
const next = { ...store, workflows };
|
|
4879
|
+
const srcRetro = source.retro_meta?.[key];
|
|
4880
|
+
if (srcRetro) {
|
|
4881
|
+
retroMeta = mergeRetroMeta(srcRetro, store.retro_meta?.[key]);
|
|
4882
|
+
next.retro_meta = { ...store.retro_meta ?? {}, [key]: retroMeta };
|
|
4883
|
+
}
|
|
4884
|
+
return next;
|
|
4885
|
+
});
|
|
4886
|
+
} catch (e) {
|
|
4887
|
+
if (e instanceof AdoptRefused) return refuse(e.refusal);
|
|
4888
|
+
throw e;
|
|
4889
|
+
}
|
|
4890
|
+
return {
|
|
4891
|
+
ok: true,
|
|
4892
|
+
from,
|
|
4893
|
+
to: destHost,
|
|
4894
|
+
key,
|
|
4895
|
+
sourceKey,
|
|
4896
|
+
sourceRoot,
|
|
4897
|
+
destRoot: getHarnessedRoot(),
|
|
4898
|
+
phase: slot.phase,
|
|
4899
|
+
status: slot.status,
|
|
4900
|
+
// D12 — verbatim. The evidence file itself is NOT copied.
|
|
4901
|
+
evidencePath: slot.last_checkpoint_path,
|
|
4902
|
+
updatedAt,
|
|
4903
|
+
...archivedKey !== void 0 ? { archivedKey } : {},
|
|
4904
|
+
...retroMeta !== void 0 ? { retroMeta } : {}
|
|
4905
|
+
};
|
|
4906
|
+
}
|
|
4907
|
+
var DISPLACED, ARCHIVE_SEGMENT_PREFIXES2, GENERATED_COMMAND_MARKER, AdoptRefused, refuse;
|
|
4908
|
+
var init_adoptSlot = __esm({
|
|
4909
|
+
"src/checkpoint/adoptSlot.ts"() {
|
|
4910
|
+
init_harnessedRoot();
|
|
4911
|
+
init_platform();
|
|
4912
|
+
init_pruneSlots();
|
|
4913
|
+
init_state();
|
|
4914
|
+
init_workflowStore();
|
|
4915
|
+
DISPLACED = "::displaced-";
|
|
4916
|
+
ARCHIVE_SEGMENT_PREFIXES2 = ["displaced-", "premigrate-"];
|
|
4917
|
+
GENERATED_COMMAND_MARKER = "harnessed-generated:";
|
|
4918
|
+
AdoptRefused = class extends Error {
|
|
4919
|
+
constructor(refusal) {
|
|
4920
|
+
super(`adopt refused: ${refusal.kind}`);
|
|
4921
|
+
this.refusal = refusal;
|
|
4922
|
+
this.name = "AdoptRefused";
|
|
4923
|
+
}
|
|
4924
|
+
refusal;
|
|
4925
|
+
};
|
|
4926
|
+
refuse = (refusal) => ({ ok: false, refusal });
|
|
4927
|
+
}
|
|
4928
|
+
});
|
|
4929
|
+
|
|
4518
4930
|
// src/checkpoint/intentKind.ts
|
|
4519
4931
|
var intentKind_exports = {};
|
|
4520
4932
|
__export(intentKind_exports, {
|
|
@@ -4538,6 +4950,7 @@ var init_intentKind = __esm({
|
|
|
4538
4950
|
var checkpoint_exports = {};
|
|
4539
4951
|
__export(checkpoint_exports, {
|
|
4540
4952
|
registerCheckpoint: () => registerCheckpoint,
|
|
4953
|
+
runCheckpointAdopt: () => runCheckpointAdopt,
|
|
4541
4954
|
runCheckpointComplete: () => runCheckpointComplete,
|
|
4542
4955
|
runCheckpointFail: () => runCheckpointFail,
|
|
4543
4956
|
runCheckpointReopen: () => runCheckpointReopen,
|
|
@@ -4943,9 +5356,133 @@ async function runCheckpointReopen(sub, opts, deps = defaultRunDeps) {
|
|
|
4943
5356
|
);
|
|
4944
5357
|
deps.exit(0);
|
|
4945
5358
|
}
|
|
5359
|
+
function tildify(p8) {
|
|
5360
|
+
const home = homedir();
|
|
5361
|
+
if (home === "" || !p8.startsWith(home)) return p8;
|
|
5362
|
+
return `~${p8.slice(home.length).replace(/\\/g, "/")}`;
|
|
5363
|
+
}
|
|
5364
|
+
function renderHostReason(reason) {
|
|
5365
|
+
switch (reason.kind) {
|
|
5366
|
+
case "env-platform":
|
|
5367
|
+
return `${reason.envVar}=${reason.value} (\u73AF\u5883\u53D8\u91CF\u663E\u5F0F\u6307\u5B9A)`;
|
|
5368
|
+
case "host-session-env":
|
|
5369
|
+
return `\u5BBF\u4E3B session \u73AF\u5883\u53D8\u91CF ${reason.envVar} \u5DF2\u8BBE\u7F6E`;
|
|
5370
|
+
case "platform-pin":
|
|
5371
|
+
return `.platform pin: ${tildify(reason.pinPath)} \u5199\u7740 ${reason.value}`;
|
|
5372
|
+
case "directory-probe":
|
|
5373
|
+
return `directory probe (${tildify(reason.probedDir)} \u5B58\u5728,incumbent)`;
|
|
5374
|
+
case "fallback":
|
|
5375
|
+
return "\u65E0\u4EFB\u4F55\u5BBF\u4E3B\u4FE1\u53F7 \u2192 \u9ED8\u8BA4 claude";
|
|
5376
|
+
}
|
|
5377
|
+
}
|
|
5378
|
+
function renderHostSkip(skip) {
|
|
5379
|
+
switch (skip.kind) {
|
|
5380
|
+
case "env-platform-unknown":
|
|
5381
|
+
return `\u5FFD\u7565: ${skip.envVar}=${skip.value} \u4E0D\u662F\u5DF2\u77E5\u5BBF\u4E3B id`;
|
|
5382
|
+
case "host-session-env-ambiguous":
|
|
5383
|
+
return "\u5FFD\u7565: CLAUDE_CODE_SESSION_ID \u4E0E CODEX_SESSION_ID \u540C\u65F6\u5B58\u5728,\u65E0\u6CD5\u636E\u6B64\u5224\u5B9A\u5BBF\u4E3B";
|
|
5384
|
+
case "platform-pin-unknown":
|
|
5385
|
+
return `\u5FFD\u7565: .platform pin ${tildify(skip.pinPath)} \u5199\u7740 ${skip.value},\u4E0D\u662F\u5DF2\u77E5\u5BBF\u4E3B id`;
|
|
5386
|
+
}
|
|
5387
|
+
}
|
|
5388
|
+
function renderAdoptRefusal(r) {
|
|
5389
|
+
switch (r.kind) {
|
|
5390
|
+
case "unknown-from":
|
|
5391
|
+
return [`refused: --from \u672A\u77E5\u5BBF\u4E3B id '${r.value}'(\u5DF2\u77E5: ${r.known.join(" | ")})`];
|
|
5392
|
+
case "from-required":
|
|
5393
|
+
return [
|
|
5394
|
+
`refused: \u672C\u5BBF\u4E3B\u662F ${r.host},\u6E90\u5BBF\u4E3B\u6709\u591A\u4E2A\u5019\u9009,\u4E0D\u731C(\u5DF2\u77E5: ${r.known.join(" | ")})`,
|
|
5395
|
+
" \u663E\u5F0F\u6307\u5B9A --from <id>\u3002"
|
|
5396
|
+
];
|
|
5397
|
+
case "same-host": {
|
|
5398
|
+
const lines = [
|
|
5399
|
+
`refused: \u672C\u8FDB\u7A0B\u88AB\u89E3\u6790\u4E3A\u5BBF\u4E3B ${r.host}`,
|
|
5400
|
+
` \u4F9D\u636E: ${renderHostReason(r.reason)}`
|
|
5401
|
+
];
|
|
5402
|
+
for (const s of r.skipped) lines.push(` ${renderHostSkip(s)}`);
|
|
5403
|
+
lines.push(" --from \u4E0E\u5F53\u524D\u5BBF\u4E3B\u76F8\u540C,\u65E0\u4E8B\u53EF\u505A\u3002");
|
|
5404
|
+
lines.push(`\u4FEE\u6CD5: HARNESSED_PLATFORM=${r.other} harnessed checkpoint adopt --from ${r.host}`);
|
|
5405
|
+
return lines;
|
|
5406
|
+
}
|
|
5407
|
+
case "dest-not-set-up":
|
|
5408
|
+
return [
|
|
5409
|
+
`refused: \u76EE\u6807\u5BBF\u4E3B ${r.host} \u8FD8\u6CA1 setup \u8FC7`,
|
|
5410
|
+
` \u8BC1\u636E: \u547D\u4EE4\u76EE\u5F55\u91CC\u6CA1\u6709 harnessed \u751F\u6210\u7684\u547D\u4EE4: ${tildify(r.commandsDir)}`,
|
|
5411
|
+
" \u8D26\u672C\u4E0D\u662F\u76EE\u6807\u5BBF\u4E3B\u9700\u8981\u7684\u5168\u90E8 \u2014\u2014 \u6CA1\u6709\u547D\u4EE4,adopt \u6210\u529F\u4E86\u4E5F\u6CA1\u4E1C\u897F\u53EF\u8DD1\u3002\u5148\u8DD1:",
|
|
5412
|
+
` harnessed setup --platform ${r.host}`
|
|
5413
|
+
];
|
|
5414
|
+
case "no-source-ledger":
|
|
5415
|
+
return [`refused: \u6E90\u5BBF\u4E3B ${r.from} \u8FD8\u6CA1\u6709\u8D26\u672C`, ` \u67E5\u8FC7: ${tildify(r.path)}`];
|
|
5416
|
+
case "source-ledger-unreadable":
|
|
5417
|
+
return [
|
|
5418
|
+
`refused: \u6E90\u8D26\u672C\u5728\u4F46\u8BFB\u4E0D\u52A8(JSON \u635F\u574F\u6216 schema \u4E0D\u5BF9): ${r.path}`,
|
|
5419
|
+
" \u4E0D\u81EA\u52A8\u4FEE\u3002\u5907\u4EFD\u540E\u68C0\u67E5,\u6216\u5728\u6E90\u5BBF\u4E3B\u91CD\u5EFA\u3002"
|
|
5420
|
+
];
|
|
5421
|
+
case "no-candidate": {
|
|
5422
|
+
const lines = [
|
|
5423
|
+
`refused: \u6E90\u5BBF\u4E3B ${r.from} \u7684\u8D26\u672C\u91CC\u6CA1\u6709\u8FD9\u4E2A\u4ED3\u7684\u69FD\u4F4D`,
|
|
5424
|
+
` \u4ED3\u952E: ${r.repoKey}`,
|
|
5425
|
+
" \u6E90\u8D26\u672C\u73B0\u6709\u952E:"
|
|
5426
|
+
];
|
|
5427
|
+
if (r.sourceKeys.length === 0) lines.push(" (\u7A7A)");
|
|
5428
|
+
else for (const k of r.sourceKeys) lines.push(` - ${k}`);
|
|
5429
|
+
return lines;
|
|
5430
|
+
}
|
|
5431
|
+
case "ambiguous": {
|
|
5432
|
+
const lines = [`refused: \u6E90\u5BBF\u4E3B ${r.from} \u6709 ${r.candidates.length} \u4E2A\u5019\u9009\u69FD\u4F4D,\u4E0D\u731C`];
|
|
5433
|
+
for (const k of r.candidates) lines.push(` - ${k}`);
|
|
5434
|
+
lines.push(" \u5B83\u4EEC\u662F\u540C\u4E00\u5BBF\u4E3B\u5185\u7684\u591A\u4F1A\u8BDD\u69FD\u4F4D,--from \u65E0\u4ECE\u6D88\u6B67\u3002");
|
|
5435
|
+
lines.push(" \u5728\u6E90\u5BBF\u4E3B\u4FA7\u628A\u591A\u4F59\u7684 complete / pause \u6389\u3001\u53EA\u7559\u4E00\u4E2A,\u518D adopt\u3002");
|
|
5436
|
+
return lines;
|
|
5437
|
+
}
|
|
5438
|
+
case "dest-occupied": {
|
|
5439
|
+
const subs = r.mine.total > 0 ? `, ${r.mine.done}/${r.mine.total} subs done` : "";
|
|
5440
|
+
return [
|
|
5441
|
+
"refused: \u672C\u5BBF\u4E3B\u5F53\u524D\u69FD\u4F4D\u975E\u7A7A",
|
|
5442
|
+
` \u6211\u7684: ${r.mine.phase} (status:${r.mine.status}${subs})`,
|
|
5443
|
+
` \u8981\u63A5: ${r.theirs.phase} (\u6765\u81EA ${r.from})`,
|
|
5444
|
+
" adopt \u4E0D\u8986\u76D6\u5728\u9014\u8D26\u672C\u3002\u5148\u8DD1:",
|
|
5445
|
+
" harnessed checkpoint complete # \u6216 pause"
|
|
5446
|
+
];
|
|
5447
|
+
}
|
|
5448
|
+
}
|
|
5449
|
+
}
|
|
5450
|
+
function renderAdoptSuccess(r) {
|
|
5451
|
+
const lines = [
|
|
5452
|
+
`adopted: ${r.phase} \u2190 \u5BBF\u4E3B ${r.from}`,
|
|
5453
|
+
` \u5199\u5165: ${tildify(r.destRoot)}/workflows.json \u7684\u88F8\u4ED3\u952E ${r.key}`,
|
|
5454
|
+
` \u6E90\u69FD\u4F4D\u952E: ${r.sourceKey} (status:${r.status})`
|
|
5455
|
+
];
|
|
5456
|
+
if (r.archivedKey !== void 0) {
|
|
5457
|
+
lines.push(` \u88AB\u9876\u6389\u7684 paused \u69FD\u4F4D\u5DF2\u5F52\u6863(\u4EC5\u5F52\u6863,\u4EFB\u4F55\u8BFB\u8DEF\u5F84\u90FD\u4E0D\u8BA4\u5B83): ${r.archivedKey}`);
|
|
5458
|
+
}
|
|
5459
|
+
if (r.retroMeta !== void 0) {
|
|
5460
|
+
lines.push(` retro \u8282\u594F\u5DF2\u5E26\u8D70: phases_since_retro=${r.retroMeta.phases_since_retro}`);
|
|
5461
|
+
}
|
|
5462
|
+
lines.push(
|
|
5463
|
+
` \u8BC1\u636E\u6307\u9488\u672A\u52A8: ${r.evidencePath ?? "(\u65E0)"}`,
|
|
5464
|
+
" \u5B83\u4ECD\u6307\u5411\u6E90\u6839;\u4E0B\u4E00\u6761 `harnessed checkpoint complete` \u4F1A\u5728\u672C\u5BBF\u4E3B\u6839\u5199\u540C\u540D\u6587\u4EF6,\u6307\u9488\u81EA\u7136\u8F6C\u6B63\u3002",
|
|
5465
|
+
" \u63A5\u529B\u5BFF\u547D = \u672C\u4F1A\u8BDD: \u9996\u6B21 `harnessed checkpoint complete` \u628A\u69FD\u4F4D\u53C9\u5230\u672C\u4F1A\u8BDD\u7684\u590D\u5408\u952E,\u88F8\u69FD\u4F4D\u4ECE\u6B64\u51BB\u7ED3(\u4E0E\u540C\u5BBF\u4E3B\u591A\u4F1A\u8BDD\u884C\u4E3A\u4E00\u81F4)\u3002",
|
|
5466
|
+
` \u6E90\u69FD\u4F4D\u4ECD\u5728\u3001\u672A\u88AB\u6539: ${r.from} \u7684 ${r.sourceKey} \u8FD8\u662F status:${r.status}`,
|
|
5467
|
+
` \u5728\u6E90\u5BBF\u4E3B\u4FA7\u9000\u4F11\u5B83: HARNESSED_PLATFORM=${r.from} harnessed checkpoint complete ${r.phase} --force`,
|
|
5468
|
+
"\u8DE8\u6839\u8BBF\u95EE: \u53EA\u8BFB, \u5168\u7A0B\u672A\u5199\u6E90\u6839"
|
|
5469
|
+
);
|
|
5470
|
+
return lines;
|
|
5471
|
+
}
|
|
5472
|
+
async function runCheckpointAdopt(opts, deps = defaultRunDeps) {
|
|
5473
|
+
const { adoptSlot: adoptSlot2 } = await Promise.resolve().then(() => (init_adoptSlot(), adoptSlot_exports));
|
|
5474
|
+
const outcome = await adoptSlot2({ ...opts.from !== void 0 ? { from: opts.from } : {} });
|
|
5475
|
+
if (!outcome.ok) {
|
|
5476
|
+
for (const line of renderAdoptRefusal(outcome.refusal)) deps.error(line);
|
|
5477
|
+
deps.exit(1);
|
|
5478
|
+
return;
|
|
5479
|
+
}
|
|
5480
|
+
for (const line of renderAdoptSuccess(outcome)) deps.log(line);
|
|
5481
|
+
deps.exit(0);
|
|
5482
|
+
}
|
|
4946
5483
|
function registerCheckpoint(program2) {
|
|
4947
|
-
program2.command("checkpoint <action>
|
|
4948
|
-
"Record workflow progress: intent | start | complete | fail | reopen <sub-workflow
|
|
5484
|
+
program2.command("checkpoint <action> [sub]").description(
|
|
5485
|
+
"Record workflow progress: intent | start | complete | fail | reopen <sub-workflow>, or adopt (cross-host relay) (writes under the active host state root)"
|
|
4949
5486
|
).option("--summary <text>", "short summary stored as the checkpoint lastTask").option("--plan <json>", "gates plan JSON (start only) \u2014 seeds the sub-progress ledger").option(
|
|
4950
5487
|
"--force",
|
|
4951
5488
|
"complete/fail \u2014 override a fail-closed guard: the missing-artifact evidence block (complete; records overridden) or the serial-order guard"
|
|
@@ -4967,6 +5504,9 @@ function registerCheckpoint(program2) {
|
|
|
4967
5504
|
).option(
|
|
4968
5505
|
"--failure <kind>",
|
|
4969
5506
|
"fail only \u2014 which named spawn failure ended the attempt: SpawnTimeout | SpawnExitNonZero | SpawnOutputMalformed | SpawnAuthFailed | SpawnRefused (recorded on the ledger entry; an unknown value is rejected)"
|
|
5507
|
+
).option(
|
|
5508
|
+
"--from <host>",
|
|
5509
|
+
`adopt only \u2014 which host's ledger to copy this repo's slot FROM: ${HOST_IDS.join(" | ")} (omitted \u2192 the other host)`
|
|
4970
5510
|
).action(
|
|
4971
5511
|
async (action, sub, opts) => {
|
|
4972
5512
|
if (!isAction(action)) {
|
|
@@ -4976,6 +5516,17 @@ function registerCheckpoint(program2) {
|
|
|
4976
5516
|
process.exit(1);
|
|
4977
5517
|
return;
|
|
4978
5518
|
}
|
|
5519
|
+
if (action === "adopt") {
|
|
5520
|
+
await runCheckpointAdopt(opts);
|
|
5521
|
+
return;
|
|
5522
|
+
}
|
|
5523
|
+
if (sub === void 0) {
|
|
5524
|
+
console.error(
|
|
5525
|
+
`[harnessed] checkpoint ${action}: missing required argument <sub> (the sub-workflow name)`
|
|
5526
|
+
);
|
|
5527
|
+
process.exit(1);
|
|
5528
|
+
return;
|
|
5529
|
+
}
|
|
4979
5530
|
if (action === "intent") {
|
|
4980
5531
|
try {
|
|
4981
5532
|
checkPathSafe(sub);
|
|
@@ -5027,9 +5578,10 @@ var ACTIONS;
|
|
|
5027
5578
|
var init_checkpoint = __esm({
|
|
5028
5579
|
"src/cli/checkpoint.ts"() {
|
|
5029
5580
|
init_path_guard();
|
|
5581
|
+
init_platform();
|
|
5030
5582
|
init_runDeps();
|
|
5031
5583
|
init_ledger();
|
|
5032
|
-
ACTIONS = ["start", "complete", "fail", "reopen", "intent"];
|
|
5584
|
+
ACTIONS = ["start", "complete", "fail", "reopen", "intent", "adopt"];
|
|
5033
5585
|
}
|
|
5034
5586
|
});
|
|
5035
5587
|
function realProbe(p8) {
|
|
@@ -5091,7 +5643,7 @@ function compute(d) {
|
|
|
5091
5643
|
const gitFirst = d.where("git")[0];
|
|
5092
5644
|
if (gitFirst && /git\.exe$/i.test(gitFirst)) {
|
|
5093
5645
|
const root = dirname9(dirname9(gitFirst));
|
|
5094
|
-
for (const cand of [
|
|
5646
|
+
for (const cand of [join27(root, "bin", "bash.exe"), join27(root, "usr", "bin", "bash.exe")]) {
|
|
5095
5647
|
if (d.exists(cand) && usable(cand)) return { path: cand, source: "git-derived", wslOnPath };
|
|
5096
5648
|
}
|
|
5097
5649
|
}
|
|
@@ -5099,13 +5651,13 @@ function compute(d) {
|
|
|
5099
5651
|
d.env.ProgramFiles,
|
|
5100
5652
|
d.env.ProgramW6432,
|
|
5101
5653
|
d.env["ProgramFiles(x86)"],
|
|
5102
|
-
d.env.LOCALAPPDATA ?
|
|
5654
|
+
d.env.LOCALAPPDATA ? join27(d.env.LOCALAPPDATA, "Programs") : void 0
|
|
5103
5655
|
];
|
|
5104
5656
|
for (const base of bases) {
|
|
5105
5657
|
if (!base) continue;
|
|
5106
5658
|
for (const cand of [
|
|
5107
|
-
|
|
5108
|
-
|
|
5659
|
+
join27(base, "Git", "bin", "bash.exe"),
|
|
5660
|
+
join27(base, "Git", "usr", "bin", "bash.exe")
|
|
5109
5661
|
]) {
|
|
5110
5662
|
if (d.exists(cand) && usable(cand))
|
|
5111
5663
|
return { path: cand, source: "standard-location", wslOnPath };
|
|
@@ -5118,10 +5670,10 @@ function compute(d) {
|
|
|
5118
5670
|
}
|
|
5119
5671
|
return { path: "bash", source: "path-fallback" };
|
|
5120
5672
|
}
|
|
5121
|
-
var dirname9,
|
|
5673
|
+
var dirname9, join27, WSL_STUB_RE, cache4;
|
|
5122
5674
|
var init_resolveBash = __esm({
|
|
5123
5675
|
"src/installers/lib/resolveBash.ts"() {
|
|
5124
|
-
({ dirname: dirname9, join:
|
|
5676
|
+
({ dirname: dirname9, join: join27 } = win32);
|
|
5125
5677
|
WSL_STUB_RE = /[\\/](windows[\\/](system32|sysnative|syswow64)|microsoft[\\/]windowsapps)[\\/]bash\.exe$/i;
|
|
5126
5678
|
cache4 = null;
|
|
5127
5679
|
}
|
|
@@ -5755,14 +6307,14 @@ __export(check_mcp_availability_exports, {
|
|
|
5755
6307
|
checkMcpAvailability: () => checkMcpAvailability
|
|
5756
6308
|
});
|
|
5757
6309
|
async function checkMcpAvailability() {
|
|
5758
|
-
const
|
|
6310
|
+
const installed2 = [];
|
|
5759
6311
|
const missing = [];
|
|
5760
6312
|
for (const s of TARGET_SERVERS) {
|
|
5761
|
-
if (await isMcpServerRegistered(s))
|
|
6313
|
+
if (await isMcpServerRegistered(s)) installed2.push(s);
|
|
5762
6314
|
else missing.push(s);
|
|
5763
6315
|
}
|
|
5764
6316
|
const keyless = [];
|
|
5765
|
-
for (const s of
|
|
6317
|
+
for (const s of installed2) {
|
|
5766
6318
|
const probe = await probeSearchMcpKey(s);
|
|
5767
6319
|
if (!probe.present) keyless.push(probe);
|
|
5768
6320
|
}
|
|
@@ -5770,11 +6322,11 @@ async function checkMcpAvailability() {
|
|
|
5770
6322
|
return {
|
|
5771
6323
|
name: CHECK_NAME,
|
|
5772
6324
|
status: "pass",
|
|
5773
|
-
message: `installed: ${
|
|
6325
|
+
message: `installed: ${installed2.join(", ")} (API keys configured)`
|
|
5774
6326
|
};
|
|
5775
6327
|
}
|
|
5776
6328
|
const parts = [];
|
|
5777
|
-
if (
|
|
6329
|
+
if (installed2.length > 0) parts.push(`installed: ${installed2.join(", ")}`);
|
|
5778
6330
|
if (missing.length > 0) parts.push(`not registered: ${missing.join(", ")}`);
|
|
5779
6331
|
if (keyless.length > 0) {
|
|
5780
6332
|
parts.push(`API key missing: ${keyless.map((k) => `${k.server} \u2192 ${k.envVar}`).join(", ")}`);
|
|
@@ -5963,17 +6515,17 @@ async function auditInstalledSkills(workflows, skillsBase, workflowsDir, opts =
|
|
|
5963
6515
|
const srcMarker = typeof src === "string" ? HARNESSED_MARKER_RX.exec(src) : null;
|
|
5964
6516
|
if (!srcMarker) continue;
|
|
5965
6517
|
const srcVersion = srcMarker[1] ?? "0.0.0";
|
|
5966
|
-
let
|
|
6518
|
+
let installed2;
|
|
5967
6519
|
try {
|
|
5968
|
-
|
|
6520
|
+
installed2 = await readFile(join(skillsBase, wf.name, "SKILL.md"), "utf8");
|
|
5969
6521
|
} catch {
|
|
5970
|
-
|
|
6522
|
+
installed2 = null;
|
|
5971
6523
|
}
|
|
5972
|
-
if (
|
|
6524
|
+
if (installed2 === null || typeof installed2 !== "string") {
|
|
5973
6525
|
out.push({ name: wf.name, status: "missing" });
|
|
5974
6526
|
continue;
|
|
5975
6527
|
}
|
|
5976
|
-
const marker = HARNESSED_MARKER_RX.exec(
|
|
6528
|
+
const marker = HARNESSED_MARKER_RX.exec(installed2);
|
|
5977
6529
|
if (!marker) {
|
|
5978
6530
|
out.push({ name: wf.name, status: "foreign" });
|
|
5979
6531
|
continue;
|
|
@@ -5990,7 +6542,7 @@ async function auditInstalledSkills(workflows, skillsBase, workflowsDir, opts =
|
|
|
5990
6542
|
}
|
|
5991
6543
|
out.push({
|
|
5992
6544
|
name: wf.name,
|
|
5993
|
-
status: sha256Of(
|
|
6545
|
+
status: sha256Of(installed2) === record.sha256 ? "ok" : "tampered"
|
|
5994
6546
|
});
|
|
5995
6547
|
}
|
|
5996
6548
|
return out;
|
|
@@ -6108,8 +6660,8 @@ function parse3(v) {
|
|
|
6108
6660
|
if (!m) return null;
|
|
6109
6661
|
return { nums: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ?? null };
|
|
6110
6662
|
}
|
|
6111
|
-
function compareVersions(
|
|
6112
|
-
const a = parse3(
|
|
6663
|
+
function compareVersions(installed2, latest) {
|
|
6664
|
+
const a = parse3(installed2);
|
|
6113
6665
|
const b = parse3(latest);
|
|
6114
6666
|
if (!a || !b) return "unknown";
|
|
6115
6667
|
for (let i = 0; i < 3; i++) {
|
|
@@ -6156,6 +6708,42 @@ var init_version_check = __esm({
|
|
|
6156
6708
|
}
|
|
6157
6709
|
});
|
|
6158
6710
|
|
|
6711
|
+
// src/cli/lib/proxyDispatcher.ts
|
|
6712
|
+
function hasProxyEnv() {
|
|
6713
|
+
return PROXY_VARS.some((k) => (process.env[k] ?? "").trim() !== "");
|
|
6714
|
+
}
|
|
6715
|
+
async function ensureProxyDispatcher(deps = {}) {
|
|
6716
|
+
if (installed) return "already";
|
|
6717
|
+
if (!hasProxyEnv()) return "no-proxy-env";
|
|
6718
|
+
const isCompiled = deps.isCompiled ?? (() => isCompiledRuntime());
|
|
6719
|
+
if (isCompiled()) return "native-runtime";
|
|
6720
|
+
const load = deps.loadUndici ?? (async () => {
|
|
6721
|
+
const spec = "undici";
|
|
6722
|
+
return await import(spec);
|
|
6723
|
+
});
|
|
6724
|
+
try {
|
|
6725
|
+
const mod = await load();
|
|
6726
|
+
const Agent = mod.EnvHttpProxyAgent;
|
|
6727
|
+
const setGlobalDispatcher = mod.setGlobalDispatcher;
|
|
6728
|
+
if (typeof Agent !== "function" || typeof setGlobalDispatcher !== "function") {
|
|
6729
|
+
return "unavailable";
|
|
6730
|
+
}
|
|
6731
|
+
setGlobalDispatcher(new Agent());
|
|
6732
|
+
installed = true;
|
|
6733
|
+
return "installed";
|
|
6734
|
+
} catch {
|
|
6735
|
+
return "unavailable";
|
|
6736
|
+
}
|
|
6737
|
+
}
|
|
6738
|
+
var PROXY_VARS, installed;
|
|
6739
|
+
var init_proxyDispatcher = __esm({
|
|
6740
|
+
"src/cli/lib/proxyDispatcher.ts"() {
|
|
6741
|
+
init_assetsRoot();
|
|
6742
|
+
PROXY_VARS = ["HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy", "ALL_PROXY"];
|
|
6743
|
+
installed = false;
|
|
6744
|
+
}
|
|
6745
|
+
});
|
|
6746
|
+
|
|
6159
6747
|
// src/cli/lib/update-check-cache.ts
|
|
6160
6748
|
var update_check_cache_exports = {};
|
|
6161
6749
|
__export(update_check_cache_exports, {
|
|
@@ -6203,6 +6791,7 @@ async function resolveLatestCached(d) {
|
|
|
6203
6791
|
}
|
|
6204
6792
|
async function fetchGitHubLatestVersion(timeoutMs) {
|
|
6205
6793
|
try {
|
|
6794
|
+
await ensureProxyDispatcher();
|
|
6206
6795
|
const ac = new AbortController();
|
|
6207
6796
|
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
6208
6797
|
try {
|
|
@@ -6243,6 +6832,7 @@ var init_update_check_cache = __esm({
|
|
|
6243
6832
|
init_package();
|
|
6244
6833
|
init_assetsRoot();
|
|
6245
6834
|
init_platform();
|
|
6835
|
+
init_proxyDispatcher();
|
|
6246
6836
|
init_version_check();
|
|
6247
6837
|
DEFAULT_UPDATE_CHECK_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
6248
6838
|
DEFAULT_UPDATE_CHECK_TIMEOUT_MS = 2e3;
|
|
@@ -6258,20 +6848,20 @@ async function defaultResolver() {
|
|
|
6258
6848
|
const { resolveLatestCachedDefault: resolveLatestCachedDefault2 } = await Promise.resolve().then(() => (init_update_check_cache(), update_check_cache_exports));
|
|
6259
6849
|
return resolveLatestCachedDefault2();
|
|
6260
6850
|
}
|
|
6261
|
-
async function checkUpdate(
|
|
6851
|
+
async function checkUpdate(installed2 = package_default.version, fetch2 = defaultResolver) {
|
|
6262
6852
|
const latest = await fetch2();
|
|
6263
6853
|
if (!latest) {
|
|
6264
6854
|
return { name: "update", status: "pass", message: "update check skipped (npm unreachable)" };
|
|
6265
6855
|
}
|
|
6266
|
-
if (compareVersions(
|
|
6856
|
+
if (compareVersions(installed2, latest) === "behind") {
|
|
6267
6857
|
return {
|
|
6268
6858
|
name: "update",
|
|
6269
6859
|
status: "warn",
|
|
6270
|
-
message: `update available: ${
|
|
6860
|
+
message: `update available: ${installed2} \u2192 ${latest}`,
|
|
6271
6861
|
fix: "run `harnessed update`"
|
|
6272
6862
|
};
|
|
6273
6863
|
}
|
|
6274
|
-
return { name: "update", status: "pass", message: `up to date (${
|
|
6864
|
+
return { name: "update", status: "pass", message: `up to date (${installed2})` };
|
|
6275
6865
|
}
|
|
6276
6866
|
var init_check_update = __esm({
|
|
6277
6867
|
"src/cli/lib/check-update.ts"() {
|
|
@@ -6918,15 +7508,15 @@ function checkPluginStaleness(overrides) {
|
|
|
6918
7508
|
if (deps.registryPath === null) {
|
|
6919
7509
|
return { name: NAME4, status: "skipped", message: "no plugin registry on this harness" };
|
|
6920
7510
|
}
|
|
6921
|
-
const
|
|
6922
|
-
if (
|
|
7511
|
+
const installed2 = readInstalledVersions(deps, deps.registryPath);
|
|
7512
|
+
if (installed2 === null) {
|
|
6923
7513
|
return { name: NAME4, status: "pass", message: "plugin registry unreadable \u2014 skipped" };
|
|
6924
7514
|
}
|
|
6925
7515
|
const manifests = collectPluginManifests(deps);
|
|
6926
7516
|
const behind = [];
|
|
6927
7517
|
let compared = 0;
|
|
6928
7518
|
for (const m of manifests) {
|
|
6929
|
-
const have =
|
|
7519
|
+
const have = installed2.get(m.name);
|
|
6930
7520
|
if (have === void 0) continue;
|
|
6931
7521
|
compared += 1;
|
|
6932
7522
|
if (compareVersions(have, m.recorded) === "behind") {
|
|
@@ -7809,7 +8399,7 @@ async function checkCodexHooks(deps) {
|
|
|
7809
8399
|
const plugins = await d.pluginDirs();
|
|
7810
8400
|
if (plugins.length === 0)
|
|
7811
8401
|
return { name: NAME6, status: "pass", message: "no harnessed codex hook plugins installed" };
|
|
7812
|
-
const [
|
|
8402
|
+
const [installed2, listed] = await Promise.all([d.installedPlugins(), d.listHooks()]);
|
|
7813
8403
|
const problems = [];
|
|
7814
8404
|
const fixes = [];
|
|
7815
8405
|
const ok = [];
|
|
@@ -7817,7 +8407,7 @@ async function checkCodexHooks(deps) {
|
|
|
7817
8407
|
const manifest = pluginName.replace(/^harnessed-/, "");
|
|
7818
8408
|
const pluginId = `${pluginName}@${CODEX_HOOK_MARKETPLACE}`;
|
|
7819
8409
|
const issues = [];
|
|
7820
|
-
if (
|
|
8410
|
+
if (installed2 && !installed2.has(pluginId)) issues.push("not installed in codex");
|
|
7821
8411
|
const hooks = listed.ok ? listed.value.filter((h) => h.key.startsWith(`${pluginId}:`)) : [];
|
|
7822
8412
|
const trust = !listed.ok ? "unknown" : hooks.length === 0 ? "unknown" : hooks.find((h) => h.trustStatus !== "trusted")?.trustStatus ?? "trusted";
|
|
7823
8413
|
if (trust !== "trusted") issues.push(`trust: ${trust}`);
|
|
@@ -10678,6 +11268,7 @@ var init_gates = __esm({
|
|
|
10678
11268
|
var gc_exports = {};
|
|
10679
11269
|
__export(gc_exports, {
|
|
10680
11270
|
gcCompiledArtifacts: () => gcCompiledArtifacts,
|
|
11271
|
+
gcLedger: () => gcLedger,
|
|
10681
11272
|
registerGc: () => registerGc
|
|
10682
11273
|
});
|
|
10683
11274
|
function byVersion(a, b) {
|
|
@@ -10758,6 +11349,21 @@ async function dirSizeKb(dir) {
|
|
|
10758
11349
|
}
|
|
10759
11350
|
return Math.round(total / 1024);
|
|
10760
11351
|
}
|
|
11352
|
+
async function gcLedger(olderMs, dryRun) {
|
|
11353
|
+
try {
|
|
11354
|
+
const r = await pruneSlots({ olderThanMs: olderMs, dryRun });
|
|
11355
|
+
if (r.pruned.length === 0) return;
|
|
11356
|
+
console.log(
|
|
11357
|
+
t(dryRun ? "gc.ledger_will_prune" : "gc.ledger_pruned", {
|
|
11358
|
+
count: r.pruned.length,
|
|
11359
|
+
kept: r.keptCount
|
|
11360
|
+
})
|
|
11361
|
+
);
|
|
11362
|
+
for (const k of r.pruned) console.log(` ${k}`);
|
|
11363
|
+
} catch (e) {
|
|
11364
|
+
console.error(`gc: ledger prune skipped: ${e instanceof Error ? e.message : String(e)}`);
|
|
11365
|
+
}
|
|
11366
|
+
}
|
|
10761
11367
|
function registerGc(program2) {
|
|
10762
11368
|
program2.command("gc").description(
|
|
10763
11369
|
"Garbage-collect old backup snapshots (immediate by default \u2014 use --dry-run for preview)"
|
|
@@ -10772,6 +11378,7 @@ ${t("gc.invalid_duration.fix")}`
|
|
|
10772
11378
|
process.exit(1);
|
|
10773
11379
|
return;
|
|
10774
11380
|
}
|
|
11381
|
+
await gcLedger(olderMs, dryRun);
|
|
10775
11382
|
const keepLast = Number.parseInt(opts.keepLast ?? "0", 10);
|
|
10776
11383
|
const root = getBackupRoot();
|
|
10777
11384
|
let dirs;
|
|
@@ -10840,6 +11447,7 @@ var DURATION_RE;
|
|
|
10840
11447
|
var init_gc = __esm({
|
|
10841
11448
|
"src/cli/gc.ts"() {
|
|
10842
11449
|
init_package();
|
|
11450
|
+
init_pruneSlots();
|
|
10843
11451
|
init_i18n();
|
|
10844
11452
|
init_backup();
|
|
10845
11453
|
init_version_check();
|
|
@@ -12768,7 +13376,7 @@ async function listBaseManifests(cwd) {
|
|
|
12768
13376
|
return out;
|
|
12769
13377
|
}
|
|
12770
13378
|
async function installBaseProfile(opts) {
|
|
12771
|
-
const
|
|
13379
|
+
const installed2 = [];
|
|
12772
13380
|
const alreadyInstalled = [];
|
|
12773
13381
|
const skipped = [];
|
|
12774
13382
|
const failed = [];
|
|
@@ -12789,10 +13397,10 @@ async function installBaseProfile(opts) {
|
|
|
12789
13397
|
const r = await runInstall(v.manifest, opts);
|
|
12790
13398
|
if ("aborted" in r) skipped.push({ name, reason: `aborted: ${r.reason}` });
|
|
12791
13399
|
else if (r.ok && "alreadyInstalled" in r && r.alreadyInstalled) alreadyInstalled.push(name);
|
|
12792
|
-
else if (r.ok)
|
|
13400
|
+
else if (r.ok) installed2.push(name);
|
|
12793
13401
|
else failed.push({ name, reason: r.error.message });
|
|
12794
13402
|
}
|
|
12795
|
-
return { installed, alreadyInstalled, skipped, failed };
|
|
13403
|
+
return { installed: installed2, alreadyInstalled, skipped, failed };
|
|
12796
13404
|
}
|
|
12797
13405
|
function registerInstallBase(program2) {
|
|
12798
13406
|
program2.command("install-base").description(
|
|
@@ -12807,18 +13415,18 @@ function registerInstallBase(program2) {
|
|
|
12807
13415
|
fullDiff: false,
|
|
12808
13416
|
color: "auto"
|
|
12809
13417
|
};
|
|
12810
|
-
const { installed, alreadyInstalled, skipped, failed } = await installBaseProfile(opts);
|
|
13418
|
+
const { installed: installed2, alreadyInstalled, skipped, failed } = await installBaseProfile(opts);
|
|
12811
13419
|
console.log(
|
|
12812
13420
|
`
|
|
12813
|
-
installed: ${
|
|
13421
|
+
installed: ${installed2.length} / already-installed: ${alreadyInstalled.length} / skipped (user-aborted): ${skipped.length} / failed: ${failed.length}`
|
|
12814
13422
|
);
|
|
12815
|
-
for (const i of
|
|
13423
|
+
for (const i of installed2) console.log(` installed ${i}`);
|
|
12816
13424
|
for (const a of alreadyInstalled)
|
|
12817
13425
|
console.log(` already-installed ${a} \u2014 run \`/mcp\` in Claude Code to verify connection`);
|
|
12818
13426
|
for (const s of skipped) console.log(` skipped ${s.name} \u2014 ${s.reason}`);
|
|
12819
13427
|
for (const f of failed) console.error(` failed ${f.name} \u2014 ${f.reason}`);
|
|
12820
13428
|
if (failed.length > 0) process.exit(1);
|
|
12821
|
-
if (
|
|
13429
|
+
if (installed2.length === 0 && alreadyInstalled.length === 0) process.exit(2);
|
|
12822
13430
|
process.exit(0);
|
|
12823
13431
|
});
|
|
12824
13432
|
}
|
|
@@ -13235,8 +13843,8 @@ async function runResume() {
|
|
|
13235
13843
|
}
|
|
13236
13844
|
const cwd = process.cwd();
|
|
13237
13845
|
const cwdWarn = validated.cwd !== cwd ? `\u26A0 checkpoint cwd '${validated.cwd}' \u2260 current cwd '${cwd}' \u2014 SDK session resume may fail (\xA7 1.3); fresh-session fallback` : void 0;
|
|
13238
|
-
const sidHint = validated.session_id ? ` (session_id: ${validated.session_id}
|
|
13239
|
-
const resumeHint = `\u2192
|
|
13846
|
+
const sidHint = validated.session_id ? ` (recorded session_id: ${validated.session_id}, resumable only on the host that created it; other hosts reload context from the checkpoint)` : " (fresh session \u2014 context reloaded from checkpoint)";
|
|
13847
|
+
const resumeHint = `\u2192 next: /gsd-execute-phase ${validated.phase}${sidHint}`;
|
|
13240
13848
|
const allEvidence = (current.sub_progress ?? []).flatMap(
|
|
13241
13849
|
(e) => e.evidence ?? []
|
|
13242
13850
|
);
|
|
@@ -14073,6 +14681,7 @@ async function runBinaryRollback(deps, opts) {
|
|
|
14073
14681
|
return { status: "rolled-back", from: deps.currentVersion, to: target, backupUsed: backupBin };
|
|
14074
14682
|
}
|
|
14075
14683
|
async function fetchWithTimeout(url, timeoutMs) {
|
|
14684
|
+
await ensureProxyDispatcher();
|
|
14076
14685
|
const ac = new AbortController();
|
|
14077
14686
|
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
14078
14687
|
try {
|
|
@@ -14157,6 +14766,7 @@ var init_selfUpdateBinary = __esm({
|
|
|
14157
14766
|
"src/cli/lib/selfUpdateBinary.ts"() {
|
|
14158
14767
|
init_package();
|
|
14159
14768
|
init_platform();
|
|
14769
|
+
init_proxyDispatcher();
|
|
14160
14770
|
init_updateSignature();
|
|
14161
14771
|
init_version_check();
|
|
14162
14772
|
OWNER_REPO = "easyinplay/harnessed";
|
|
@@ -14201,6 +14811,7 @@ var init_migration_report = __esm({
|
|
|
14201
14811
|
|
|
14202
14812
|
// src/cli.ts
|
|
14203
14813
|
init_package();
|
|
14814
|
+
init_workflowStore();
|
|
14204
14815
|
|
|
14205
14816
|
// src/cli/advance.ts
|
|
14206
14817
|
function registerAdvance(program2) {
|
|
@@ -14722,50 +15333,49 @@ async function readStdin() {
|
|
|
14722
15333
|
return "";
|
|
14723
15334
|
}
|
|
14724
15335
|
}
|
|
15336
|
+
async function runCheckDocsCommand(opts) {
|
|
15337
|
+
if (opts.hook && isAblated()) process.exit(0);
|
|
15338
|
+
if (opts.hook && !shouldGateForHookPayload(await readStdin())) process.exit(0);
|
|
15339
|
+
const parsed = Number(opts.maxStateLines);
|
|
15340
|
+
const violations = collectDocViolations({
|
|
15341
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
15342
|
+
...Number.isFinite(parsed) && parsed > 0 ? { maxStateLines: parsed } : {},
|
|
15343
|
+
allowLongState: !!process.env.HARNESSED_ALLOW_LONG_STATE
|
|
15344
|
+
});
|
|
15345
|
+
const code2 = exitCodeFor(violations);
|
|
15346
|
+
const summary = code2 === 2 ? "halt" : code2 === 1 ? "warn" : "pass";
|
|
15347
|
+
if (opts.hook && opts.platform === "codex") {
|
|
15348
|
+
const lines = violations.map((v) => {
|
|
15349
|
+
const where = v.line === void 0 ? v.file : `${v.file}:${v.line}`;
|
|
15350
|
+
return `${v.tier === "halt" ? "\u2717" : "\u26A0"} ${where} [${v.rule}] ${v.message}`;
|
|
15351
|
+
});
|
|
15352
|
+
const verdict = codexHookOutput(code2, lines);
|
|
15353
|
+
if (verdict !== null) process.stdout.write(`${verdict}
|
|
15354
|
+
`);
|
|
15355
|
+
process.exit(0);
|
|
15356
|
+
}
|
|
15357
|
+
if (opts.json) {
|
|
15358
|
+
console.log(JSON.stringify({ violations, summary, exit_code: code2 }, null, 2));
|
|
15359
|
+
} else if (violations.length === 0) {
|
|
15360
|
+
console.log(t("check_docs.clean"));
|
|
15361
|
+
} else {
|
|
15362
|
+
for (const v of violations) {
|
|
15363
|
+
const where = v.line === void 0 ? v.file : `${v.file}:${v.line}`;
|
|
15364
|
+
console.error(`${v.tier === "halt" ? "\u2717" : "\u26A0"} ${where} [${v.rule}] ${v.message}`);
|
|
15365
|
+
}
|
|
15366
|
+
console.error(
|
|
15367
|
+
code2 === 2 ? t("check_docs.summary_halt", {
|
|
15368
|
+
halt: violations.filter((v) => v.tier === "halt").length,
|
|
15369
|
+
warn: violations.filter((v) => v.tier === "warn").length
|
|
15370
|
+
}) : t("check_docs.summary_warn", { warn: violations.length })
|
|
15371
|
+
);
|
|
15372
|
+
}
|
|
15373
|
+
process.exit(code2);
|
|
15374
|
+
}
|
|
14725
15375
|
function registerCheckDocs(program2) {
|
|
14726
15376
|
program2.command("check-docs").description(
|
|
14727
15377
|
"Documentation-discipline gate over .planning/ (STATE digest limit + archive cadence + ROADMAP pointer-not-narrative). Exits 2 on a blocking violation, 1 on advisory-only."
|
|
14728
|
-
).option("--json", "output JSON instead of human-readable").option("--cwd <dir>", "repo root holding .planning/ (default: current directory)").option("--max-state-lines <n>", `STATE.md digest ceiling (default ${DEFAULT_MAX_STATE_LINES})`).option("--hook", "PreToolUse mode: read the tool payload on stdin, gate only git commit").option("--platform <id>", "(hook) host harness; codex \u2192 verdict as JSON on stdout, exit 0").action(
|
|
14729
|
-
async (opts) => {
|
|
14730
|
-
if (opts.hook && isAblated()) process.exit(0);
|
|
14731
|
-
if (opts.hook && !shouldGateForHookPayload(await readStdin())) process.exit(0);
|
|
14732
|
-
const parsed = Number(opts.maxStateLines);
|
|
14733
|
-
const violations = collectDocViolations({
|
|
14734
|
-
cwd: opts.cwd ?? process.cwd(),
|
|
14735
|
-
...Number.isFinite(parsed) && parsed > 0 ? { maxStateLines: parsed } : {},
|
|
14736
|
-
allowLongState: !!process.env.HARNESSED_ALLOW_LONG_STATE
|
|
14737
|
-
});
|
|
14738
|
-
const code2 = exitCodeFor(violations);
|
|
14739
|
-
const summary = code2 === 2 ? "halt" : code2 === 1 ? "warn" : "pass";
|
|
14740
|
-
if (opts.hook && opts.platform === "codex") {
|
|
14741
|
-
const lines = violations.map((v) => {
|
|
14742
|
-
const where = v.line === void 0 ? v.file : `${v.file}:${v.line}`;
|
|
14743
|
-
return `${v.tier === "halt" ? "\u2717" : "\u26A0"} ${where} [${v.rule}] ${v.message}`;
|
|
14744
|
-
});
|
|
14745
|
-
const verdict = codexHookOutput(code2, lines);
|
|
14746
|
-
if (verdict !== null) process.stdout.write(`${verdict}
|
|
14747
|
-
`);
|
|
14748
|
-
process.exit(0);
|
|
14749
|
-
}
|
|
14750
|
-
if (opts.json) {
|
|
14751
|
-
console.log(JSON.stringify({ violations, summary, exit_code: code2 }, null, 2));
|
|
14752
|
-
} else if (violations.length === 0) {
|
|
14753
|
-
console.log(t("check_docs.clean"));
|
|
14754
|
-
} else {
|
|
14755
|
-
for (const v of violations) {
|
|
14756
|
-
const where = v.line === void 0 ? v.file : `${v.file}:${v.line}`;
|
|
14757
|
-
console.error(`${v.tier === "halt" ? "\u2717" : "\u26A0"} ${where} [${v.rule}] ${v.message}`);
|
|
14758
|
-
}
|
|
14759
|
-
console.error(
|
|
14760
|
-
code2 === 2 ? t("check_docs.summary_halt", {
|
|
14761
|
-
halt: violations.filter((v) => v.tier === "halt").length,
|
|
14762
|
-
warn: violations.filter((v) => v.tier === "warn").length
|
|
14763
|
-
}) : t("check_docs.summary_warn", { warn: violations.length })
|
|
14764
|
-
);
|
|
14765
|
-
}
|
|
14766
|
-
process.exit(code2);
|
|
14767
|
-
}
|
|
14768
|
-
);
|
|
15378
|
+
).option("--json", "output JSON instead of human-readable").option("--cwd <dir>", "repo root holding .planning/ (default: current directory)").option("--max-state-lines <n>", `STATE.md digest ceiling (default ${DEFAULT_MAX_STATE_LINES})`).option("--hook", "PreToolUse mode: read the tool payload on stdin, gate only git commit").option("--platform <id>", "(hook) host harness; codex \u2192 verdict as JSON on stdout, exit 0").action((opts) => runCheckDocsCommand(opts));
|
|
14769
15379
|
}
|
|
14770
15380
|
|
|
14771
15381
|
// src/cli.ts
|
|
@@ -17576,18 +18186,18 @@ async function runStepBInstall(manifestPaths, runOpts = {}) {
|
|
|
17576
18186
|
const restEntries = restSettled.map(
|
|
17577
18187
|
(s) => s.status === "fulfilled" ? s.value : { status: "failed", name: "?", reason: String(s.reason) }
|
|
17578
18188
|
);
|
|
17579
|
-
const
|
|
18189
|
+
const installed2 = [];
|
|
17580
18190
|
const alreadyInstalled = [];
|
|
17581
18191
|
const skipped = [];
|
|
17582
18192
|
const failed = [];
|
|
17583
18193
|
for (const v of [...invalid, ...mcpEntries, ...restEntries]) {
|
|
17584
|
-
if (v.status === "installed")
|
|
18194
|
+
if (v.status === "installed") installed2.push(v.name);
|
|
17585
18195
|
else if (v.status === "already-installed") alreadyInstalled.push(v.name);
|
|
17586
18196
|
else if (v.status === "skipped") skipped.push({ name: v.name, reason: v.reason });
|
|
17587
18197
|
else if (v.status === "failed") failed.push(`${v.name}: ${v.reason}`);
|
|
17588
18198
|
}
|
|
17589
18199
|
return {
|
|
17590
|
-
installed,
|
|
18200
|
+
installed: installed2,
|
|
17591
18201
|
alreadyInstalled,
|
|
17592
18202
|
skipped,
|
|
17593
18203
|
failed,
|
|
@@ -17654,19 +18264,19 @@ async function makeIdempotentProbe(manifestPaths) {
|
|
|
17654
18264
|
init_package();
|
|
17655
18265
|
init_assetsRoot();
|
|
17656
18266
|
init_version_check();
|
|
17657
|
-
function versionBannerLines(
|
|
17658
|
-
const lines = [`harnessed setup v${
|
|
18267
|
+
function versionBannerLines(installed2, latest, updateHint = "npm install -g harnessed@latest") {
|
|
18268
|
+
const lines = [`harnessed setup v${installed2}`];
|
|
17659
18269
|
if (latest === null) {
|
|
17660
18270
|
lines.push(" could not check latest version");
|
|
17661
18271
|
return lines;
|
|
17662
18272
|
}
|
|
17663
|
-
const cmp = compareVersions(
|
|
18273
|
+
const cmp = compareVersions(installed2, latest);
|
|
17664
18274
|
if (cmp === "behind") {
|
|
17665
|
-
lines.push(`\u26A0 update available: ${
|
|
18275
|
+
lines.push(`\u26A0 update available: ${installed2} \u2192 ${latest} \u2014 ${updateHint}`);
|
|
17666
18276
|
} else if (cmp === "current") {
|
|
17667
18277
|
lines.push(`\u2713 latest (v${latest})`);
|
|
17668
18278
|
} else if (cmp === "ahead") {
|
|
17669
|
-
lines.push(`\u2713 latest (v${
|
|
18279
|
+
lines.push(`\u2713 latest (v${installed2})`);
|
|
17670
18280
|
}
|
|
17671
18281
|
return lines;
|
|
17672
18282
|
}
|
|
@@ -17685,7 +18295,7 @@ async function printSetupVersionBanner() {
|
|
|
17685
18295
|
}
|
|
17686
18296
|
|
|
17687
18297
|
// src/cli/setup.ts
|
|
17688
|
-
var KNOWN_PLATFORMS =
|
|
18298
|
+
var KNOWN_PLATFORMS = HOST_IDS;
|
|
17689
18299
|
async function applyPlatformOption(platform, persist) {
|
|
17690
18300
|
if (!KNOWN_PLATFORMS.includes(platform)) {
|
|
17691
18301
|
console.error(
|
|
@@ -19098,6 +19708,11 @@ process.on("unhandledRejection", (reason) => {
|
|
|
19098
19708
|
process.on("uncaughtException", (err2) => {
|
|
19099
19709
|
fatal(err2 instanceof Error ? err2.message : String(err2));
|
|
19100
19710
|
});
|
|
19711
|
+
await migrateRepoKeyCase().catch((e) => {
|
|
19712
|
+
console.error(
|
|
19713
|
+
`[harnessed] WARN: repo-key case migration deferred: ${e instanceof Error ? e.message : String(e)}`
|
|
19714
|
+
);
|
|
19715
|
+
});
|
|
19101
19716
|
var program = new Command();
|
|
19102
19717
|
program.name("harnessed").description("AI coding harness package manager + composition orchestrator").version(package_default.version).option("--lang <code>", "output language: en | zh (auto-detect from $LANG / Intl if absent)");
|
|
19103
19718
|
registerInstall(program);
|