opencode-swarm 7.153.0 → 7.153.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/dist/background/pending-delegations.d.ts +7 -0
- package/dist/cli/{config-doctor-7s7xga6f.js → config-doctor-ze21qs6b.js} +2 -2
- package/dist/cli/{core-vkpy14vv.js → core-qdmhh1kx.js} +1 -1
- package/dist/cli/{curation-policy-xy7tm4ad.js → curation-policy-twa6agf8.js} +7 -7
- package/dist/cli/{curator-6freqnhf.js → curator-hxb3wsxr.js} +30 -30
- package/dist/cli/{curator-llm-factory-q5cjk7mt.js → curator-llm-factory-s8atmc2n.js} +30 -30
- package/dist/cli/{evidence-summary-service-engtgjww.js → evidence-summary-service-wzzym9r7.js} +13 -13
- package/dist/cli/{gate-evidence-6bzzz8kq.js → gate-evidence-f71dn9vv.js} +7 -7
- package/dist/cli/{guardrail-explain-vsck39dh.js → guardrail-explain-5kzeem4m.js} +31 -31
- package/dist/cli/{guardrail-log-0dn8m3k6.js → guardrail-log-38jnajpa.js} +5 -5
- package/dist/cli/{guardrail-reset-6e2vyfn9.js → guardrail-reset-wzvtmpn2.js} +30 -30
- package/dist/cli/{hive-promoter-021abs6z.js → hive-promoter-55qcqgfx.js} +30 -30
- package/dist/cli/{index-hw49515c.js → index-0tyc8kdg.js} +1 -1
- package/dist/cli/{index-9vdh4kdx.js → index-0tzv5zg2.js} +2 -2
- package/dist/cli/{index-e2hs0bh7.js → index-1akn19mp.js} +1 -1
- package/dist/cli/{index-5x67858f.js → index-1dtshrzg.js} +5 -5
- package/dist/cli/{index-9gjbe4e4.js → index-1gzdnjg9.js} +2 -2
- package/dist/cli/{index-dh1gk5c5.js → index-23rneydq.js} +32 -32
- package/dist/cli/{index-z4bg1hv8.js → index-2mqmvxac.js} +9 -2
- package/dist/cli/index-3cegckkq.js +239 -0
- package/dist/cli/{index-1yfpw7w0.js → index-3ttktt56.js} +1 -1
- package/dist/cli/{index-eajfs7v4.js → index-4g0g3dqz.js} +1 -1
- package/dist/cli/{index-x6zy6veh.js → index-4pjkdcgc.js} +1 -1
- package/dist/cli/{index-g0m6kypc.js → index-6vgb5fyb.js} +1 -1
- package/dist/cli/{index-95qra69h.js → index-6ybjrqf7.js} +4397 -2470
- package/dist/cli/{index-txbd25bc.js → index-891g7hbf.js} +1 -1
- package/dist/cli/{index-7q56f3se.js → index-8v9sj4aq.js} +2 -2
- package/dist/cli/{index-babtfqa0.js → index-9v8d3c0k.js} +450 -48
- package/dist/cli/{index-eqh3t8eh.js → index-af0cqe6n.js} +14 -14
- package/dist/cli/{index-hkmgzesw.js → index-ajkxx2k6.js} +2 -2
- package/dist/cli/{index-6v77adf7.js → index-gn26q90p.js} +2 -2
- package/dist/cli/{index-77xy577c.js → index-k10qtq71.js} +9 -9
- package/dist/cli/{index-80ekaf5b.js → index-mb7b1gye.js} +3 -3
- package/dist/cli/{index-0q2mjxp2.js → index-meg33yyv.js} +1 -1
- package/dist/cli/{index-3z2f1cy8.js → index-n5pxkera.js} +4 -4
- package/dist/cli/{index-3z5jtyan.js → index-n823qsae.js} +3 -2
- package/dist/cli/{index-6zkm4p7p.js → index-pk1gbqmq.js} +1 -1
- package/dist/cli/{index-4gn111h3.js → index-smqsp8hs.js} +5 -5
- package/dist/cli/{index-k2ydsqs7.js → index-td0jz8xe.js} +4 -4
- package/dist/cli/{index-xv881ahz.js → index-tdzbm974.js} +7 -7
- package/dist/cli/{index-5w915x8b.js → index-v689bmr2.js} +4 -4
- package/dist/cli/{index-qgfnd206.js → index-x3y6zhgj.js} +1 -1
- package/dist/cli/{index-aw492hpn.js → index-x8vw6ap1.js} +58 -41
- package/dist/cli/{index-hexhzq5j.js → index-xkjrg9k4.js} +3 -3
- package/dist/cli/{index-0n7nm9e8.js → index-zppxpc3y.js} +2 -2
- package/dist/cli/index.js +30 -30
- package/dist/cli/{knowledge-escalator-79zbhpz5.js → knowledge-escalator-w05ztgvk.js} +12 -12
- package/dist/cli/{knowledge-events-79cak7eb.js → knowledge-events-pwm9jc0m.js} +10 -10
- package/dist/cli/{knowledge-link-40zsr5ja.js → knowledge-link-ge0rddxw.js} +6 -6
- package/dist/cli/{knowledge-store-w29aw5w0.js → knowledge-store-4xv65tj2.js} +7 -7
- package/dist/cli/{knowledge-validator-qsecnt2d.js → knowledge-validator-0ttfsca7.js} +9 -9
- package/dist/cli/{pending-delegations-a2nmssr1.js → pending-delegations-nk78wx7h.js} +4 -4
- package/dist/cli/{pr-subscriptions-7879nq5k.js → pr-subscriptions-dq1f61ye.js} +4 -4
- package/dist/cli/{runner-fbgsxs74.js → runner-n50w1y4w.js} +7 -7
- package/dist/cli/{scan-cursor-1r3pcdqp.js → scan-cursor-b6n15w8d.js} +8 -8
- package/dist/cli/{schema-19qsv6fw.js → schema-jkbfwqr2.js} +1 -1
- package/dist/cli/{scope-persistence-ypcrvqtt.js → scope-persistence-5xt2m5ep.js} +9 -9
- package/dist/cli/{skill-generator-wpp9kpa0.js → skill-generator-3keadpf7.js} +14 -14
- package/dist/cli/{telemetry-52pw5xac.js → telemetry-hh1j99za.js} +1 -1
- package/dist/cli/{worktree-collision-ownership-p31zm5k0.js → worktree-collision-ownership-4drcjymy.js} +15 -10
- package/dist/cli/{worktree-isolation-wcry8qnn.js → worktree-isolation-1ymaxn4h.js} +30 -30
- package/dist/commands/lanes.d.ts +25 -0
- package/dist/consensus/corpus.d.ts +16 -0
- package/dist/hooks/delegation-gate/worktree-isolation.d.ts +50 -3
- package/dist/hooks/delegation-gate/worktree-provisioning-owner.d.ts +40 -2
- package/dist/hooks/delegation-gate/worktree-recovery-authority.d.ts +201 -0
- package/dist/hooks/init-orphan-recovery.d.ts +5 -1
- package/dist/hooks/trajectory-logger.d.ts +22 -6
- package/dist/hooks/trajectory-step-state.d.ts +43 -2
- package/dist/index.js +556 -551
- package/dist/observability/catalog.d.ts +6 -4
- package/dist/prm/index.d.ts +3 -3
- package/dist/prm/replay.d.ts +29 -2
- package/dist/prm/trajectory-store.d.ts +210 -20
- package/dist/telemetry.d.ts +21 -1
- package/dist/utils/atomic-write.d.ts +2 -0
- package/dist/utils/canonical-root.d.ts +31 -0
- package/dist/workflow/coder-settlement.d.ts +2 -0
- package/dist/worktree/index.d.ts +2 -2
- package/dist/worktree/merge.d.ts +47 -0
- package/package.json +2 -1
- package/dist/cli/index-fxvgaeq4.js +0 -125
- package/dist/cli/worktree-provisioning-owner-cve95q4f.js +0 -22
- package/dist/cli/{curator-drift-2h1d2fnq.js → curator-drift-h57z6tm3.js} +1 -1
|
@@ -14,14 +14,14 @@ import {
|
|
|
14
14
|
detectWindowsWrites,
|
|
15
15
|
getSharedClassifierGuardrailBlock,
|
|
16
16
|
resolveWriteTargets
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-6ybjrqf7.js";
|
|
18
18
|
import {
|
|
19
19
|
checkFileAuthority,
|
|
20
20
|
classifyFile,
|
|
21
21
|
isInDeclaredScope,
|
|
22
22
|
redactPath,
|
|
23
23
|
redactShellCommand
|
|
24
|
-
} from "./index-
|
|
24
|
+
} from "./index-gn26q90p.js";
|
|
25
25
|
|
|
26
26
|
// src/services/guardrail-explain-service.ts
|
|
27
27
|
import path from "path";
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
import {
|
|
3
3
|
computePlanStructureHash,
|
|
4
4
|
derivePlanId
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-mb7b1gye.js";
|
|
6
6
|
import {
|
|
7
7
|
appendCoreEventSync
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-pk1gbqmq.js";
|
|
9
9
|
import {
|
|
10
10
|
unsafePathTextReason
|
|
11
11
|
} from "./index-556ja8an.js";
|
|
12
12
|
import {
|
|
13
13
|
PlanSchema
|
|
14
|
-
} from "./index-
|
|
14
|
+
} from "./index-1akn19mp.js";
|
|
15
15
|
import {
|
|
16
16
|
atomicWriteSwarmFile,
|
|
17
17
|
atomicWriteSwarmFileSync
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-td0jz8xe.js";
|
|
19
19
|
import {
|
|
20
20
|
assertProjectRoot
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-891g7hbf.js";
|
|
22
22
|
import {
|
|
23
23
|
require_proper_lockfile
|
|
24
24
|
} from "./index-7g4c7s5r.js";
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
} from "./index-y8552snf.js";
|
|
10
10
|
import {
|
|
11
11
|
atomicWriteFile
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-zppxpc3y.js";
|
|
13
13
|
import {
|
|
14
14
|
assertProjectRoot,
|
|
15
15
|
withEvidenceLock
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-891g7hbf.js";
|
|
17
17
|
import {
|
|
18
18
|
exports_external,
|
|
19
19
|
init_zod
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
handleGuardrailExplain
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-0tzv5zg2.js";
|
|
5
5
|
import {
|
|
6
6
|
handleGuardrailLog
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-6vgb5fyb.js";
|
|
8
8
|
import {
|
|
9
9
|
COMMAND_REGISTRY,
|
|
10
10
|
SWARM_COMMAND_TOOL_ALLOWLIST,
|
|
@@ -86,51 +86,51 @@ import {
|
|
|
86
86
|
handleWriteRetroCommand,
|
|
87
87
|
normalizeSwarmCommandInput,
|
|
88
88
|
resolveCommand
|
|
89
|
-
} from "./index-
|
|
90
|
-
import"./index-
|
|
91
|
-
import"./index-
|
|
92
|
-
import"./index-
|
|
93
|
-
import"./index-eqh3t8eh.js";
|
|
94
|
-
import"./index-9gjbe4e4.js";
|
|
89
|
+
} from "./index-6ybjrqf7.js";
|
|
90
|
+
import"./index-gn26q90p.js";
|
|
91
|
+
import"./index-0tyc8kdg.js";
|
|
92
|
+
import"./index-af0cqe6n.js";
|
|
95
93
|
import"./index-134d35c1.js";
|
|
96
94
|
import"./index-nj6rmyeh.js";
|
|
95
|
+
import"./index-4pjkdcgc.js";
|
|
96
|
+
import"./index-1gzdnjg9.js";
|
|
97
97
|
import"./index-y8552snf.js";
|
|
98
|
-
import"./index-
|
|
99
|
-
import"./index-7q56f3se.js";
|
|
98
|
+
import"./index-8v9sj4aq.js";
|
|
100
99
|
import"./index-70ha9e09.js";
|
|
101
100
|
import"./index-c8s9a3zh.js";
|
|
102
101
|
import"./index-9ss2m4rs.js";
|
|
103
102
|
import"./index-vnn7qq8c.js";
|
|
104
|
-
import"./index-
|
|
105
|
-
import"./index-
|
|
106
|
-
import"./index-
|
|
107
|
-
import"./index-
|
|
103
|
+
import"./index-meg33yyv.js";
|
|
104
|
+
import"./index-n5pxkera.js";
|
|
105
|
+
import"./index-smqsp8hs.js";
|
|
106
|
+
import"./index-v689bmr2.js";
|
|
107
|
+
import"./index-3ttktt56.js";
|
|
108
108
|
import"./index-rtry5xyf.js";
|
|
109
|
+
import"./index-3cegckkq.js";
|
|
109
110
|
import"./index-zsrtt42s.js";
|
|
110
|
-
import"./index-
|
|
111
|
-
import"./index-
|
|
112
|
-
import"./index-
|
|
113
|
-
import"./index-
|
|
114
|
-
import"./index-
|
|
115
|
-
import"./index-
|
|
116
|
-
import"./index-6zkm4p7p.js";
|
|
111
|
+
import"./index-9v8d3c0k.js";
|
|
112
|
+
import"./index-4g0g3dqz.js";
|
|
113
|
+
import"./index-2mqmvxac.js";
|
|
114
|
+
import"./index-1dtshrzg.js";
|
|
115
|
+
import"./index-mb7b1gye.js";
|
|
116
|
+
import"./index-pk1gbqmq.js";
|
|
117
117
|
import"./index-556ja8an.js";
|
|
118
118
|
import"./index-b43rt5ph.js";
|
|
119
119
|
import"./index-q7sjgr1y.js";
|
|
120
120
|
import"./index-4fwbbad3.js";
|
|
121
|
-
import"./index-
|
|
122
|
-
import"./index-
|
|
123
|
-
import"./index-
|
|
121
|
+
import"./index-k10qtq71.js";
|
|
122
|
+
import"./index-tdzbm974.js";
|
|
123
|
+
import"./index-ajkxx2k6.js";
|
|
124
124
|
import"./index-gprxjmm7.js";
|
|
125
125
|
import"./index-n832052r.js";
|
|
126
126
|
import"./index-4cgee5vh.js";
|
|
127
127
|
import"./index-z6xqpmqg.js";
|
|
128
128
|
import"./index-r3mvsbtq.js";
|
|
129
|
-
import"./index-
|
|
129
|
+
import"./index-1akn19mp.js";
|
|
130
130
|
import {
|
|
131
131
|
init_schema,
|
|
132
132
|
stripKnownSwarmPrefix
|
|
133
|
-
} from "./index-
|
|
133
|
+
} from "./index-n823qsae.js";
|
|
134
134
|
import {
|
|
135
135
|
AGENT_TOOL_MAP,
|
|
136
136
|
ORCHESTRATOR_NAME,
|
|
@@ -140,15 +140,15 @@ import"./index-9e6fdz2h.js";
|
|
|
140
140
|
import"./index-4rhhvd1a.js";
|
|
141
141
|
import"./index-zjygnfay.js";
|
|
142
142
|
import"./index-ae75rja9.js";
|
|
143
|
-
import"./index-
|
|
144
|
-
import"./index-
|
|
143
|
+
import"./index-x3y6zhgj.js";
|
|
144
|
+
import"./index-zppxpc3y.js";
|
|
145
145
|
import"./index-bk5tah7q.js";
|
|
146
|
-
import"./index-
|
|
147
|
-
import"./index-
|
|
148
|
-
import"./index-
|
|
146
|
+
import"./index-td0jz8xe.js";
|
|
147
|
+
import"./index-891g7hbf.js";
|
|
148
|
+
import"./index-ed5ykebp.js";
|
|
149
|
+
import"./index-x8vw6ap1.js";
|
|
149
150
|
import"./index-7g4c7s5r.js";
|
|
150
151
|
import"./index-bpmtbmy9.js";
|
|
151
|
-
import"./index-ed5ykebp.js";
|
|
152
152
|
import"./index-zgwm4ryv.js";
|
|
153
153
|
import"./index-a76rekgs.js";
|
|
154
154
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
EvidenceLockTimeoutError,
|
|
10
10
|
withEvidenceLock
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-891g7hbf.js";
|
|
12
12
|
import {
|
|
13
13
|
exports_external,
|
|
14
14
|
init_zod
|
|
@@ -469,7 +469,14 @@ var WorktreeDescriptorSchema = exports_external.object({
|
|
|
469
469
|
worktreeSessionId: exports_external.string().min(1).max(256),
|
|
470
470
|
mergeStrategy: exports_external.enum(["merge", "rebase", "cherry-pick"]),
|
|
471
471
|
laneIndex: exports_external.number().int().nonnegative().max(255),
|
|
472
|
-
worktreeDir: exports_external.string().min(1).max(4096).nullable()
|
|
472
|
+
worktreeDir: exports_external.string().min(1).max(4096).nullable(),
|
|
473
|
+
reservationId: exports_external.string().min(1).max(512).optional(),
|
|
474
|
+
generation: exports_external.number().int().min(1).optional(),
|
|
475
|
+
provisioningOwner: exports_external.object({
|
|
476
|
+
reservationId: exports_external.string().min(1).max(512),
|
|
477
|
+
generation: exports_external.number().int().min(1),
|
|
478
|
+
branchName: exports_external.string().min(1).max(1024)
|
|
479
|
+
}).strict().optional()
|
|
473
480
|
}).strict();
|
|
474
481
|
var TerminalResultSchema = exports_external.object({
|
|
475
482
|
eventId: exports_external.string().min(1).max(256),
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
validateSwarmPath
|
|
4
|
+
} from "./index-4cgee5vh.js";
|
|
5
|
+
import {
|
|
6
|
+
atomicWriteSwarmFileSync
|
|
7
|
+
} from "./index-td0jz8xe.js";
|
|
8
|
+
|
|
9
|
+
// src/hooks/delegation-gate/worktree-provisioning-owner.ts
|
|
10
|
+
import { createHash } from "crypto";
|
|
11
|
+
import * as fs from "fs";
|
|
12
|
+
import * as path from "path";
|
|
13
|
+
var PROVISIONING_OWNER_DIR = "worktree-provisioning-owners";
|
|
14
|
+
var MAX_PROVISIONING_OWNERS = 512;
|
|
15
|
+
var MAX_PROVISIONING_OWNER_BYTES = 16 * 1024;
|
|
16
|
+
var PROVISIONING_JOURNAL_PATH = path.join(".swarm", "worktree-provisioning-lifecycle.json");
|
|
17
|
+
var MAX_PROVISIONING_JOURNAL_BYTES = 256 * 1024;
|
|
18
|
+
var MAX_PROVISIONING_JOURNAL_ENTRIES = 512;
|
|
19
|
+
var WORKTREE_PROVISIONING_OWNER_LEASE_MS = 5 * 60 * 1000;
|
|
20
|
+
var WORKTREE_LIFECYCLE_LOCK_FILE = ".swarm/locks/init-orphan-recovery.lock";
|
|
21
|
+
var WORKTREE_PROVISIONING_LIFECYCLE_STATES = [
|
|
22
|
+
"OWNER_PUBLISHED",
|
|
23
|
+
"OWNER_REMOVED"
|
|
24
|
+
];
|
|
25
|
+
function ownerDirectory(directory) {
|
|
26
|
+
return path.dirname(validateSwarmPath(directory, path.join(PROVISIONING_OWNER_DIR, ".containment-anchor")));
|
|
27
|
+
}
|
|
28
|
+
function ownerPath(directory, callID) {
|
|
29
|
+
const digest = createHash("sha256").update(callID).digest("hex");
|
|
30
|
+
return validateSwarmPath(directory, path.join(PROVISIONING_OWNER_DIR, `${digest}.json`));
|
|
31
|
+
}
|
|
32
|
+
function journalPath(directory) {
|
|
33
|
+
return validateSwarmPath(directory, PROVISIONING_JOURNAL_PATH);
|
|
34
|
+
}
|
|
35
|
+
function isOwner(value) {
|
|
36
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
37
|
+
return false;
|
|
38
|
+
const candidate = value;
|
|
39
|
+
const schemaVersion = candidate.schemaVersion;
|
|
40
|
+
const validTaskIdentity = schemaVersion === 1 ? candidate.taskId === undefined && candidate.reservationId === undefined && candidate.generation === undefined && candidate.branchName === undefined : schemaVersion === 2 && typeof candidate.taskId === "string" && candidate.taskId.length > 0 && candidate.taskId.length <= 512 && candidate.reservationId === undefined && candidate.generation === undefined && candidate.branchName === undefined;
|
|
41
|
+
const validV3Identity = schemaVersion === 3 && typeof candidate.taskId === "string" && candidate.taskId.length > 0 && candidate.taskId.length <= 512 && typeof candidate.reservationId === "string" && candidate.reservationId.length > 0 && candidate.reservationId.length <= 512 && typeof candidate.generation === "number" && Number.isInteger(candidate.generation) && candidate.generation > 0 && typeof candidate.branchName === "string" && candidate.branchName.length > 0 && candidate.branchName.length <= 1024;
|
|
42
|
+
return (schemaVersion === 1 || schemaVersion === 2 || schemaVersion === 3) && (validTaskIdentity || validV3Identity) && typeof candidate.callID === "string" && candidate.callID.length > 0 && candidate.callID.length <= 512 && typeof candidate.parentSessionId === "string" && candidate.parentSessionId.length > 0 && candidate.parentSessionId.length <= 512 && typeof candidate.worktreeSessionId === "string" && candidate.worktreeSessionId.length > 0 && candidate.worktreeSessionId.length <= 512 && typeof candidate.createdAt === "number" && Number.isFinite(candidate.createdAt) && candidate.createdAt >= 0;
|
|
43
|
+
}
|
|
44
|
+
function isLifecycleEntry(value) {
|
|
45
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
46
|
+
return false;
|
|
47
|
+
const candidate = value;
|
|
48
|
+
const validState = WORKTREE_PROVISIONING_LIFECYCLE_STATES.includes(candidate.state);
|
|
49
|
+
return candidate.schemaVersion === 1 && validState && typeof candidate.callID === "string" && candidate.callID.length > 0 && candidate.callID.length <= 512 && typeof candidate.parentSessionId === "string" && candidate.parentSessionId.length > 0 && candidate.parentSessionId.length <= 512 && typeof candidate.worktreeSessionId === "string" && candidate.worktreeSessionId.length > 0 && candidate.worktreeSessionId.length <= 512 && (candidate.taskId === undefined || typeof candidate.taskId === "string" && candidate.taskId.length > 0 && candidate.taskId.length <= 512) && (candidate.reservationId === undefined || typeof candidate.reservationId === "string" && candidate.reservationId.length > 0 && candidate.reservationId.length <= 512) && (candidate.generation === undefined || typeof candidate.generation === "number" && Number.isInteger(candidate.generation) && candidate.generation > 0) && (candidate.branchName === undefined || typeof candidate.branchName === "string" && candidate.branchName.length > 0 && candidate.branchName.length <= 1024) && typeof candidate.recordedAt === "number" && Number.isFinite(candidate.recordedAt) && candidate.recordedAt >= 0;
|
|
50
|
+
}
|
|
51
|
+
function readBoundedJsonFile(filePath, maxBytes) {
|
|
52
|
+
try {
|
|
53
|
+
const stat = fs.statSync(filePath);
|
|
54
|
+
if (stat.size > maxBytes) {
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
reason: `${path.basename(filePath)} exceeds the ${maxBytes}-byte safety bound`
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const raw = fs.readFileSync(filePath, "utf8");
|
|
61
|
+
if (Buffer.byteLength(raw, "utf8") > maxBytes) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
reason: `${path.basename(filePath)} changed beyond the ${maxBytes}-byte safety bound`
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return { ok: true, value: JSON.parse(raw) };
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error.code === "ENOENT") {
|
|
70
|
+
return { ok: true, value: undefined };
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
reason: `${path.basename(filePath)} is unreadable or malformed: ${error instanceof Error ? error.message : String(error)}`
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function readOwner(directory, callID) {
|
|
79
|
+
const absolutePath = ownerPath(directory, callID);
|
|
80
|
+
const loaded = readBoundedJsonFile(absolutePath, MAX_PROVISIONING_OWNER_BYTES);
|
|
81
|
+
if (!loaded.ok || loaded.value === undefined)
|
|
82
|
+
return null;
|
|
83
|
+
return isOwner(loaded.value) ? loaded.value : null;
|
|
84
|
+
}
|
|
85
|
+
function loadLifecycleJournal(directory) {
|
|
86
|
+
const loaded = readBoundedJsonFile(journalPath(directory), MAX_PROVISIONING_JOURNAL_BYTES);
|
|
87
|
+
if (!loaded.ok)
|
|
88
|
+
return { status: "uncertain", reason: loaded.reason };
|
|
89
|
+
if (loaded.value === undefined)
|
|
90
|
+
return { status: "ok", entries: [] };
|
|
91
|
+
const parsed = loaded.value;
|
|
92
|
+
if (parsed.schemaVersion !== 1 || !Array.isArray(parsed.entries)) {
|
|
93
|
+
return {
|
|
94
|
+
status: "uncertain",
|
|
95
|
+
reason: "worktree provisioning lifecycle journal is malformed"
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (parsed.entries.length > MAX_PROVISIONING_JOURNAL_ENTRIES) {
|
|
99
|
+
return {
|
|
100
|
+
status: "uncertain",
|
|
101
|
+
reason: `worktree provisioning lifecycle journal exceeds the ${MAX_PROVISIONING_JOURNAL_ENTRIES}-entry safety bound`
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const entries = [];
|
|
105
|
+
for (const entry of parsed.entries) {
|
|
106
|
+
if (!isLifecycleEntry(entry)) {
|
|
107
|
+
return {
|
|
108
|
+
status: "uncertain",
|
|
109
|
+
reason: "worktree provisioning lifecycle journal contains an invalid entry"
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
entries.push(entry);
|
|
113
|
+
}
|
|
114
|
+
return { status: "ok", entries };
|
|
115
|
+
}
|
|
116
|
+
function appendLifecycleEntry(directory, owner, state) {
|
|
117
|
+
const loaded = loadLifecycleJournal(directory);
|
|
118
|
+
if (loaded.status === "uncertain") {
|
|
119
|
+
throw new Error(loaded.reason);
|
|
120
|
+
}
|
|
121
|
+
const entries = [
|
|
122
|
+
...loaded.entries,
|
|
123
|
+
{
|
|
124
|
+
schemaVersion: 1,
|
|
125
|
+
state,
|
|
126
|
+
callID: owner.callID,
|
|
127
|
+
parentSessionId: owner.parentSessionId,
|
|
128
|
+
worktreeSessionId: owner.worktreeSessionId,
|
|
129
|
+
...owner.taskId ? { taskId: owner.taskId } : {},
|
|
130
|
+
...owner.reservationId ? { reservationId: owner.reservationId } : {},
|
|
131
|
+
...owner.generation !== undefined ? { generation: owner.generation } : {},
|
|
132
|
+
...owner.branchName ? { branchName: owner.branchName } : {},
|
|
133
|
+
recordedAt: Date.now()
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
const journal = {
|
|
137
|
+
schemaVersion: 1,
|
|
138
|
+
entries: entries.slice(-MAX_PROVISIONING_JOURNAL_ENTRIES)
|
|
139
|
+
};
|
|
140
|
+
atomicWriteSwarmFileSync(journalPath(directory), JSON.stringify(journal, null, 2));
|
|
141
|
+
}
|
|
142
|
+
function recordWorktreeProvisioningOwner(directory, input) {
|
|
143
|
+
const wantsV3 = input.reservationId !== undefined || input.generation !== undefined || input.branchName !== undefined;
|
|
144
|
+
if (wantsV3 && (!input.taskId || !input.reservationId || input.generation === undefined || !input.branchName)) {
|
|
145
|
+
throw new Error("worktree provisioning owner v3 requires taskId, reservationId, generation, and branchName");
|
|
146
|
+
}
|
|
147
|
+
const owner = {
|
|
148
|
+
schemaVersion: wantsV3 ? 3 : input.taskId ? 2 : 1,
|
|
149
|
+
callID: input.callID,
|
|
150
|
+
parentSessionId: input.parentSessionId,
|
|
151
|
+
worktreeSessionId: input.worktreeSessionId,
|
|
152
|
+
...input.taskId ? { taskId: input.taskId } : {},
|
|
153
|
+
...input.reservationId ? { reservationId: input.reservationId } : {},
|
|
154
|
+
...input.generation !== undefined ? { generation: input.generation } : {},
|
|
155
|
+
...input.branchName ? { branchName: input.branchName } : {},
|
|
156
|
+
createdAt: Date.now()
|
|
157
|
+
};
|
|
158
|
+
if (!isOwner(owner)) {
|
|
159
|
+
throw new Error("invalid worktree provisioning owner");
|
|
160
|
+
}
|
|
161
|
+
const absolutePath = ownerPath(directory, input.callID);
|
|
162
|
+
fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
|
|
163
|
+
atomicWriteSwarmFileSync(absolutePath, `${JSON.stringify(owner)}
|
|
164
|
+
`);
|
|
165
|
+
appendLifecycleEntry(directory, owner, "OWNER_PUBLISHED");
|
|
166
|
+
return owner;
|
|
167
|
+
}
|
|
168
|
+
function removeWorktreeProvisioningOwner(directory, callID, expected) {
|
|
169
|
+
try {
|
|
170
|
+
const owner = readOwner(directory, callID);
|
|
171
|
+
if (owner?.schemaVersion === 3 && (!expected || expected.reservationId !== owner.reservationId || expected.generation !== owner.generation || expected.branchName !== owner.branchName)) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
fs.unlinkSync(ownerPath(directory, callID));
|
|
175
|
+
if (owner)
|
|
176
|
+
appendLifecycleEntry(directory, owner, "OWNER_REMOVED");
|
|
177
|
+
return true;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
return error.code === "ENOENT";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function scanWorktreeProvisioningOwnersForRecovery(directory) {
|
|
183
|
+
let directoryPath;
|
|
184
|
+
let entries;
|
|
185
|
+
try {
|
|
186
|
+
directoryPath = ownerDirectory(directory);
|
|
187
|
+
entries = fs.readdirSync(directoryPath, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json"));
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error.code === "ENOENT") {
|
|
190
|
+
return { status: "ok", owners: [] };
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
status: "uncertain",
|
|
194
|
+
reason: `worktree provisioning-owner directory is unreadable: ${error instanceof Error ? error.message : String(error)}`
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (entries.length > MAX_PROVISIONING_OWNERS) {
|
|
198
|
+
return {
|
|
199
|
+
status: "uncertain",
|
|
200
|
+
reason: `worktree provisioning-owner count exceeds the ${MAX_PROVISIONING_OWNERS}-marker safety bound`
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const owners = [];
|
|
204
|
+
for (const entry of entries) {
|
|
205
|
+
const absolutePath = path.join(directoryPath, entry.name);
|
|
206
|
+
try {
|
|
207
|
+
const stat = fs.statSync(absolutePath);
|
|
208
|
+
if (stat.size > MAX_PROVISIONING_OWNER_BYTES) {
|
|
209
|
+
return {
|
|
210
|
+
status: "uncertain",
|
|
211
|
+
reason: `worktree provisioning owner "${entry.name}" exceeds the recovery size bound`
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const raw = fs.readFileSync(absolutePath, "utf8");
|
|
215
|
+
if (Buffer.byteLength(raw, "utf8") > MAX_PROVISIONING_OWNER_BYTES) {
|
|
216
|
+
return {
|
|
217
|
+
status: "uncertain",
|
|
218
|
+
reason: `worktree provisioning owner "${entry.name}" changed beyond the recovery size bound`
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const parsed = JSON.parse(raw);
|
|
222
|
+
if (!isOwner(parsed)) {
|
|
223
|
+
return {
|
|
224
|
+
status: "uncertain",
|
|
225
|
+
reason: `worktree provisioning owner "${entry.name}" is invalid`
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
owners.push(parsed);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
return {
|
|
231
|
+
status: "uncertain",
|
|
232
|
+
reason: `worktree provisioning owner "${entry.name}" is unreadable or malformed: ${error instanceof Error ? error.message : String(error)}`
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return { status: "ok", owners };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export { WORKTREE_PROVISIONING_OWNER_LEASE_MS, WORKTREE_LIFECYCLE_LOCK_FILE, recordWorktreeProvisioningOwner, removeWorktreeProvisioningOwner, scanWorktreeProvisioningOwnersForRecovery };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
readLinkPointer,
|
|
8
8
|
resolveKnowledgeStoreDir,
|
|
9
9
|
resolveLinkDir
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-x3y6zhgj.js";
|
|
11
11
|
|
|
12
12
|
// src/knowledge/curation-policy.ts
|
|
13
13
|
import { appendFile, mkdir as mkdir2, readFile as readFile2 } from "fs/promises";
|
|
@@ -92,7 +92,7 @@ var _internals = {
|
|
|
92
92
|
symlinkSync: fs.symlinkSync
|
|
93
93
|
},
|
|
94
94
|
writeScopeToDisk: async (directory, taskId, files) => {
|
|
95
|
-
const { writeScopeToDisk: realWrite } = await import("./scope-persistence-
|
|
95
|
+
const { writeScopeToDisk: realWrite } = await import("./scope-persistence-5xt2m5ep.js");
|
|
96
96
|
return realWrite(directory, taskId, files);
|
|
97
97
|
},
|
|
98
98
|
writeLaneProfileToDisk: async (_worktreePath, _laneIndex, _envOverrides) => {
|