opencode-swarm 7.163.1 → 7.164.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli/{coder-settlement-f1gtvcy8.js → coder-settlement-84je6bza.js} +8 -8
- package/dist/cli/{config-doctor-0fnqzqz1.js → config-doctor-vfze38e1.js} +2 -2
- package/dist/cli/{core-w81fk5sc.js → core-q5hv8e2w.js} +1 -1
- package/dist/cli/{curation-policy-j12j2gvc.js → curation-policy-a2zty4br.js} +5 -5
- package/dist/cli/{curator-as495r18.js → curator-4pckmmyf.js} +32 -32
- package/dist/cli/{curator-drift-g6w4ga1q.js → curator-drift-wy7ejcvw.js} +105 -37
- package/dist/cli/{curator-llm-factory-v8vwz20c.js → curator-llm-factory-msbj3hpn.js} +32 -32
- package/dist/cli/{evidence-summary-service-51dxfcn5.js → evidence-summary-service-b15yes21.js} +14 -14
- package/dist/cli/{gate-evidence-nb1e8hz0.js → gate-evidence-70h0w4tb.js} +5 -5
- package/dist/cli/{guardrail-explain-z2qb6v67.js → guardrail-explain-kksdy032.js} +33 -33
- package/dist/cli/{guardrail-log-2kwntcqw.js → guardrail-log-7rxbd20p.js} +6 -6
- package/dist/cli/{guardrail-reset-mrxrc56j.js → guardrail-reset-3b4gs357.js} +32 -32
- package/dist/cli/{hive-promoter-c62x2ncb.js → hive-promoter-s80g1gwb.js} +32 -32
- package/dist/cli/index-0515j0cz.js +403 -0
- package/dist/cli/{index-ma52g2pq.js → index-12f1tsn2.js} +3 -3
- package/dist/cli/{index-2zgjcmmc.js → index-1b1h770t.js} +3 -3
- package/dist/cli/{index-9ss2m4rs.js → index-1hpjwz3s.js} +410 -1
- package/dist/cli/{index-kvra3nv1.js → index-1z4jzwja.js} +3 -3
- package/dist/cli/{index-0103w5pf.js → index-2s4s9n82.js} +2 -2
- package/dist/cli/{index-9crtmnqg.js → index-36nt17m8.js} +1 -1
- package/dist/cli/{index-g3znh2yd.js → index-4afh2cz7.js} +5 -5
- package/dist/cli/{index-2n1ym7jb.js → index-4jersar8.js} +4 -4
- package/dist/cli/{index-n67vx5zw.js → index-70bfj3v1.js} +1 -1
- package/dist/cli/{index-zjme8atd.js → index-7r9vpkwa.js} +4 -4
- package/dist/cli/{index-8ada7ag7.js → index-93sepnc9.js} +2 -2
- package/dist/cli/{index-qynqyfgj.js → index-9sy65e94.js} +3 -3
- package/dist/cli/{index-f923njwh.js → index-bm73pych.js} +6 -6
- package/dist/cli/{index-xyhmt813.js → index-c4pynht5.js} +1 -1
- package/dist/cli/{index-m1fvbah1.js → index-c69jbpex.js} +2 -2
- package/dist/cli/{index-t34daffb.js → index-e3hwzcjv.js} +2 -2
- package/dist/cli/{index-r56f3f81.js → index-g64154pd.js} +1 -1
- package/dist/cli/{index-08y8pccg.js → index-gxd8fwyt.js} +4 -4
- package/dist/cli/{index-d3azve4r.js → index-hyq20s2v.js} +118 -296
- package/dist/cli/{index-7n9jznv0.js → index-ma8w6pfp.js} +3 -3
- package/dist/cli/{index-tnpf9wwv.js → index-nhxaa9j5.js} +1 -1
- package/dist/cli/{index-d9gdwh34.js → index-nzrhw31r.js} +1 -1
- package/dist/cli/{index-n985274d.js → index-pvgcex0d.js} +3 -3
- package/dist/cli/{index-etvq73mp.js → index-qkk2skff.js} +34 -34
- package/dist/cli/{index-2v06a1yh.js → index-t5t82jy8.js} +5 -5
- package/dist/cli/{index-5056zmpt.js → index-t90gjc0k.js} +1 -1
- package/dist/cli/{index-66073kej.js → index-t9rhtvy9.js} +2 -2
- package/dist/cli/{index-hm239n1p.js → index-tb1k8jya.js} +1 -1
- package/dist/cli/{index-x2f1f011.js → index-td6n935w.js} +3 -2
- package/dist/cli/{index-swgy9xvk.js → index-v3a9rmyh.js} +3 -3
- package/dist/cli/{index-cqgpvx2d.js → index-wdtckfnf.js} +1 -1
- package/dist/cli/{index-0tervb1m.js → index-xk0kc1py.js} +522 -358
- package/dist/cli/{index-n2mhyect.js → index-ynqp3jb6.js} +1 -1
- package/dist/cli/{index-n249fbw7.js → index-zaab1wz9.js} +5 -0
- package/dist/cli/{index-4p0wyz5p.js → index-zbpcpsk0.js} +8 -8
- package/dist/cli/index.js +32 -32
- package/dist/cli/{knowledge-escalator-fq7dm2g4.js → knowledge-escalator-sttdnwf8.js} +11 -11
- package/dist/cli/{knowledge-events-3zanyfkr.js → knowledge-events-4h88stj7.js} +9 -9
- package/dist/cli/{knowledge-link-vmdj5e5d.js → knowledge-link-yykmxdyw.js} +4 -4
- package/dist/cli/{knowledge-store-vhehnw52.js → knowledge-store-j832fxpx.js} +5 -5
- package/dist/cli/{knowledge-validator-0tt0pe6b.js → knowledge-validator-edbg761g.js} +7 -7
- package/dist/cli/{pending-delegations-b92pecbj.js → pending-delegations-sphntrs0.js} +4 -4
- package/dist/cli/{pr-subscriptions-2mkdt0ak.js → pr-subscriptions-1a4gcnzv.js} +4 -4
- package/dist/cli/{runner-3gw2njnx.js → runner-d294h1by.js} +5 -5
- package/dist/cli/{scan-cursor-1c8a3b0m.js → scan-cursor-5frvp7nb.js} +6 -6
- package/dist/cli/{schema-c554j5c8.js → schema-9xkt5hvd.js} +1 -1
- package/dist/cli/{scope-persistence-vtbcszvv.js → scope-persistence-gk55h3sp.js} +8 -8
- package/dist/cli/{skill-generator-0es21fck.js → skill-generator-sxxf7jbb.js} +13 -13
- package/dist/cli/{sqlite-loader-c92413n7.js → sqlite-loader-8zefc142.js} +1 -1
- package/dist/cli/{telemetry-x4zggfd7.js → telemetry-q51s6tyt.js} +1 -1
- package/dist/cli/{worktree-collision-ownership-043dg8gg.js → worktree-collision-ownership-7kj2ryt1.js} +4 -4
- package/dist/cli/{worktree-isolation-hk42yxw7.js → worktree-isolation-67fs6rz9.js} +32 -32
- package/dist/db/canonical-project.d.ts +31 -0
- package/dist/db/db-errors.d.ts +24 -0
- package/dist/db/driver-parity.d.ts +31 -0
- package/dist/db/durability.d.ts +40 -0
- package/dist/db/group-commit-writer.d.ts +117 -0
- package/dist/db/health.d.ts +35 -0
- package/dist/db/insight-candidate-store.d.ts +61 -0
- package/dist/db/legacy-import.d.ts +77 -0
- package/dist/db/phase-report-store.d.ts +45 -0
- package/dist/db/project-db.d.ts +35 -8
- package/dist/db/qa-gate-profile.d.ts +2 -0
- package/dist/hooks/curator-drift.d.ts +9 -5
- package/dist/hooks/curator-types.d.ts +1 -0
- package/dist/hooks/knowledge-curator.d.ts +5 -3
- package/dist/hooks/micro-reflector.d.ts +12 -7
- package/dist/index.js +619 -567
- package/dist/memory/schema.d.ts +4 -4
- package/dist/prm/index.d.ts +3 -1
- package/package.json +3 -2
- package/dist/cli/index-c8s9a3zh.js +0 -73
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
resolveExecutableFromPath,
|
|
7
7
|
runEvaluation,
|
|
8
8
|
runExternalTool
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-c4pynht5.js";
|
|
10
10
|
import {
|
|
11
11
|
finalizeShellAuditForClose,
|
|
12
12
|
isPolicyProtectedPath,
|
|
@@ -15,20 +15,19 @@ import {
|
|
|
15
15
|
protectedRoots,
|
|
16
16
|
redactDecisionLineForArchive,
|
|
17
17
|
stableCanonicalStringify
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-9sy65e94.js";
|
|
19
19
|
import {
|
|
20
20
|
detectStraySwarmDirs,
|
|
21
21
|
readDoctorArtifact,
|
|
22
22
|
removeStraySwarmDir,
|
|
23
23
|
runConfigDoctor
|
|
24
|
-
} from "./index-
|
|
24
|
+
} from "./index-g64154pd.js";
|
|
25
25
|
import {
|
|
26
26
|
MAX_TRANSIENT_RETRIES,
|
|
27
27
|
archiveEvidence,
|
|
28
28
|
buildTaskCompletionDescriptor,
|
|
29
29
|
checkRequirementCoverage,
|
|
30
30
|
closePlanTerminalState,
|
|
31
|
-
closeProjectDb,
|
|
32
31
|
containsControlChars,
|
|
33
32
|
containsPathTraversal,
|
|
34
33
|
derivePlanMarkdown,
|
|
@@ -39,7 +38,6 @@ import {
|
|
|
39
38
|
getDefaultBaseBranch,
|
|
40
39
|
getDurableGateEvidenceStatusForTask,
|
|
41
40
|
getGitRepositoryStatus,
|
|
42
|
-
getProjectDb,
|
|
43
41
|
isEpicModeActive,
|
|
44
42
|
isGitRepo,
|
|
45
43
|
isGlobalFile,
|
|
@@ -55,7 +53,6 @@ import {
|
|
|
55
53
|
loadPlanJsonOnly,
|
|
56
54
|
normalizePath,
|
|
57
55
|
pathsConflict,
|
|
58
|
-
projectDbExists,
|
|
59
56
|
readTaskScopes,
|
|
60
57
|
resetToMainAfterMerge,
|
|
61
58
|
resetToRemoteBranch,
|
|
@@ -68,7 +65,7 @@ import {
|
|
|
68
65
|
validateProjectRoot,
|
|
69
66
|
validateSymlinkBoundary,
|
|
70
67
|
validateTargetWithinRoot
|
|
71
|
-
} from "./index-
|
|
68
|
+
} from "./index-hyq20s2v.js";
|
|
72
69
|
import {
|
|
73
70
|
EvaluationTaskV1Schema,
|
|
74
71
|
GateAuditManifestV1Schema,
|
|
@@ -85,7 +82,7 @@ import {
|
|
|
85
82
|
saveGateAuditResult,
|
|
86
83
|
savePromotionDecision,
|
|
87
84
|
saveTaskSetSnapshot
|
|
88
|
-
} from "./index-
|
|
85
|
+
} from "./index-2s4s9n82.js";
|
|
89
86
|
import {
|
|
90
87
|
canonicalHash,
|
|
91
88
|
canonicalJson,
|
|
@@ -97,9 +94,6 @@ import {
|
|
|
97
94
|
resolveContainedExistingPath,
|
|
98
95
|
sha256
|
|
99
96
|
} from "./index-txdagbh7.js";
|
|
100
|
-
import {
|
|
101
|
-
loadDatabaseCtor
|
|
102
|
-
} from "./index-n249fbw7.js";
|
|
103
97
|
import {
|
|
104
98
|
LANGUAGE_REGISTRY,
|
|
105
99
|
_internals as _internals3,
|
|
@@ -130,39 +124,52 @@ import {
|
|
|
130
124
|
retireSkill,
|
|
131
125
|
selectCandidateEntries,
|
|
132
126
|
syncBundledProjectSkillsIfMissingAsync
|
|
133
|
-
} from "./index-
|
|
127
|
+
} from "./index-pvgcex0d.js";
|
|
134
128
|
import {
|
|
135
129
|
readRecentEscalations
|
|
136
|
-
} from "./index-
|
|
130
|
+
} from "./index-t5t82jy8.js";
|
|
137
131
|
import {
|
|
138
132
|
alreadyCuratedThisGeneration,
|
|
139
133
|
claimNextScanBatch,
|
|
140
134
|
resolveCohortId
|
|
141
|
-
} from "./index-
|
|
135
|
+
} from "./index-e3hwzcjv.js";
|
|
142
136
|
import {
|
|
143
137
|
CURATOR_INIT_PROMPT,
|
|
144
138
|
CURATOR_PHASE_PROMPT,
|
|
145
139
|
READ_ONLY_LANE_GUIDANCE
|
|
146
140
|
} from "./index-70ha9e09.js";
|
|
147
141
|
import {
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
closeGroupCommitWriter,
|
|
143
|
+
getGlobalEventBus,
|
|
144
|
+
getGroupCommitWriter,
|
|
145
|
+
importLegacyJsonl
|
|
146
|
+
} from "./index-0515j0cz.js";
|
|
150
147
|
import {
|
|
148
|
+
DURABILITY_CLASSES,
|
|
149
|
+
applySynchronousForClass,
|
|
151
150
|
buildOpenSpecProjectionSync,
|
|
151
|
+
canonicalProjectKey,
|
|
152
|
+
closeProjectDb,
|
|
152
153
|
detectSpeckit,
|
|
154
|
+
getProjectDb,
|
|
153
155
|
loadSddStatusSync,
|
|
156
|
+
projectDbExists,
|
|
157
|
+
projectDbPath,
|
|
154
158
|
readEffectiveSpecSync,
|
|
155
159
|
resolveSpeckitProjection,
|
|
156
160
|
validateSpeckit,
|
|
157
161
|
writeProjectedSpecSync
|
|
158
|
-
} from "./index-
|
|
162
|
+
} from "./index-1hpjwz3s.js";
|
|
163
|
+
import {
|
|
164
|
+
loadDatabaseCtor
|
|
165
|
+
} from "./index-zaab1wz9.js";
|
|
159
166
|
import {
|
|
160
167
|
buildCorrelationId,
|
|
161
168
|
getPrSubscriptionHealth,
|
|
162
169
|
listActive,
|
|
163
170
|
subscribe,
|
|
164
171
|
unsubscribe
|
|
165
|
-
} from "./index-
|
|
172
|
+
} from "./index-ma8w6pfp.js";
|
|
166
173
|
import {
|
|
167
174
|
clearWorktreeMergeStatus,
|
|
168
175
|
getAllWorktreeMergeFailures,
|
|
@@ -174,7 +181,7 @@ import {
|
|
|
174
181
|
listCoderSettlementWalStates,
|
|
175
182
|
recoverCoderSettlement,
|
|
176
183
|
recoverStaleCoderSettlements
|
|
177
|
-
} from "./index-
|
|
184
|
+
} from "./index-4afh2cz7.js";
|
|
178
185
|
import {
|
|
179
186
|
parsePorcelainV2Snapshot,
|
|
180
187
|
resolveCommitCountSince,
|
|
@@ -218,11 +225,11 @@ import {
|
|
|
218
225
|
validateActionableFields,
|
|
219
226
|
validateLesson,
|
|
220
227
|
validateSkillPath
|
|
221
|
-
} from "./index-
|
|
228
|
+
} from "./index-gxd8fwyt.js";
|
|
222
229
|
import {
|
|
223
230
|
authorizeCuration,
|
|
224
231
|
buildConfigFingerprintInput
|
|
225
|
-
} from "./index-
|
|
232
|
+
} from "./index-tb1k8jya.js";
|
|
226
233
|
import {
|
|
227
234
|
cohortConfigFingerprint
|
|
228
235
|
} from "./index-rtry5xyf.js";
|
|
@@ -253,12 +260,12 @@ import {
|
|
|
253
260
|
transitionTaskWorkflowEvidence,
|
|
254
261
|
withTaskEvidenceTransaction,
|
|
255
262
|
writeWorkflowWalFile
|
|
256
|
-
} from "./index-
|
|
263
|
+
} from "./index-7r9vpkwa.js";
|
|
257
264
|
import {
|
|
258
265
|
makeWorktreeBranchName,
|
|
259
266
|
provisionWorktree,
|
|
260
267
|
removeWorktree
|
|
261
|
-
} from "./index-
|
|
268
|
+
} from "./index-nzrhw31r.js";
|
|
262
269
|
import {
|
|
263
270
|
DEFAULT_STALE_DELEGATION_TIMEOUT_MS,
|
|
264
271
|
DELEGATION_COMPACTION_HIGH_WATER_BYTES,
|
|
@@ -273,7 +280,7 @@ import {
|
|
|
273
280
|
scanBackgroundCoderReservationsForAdmission,
|
|
274
281
|
scanDelegationsForRecovery,
|
|
275
282
|
sweepStaleDelegations
|
|
276
|
-
} from "./index-
|
|
283
|
+
} from "./index-12f1tsn2.js";
|
|
277
284
|
import {
|
|
278
285
|
compositeSessionKey,
|
|
279
286
|
sessionKeySuffix
|
|
@@ -323,7 +330,7 @@ import {
|
|
|
323
330
|
clearAllScopes,
|
|
324
331
|
clearScopeBindingFromDisk,
|
|
325
332
|
clearScopeBindings
|
|
326
|
-
} from "./index-
|
|
333
|
+
} from "./index-4jersar8.js";
|
|
327
334
|
import {
|
|
328
335
|
appendLedgerEvent,
|
|
329
336
|
computePlanHash,
|
|
@@ -338,7 +345,7 @@ import {
|
|
|
338
345
|
readPlanEpochIdentity,
|
|
339
346
|
replayFromLedgerWithStatus,
|
|
340
347
|
takeSnapshotEvent
|
|
341
|
-
} from "./index-
|
|
348
|
+
} from "./index-1z4jzwja.js";
|
|
342
349
|
import {
|
|
343
350
|
CORE_EVENT_LOCKED,
|
|
344
351
|
appendCoreEventSync,
|
|
@@ -348,7 +355,7 @@ import {
|
|
|
348
355
|
hasSpecDriftAuditEvent,
|
|
349
356
|
hasTaskRepairAuditEvent,
|
|
350
357
|
readCoreEvents
|
|
351
|
-
} from "./index-
|
|
358
|
+
} from "./index-93sepnc9.js";
|
|
352
359
|
import {
|
|
353
360
|
sanitizeDiagnosticText
|
|
354
361
|
} from "./index-556ja8an.js";
|
|
@@ -397,7 +404,7 @@ import {
|
|
|
397
404
|
transactFile,
|
|
398
405
|
transactKnowledge,
|
|
399
406
|
wordBigrams
|
|
400
|
-
} from "./index-
|
|
407
|
+
} from "./index-bm73pych.js";
|
|
401
408
|
import {
|
|
402
409
|
MAX_EVENT_LOG_ENTRIES,
|
|
403
410
|
_internals as _internals2,
|
|
@@ -413,10 +420,10 @@ import {
|
|
|
413
420
|
recordKnowledgeEvent,
|
|
414
421
|
recordPhaseCloseIntent,
|
|
415
422
|
resolveKnowledgeEventsPath
|
|
416
|
-
} from "./index-
|
|
423
|
+
} from "./index-zbpcpsk0.js";
|
|
417
424
|
import {
|
|
418
425
|
resolveWorktreeIsolationConfig
|
|
419
|
-
} from "./index-
|
|
426
|
+
} from "./index-t9rhtvy9.js";
|
|
420
427
|
import {
|
|
421
428
|
RetrospectiveEvidenceSchema
|
|
422
429
|
} from "./index-zg9d392c.js";
|
|
@@ -439,7 +446,7 @@ import {
|
|
|
439
446
|
init_loader,
|
|
440
447
|
loadPluginConfig,
|
|
441
448
|
loadPluginConfigWithMeta
|
|
442
|
-
} from "./index-
|
|
449
|
+
} from "./index-nhxaa9j5.js";
|
|
443
450
|
import {
|
|
444
451
|
DEFAULT_HARNESS_EVOLUTION_CONFIG,
|
|
445
452
|
DEFAULT_PR_REVIEW_RESILIENCE_CONFIG,
|
|
@@ -455,7 +462,7 @@ import {
|
|
|
455
462
|
package_default,
|
|
456
463
|
resolveAutoReviewConfig,
|
|
457
464
|
stripKnownSwarmPrefix
|
|
458
|
-
} from "./index-
|
|
465
|
+
} from "./index-td6n935w.js";
|
|
459
466
|
import {
|
|
460
467
|
init_git_executable,
|
|
461
468
|
resolveGitExecutable,
|
|
@@ -471,7 +478,7 @@ import {
|
|
|
471
478
|
observeCuratorCompliance,
|
|
472
479
|
observeStoreHealth,
|
|
473
480
|
readLearningHealth
|
|
474
|
-
} from "./index-
|
|
481
|
+
} from "./index-wdtckfnf.js";
|
|
475
482
|
import {
|
|
476
483
|
AGENT_TOOL_MAP,
|
|
477
484
|
ALL_AGENT_NAMES,
|
|
@@ -501,10 +508,10 @@ import {
|
|
|
501
508
|
resolveLinkDir,
|
|
502
509
|
sanitizeLinkId,
|
|
503
510
|
writeLinkPointer
|
|
504
|
-
} from "./index-
|
|
511
|
+
} from "./index-ynqp3jb6.js";
|
|
505
512
|
import {
|
|
506
513
|
atomicWriteFile
|
|
507
|
-
} from "./index-
|
|
514
|
+
} from "./index-70bfj3v1.js";
|
|
508
515
|
import {
|
|
509
516
|
KNOWLEDGE_SCHEMA_VERSION,
|
|
510
517
|
OUTCOME_BLOCK_THRESHOLD,
|
|
@@ -518,7 +525,7 @@ import {
|
|
|
518
525
|
listActiveLocks,
|
|
519
526
|
tryAcquireLock,
|
|
520
527
|
withEvidenceLock
|
|
521
|
-
} from "./index-
|
|
528
|
+
} from "./index-36nt17m8.js";
|
|
522
529
|
import {
|
|
523
530
|
atomicWriteSwarmFile,
|
|
524
531
|
atomicWriteSwarmFileSync,
|
|
@@ -529,7 +536,7 @@ import {
|
|
|
529
536
|
emit,
|
|
530
537
|
getLastHeartbeat,
|
|
531
538
|
telemetry
|
|
532
|
-
} from "./index-
|
|
539
|
+
} from "./index-1b1h770t.js";
|
|
533
540
|
import {
|
|
534
541
|
invalidateCachedArtifact,
|
|
535
542
|
resetSwarmArtifactCache
|
|
@@ -680,7 +687,8 @@ var _internals5 = {
|
|
|
680
687
|
getEffectiveGates,
|
|
681
688
|
computeProfileHash,
|
|
682
689
|
hasAnyProfileWithEnabledGate,
|
|
683
|
-
afterSetGatesRead: () => {}
|
|
690
|
+
afterSetGatesRead: () => {},
|
|
691
|
+
lastTxnSynchronous: -1
|
|
684
692
|
};
|
|
685
693
|
var DEFAULT_QA_GATES = {
|
|
686
694
|
reviewer: true,
|
|
@@ -713,8 +721,17 @@ function buildProfileIdentity(identity) {
|
|
|
713
721
|
};
|
|
714
722
|
}
|
|
715
723
|
function withImmediateTransaction(db, fn) {
|
|
724
|
+
applySynchronousForClass(db, DURABILITY_CLASSES.qa_gate_profile);
|
|
725
|
+
_internals5.lastTxnSynchronous = db.query("PRAGMA synchronous").get()?.synchronous ?? -1;
|
|
726
|
+
const restoreSynchronous = () => {
|
|
727
|
+
applySynchronousForClass(db, "normal");
|
|
728
|
+
};
|
|
716
729
|
if (db.inTransaction) {
|
|
717
|
-
|
|
730
|
+
try {
|
|
731
|
+
return db.transaction(fn)();
|
|
732
|
+
} finally {
|
|
733
|
+
restoreSynchronous();
|
|
734
|
+
}
|
|
718
735
|
}
|
|
719
736
|
db.run("BEGIN IMMEDIATE");
|
|
720
737
|
try {
|
|
@@ -726,9 +743,10 @@ function withImmediateTransaction(db, fn) {
|
|
|
726
743
|
db.run("ROLLBACK");
|
|
727
744
|
} catch {}
|
|
728
745
|
throw err;
|
|
746
|
+
} finally {
|
|
747
|
+
restoreSynchronous();
|
|
729
748
|
}
|
|
730
749
|
}
|
|
731
|
-
var qaGateProfileSavepointCounter = 0;
|
|
732
750
|
function rowToProfile(row) {
|
|
733
751
|
return rowToProfileWithBinding(row);
|
|
734
752
|
}
|
|
@@ -913,11 +931,10 @@ function getOrCreateProfile(directory, planId, projectType, initialGates = {}) {
|
|
|
913
931
|
}
|
|
914
932
|
}
|
|
915
933
|
const gatesJson = JSON.stringify(seededGates);
|
|
916
|
-
const insert = db.transaction(() => {
|
|
917
|
-
db.run("INSERT INTO qa_gate_profile (plan_id, project_type, gates) VALUES (?, ?, ?)", [planId, projectType ?? null, gatesJson]);
|
|
918
|
-
});
|
|
919
934
|
try {
|
|
920
|
-
|
|
935
|
+
withImmediateTransaction(db, () => {
|
|
936
|
+
db.run("INSERT INTO qa_gate_profile (plan_id, project_type, gates) VALUES (?, ?, ?)", [planId, projectType ?? null, gatesJson]);
|
|
937
|
+
});
|
|
921
938
|
} catch (err) {
|
|
922
939
|
const msg = err instanceof Error ? err.message : String(err);
|
|
923
940
|
if (!msg.toLowerCase().includes("unique")) {
|
|
@@ -938,18 +955,12 @@ function getOrCreateProfileForIdentity(directory, identity, projectType, initial
|
|
|
938
955
|
if (lookup.kind === "bound") {
|
|
939
956
|
return lookup.profile;
|
|
940
957
|
}
|
|
941
|
-
if (lookup.kind === "unbound_legacy") {
|
|
942
|
-
return createExactProfileTx(db, exact, projectType, initialGates);
|
|
943
|
-
}
|
|
944
958
|
return createExactProfileTx(db, exact, projectType, initialGates);
|
|
945
959
|
});
|
|
946
960
|
}
|
|
947
961
|
function setGates(directory, planId, gates) {
|
|
948
962
|
const db = getProjectDb(directory);
|
|
949
|
-
|
|
950
|
-
const startedTransaction = !db.inTransaction;
|
|
951
|
-
db.run(startedTransaction ? "BEGIN IMMEDIATE" : `SAVEPOINT ${savepointName}`);
|
|
952
|
-
try {
|
|
963
|
+
return withImmediateTransaction(db, () => {
|
|
953
964
|
const currentRow = db.query("SELECT * FROM qa_gate_profile WHERE plan_id = ?").get(planId);
|
|
954
965
|
if (!currentRow) {
|
|
955
966
|
throw new Error(`No QA gate profile found for plan_id=${planId} \u2014 call getOrCreateProfile first`);
|
|
@@ -979,39 +990,16 @@ function setGates(directory, planId, gates) {
|
|
|
979
990
|
if (!updatedRow) {
|
|
980
991
|
throw new Error(`Failed to re-read QA gate profile after update for plan_id=${planId}`);
|
|
981
992
|
}
|
|
982
|
-
db.run(startedTransaction ? "COMMIT" : `RELEASE ${savepointName}`);
|
|
983
993
|
return rowToProfile(updatedRow);
|
|
984
|
-
}
|
|
985
|
-
try {
|
|
986
|
-
db.run(startedTransaction ? "ROLLBACK" : `ROLLBACK TO ${savepointName}`);
|
|
987
|
-
if (!startedTransaction) {
|
|
988
|
-
db.run(`RELEASE ${savepointName}`);
|
|
989
|
-
}
|
|
990
|
-
} catch {}
|
|
991
|
-
throw err;
|
|
992
|
-
}
|
|
994
|
+
});
|
|
993
995
|
}
|
|
994
996
|
function setGatesForIdentity(directory, identity, gates, options = {}) {
|
|
995
997
|
const db = getProjectDb(directory);
|
|
996
998
|
const exact = buildProfileIdentity(identity);
|
|
997
|
-
|
|
998
|
-
const startedTransaction = !db.inTransaction;
|
|
999
|
-
const finishTransaction = () => {
|
|
1000
|
-
db.run(startedTransaction ? "COMMIT" : `RELEASE ${savepointName}`);
|
|
1001
|
-
};
|
|
1002
|
-
const rollbackTransaction = () => {
|
|
1003
|
-
db.run(startedTransaction ? "ROLLBACK" : `ROLLBACK TO ${savepointName}`);
|
|
1004
|
-
if (!startedTransaction) {
|
|
1005
|
-
db.run(`RELEASE ${savepointName}`);
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
db.run(startedTransaction ? "BEGIN IMMEDIATE" : `SAVEPOINT ${savepointName}`);
|
|
1009
|
-
try {
|
|
999
|
+
return withImmediateTransaction(db, () => {
|
|
1010
1000
|
let lookup = lookupProfileForIdentityTx(db, exact);
|
|
1011
1001
|
if (lookup.kind === "missing") {
|
|
1012
|
-
|
|
1013
|
-
finishTransaction();
|
|
1014
|
-
return created;
|
|
1002
|
+
return createExactProfileTx(db, exact, options.projectType, gates);
|
|
1015
1003
|
}
|
|
1016
1004
|
if (lookup.kind === "unbound_legacy") {
|
|
1017
1005
|
if (shouldAdoptLegacyProfile(exact, options)) {
|
|
@@ -1021,9 +1009,7 @@ function setGatesForIdentity(directory, identity, gates, options = {}) {
|
|
|
1021
1009
|
throw new Error(`Failed to adopt legacy QA gate profile for exact identity plan_id=${exact.planId}`);
|
|
1022
1010
|
}
|
|
1023
1011
|
} else if (options.allowLegacyCollisionCreate === true) {
|
|
1024
|
-
|
|
1025
|
-
finishTransaction();
|
|
1026
|
-
return created;
|
|
1012
|
+
return createExactProfileTx(db, exact, options.projectType, gates);
|
|
1027
1013
|
} else {
|
|
1028
1014
|
throw new QaGateProfileIdentityUnboundError(lookup.identity);
|
|
1029
1015
|
}
|
|
@@ -1041,7 +1027,6 @@ function setGatesForIdentity(directory, identity, gates, options = {}) {
|
|
|
1041
1027
|
});
|
|
1042
1028
|
if (current.locked_at !== null) {
|
|
1043
1029
|
if (!hasAnyGatePatch(gates)) {
|
|
1044
|
-
finishTransaction();
|
|
1045
1030
|
return current;
|
|
1046
1031
|
}
|
|
1047
1032
|
throw new Error("Cannot modify gates: QA gate profile is locked after critic approval");
|
|
@@ -1067,14 +1052,8 @@ function setGatesForIdentity(directory, identity, gates, options = {}) {
|
|
|
1067
1052
|
if (!updatedRow || !binding) {
|
|
1068
1053
|
throw new Error(`Failed to re-read QA gate profile after exact-identity update for plan_id=${exact.planId}`);
|
|
1069
1054
|
}
|
|
1070
|
-
finishTransaction();
|
|
1071
1055
|
return rowToProfileWithBinding(updatedRow, binding);
|
|
1072
|
-
}
|
|
1073
|
-
try {
|
|
1074
|
-
rollbackTransaction();
|
|
1075
|
-
} catch {}
|
|
1076
|
-
throw err;
|
|
1077
|
-
}
|
|
1056
|
+
});
|
|
1078
1057
|
}
|
|
1079
1058
|
function lockProfileForIdentity(directory, identity, snapshotSeq) {
|
|
1080
1059
|
const db = getProjectDb(directory);
|
|
@@ -2779,10 +2758,140 @@ function detectPatterns(trajectory, config, lastProcessedStep = 0) {
|
|
|
2779
2758
|
}
|
|
2780
2759
|
// src/hooks/micro-reflector.ts
|
|
2781
2760
|
init_schema();
|
|
2782
|
-
import { existsSync as
|
|
2783
|
-
import { readFile as readFile2
|
|
2761
|
+
import { existsSync as existsSync6 } from "fs";
|
|
2762
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
2784
2763
|
import * as path7 from "path";
|
|
2785
2764
|
|
|
2765
|
+
// src/db/insight-candidate-store.ts
|
|
2766
|
+
import { existsSync } from "fs";
|
|
2767
|
+
import { join } from "path";
|
|
2768
|
+
var INSIGHT_CANDIDATE_STREAM_ID = "insight-candidates";
|
|
2769
|
+
var INSIGHT_CANDIDATES_LEGACY_FILE = "insight-candidates.jsonl";
|
|
2770
|
+
var INSIGHT_PENDING_CAP = 500;
|
|
2771
|
+
var INSIGHT_CONSUMED_RETENTION_DAYS = 7;
|
|
2772
|
+
var importedRoots = new Set;
|
|
2773
|
+
function hasAnyInsightState(directory) {
|
|
2774
|
+
if (projectDbExists(directory))
|
|
2775
|
+
return true;
|
|
2776
|
+
try {
|
|
2777
|
+
return existsSync(join(canonicalProjectKey(directory), ".swarm", INSIGHT_CANDIDATES_LEGACY_FILE));
|
|
2778
|
+
} catch {
|
|
2779
|
+
return false;
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
function ensureInsightLegacyImported(directory) {
|
|
2783
|
+
const root = canonicalProjectKey(directory);
|
|
2784
|
+
if (importedRoots.has(root))
|
|
2785
|
+
return;
|
|
2786
|
+
importLegacyJsonl(directory, {
|
|
2787
|
+
fileName: INSIGHT_CANDIDATES_LEGACY_FILE,
|
|
2788
|
+
streamCount: (db) => db.query("SELECT COUNT(*) as count FROM insight_candidate WHERE stream_id = ?").get(INSIGHT_CANDIDATE_STREAM_ID)?.count ?? 0,
|
|
2789
|
+
insertRow: (db, version, payload) => {
|
|
2790
|
+
let createdAt = new Date().toISOString();
|
|
2791
|
+
try {
|
|
2792
|
+
const parsed = JSON.parse(payload);
|
|
2793
|
+
if (typeof parsed.created_at === "string")
|
|
2794
|
+
createdAt = parsed.created_at;
|
|
2795
|
+
} catch {}
|
|
2796
|
+
db.run("INSERT INTO insight_candidate (stream_id, version, payload, created_at) VALUES (?, ?, ?, ?)", [INSIGHT_CANDIDATE_STREAM_ID, version, payload, createdAt]);
|
|
2797
|
+
},
|
|
2798
|
+
parseLine: (line) => {
|
|
2799
|
+
try {
|
|
2800
|
+
JSON.parse(line);
|
|
2801
|
+
return line;
|
|
2802
|
+
} catch {
|
|
2803
|
+
return null;
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
});
|
|
2807
|
+
importedRoots.add(root);
|
|
2808
|
+
}
|
|
2809
|
+
async function appendInsightCandidatesDb(directory, rows) {
|
|
2810
|
+
if (rows.length === 0)
|
|
2811
|
+
return;
|
|
2812
|
+
ensureInsightLegacyImported(directory);
|
|
2813
|
+
const writer = getGroupCommitWriter(directory);
|
|
2814
|
+
writer.enqueue({
|
|
2815
|
+
durability: DURABILITY_CLASSES.insight_candidate,
|
|
2816
|
+
run: (db) => {
|
|
2817
|
+
const next = db.query("SELECT MAX(version) as max FROM insight_candidate WHERE stream_id = ?").get(INSIGHT_CANDIDATE_STREAM_ID)?.max ?? 0;
|
|
2818
|
+
let version = next;
|
|
2819
|
+
for (const row of rows) {
|
|
2820
|
+
version += 1;
|
|
2821
|
+
db.run("INSERT INTO insight_candidate (stream_id, version, payload, created_at) VALUES (?, ?, ?, ?)", [INSIGHT_CANDIDATE_STREAM_ID, version, row.payload, row.createdAt]);
|
|
2822
|
+
}
|
|
2823
|
+
db.run(`DELETE FROM insight_candidate
|
|
2824
|
+
WHERE stream_id = ?
|
|
2825
|
+
AND consumed_at IS NULL
|
|
2826
|
+
AND version < (
|
|
2827
|
+
SELECT MIN(version) FROM (
|
|
2828
|
+
SELECT version FROM insight_candidate
|
|
2829
|
+
WHERE stream_id = ? AND consumed_at IS NULL
|
|
2830
|
+
ORDER BY version DESC
|
|
2831
|
+
LIMIT ${INSIGHT_PENDING_CAP}
|
|
2832
|
+
)
|
|
2833
|
+
)`, [INSIGHT_CANDIDATE_STREAM_ID, INSIGHT_CANDIDATE_STREAM_ID]);
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
await writer.flush();
|
|
2837
|
+
}
|
|
2838
|
+
function consumeInsightCandidatesDb(directory, limit) {
|
|
2839
|
+
if (!hasAnyInsightState(directory))
|
|
2840
|
+
return [];
|
|
2841
|
+
ensureInsightLegacyImported(directory);
|
|
2842
|
+
const db = getProjectDb(directory);
|
|
2843
|
+
const payloads = [];
|
|
2844
|
+
db.run("BEGIN IMMEDIATE");
|
|
2845
|
+
try {
|
|
2846
|
+
const rows = db.query(`SELECT payload FROM insight_candidate
|
|
2847
|
+
WHERE stream_id = ? AND consumed_at IS NULL
|
|
2848
|
+
ORDER BY version
|
|
2849
|
+
LIMIT ?`).all(INSIGHT_CANDIDATE_STREAM_ID, limit);
|
|
2850
|
+
if (rows.length > 0) {
|
|
2851
|
+
db.run(`UPDATE insight_candidate
|
|
2852
|
+
SET consumed_at = datetime('now')
|
|
2853
|
+
WHERE stream_id = ?
|
|
2854
|
+
AND consumed_at IS NULL
|
|
2855
|
+
AND version IN (
|
|
2856
|
+
SELECT version FROM insight_candidate
|
|
2857
|
+
WHERE stream_id = ? AND consumed_at IS NULL
|
|
2858
|
+
ORDER BY version
|
|
2859
|
+
LIMIT ?
|
|
2860
|
+
)`, [INSIGHT_CANDIDATE_STREAM_ID, INSIGHT_CANDIDATE_STREAM_ID, rows.length]);
|
|
2861
|
+
}
|
|
2862
|
+
db.run(`DELETE FROM insight_candidate
|
|
2863
|
+
WHERE consumed_at IS NOT NULL
|
|
2864
|
+
AND consumed_at < datetime('now', '-${INSIGHT_CONSUMED_RETENTION_DAYS} days')`);
|
|
2865
|
+
db.run("COMMIT");
|
|
2866
|
+
for (const row of rows) {
|
|
2867
|
+
payloads.push(row.payload);
|
|
2868
|
+
}
|
|
2869
|
+
} catch (err) {
|
|
2870
|
+
try {
|
|
2871
|
+
db.run("ROLLBACK");
|
|
2872
|
+
} catch {}
|
|
2873
|
+
throw err;
|
|
2874
|
+
}
|
|
2875
|
+
return payloads;
|
|
2876
|
+
}
|
|
2877
|
+
function countPendingInsightCandidatesDb(directory) {
|
|
2878
|
+
if (!hasAnyInsightState(directory))
|
|
2879
|
+
return 0;
|
|
2880
|
+
ensureInsightLegacyImported(directory);
|
|
2881
|
+
const db = getProjectDb(directory);
|
|
2882
|
+
return db.query("SELECT COUNT(*) as count FROM insight_candidate WHERE stream_id = ? AND consumed_at IS NULL").get(INSIGHT_CANDIDATE_STREAM_ID)?.count ?? 0;
|
|
2883
|
+
}
|
|
2884
|
+
function listPendingInsightCandidatesDb(directory, max) {
|
|
2885
|
+
if (!hasAnyInsightState(directory))
|
|
2886
|
+
return [];
|
|
2887
|
+
ensureInsightLegacyImported(directory);
|
|
2888
|
+
const db = getProjectDb(directory);
|
|
2889
|
+
return db.query(`SELECT payload FROM insight_candidate
|
|
2890
|
+
WHERE stream_id = ? AND consumed_at IS NULL
|
|
2891
|
+
ORDER BY version
|
|
2892
|
+
LIMIT ?`).all(INSIGHT_CANDIDATE_STREAM_ID, max).map((row) => row.payload);
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2786
2895
|
// src/learning/candidate-queue.ts
|
|
2787
2896
|
var MAX_TRACKED_SESSIONS2 = 500;
|
|
2788
2897
|
var queuesBySession = new Map;
|
|
@@ -2845,7 +2954,7 @@ function resetSessionQueue(sessionID) {
|
|
|
2845
2954
|
|
|
2846
2955
|
// src/services/skill-improver-quota.ts
|
|
2847
2956
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
2848
|
-
import { existsSync } from "fs";
|
|
2957
|
+
import { existsSync as existsSync2 } from "fs";
|
|
2849
2958
|
import { mkdir, readFile, rename, writeFile } from "fs/promises";
|
|
2850
2959
|
import * as path2 from "path";
|
|
2851
2960
|
var LOCK_ACQUIRE_TIMEOUT_MS = 1e4;
|
|
@@ -2888,7 +2997,7 @@ function todayKey(window, now = new Date) {
|
|
|
2888
2997
|
return `${yr}-${m}-${d}`;
|
|
2889
2998
|
}
|
|
2890
2999
|
async function readState(filePath) {
|
|
2891
|
-
if (!
|
|
3000
|
+
if (!existsSync2(filePath))
|
|
2892
3001
|
return null;
|
|
2893
3002
|
try {
|
|
2894
3003
|
const raw = await readFile(filePath, "utf-8");
|
|
@@ -5986,7 +6095,7 @@ async function readTaskTrajectory(directory, taskId) {
|
|
|
5986
6095
|
try {
|
|
5987
6096
|
const rel = path7.join("evidence", sanitizeTaskId(taskId), "trajectory.jsonl");
|
|
5988
6097
|
const filePath = validateSwarmPath(directory, rel);
|
|
5989
|
-
if (!
|
|
6098
|
+
if (!existsSync6(filePath))
|
|
5990
6099
|
return [];
|
|
5991
6100
|
const content = await readFile2(filePath, "utf-8");
|
|
5992
6101
|
const out = [];
|
|
@@ -6004,43 +6113,13 @@ async function readTaskTrajectory(directory, taskId) {
|
|
|
6004
6113
|
return [];
|
|
6005
6114
|
}
|
|
6006
6115
|
}
|
|
6007
|
-
var INSIGHT_CANDIDATES_MAX_ENTRIES = 500;
|
|
6008
6116
|
async function appendInsightCandidates(directory, candidates) {
|
|
6009
6117
|
if (candidates.length === 0)
|
|
6010
6118
|
return;
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
return readInsightJsonl(content);
|
|
6016
|
-
} catch (err) {
|
|
6017
|
-
if (err?.code === "ENOENT")
|
|
6018
|
-
return [];
|
|
6019
|
-
throw err;
|
|
6020
|
-
}
|
|
6021
|
-
}, async (p, data) => {
|
|
6022
|
-
const body = data.length === 0 ? "" : `${data.map((c) => JSON.stringify(c)).join(`
|
|
6023
|
-
`)}
|
|
6024
|
-
`;
|
|
6025
|
-
await writeFile2(p, body, "utf-8");
|
|
6026
|
-
}, (all) => {
|
|
6027
|
-
const merged = [...all, ...candidates];
|
|
6028
|
-
const capped = merged.length > INSIGHT_CANDIDATES_MAX_ENTRIES ? merged.slice(-INSIGHT_CANDIDATES_MAX_ENTRIES) : merged;
|
|
6029
|
-
return capped;
|
|
6030
|
-
});
|
|
6031
|
-
}
|
|
6032
|
-
function readInsightJsonl(content) {
|
|
6033
|
-
const out = [];
|
|
6034
|
-
for (const line of content.split(`
|
|
6035
|
-
`)) {
|
|
6036
|
-
const t = line.trim();
|
|
6037
|
-
if (!t)
|
|
6038
|
-
continue;
|
|
6039
|
-
try {
|
|
6040
|
-
out.push(JSON.parse(t));
|
|
6041
|
-
} catch {}
|
|
6042
|
-
}
|
|
6043
|
-
return out;
|
|
6119
|
+
await appendInsightCandidatesDb(directory, candidates.map((candidate) => ({
|
|
6120
|
+
payload: JSON.stringify(candidate),
|
|
6121
|
+
createdAt: candidate.created_at
|
|
6122
|
+
})));
|
|
6044
6123
|
}
|
|
6045
6124
|
|
|
6046
6125
|
// src/learning/prm-pattern-support.ts
|
|
@@ -8314,7 +8393,7 @@ ${trimmed}`;
|
|
|
8314
8393
|
init_zod();
|
|
8315
8394
|
import { createHash as createHash5 } from "crypto";
|
|
8316
8395
|
import {
|
|
8317
|
-
existsSync as
|
|
8396
|
+
existsSync as existsSync7,
|
|
8318
8397
|
mkdirSync as mkdirSync4,
|
|
8319
8398
|
readFileSync as readFileSync4,
|
|
8320
8399
|
renameSync as renameSync3,
|
|
@@ -8355,7 +8434,7 @@ function readLaneOutput(directory, ref) {
|
|
|
8355
8434
|
if (!REF_RE.test(ref))
|
|
8356
8435
|
return null;
|
|
8357
8436
|
const absPath = validateSwarmPath(directory, laneOutputRelativePath(ref));
|
|
8358
|
-
if (!
|
|
8437
|
+
if (!existsSync7(absPath))
|
|
8359
8438
|
return null;
|
|
8360
8439
|
let parsed;
|
|
8361
8440
|
try {
|
|
@@ -11042,9 +11121,9 @@ async function checkPublicationIdentity(directory, state, active) {
|
|
|
11042
11121
|
function publicationEvidenceJoinIntact(state, active) {
|
|
11043
11122
|
if (state.prFeedbackStageA?.validatedAt !== active.evidence.stageAValidatedAt)
|
|
11044
11123
|
return false;
|
|
11045
|
-
for (const
|
|
11046
|
-
const batch = [...state.prFeedbackGateBatches ?? []].reverse().find((candidate) => candidate.phase ===
|
|
11047
|
-
if (!batch || batch.batchId !==
|
|
11124
|
+
for (const join13 of active.evidence.batches) {
|
|
11125
|
+
const batch = [...state.prFeedbackGateBatches ?? []].reverse().find((candidate) => candidate.phase === join13.phase);
|
|
11126
|
+
if (!batch || batch.batchId !== join13.batchId || batch.laneId !== join13.laneId)
|
|
11048
11127
|
return false;
|
|
11049
11128
|
}
|
|
11050
11129
|
return true;
|
|
@@ -14394,7 +14473,7 @@ ${USAGE2}`;
|
|
|
14394
14473
|
// src/security/write-authority.ts
|
|
14395
14474
|
import { AsyncLocalStorage } from "async_hooks";
|
|
14396
14475
|
import { createHash as createHash11, randomUUID as randomUUID3 } from "crypto";
|
|
14397
|
-
import { existsSync as
|
|
14476
|
+
import { existsSync as existsSync8, readFileSync as readFileSync6 } from "fs";
|
|
14398
14477
|
import * as path14 from "path";
|
|
14399
14478
|
var DEFAULT_TTL_MS = 30 * 60 * 1000;
|
|
14400
14479
|
var MAX_LEDGER_ENTRIES = 512;
|
|
@@ -14436,7 +14515,7 @@ function stableSerialize(value) {
|
|
|
14436
14515
|
return JSON.stringify(value);
|
|
14437
14516
|
}
|
|
14438
14517
|
function ledgerRead(filePath) {
|
|
14439
|
-
if (!
|
|
14518
|
+
if (!existsSync8(filePath))
|
|
14440
14519
|
return Promise.resolve([]);
|
|
14441
14520
|
const entries = [];
|
|
14442
14521
|
for (const line of readFileSync6(filePath, "utf8").split(`
|
|
@@ -19342,7 +19421,7 @@ function createCuratorLLMDelegate(directory, mode = "init", sessionId) {
|
|
|
19342
19421
|
}
|
|
19343
19422
|
|
|
19344
19423
|
// src/hooks/curator-postmortem.ts
|
|
19345
|
-
import { existsSync as
|
|
19424
|
+
import { existsSync as existsSync15, readdirSync as readdirSync3, readFileSync as readFileSync13 } from "fs";
|
|
19346
19425
|
import * as path26 from "path";
|
|
19347
19426
|
|
|
19348
19427
|
// src/hooks/curator.ts
|
|
@@ -20127,7 +20206,7 @@ var _internals24 = {
|
|
|
20127
20206
|
};
|
|
20128
20207
|
|
|
20129
20208
|
// src/services/skill-optimizer/promoted-external-staleness.ts
|
|
20130
|
-
import { existsSync as
|
|
20209
|
+
import { existsSync as existsSync13, readFileSync as readFileSync11 } from "fs";
|
|
20131
20210
|
import * as path23 from "path";
|
|
20132
20211
|
function parsePromotedExternalFrontmatter(content) {
|
|
20133
20212
|
const match = /^---\n([\s\S]*?)\n---/.exec(content);
|
|
@@ -20164,7 +20243,7 @@ function parsePromotedExternalFrontmatter(content) {
|
|
|
20164
20243
|
return { origin, sourceKnowledgeIds, promotedAt };
|
|
20165
20244
|
}
|
|
20166
20245
|
function readPromotedExternalFrontmatter(skillPath) {
|
|
20167
|
-
if (!
|
|
20246
|
+
if (!existsSync13(skillPath))
|
|
20168
20247
|
return {};
|
|
20169
20248
|
const content = readFileSync11(skillPath, "utf8");
|
|
20170
20249
|
return parsePromotedExternalFrontmatter(content);
|
|
@@ -20199,7 +20278,7 @@ function evaluatePromotedExternalStaleness(input) {
|
|
|
20199
20278
|
}
|
|
20200
20279
|
function buildPromotedExternalInputFromSkill(directory, skillSlug, usage, ageDays, retirementMinAgeDays) {
|
|
20201
20280
|
const skillPath = path23.join(directory, ".opencode", "skills", "generated", skillSlug, "SKILL.md");
|
|
20202
|
-
if (!
|
|
20281
|
+
if (!existsSync13(skillPath))
|
|
20203
20282
|
return null;
|
|
20204
20283
|
const fm = readPromotedExternalFrontmatter(skillPath);
|
|
20205
20284
|
if (fm.origin !== "promoted_external")
|
|
@@ -20217,7 +20296,7 @@ function buildPromotedExternalInputFromSkill(directory, skillSlug, usage, ageDay
|
|
|
20217
20296
|
|
|
20218
20297
|
// src/services/skill-reviser.ts
|
|
20219
20298
|
init_logger();
|
|
20220
|
-
import { readFile as readFile7, rename as rename3, writeFile as
|
|
20299
|
+
import { readFile as readFile7, rename as rename3, writeFile as writeFile3 } from "fs/promises";
|
|
20221
20300
|
var REVISION_VIOLATION_THRESHOLD = 0.15;
|
|
20222
20301
|
var MAX_REVISION_CALLS_PER_PHASE = 3;
|
|
20223
20302
|
var DEFAULT_MAX_CALLS = 10;
|
|
@@ -20360,7 +20439,7 @@ async function reviseSkill(params) {
|
|
|
20360
20439
|
};
|
|
20361
20440
|
}
|
|
20362
20441
|
const tmpPath = `${params.skillPath}.tmp-${process.pid}-${Date.now()}`;
|
|
20363
|
-
await
|
|
20442
|
+
await writeFile3(tmpPath, revised, "utf-8");
|
|
20364
20443
|
await rename3(tmpPath, params.skillPath);
|
|
20365
20444
|
const newVersion = params.currentVersion + 1;
|
|
20366
20445
|
const entry = {
|
|
@@ -20437,7 +20516,7 @@ async function reviseSkill(params) {
|
|
|
20437
20516
|
};
|
|
20438
20517
|
}
|
|
20439
20518
|
const tmpPath = `${params.skillPath}.tmp-${process.pid}-${Date.now()}`;
|
|
20440
|
-
await
|
|
20519
|
+
await writeFile3(tmpPath, `${finalOutput}
|
|
20441
20520
|
`, "utf-8");
|
|
20442
20521
|
await rename3(tmpPath, params.skillPath);
|
|
20443
20522
|
const newVersion = expectedVersion;
|
|
@@ -20856,7 +20935,7 @@ function planMerges(active, threshold, maxComparisons, maxMerges) {
|
|
|
20856
20935
|
};
|
|
20857
20936
|
}
|
|
20858
20937
|
async function sweepActiveNearDuplicates(directory, options = {}) {
|
|
20859
|
-
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-
|
|
20938
|
+
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-v3a9rmyh.js");
|
|
20860
20939
|
const { config } = loadPluginConfigWithMeta2(directory);
|
|
20861
20940
|
const sweepConfig = config.learning?.dedup_sweep;
|
|
20862
20941
|
if (sweepConfig?.enabled === false)
|
|
@@ -21993,7 +22072,7 @@ async function runCuratorPhase(directory, phase, agentsDispatched, config, knowl
|
|
|
21993
22072
|
}
|
|
21994
22073
|
if (config.skill_generation_enabled === true && skillCandidates.length > 0) {
|
|
21995
22074
|
try {
|
|
21996
|
-
const skillModule = await import("./skill-generator-
|
|
22075
|
+
const skillModule = await import("./skill-generator-sxxf7jbb.js");
|
|
21997
22076
|
for (const cand of skillCandidates) {
|
|
21998
22077
|
if (cand.confidence < (config.min_skill_confidence ?? DEFAULT_SKILL_MIN_CONFIDENCE)) {
|
|
21999
22078
|
continue;
|
|
@@ -22465,7 +22544,7 @@ async function applyCuratorKnowledgeUpdates(directory, recommendations, knowledg
|
|
|
22465
22544
|
} catch {}
|
|
22466
22545
|
}
|
|
22467
22546
|
if (contradictedEntries.length > 0 && knowledgeConfig.contradiction_threshold_action === "quarantine") {
|
|
22468
|
-
const { maybeQuarantineOnContradiction } = await import("./knowledge-escalator-
|
|
22547
|
+
const { maybeQuarantineOnContradiction } = await import("./knowledge-escalator-sttdnwf8.js");
|
|
22469
22548
|
for (const { id } of contradictedEntries) {
|
|
22470
22549
|
try {
|
|
22471
22550
|
await maybeQuarantineOnContradiction(directory, id, knowledgeConfig.contradiction_quarantine_threshold, knowledgeConfig.contradiction_quarantine_window_days);
|
|
@@ -22997,7 +23076,7 @@ async function repairPostMortemActions(llmOutput, diagnostics, options) {
|
|
|
22997
23076
|
}
|
|
22998
23077
|
function readJsonlFile(filePath, maxLines) {
|
|
22999
23078
|
try {
|
|
23000
|
-
if (!
|
|
23079
|
+
if (!existsSync15(filePath))
|
|
23001
23080
|
return [];
|
|
23002
23081
|
const content = readFileSync13(filePath, "utf-8");
|
|
23003
23082
|
const results = [];
|
|
@@ -23021,12 +23100,12 @@ function collectRetrospectives(directory) {
|
|
|
23021
23100
|
const results = [];
|
|
23022
23101
|
const evidenceDir = path26.join(directory, ".swarm", "evidence");
|
|
23023
23102
|
try {
|
|
23024
|
-
if (!
|
|
23103
|
+
if (!existsSync15(evidenceDir))
|
|
23025
23104
|
return results;
|
|
23026
23105
|
const retroDirs = readdirSync3(evidenceDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("retro-")).slice(0, MAX_RETROSPECTIVES);
|
|
23027
23106
|
for (const entry of retroDirs) {
|
|
23028
23107
|
const retroPath = path26.join(evidenceDir, entry.name, "evidence.json");
|
|
23029
|
-
if (
|
|
23108
|
+
if (existsSync15(retroPath)) {
|
|
23030
23109
|
try {
|
|
23031
23110
|
results.push(readFileSync13(retroPath, "utf-8"));
|
|
23032
23111
|
} catch {}
|
|
@@ -23045,8 +23124,21 @@ async function collectDriftReports(directory) {
|
|
|
23045
23124
|
}
|
|
23046
23125
|
function collectPendingProposals(directory) {
|
|
23047
23126
|
const results = [];
|
|
23127
|
+
try {
|
|
23128
|
+
if (projectDbExists(directory)) {
|
|
23129
|
+
const pending = listPendingInsightCandidatesDb(directory, MAX_PROPOSALS);
|
|
23130
|
+
if (pending.length > 0) {
|
|
23131
|
+
results.push({
|
|
23132
|
+
source: "insight-candidates",
|
|
23133
|
+
content: pending.join(`
|
|
23134
|
+
`)
|
|
23135
|
+
});
|
|
23136
|
+
}
|
|
23137
|
+
return results;
|
|
23138
|
+
}
|
|
23139
|
+
} catch {}
|
|
23048
23140
|
const insightPath = path26.join(directory, ".swarm", "insight-candidates.jsonl");
|
|
23049
|
-
if (
|
|
23141
|
+
if (existsSync15(insightPath)) {
|
|
23050
23142
|
try {
|
|
23051
23143
|
results.push({
|
|
23052
23144
|
source: "insight-candidates",
|
|
@@ -23056,7 +23148,7 @@ function collectPendingProposals(directory) {
|
|
|
23056
23148
|
}
|
|
23057
23149
|
const proposalsDir = path26.join(directory, ".swarm", "skills", "proposals");
|
|
23058
23150
|
try {
|
|
23059
|
-
if (
|
|
23151
|
+
if (existsSync15(proposalsDir)) {
|
|
23060
23152
|
const proposalFiles = readdirSync3(proposalsDir).filter((e) => e.endsWith(".md") || e.endsWith(".json")).slice(0, MAX_PROPOSALS);
|
|
23061
23153
|
for (const entry of proposalFiles) {
|
|
23062
23154
|
try {
|
|
@@ -23072,7 +23164,7 @@ function collectPendingProposals(directory) {
|
|
|
23072
23164
|
}
|
|
23073
23165
|
function isReportValid(reportPath) {
|
|
23074
23166
|
try {
|
|
23075
|
-
if (!
|
|
23167
|
+
if (!existsSync15(reportPath))
|
|
23076
23168
|
return false;
|
|
23077
23169
|
const content = readFileSync13(reportPath, "utf-8").trim();
|
|
23078
23170
|
if (content.length === 0)
|
|
@@ -23284,7 +23376,7 @@ async function runCuratorPostMortem(directory, options = {}) {
|
|
|
23284
23376
|
warnings.push("Failed to collect knowledge summary.");
|
|
23285
23377
|
}
|
|
23286
23378
|
try {
|
|
23287
|
-
const { getScanStatus } = await import("./scan-cursor-
|
|
23379
|
+
const { getScanStatus } = await import("./scan-cursor-5frvp7nb.js");
|
|
23288
23380
|
const scanStatus = await getScanStatus(directory);
|
|
23289
23381
|
if (scanStatus.remaining_estimate > 0) {
|
|
23290
23382
|
warnings.push(`Fair scan: reviewed ${knowledgeSummary.length} entries this sweep (generation ${scanStatus.generation}); ${scanStatus.remaining_estimate} more eligible entries will be visited in future curation sweeps.`);
|
|
@@ -23456,9 +23548,9 @@ var _internals27 = {
|
|
|
23456
23548
|
verifyPostMortemKnowledgeActions,
|
|
23457
23549
|
repairPostMortemActions,
|
|
23458
23550
|
loadDefaultKnowledgeConfig: async (directory) => {
|
|
23459
|
-
const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-
|
|
23551
|
+
const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-9xkt5hvd.js");
|
|
23460
23552
|
try {
|
|
23461
|
-
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-
|
|
23553
|
+
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-v3a9rmyh.js");
|
|
23462
23554
|
const loaded = loadPluginConfigWithMeta2(directory);
|
|
23463
23555
|
return KnowledgeConfigSchema2.parse(loaded.config.knowledge ?? {});
|
|
23464
23556
|
} catch {
|
|
@@ -23466,11 +23558,11 @@ var _internals27 = {
|
|
|
23466
23558
|
}
|
|
23467
23559
|
},
|
|
23468
23560
|
applyCuratorKnowledgeUpdates: async (directory, recommendations, knowledgeConfig, generation) => {
|
|
23469
|
-
const { applyCuratorKnowledgeUpdates: applyCuratorKnowledgeUpdates2 } = await import("./curator-
|
|
23561
|
+
const { applyCuratorKnowledgeUpdates: applyCuratorKnowledgeUpdates2 } = await import("./curator-4pckmmyf.js");
|
|
23470
23562
|
return applyCuratorKnowledgeUpdates2(directory, recommendations, knowledgeConfig, generation);
|
|
23471
23563
|
},
|
|
23472
23564
|
checkHivePromotions: async (entries, knowledgeConfig, directory) => {
|
|
23473
|
-
const { checkHivePromotions } = await import("./hive-promoter-
|
|
23565
|
+
const { checkHivePromotions } = await import("./hive-promoter-s80g1gwb.js");
|
|
23474
23566
|
return checkHivePromotions(entries, knowledgeConfig, directory);
|
|
23475
23567
|
},
|
|
23476
23568
|
applyProposalTriage: async (directory, triage) => {
|
|
@@ -23479,7 +23571,7 @@ var _internals27 = {
|
|
|
23479
23571
|
activateProposal,
|
|
23480
23572
|
listSkills: listSkills2,
|
|
23481
23573
|
sanitizeSlug
|
|
23482
|
-
} = await import("./skill-generator-
|
|
23574
|
+
} = await import("./skill-generator-sxxf7jbb.js");
|
|
23483
23575
|
const result = {
|
|
23484
23576
|
approved: [],
|
|
23485
23577
|
rejected: [],
|
|
@@ -23521,7 +23613,7 @@ var _internals27 = {
|
|
|
23521
23613
|
return result;
|
|
23522
23614
|
},
|
|
23523
23615
|
readPriorDriftReports: async (directory) => {
|
|
23524
|
-
const { readPriorDriftReports } = await import("./curator-drift-
|
|
23616
|
+
const { readPriorDriftReports } = await import("./curator-drift-wy7ejcvw.js");
|
|
23525
23617
|
return readPriorDriftReports(directory);
|
|
23526
23618
|
},
|
|
23527
23619
|
readSwarmKnowledge: (directory) => readKnowledge(resolveSwarmKnowledgePath(directory))
|
|
@@ -23806,8 +23898,8 @@ async function realpathQuiet(target) {
|
|
|
23806
23898
|
}
|
|
23807
23899
|
async function trimHiveEventsUnderLock(eventsPath) {
|
|
23808
23900
|
const { readFile: readFile8 } = await import("fs/promises");
|
|
23809
|
-
const { existsSync:
|
|
23810
|
-
if (!
|
|
23901
|
+
const { existsSync: existsSync16 } = await import("fs");
|
|
23902
|
+
if (!existsSync16(eventsPath))
|
|
23811
23903
|
return;
|
|
23812
23904
|
const content = await readFile8(eventsPath, "utf-8");
|
|
23813
23905
|
const lines = content.split(`
|
|
@@ -24575,8 +24667,7 @@ async function promoteFromSwarm(directory, lessonId, options, config) {
|
|
|
24575
24667
|
|
|
24576
24668
|
// src/hooks/knowledge-curator.ts
|
|
24577
24669
|
import { createHash as createHash15 } from "crypto";
|
|
24578
|
-
import {
|
|
24579
|
-
import { readFile as readFile9, realpath as realpath3, writeFile as writeFile6 } from "fs/promises";
|
|
24670
|
+
import { realpath as realpath3 } from "fs/promises";
|
|
24580
24671
|
import * as path30 from "path";
|
|
24581
24672
|
|
|
24582
24673
|
// src/services/synonym-map.ts
|
|
@@ -24587,7 +24678,7 @@ import {
|
|
|
24587
24678
|
rename as rename4,
|
|
24588
24679
|
stat as stat2,
|
|
24589
24680
|
unlink as unlink3,
|
|
24590
|
-
writeFile as
|
|
24681
|
+
writeFile as writeFile4
|
|
24591
24682
|
} from "fs/promises";
|
|
24592
24683
|
import * as path29 from "path";
|
|
24593
24684
|
var SYNONYM_MAP_FILENAME = "synonym-map.json";
|
|
@@ -24747,7 +24838,7 @@ async function writeSynonymMapAtomic(filePath, map) {
|
|
|
24747
24838
|
await mkdir8(path29.dirname(filePath), { recursive: true });
|
|
24748
24839
|
const tmp = `${filePath}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`;
|
|
24749
24840
|
try {
|
|
24750
|
-
await
|
|
24841
|
+
await writeFile4(tmp, JSON.stringify(map, null, 2), "utf-8");
|
|
24751
24842
|
await rename4(tmp, filePath);
|
|
24752
24843
|
} finally {
|
|
24753
24844
|
try {
|
|
@@ -24809,9 +24900,9 @@ function hashContent(content) {
|
|
|
24809
24900
|
return createHash15("sha1").update(content).digest("hex");
|
|
24810
24901
|
}
|
|
24811
24902
|
async function loadConfigForPolicyCurator(directory) {
|
|
24812
|
-
const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-
|
|
24903
|
+
const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-9xkt5hvd.js");
|
|
24813
24904
|
try {
|
|
24814
|
-
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-
|
|
24905
|
+
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-v3a9rmyh.js");
|
|
24815
24906
|
const { config: loadedConfig } = loadPluginConfigWithMeta2(directory);
|
|
24816
24907
|
return KnowledgeConfigSchema2.parse(loadedConfig.knowledge ?? {});
|
|
24817
24908
|
} catch {
|
|
@@ -25314,37 +25405,15 @@ var KNOWLEDGE_CATEGORIES = new Set([
|
|
|
25314
25405
|
"todo",
|
|
25315
25406
|
"other"
|
|
25316
25407
|
]);
|
|
25317
|
-
function readInsightJsonl2(content) {
|
|
25318
|
-
const out = [];
|
|
25319
|
-
for (const line of content.split(`
|
|
25320
|
-
`)) {
|
|
25321
|
-
const t = line.trim();
|
|
25322
|
-
if (!t)
|
|
25323
|
-
continue;
|
|
25324
|
-
try {
|
|
25325
|
-
out.push(JSON.parse(t));
|
|
25326
|
-
} catch {}
|
|
25327
|
-
}
|
|
25328
|
-
return out;
|
|
25329
|
-
}
|
|
25330
25408
|
async function consumeInsightCandidates(directory, batchLimit = MESO_INSIGHT_BATCH_LIMIT) {
|
|
25331
25409
|
try {
|
|
25332
|
-
const
|
|
25333
|
-
if (!existsSync15(filePath))
|
|
25334
|
-
return [];
|
|
25410
|
+
const payloads = consumeInsightCandidatesDb(directory, batchLimit);
|
|
25335
25411
|
const consumed = [];
|
|
25336
|
-
|
|
25337
|
-
|
|
25338
|
-
|
|
25339
|
-
|
|
25340
|
-
|
|
25341
|
-
}, (all) => {
|
|
25342
|
-
if (all.length === 0)
|
|
25343
|
-
return null;
|
|
25344
|
-
const batch = all.slice(0, batchLimit);
|
|
25345
|
-
consumed.push(...batch);
|
|
25346
|
-
return all.slice(batch.length);
|
|
25347
|
-
});
|
|
25412
|
+
for (const payload of payloads) {
|
|
25413
|
+
try {
|
|
25414
|
+
consumed.push(JSON.parse(payload));
|
|
25415
|
+
} catch {}
|
|
25416
|
+
}
|
|
25348
25417
|
return consumed;
|
|
25349
25418
|
} catch {
|
|
25350
25419
|
return [];
|
|
@@ -27950,10 +28019,10 @@ import { existsSync as existsSync17, readFileSync as readFileSync15, writeFileSy
|
|
|
27950
28019
|
import {
|
|
27951
28020
|
appendFile as appendFile3,
|
|
27952
28021
|
mkdir as mkdir9,
|
|
27953
|
-
readFile as
|
|
28022
|
+
readFile as readFile9,
|
|
27954
28023
|
rename as rename5,
|
|
27955
28024
|
truncate,
|
|
27956
|
-
writeFile as
|
|
28025
|
+
writeFile as writeFile5
|
|
27957
28026
|
} from "fs/promises";
|
|
27958
28027
|
import * as path33 from "path";
|
|
27959
28028
|
|
|
@@ -29032,7 +29101,7 @@ function validateLoadedProposals(values, config) {
|
|
|
29032
29101
|
async function readJsonl(filePath) {
|
|
29033
29102
|
if (!existsSync17(filePath))
|
|
29034
29103
|
return [];
|
|
29035
|
-
const content = await
|
|
29104
|
+
const content = await readFile9(filePath, "utf-8");
|
|
29036
29105
|
const records = [];
|
|
29037
29106
|
for (const line of content.split(`
|
|
29038
29107
|
`)) {
|
|
@@ -29048,7 +29117,7 @@ async function readJsonl(filePath) {
|
|
|
29048
29117
|
async function readProposalJsonl(filePath) {
|
|
29049
29118
|
if (!existsSync17(filePath))
|
|
29050
29119
|
return { values: [], invalidRows: [] };
|
|
29051
|
-
const content = await
|
|
29120
|
+
const content = await readFile9(filePath, "utf-8");
|
|
29052
29121
|
const values = [];
|
|
29053
29122
|
const invalidRows = [];
|
|
29054
29123
|
for (const [index, line] of content.split(`
|
|
@@ -29139,13 +29208,13 @@ async function writeJsonlAtomic(filePath, values) {
|
|
|
29139
29208
|
const content = values.map((value) => JSON.stringify(value)).join(`
|
|
29140
29209
|
`) + (values.length > 0 ? `
|
|
29141
29210
|
` : "");
|
|
29142
|
-
await
|
|
29211
|
+
await writeFile5(tmp, content, "utf-8");
|
|
29143
29212
|
await rename5(tmp, filePath);
|
|
29144
29213
|
}
|
|
29145
29214
|
async function repairIncompleteJsonlTail(filePath) {
|
|
29146
29215
|
if (!existsSync17(filePath))
|
|
29147
29216
|
return;
|
|
29148
|
-
const content = await
|
|
29217
|
+
const content = await readFile9(filePath, "utf-8");
|
|
29149
29218
|
if (content.length === 0 || content.endsWith(`
|
|
29150
29219
|
`))
|
|
29151
29220
|
return;
|
|
@@ -29526,7 +29595,7 @@ function resolveRerankerCacheDir() {
|
|
|
29526
29595
|
|
|
29527
29596
|
// src/memory/jsonl-migration.ts
|
|
29528
29597
|
import { existsSync as existsSync18, renameSync as renameSync7, unlinkSync as unlinkSync6 } from "fs";
|
|
29529
|
-
import { copyFile, mkdir as mkdir10, readFile as
|
|
29598
|
+
import { copyFile, mkdir as mkdir10, readFile as readFile10, stat as stat3, writeFile as writeFile6 } from "fs/promises";
|
|
29530
29599
|
import * as path36 from "path";
|
|
29531
29600
|
var LEGACY_JSONL_MIGRATION_VERSION = 2;
|
|
29532
29601
|
var LEGACY_JSONL_MIGRATION_NAME = "legacy_jsonl_import_complete";
|
|
@@ -29592,7 +29661,7 @@ async function writeJsonlExport(rootDirectory, config, memories, proposals, outc
|
|
|
29592
29661
|
const outcomesPath = path36.join(exportDir, "outcome-events.jsonl");
|
|
29593
29662
|
const memoriesTempPath = path36.join(path36.dirname(memoriesPath), `${path36.basename(memoriesPath)}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`);
|
|
29594
29663
|
try {
|
|
29595
|
-
await
|
|
29664
|
+
await writeFile6(memoriesTempPath, toJsonl(memories), "utf-8");
|
|
29596
29665
|
renameSync7(memoriesTempPath, memoriesPath);
|
|
29597
29666
|
} catch (err) {
|
|
29598
29667
|
try {
|
|
@@ -29602,7 +29671,7 @@ async function writeJsonlExport(rootDirectory, config, memories, proposals, outc
|
|
|
29602
29671
|
}
|
|
29603
29672
|
const proposalsTempPath = path36.join(path36.dirname(proposalsPath), `${path36.basename(proposalsPath)}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`);
|
|
29604
29673
|
try {
|
|
29605
|
-
await
|
|
29674
|
+
await writeFile6(proposalsTempPath, toJsonl(proposals), "utf-8");
|
|
29606
29675
|
renameSync7(proposalsTempPath, proposalsPath);
|
|
29607
29676
|
} catch (err) {
|
|
29608
29677
|
try {
|
|
@@ -29612,7 +29681,7 @@ async function writeJsonlExport(rootDirectory, config, memories, proposals, outc
|
|
|
29612
29681
|
}
|
|
29613
29682
|
const outcomesTempPath = path36.join(path36.dirname(outcomesPath), `${path36.basename(outcomesPath)}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`);
|
|
29614
29683
|
try {
|
|
29615
|
-
await
|
|
29684
|
+
await writeFile6(outcomesTempPath, toJsonl(outcomeEvents), "utf-8");
|
|
29616
29685
|
renameSync7(outcomesTempPath, outcomesPath);
|
|
29617
29686
|
} catch (err) {
|
|
29618
29687
|
try {
|
|
@@ -29627,7 +29696,7 @@ async function writeMigrationReport(rootDirectory, report, config = {}) {
|
|
|
29627
29696
|
await mkdir10(path36.dirname(reportPath), { recursive: true });
|
|
29628
29697
|
const reportTempPath = path36.join(path36.dirname(reportPath), `${path36.basename(reportPath)}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`);
|
|
29629
29698
|
try {
|
|
29630
|
-
await
|
|
29699
|
+
await writeFile6(reportTempPath, `${JSON.stringify(report, null, 2)}
|
|
29631
29700
|
`, "utf-8");
|
|
29632
29701
|
renameSync7(reportTempPath, reportPath);
|
|
29633
29702
|
} catch (err) {
|
|
@@ -29643,7 +29712,7 @@ async function readMigrationReport(rootDirectory, config = {}) {
|
|
|
29643
29712
|
if (!existsSync18(reportPath))
|
|
29644
29713
|
return null;
|
|
29645
29714
|
try {
|
|
29646
|
-
return JSON.parse(await
|
|
29715
|
+
return JSON.parse(await readFile10(reportPath, "utf-8"));
|
|
29647
29716
|
} catch {
|
|
29648
29717
|
return null;
|
|
29649
29718
|
}
|
|
@@ -29793,7 +29862,7 @@ async function readJsonlRows(filePath) {
|
|
|
29793
29862
|
if (!existsSync18(filePath)) {
|
|
29794
29863
|
return { rows: [], invalidRows: [], totalRows: 0 };
|
|
29795
29864
|
}
|
|
29796
|
-
const content = await
|
|
29865
|
+
const content = await readFile10(filePath, "utf-8");
|
|
29797
29866
|
const rows = [];
|
|
29798
29867
|
const invalidRows = [];
|
|
29799
29868
|
let totalRows = 0;
|
|
@@ -33744,12 +33813,12 @@ var _internals35 = {
|
|
|
33744
33813
|
|
|
33745
33814
|
// src/services/skill-improver.ts
|
|
33746
33815
|
import { existsSync as existsSync22 } from "fs";
|
|
33747
|
-
import { mkdir as mkdir12, readFile as
|
|
33816
|
+
import { mkdir as mkdir12, readFile as readFile11, unlink as unlink4 } from "fs/promises";
|
|
33748
33817
|
import * as path43 from "path";
|
|
33749
33818
|
init_logger();
|
|
33750
33819
|
|
|
33751
33820
|
// src/services/trajectory-cluster.ts
|
|
33752
|
-
import { mkdir as mkdir11, writeFile as
|
|
33821
|
+
import { mkdir as mkdir11, writeFile as writeFile7 } from "fs/promises";
|
|
33753
33822
|
import * as path42 from "path";
|
|
33754
33823
|
init_logger();
|
|
33755
33824
|
var MACRO_TRAJECTORY_WINDOW = 200;
|
|
@@ -33927,7 +33996,7 @@ async function writeMotifProposals(directory, opts = {}) {
|
|
|
33927
33996
|
continue;
|
|
33928
33997
|
const slug = `motif-${slugify(motif.signature)}`;
|
|
33929
33998
|
const filePath = path42.join(proposalsDir, `${slug}.md`);
|
|
33930
|
-
await
|
|
33999
|
+
await writeFile7(filePath, buildMotifProposal(motif, {
|
|
33931
34000
|
fingerprint: decision.fingerprint,
|
|
33932
34001
|
producedAt
|
|
33933
34002
|
}), "utf-8");
|
|
@@ -34117,7 +34186,7 @@ async function writeSuccessMotifProposals(directory, opts = {}) {
|
|
|
34117
34186
|
continue;
|
|
34118
34187
|
const slug = workflowSlug(motif.signature);
|
|
34119
34188
|
const filePath = path42.join(proposalsDir, `${slug}.md`);
|
|
34120
|
-
await
|
|
34189
|
+
await writeFile7(filePath, buildWorkflowProposal(motif, {
|
|
34121
34190
|
fingerprint: decision.fingerprint,
|
|
34122
34191
|
producedAt
|
|
34123
34192
|
}), "utf-8");
|
|
@@ -34588,7 +34657,7 @@ async function gatherInventory(directory) {
|
|
|
34588
34657
|
for (const skill of skills.active) {
|
|
34589
34658
|
let content;
|
|
34590
34659
|
try {
|
|
34591
|
-
content = await
|
|
34660
|
+
content = await readFile11(skill.path, "utf-8");
|
|
34592
34661
|
} catch {
|
|
34593
34662
|
continue;
|
|
34594
34663
|
}
|
|
@@ -34764,7 +34833,7 @@ async function reconcileStaleActiveSkills(directory, options = {}) {
|
|
|
34764
34833
|
for (const skill of skills.active) {
|
|
34765
34834
|
let content;
|
|
34766
34835
|
try {
|
|
34767
|
-
content = await
|
|
34836
|
+
content = await readFile11(skill.path, "utf-8");
|
|
34768
34837
|
} catch {
|
|
34769
34838
|
continue;
|
|
34770
34839
|
}
|
|
@@ -35232,7 +35301,7 @@ async function writeApprovedSkillImproverCandidate(prepared) {
|
|
|
35232
35301
|
try {
|
|
35233
35302
|
fileRollback.set(targetPath, {
|
|
35234
35303
|
existed: true,
|
|
35235
|
-
content: await
|
|
35304
|
+
content: await readFile11(targetPath, "utf-8")
|
|
35236
35305
|
});
|
|
35237
35306
|
} catch {
|
|
35238
35307
|
fileRollback.set(targetPath, { existed: false, content: null });
|
|
@@ -37496,7 +37565,7 @@ async function runFinalizeStage(ctx) {
|
|
|
37496
37565
|
}
|
|
37497
37566
|
}
|
|
37498
37567
|
try {
|
|
37499
|
-
const { CuratorConfigSchema: CCS } = await import("./schema-
|
|
37568
|
+
const { CuratorConfigSchema: CCS } = await import("./schema-9xkt5hvd.js");
|
|
37500
37569
|
const { config: pmLoadedConfig } = _internals41.loadPluginConfigWithMeta(ctx.directory);
|
|
37501
37570
|
const curatorCfg = CCS.parse(pmLoadedConfig.curator ?? {});
|
|
37502
37571
|
if (curatorCfg.enabled && curatorCfg.postmortem_enabled) {
|
|
@@ -37777,6 +37846,9 @@ async function runCleanStage(ctx) {
|
|
|
37777
37846
|
}
|
|
37778
37847
|
const filePath = path48.join(ctx.swarmDir, artifact);
|
|
37779
37848
|
if (artifact === "swarm.db") {
|
|
37849
|
+
try {
|
|
37850
|
+
closeGroupCommitWriter(ctx.directory);
|
|
37851
|
+
} catch {}
|
|
37780
37852
|
try {
|
|
37781
37853
|
closeProjectDb(ctx.directory);
|
|
37782
37854
|
} catch {}
|
|
@@ -38382,7 +38454,7 @@ var _internals41 = {
|
|
|
38382
38454
|
closePlanTerminalState: reconcileCloseTerminalStateForPlan,
|
|
38383
38455
|
endAgentSession,
|
|
38384
38456
|
flushAndDrainTelemetry: async () => {
|
|
38385
|
-
const { flushAndDrainTelemetry } = await import("./telemetry-
|
|
38457
|
+
const { flushAndDrainTelemetry } = await import("./telemetry-q51s6tyt.js");
|
|
38386
38458
|
return flushAndDrainTelemetry();
|
|
38387
38459
|
},
|
|
38388
38460
|
finalizeContextTelemetry: (directory) => {
|
|
@@ -38659,7 +38731,7 @@ init_schema();
|
|
|
38659
38731
|
|
|
38660
38732
|
// src/services/skill-consolidation.ts
|
|
38661
38733
|
import { existsSync as existsSync28 } from "fs";
|
|
38662
|
-
import { mkdir as mkdir13, readFile as
|
|
38734
|
+
import { mkdir as mkdir13, readFile as readFile12 } from "fs/promises";
|
|
38663
38735
|
import * as path50 from "path";
|
|
38664
38736
|
var DEFAULT_CONSOLIDATION_INTERVAL_HOURS = 24;
|
|
38665
38737
|
var DEFAULT_CONSOLIDATION_MAX_CALLS_PER_RUN = 1;
|
|
@@ -38673,7 +38745,7 @@ async function readState2(directory) {
|
|
|
38673
38745
|
if (!existsSync28(filePath))
|
|
38674
38746
|
return {};
|
|
38675
38747
|
try {
|
|
38676
|
-
const parsed = JSON.parse(await
|
|
38748
|
+
const parsed = JSON.parse(await readFile12(filePath, "utf-8"));
|
|
38677
38749
|
if (!parsed || typeof parsed !== "object")
|
|
38678
38750
|
return {};
|
|
38679
38751
|
return parsed;
|
|
@@ -39009,7 +39081,7 @@ import { promisify as promisify2 } from "util";
|
|
|
39009
39081
|
init_zod();
|
|
39010
39082
|
import * as child_process3 from "child_process";
|
|
39011
39083
|
import { randomUUID as randomUUID8 } from "crypto";
|
|
39012
|
-
import { readdir as readdir3, readFile as
|
|
39084
|
+
import { readdir as readdir3, readFile as readFile13, stat as stat4 } from "fs/promises";
|
|
39013
39085
|
import * as path51 from "path";
|
|
39014
39086
|
import { promisify } from "util";
|
|
39015
39087
|
function getExecFileAsync() {
|
|
@@ -39136,7 +39208,7 @@ async function getStaticEdges(directory) {
|
|
|
39136
39208
|
const sourceFiles = await scanSourceFiles(directory);
|
|
39137
39209
|
for (const sourceFile of sourceFiles) {
|
|
39138
39210
|
try {
|
|
39139
|
-
const content = await
|
|
39211
|
+
const content = await readFile13(sourceFile, "utf-8");
|
|
39140
39212
|
const importRegex = /(?:import|require)\s*(?:\(?\s*['"`]|.*?from\s+['"`])([^'"`]+)['"`]/g;
|
|
39141
39213
|
for (let match = importRegex.exec(content);match !== null; match = importRegex.exec(content)) {
|
|
39142
39214
|
const importPath = match[1].trim();
|
|
@@ -39720,9 +39792,9 @@ var _internals45 = {
|
|
|
39720
39792
|
loadPluginConfigWithMeta,
|
|
39721
39793
|
loadCuratorDeps: async () => {
|
|
39722
39794
|
const [{ CuratorConfigSchema }, curator, { createCuratorLLMDelegate: createCuratorLLMDelegate2 }] = await Promise.all([
|
|
39723
|
-
import("./schema-
|
|
39724
|
-
import("./curator-
|
|
39725
|
-
import("./curator-llm-factory-
|
|
39795
|
+
import("./schema-9xkt5hvd.js"),
|
|
39796
|
+
import("./curator-4pckmmyf.js"),
|
|
39797
|
+
import("./curator-llm-factory-msbj3hpn.js")
|
|
39726
39798
|
]);
|
|
39727
39799
|
return { CuratorConfigSchema, curator, createCuratorLLMDelegate: createCuratorLLMDelegate2 };
|
|
39728
39800
|
}
|
|
@@ -40222,7 +40294,7 @@ ${USAGE9}`;
|
|
|
40222
40294
|
// src/services/diagnose-service.ts
|
|
40223
40295
|
init_package();
|
|
40224
40296
|
import * as child_process5 from "child_process";
|
|
40225
|
-
import { existsSync as
|
|
40297
|
+
import { existsSync as existsSync33, readdirSync as readdirSync7, readFileSync as readFileSync23, statSync as statSync16 } from "fs";
|
|
40226
40298
|
import * as path55 from "path";
|
|
40227
40299
|
import { fileURLToPath } from "url";
|
|
40228
40300
|
|
|
@@ -40321,6 +40393,40 @@ function readCachePackageVersion(cachePath) {
|
|
|
40321
40393
|
// src/services/diagnose-service.ts
|
|
40322
40394
|
init_loader();
|
|
40323
40395
|
|
|
40396
|
+
// src/db/health.ts
|
|
40397
|
+
import { existsSync as existsSync30, statSync as statSync15 } from "fs";
|
|
40398
|
+
import { join as join43 } from "path";
|
|
40399
|
+
var SWARM_DB_QUICK_CHECK_MAX_BYTES = 64 * 1024 * 1024;
|
|
40400
|
+
function getSwarmDbHealthSnapshot(directory) {
|
|
40401
|
+
try {
|
|
40402
|
+
const size = statSync15(projectDbPath(directory)).size;
|
|
40403
|
+
if (size > SWARM_DB_QUICK_CHECK_MAX_BYTES) {
|
|
40404
|
+
return { kind: "too_large", sizeBytes: size };
|
|
40405
|
+
}
|
|
40406
|
+
} catch {
|
|
40407
|
+
return { kind: "absent" };
|
|
40408
|
+
}
|
|
40409
|
+
const staleMarker = existsSync30(join43(canonicalProjectKey(directory), ".swarm", "db-migration-failure.json"));
|
|
40410
|
+
try {
|
|
40411
|
+
const db = getProjectDb(directory);
|
|
40412
|
+
return {
|
|
40413
|
+
kind: "open",
|
|
40414
|
+
quickCheck: db.query("PRAGMA quick_check").get()?.quick_check ?? "unknown",
|
|
40415
|
+
journalMode: db.query("PRAGMA journal_mode").get()?.journal_mode ?? "unknown",
|
|
40416
|
+
pageCount: db.query("PRAGMA page_count").get()?.page_count ?? -1,
|
|
40417
|
+
migrationFailures: db.query("SELECT COUNT(*) as n FROM migration_failures").get()?.n ?? 0,
|
|
40418
|
+
staleMarker
|
|
40419
|
+
};
|
|
40420
|
+
} catch (err) {
|
|
40421
|
+
const category = err && typeof err === "object" && "category" in err ? String(err.category) : "unknown";
|
|
40422
|
+
return {
|
|
40423
|
+
kind: "error",
|
|
40424
|
+
category,
|
|
40425
|
+
message: err instanceof Error ? err.message : String(err)
|
|
40426
|
+
};
|
|
40427
|
+
}
|
|
40428
|
+
}
|
|
40429
|
+
|
|
40324
40430
|
// src/models/task-model-routing.ts
|
|
40325
40431
|
var PENDING_TASK_MODEL_ROUTE_TTL_MS = 30 * 60000;
|
|
40326
40432
|
var routesByParentCall = new Map;
|
|
@@ -40381,29 +40487,29 @@ init_git_executable();
|
|
|
40381
40487
|
|
|
40382
40488
|
// src/services/knowledge-diagnostics.ts
|
|
40383
40489
|
init_package();
|
|
40384
|
-
import { existsSync as
|
|
40385
|
-
import { readFile as
|
|
40386
|
-
import { join as
|
|
40490
|
+
import { existsSync as existsSync32, readFileSync as readFileSync22 } from "fs";
|
|
40491
|
+
import { readFile as readFile14 } from "fs/promises";
|
|
40492
|
+
import { join as join45 } from "path";
|
|
40387
40493
|
|
|
40388
40494
|
// src/services/version-check.ts
|
|
40389
|
-
import { existsSync as
|
|
40495
|
+
import { existsSync as existsSync31, mkdirSync as mkdirSync16, readFileSync as readFileSync21, writeFileSync as writeFileSync11 } from "fs";
|
|
40390
40496
|
import { homedir as homedir6 } from "os";
|
|
40391
|
-
import { join as
|
|
40497
|
+
import { join as join44 } from "path";
|
|
40392
40498
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
40393
40499
|
var SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
40394
40500
|
var MAX_RESPONSE_BYTES = 256 * 1024;
|
|
40395
40501
|
function cacheDir() {
|
|
40396
40502
|
const xdg = process.env.XDG_CACHE_HOME;
|
|
40397
|
-
const base = xdg && xdg.length > 0 ? xdg :
|
|
40398
|
-
return
|
|
40503
|
+
const base = xdg && xdg.length > 0 ? xdg : join44(homedir6(), ".cache");
|
|
40504
|
+
return join44(base, "opencode-swarm");
|
|
40399
40505
|
}
|
|
40400
40506
|
function cacheFile() {
|
|
40401
|
-
return
|
|
40507
|
+
return join44(cacheDir(), "version-check.json");
|
|
40402
40508
|
}
|
|
40403
40509
|
function readVersionCache() {
|
|
40404
40510
|
try {
|
|
40405
40511
|
const path55 = cacheFile();
|
|
40406
|
-
if (!
|
|
40512
|
+
if (!existsSync31(path55))
|
|
40407
40513
|
return null;
|
|
40408
40514
|
const raw = readFileSync21(path55, "utf-8");
|
|
40409
40515
|
const parsed = JSON.parse(raw);
|
|
@@ -40457,9 +40563,9 @@ var SEVEN_DAYS_MS2 = 7 * 24 * 60 * 60 * 1000;
|
|
|
40457
40563
|
var UNACTIONABLE_BACKLOG_WARN = 100;
|
|
40458
40564
|
var INSIGHT_BACKLOG_WARN = 50;
|
|
40459
40565
|
async function readRawLines(filePath) {
|
|
40460
|
-
if (!
|
|
40566
|
+
if (!existsSync32(filePath))
|
|
40461
40567
|
return { entries: [], corrupt: 0 };
|
|
40462
|
-
const content = await
|
|
40568
|
+
const content = await readFile14(filePath, "utf-8");
|
|
40463
40569
|
const entries = [];
|
|
40464
40570
|
let corrupt = 0;
|
|
40465
40571
|
for (const line of content.split(`
|
|
@@ -40551,7 +40657,7 @@ async function computeKnowledgeDebug(directory) {
|
|
|
40551
40657
|
}
|
|
40552
40658
|
} catch {}
|
|
40553
40659
|
const unactionableQueueDepth = await safeJsonlCount(resolveUnactionablePathSafe(directory));
|
|
40554
|
-
const insightCandidatesPending = await
|
|
40660
|
+
const insightCandidatesPending = await countInsightCandidatesPendingDiagnostic(directory);
|
|
40555
40661
|
let synonymPairs = 0;
|
|
40556
40662
|
try {
|
|
40557
40663
|
synonymPairs = Object.keys((await readSynonymMap(directory)).pairs).length;
|
|
@@ -40664,8 +40770,8 @@ function computeMemoryCohortDiagnostics(directory) {
|
|
|
40664
40770
|
const cfg = loadPluginConfig2(directory);
|
|
40665
40771
|
provider = cfg.memory?.provider ?? null;
|
|
40666
40772
|
if (pointer && cfg.memory) {
|
|
40667
|
-
const cohortConfigPath =
|
|
40668
|
-
if (
|
|
40773
|
+
const cohortConfigPath = join45(resolveLinkDir(pointer.linkId), "memory", "memory-cohort-config.json");
|
|
40774
|
+
if (existsSync32(cohortConfigPath)) {
|
|
40669
40775
|
const stored = JSON.parse(readFileSync22(cohortConfigPath, "utf-8"));
|
|
40670
40776
|
const versionCheck = classifyStoredFingerprintAlgorithmVersion(stored.algorithm_version);
|
|
40671
40777
|
if (versionCheck.status === "comparable" && typeof stored.fingerprint === "string") {
|
|
@@ -40731,7 +40837,7 @@ async function computeCurationDiagnostics(directory, entries) {
|
|
|
40731
40837
|
let scanCompleted = false;
|
|
40732
40838
|
let scanRemaining = 0;
|
|
40733
40839
|
try {
|
|
40734
|
-
const { getScanStatus } = await import("./scan-cursor-
|
|
40840
|
+
const { getScanStatus } = await import("./scan-cursor-5frvp7nb.js");
|
|
40735
40841
|
const status = await getScanStatus(directory);
|
|
40736
40842
|
scanGeneration = status.generation;
|
|
40737
40843
|
scanCompleted = status.completed;
|
|
@@ -40739,19 +40845,19 @@ async function computeCurationDiagnostics(directory, entries) {
|
|
|
40739
40845
|
} catch {}
|
|
40740
40846
|
let configMatch = null;
|
|
40741
40847
|
try {
|
|
40742
|
-
const { isLinked: isLinked2 } = await import("./knowledge-link-
|
|
40848
|
+
const { isLinked: isLinked2 } = await import("./knowledge-link-yykmxdyw.js");
|
|
40743
40849
|
if (isLinked2(directory)) {
|
|
40744
|
-
const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-
|
|
40850
|
+
const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-9xkt5hvd.js");
|
|
40745
40851
|
let config;
|
|
40746
40852
|
try {
|
|
40747
|
-
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-
|
|
40853
|
+
const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-v3a9rmyh.js");
|
|
40748
40854
|
const loaded = loadPluginConfigWithMeta2(directory);
|
|
40749
40855
|
config = KnowledgeConfigSchema2.parse(loaded.config.knowledge ?? {});
|
|
40750
40856
|
} catch {
|
|
40751
40857
|
config = KnowledgeConfigSchema2.parse({});
|
|
40752
40858
|
}
|
|
40753
40859
|
const { cohortConfigFingerprint: cohortConfigFingerprint2 } = await import("./config-fingerprint-v22xh5a2.js");
|
|
40754
|
-
const { buildConfigFingerprintInput: buildConfigFingerprintInput2, readCohortConfigFingerprint } = await import("./curation-policy-
|
|
40860
|
+
const { buildConfigFingerprintInput: buildConfigFingerprintInput2, readCohortConfigFingerprint } = await import("./curation-policy-a2zty4br.js");
|
|
40755
40861
|
const currentFp = cohortConfigFingerprint2(buildConfigFingerprintInput2(config));
|
|
40756
40862
|
const cohortFp = await readCohortConfigFingerprint(directory);
|
|
40757
40863
|
configMatch = cohortFp === null ? null : currentFp === cohortFp;
|
|
@@ -40779,14 +40885,14 @@ async function computeCurationDiagnostics(directory, entries) {
|
|
|
40779
40885
|
async function countPendingProposals(directory) {
|
|
40780
40886
|
let proposalsPath;
|
|
40781
40887
|
try {
|
|
40782
|
-
proposalsPath =
|
|
40888
|
+
proposalsPath = join45(resolveKnowledgeStoreDir(directory), "curation-proposals.jsonl");
|
|
40783
40889
|
} catch {
|
|
40784
40890
|
return 0;
|
|
40785
40891
|
}
|
|
40786
|
-
if (!
|
|
40892
|
+
if (!existsSync32(proposalsPath))
|
|
40787
40893
|
return 0;
|
|
40788
40894
|
try {
|
|
40789
|
-
const content = await
|
|
40895
|
+
const content = await readFile14(proposalsPath, "utf-8");
|
|
40790
40896
|
let n = 0;
|
|
40791
40897
|
for (const line of content.split(`
|
|
40792
40898
|
`)) {
|
|
@@ -40805,10 +40911,10 @@ async function countPendingProposals(directory) {
|
|
|
40805
40911
|
}
|
|
40806
40912
|
}
|
|
40807
40913
|
async function safeJsonlCount(filePath) {
|
|
40808
|
-
if (!filePath || !
|
|
40914
|
+
if (!filePath || !existsSync32(filePath))
|
|
40809
40915
|
return 0;
|
|
40810
40916
|
try {
|
|
40811
|
-
const content = await
|
|
40917
|
+
const content = await readFile14(filePath, "utf-8");
|
|
40812
40918
|
let n = 0;
|
|
40813
40919
|
for (const line of content.split(`
|
|
40814
40920
|
`)) {
|
|
@@ -40834,6 +40940,16 @@ function resolveInsightCandidatesPathSafe(directory) {
|
|
|
40834
40940
|
return null;
|
|
40835
40941
|
}
|
|
40836
40942
|
}
|
|
40943
|
+
async function countInsightCandidatesPendingDiagnostic(directory) {
|
|
40944
|
+
try {
|
|
40945
|
+
if (projectDbExists(directory)) {
|
|
40946
|
+
return countPendingInsightCandidatesDb(directory);
|
|
40947
|
+
}
|
|
40948
|
+
return await safeJsonlCount(resolveInsightCandidatesPathSafe(directory));
|
|
40949
|
+
} catch {
|
|
40950
|
+
return 0;
|
|
40951
|
+
}
|
|
40952
|
+
}
|
|
40837
40953
|
async function checkKnowledgeHealth(directory) {
|
|
40838
40954
|
let debug;
|
|
40839
40955
|
try {
|
|
@@ -40913,6 +41029,43 @@ var _internals47 = {
|
|
|
40913
41029
|
detectSandboxCapability: () => sandboxCapabilityProbe.detect(),
|
|
40914
41030
|
getSandboxExecutor: getExecutor
|
|
40915
41031
|
};
|
|
41032
|
+
var SWARM_DB_QUICK_CHECK_MAX_BYTES2 = 64 * 1024 * 1024;
|
|
41033
|
+
function checkSwarmDb(directory) {
|
|
41034
|
+
const runtime = process.versions.bun === undefined ? "node" : "bun";
|
|
41035
|
+
const runtimeVersion = process.versions.bun ?? process.versions.node ?? "unknown";
|
|
41036
|
+
const snapshot = getSwarmDbHealthSnapshot(directory);
|
|
41037
|
+
switch (snapshot.kind) {
|
|
41038
|
+
case "absent":
|
|
41039
|
+
return {
|
|
41040
|
+
name: "swarm.db",
|
|
41041
|
+
status: "\u2705",
|
|
41042
|
+
detail: `not created yet (driver: ${runtime} ${runtimeVersion})`
|
|
41043
|
+
};
|
|
41044
|
+
case "too_large":
|
|
41045
|
+
return {
|
|
41046
|
+
name: "swarm.db",
|
|
41047
|
+
status: "\u26A0\uFE0F",
|
|
41048
|
+
detail: `${Math.round(snapshot.sizeBytes / (1024 * 1024))} MiB exceeds the ${Math.round(SWARM_DB_QUICK_CHECK_MAX_BYTES2 / (1024 * 1024))} MiB inline quick_check cap \u2014 run an external integrity check (driver: ${runtime} ${runtimeVersion})`
|
|
41049
|
+
};
|
|
41050
|
+
case "error":
|
|
41051
|
+
return {
|
|
41052
|
+
name: "swarm.db",
|
|
41053
|
+
status: "\u274C",
|
|
41054
|
+
detail: `unavailable (${snapshot.category}): ${snapshot.message}`
|
|
41055
|
+
};
|
|
41056
|
+
case "open": {
|
|
41057
|
+
const markerNote = snapshot.staleMarker ? ", stale db-migration-failure.json marker present" : "";
|
|
41058
|
+
const detail = `quick_check ${snapshot.quickCheck}; ${snapshot.journalMode} mode, ${snapshot.pageCount} pages, ${snapshot.migrationFailures} recorded migration failure(s)${markerNote}; driver: ${runtime} ${runtimeVersion}`;
|
|
41059
|
+
if (snapshot.quickCheck !== "ok") {
|
|
41060
|
+
return { name: "swarm.db", status: "\u274C", detail };
|
|
41061
|
+
}
|
|
41062
|
+
if (snapshot.migrationFailures > 0 || snapshot.staleMarker) {
|
|
41063
|
+
return { name: "swarm.db", status: "\u26A0\uFE0F", detail };
|
|
41064
|
+
}
|
|
41065
|
+
return { name: "swarm.db", status: "\u2705", detail };
|
|
41066
|
+
}
|
|
41067
|
+
}
|
|
41068
|
+
}
|
|
40916
41069
|
function validateTaskDag(plan) {
|
|
40917
41070
|
const allTaskIds = new Set;
|
|
40918
41071
|
for (const phase of plan.phases) {
|
|
@@ -41158,7 +41311,7 @@ async function checkConfigBackups(directory) {
|
|
|
41158
41311
|
}
|
|
41159
41312
|
async function checkGitRepository(directory) {
|
|
41160
41313
|
try {
|
|
41161
|
-
if (!
|
|
41314
|
+
if (!existsSync33(directory) || !statSync16(directory).isDirectory()) {
|
|
41162
41315
|
return {
|
|
41163
41316
|
name: "Git Repository",
|
|
41164
41317
|
status: "\u274C",
|
|
@@ -41224,7 +41377,7 @@ async function checkSpecStaleness(directory, plan) {
|
|
|
41224
41377
|
}
|
|
41225
41378
|
async function checkConfigParseability(directory) {
|
|
41226
41379
|
const configPath = path55.join(directory, ".opencode/opencode-swarm.json");
|
|
41227
|
-
if (!
|
|
41380
|
+
if (!existsSync33(configPath)) {
|
|
41228
41381
|
return {
|
|
41229
41382
|
name: "Config Parseability",
|
|
41230
41383
|
status: "\u2705",
|
|
@@ -41279,11 +41432,11 @@ async function checkGrammarWasmFiles() {
|
|
|
41279
41432
|
const thisDir = path55.dirname(fileURLToPath(import.meta.url));
|
|
41280
41433
|
const grammarDir = resolveGrammarDir(thisDir);
|
|
41281
41434
|
const missing = [];
|
|
41282
|
-
if (!
|
|
41435
|
+
if (!existsSync33(path55.join(grammarDir, "tree-sitter.wasm"))) {
|
|
41283
41436
|
missing.push("tree-sitter.wasm (core runtime)");
|
|
41284
41437
|
}
|
|
41285
41438
|
for (const file of grammarFiles) {
|
|
41286
|
-
if (!
|
|
41439
|
+
if (!existsSync33(path55.join(grammarDir, file))) {
|
|
41287
41440
|
missing.push(file);
|
|
41288
41441
|
}
|
|
41289
41442
|
}
|
|
@@ -41302,7 +41455,7 @@ async function checkGrammarWasmFiles() {
|
|
|
41302
41455
|
}
|
|
41303
41456
|
async function checkCheckpointManifest(directory) {
|
|
41304
41457
|
const manifestPath = path55.join(directory, ".swarm/checkpoints.json");
|
|
41305
|
-
if (!
|
|
41458
|
+
if (!existsSync33(manifestPath)) {
|
|
41306
41459
|
return {
|
|
41307
41460
|
name: "Checkpoint Manifest",
|
|
41308
41461
|
status: "\u2705",
|
|
@@ -41478,7 +41631,7 @@ async function checkCurator(directory) {
|
|
|
41478
41631
|
};
|
|
41479
41632
|
}
|
|
41480
41633
|
const summaryPath = path55.join(directory, ".swarm/curator-summary.json");
|
|
41481
|
-
if (!
|
|
41634
|
+
if (!existsSync33(summaryPath)) {
|
|
41482
41635
|
return {
|
|
41483
41636
|
name: "Curator",
|
|
41484
41637
|
status: "\u2705",
|
|
@@ -41616,6 +41769,7 @@ async function getDiagnoseData(directory, sessionID) {
|
|
|
41616
41769
|
status: versionStatus,
|
|
41617
41770
|
detail: versionDetail
|
|
41618
41771
|
});
|
|
41772
|
+
checks.push(checkSwarmDb(directory));
|
|
41619
41773
|
const plan = await loadPlanJsonOnly(directory);
|
|
41620
41774
|
if (plan) {
|
|
41621
41775
|
checks.push({
|
|
@@ -41764,7 +41918,7 @@ async function getDiagnoseData(directory, sessionID) {
|
|
|
41764
41918
|
checks.push(await checkResidueInventory(directory));
|
|
41765
41919
|
try {
|
|
41766
41920
|
const evidenceDir = path55.join(directory, ".swarm", "evidence");
|
|
41767
|
-
const snapshotFiles =
|
|
41921
|
+
const snapshotFiles = existsSync33(evidenceDir) ? readdirSync7(evidenceDir).filter((f) => f.startsWith("agent-tools-") && f.endsWith(".json")) : [];
|
|
41768
41922
|
if (snapshotFiles.length > 0) {
|
|
41769
41923
|
const latest = snapshotFiles.sort().pop();
|
|
41770
41924
|
checks.push({
|
|
@@ -41800,13 +41954,13 @@ async function getDiagnoseData(directory, sessionID) {
|
|
|
41800
41954
|
const cacheRows = [];
|
|
41801
41955
|
for (const cachePath of cachePaths) {
|
|
41802
41956
|
try {
|
|
41803
|
-
if (!
|
|
41957
|
+
if (!existsSync33(cachePath)) {
|
|
41804
41958
|
cacheRows.push(`\u2B1C ${cachePath} \u2014 absent`);
|
|
41805
41959
|
continue;
|
|
41806
41960
|
}
|
|
41807
41961
|
const packageRoot = resolveCachePackageRoot(cachePath);
|
|
41808
41962
|
const cacheLabel = packageRoot === cachePath ? cachePath : `${cachePath} -> ${packageRoot}`;
|
|
41809
|
-
const missingGrammarAssets = REQUIRED_CACHE_GRAMMAR_ASSETS.filter((file) => !
|
|
41963
|
+
const missingGrammarAssets = REQUIRED_CACHE_GRAMMAR_ASSETS.filter((file) => !existsSync33(path55.join(packageRoot, "dist", "lang", "grammars", file)));
|
|
41810
41964
|
const pkgJsonPath = path55.join(packageRoot, "package.json");
|
|
41811
41965
|
try {
|
|
41812
41966
|
const raw = readFileSync23(pkgJsonPath, "utf-8");
|
|
@@ -42092,7 +42246,7 @@ async function handleDoctorCommand(directory, args) {
|
|
|
42092
42246
|
const result = runConfigDoctor(config, directory);
|
|
42093
42247
|
let output;
|
|
42094
42248
|
if (enableAutoFix && result.hasAutoFixableIssues) {
|
|
42095
|
-
const { runConfigDoctorWithFixes } = await import("./config-doctor-
|
|
42249
|
+
const { runConfigDoctorWithFixes } = await import("./config-doctor-vfze38e1.js");
|
|
42096
42250
|
const fixResult = await runConfigDoctorWithFixes(directory, config, true, {
|
|
42097
42251
|
applyLossy: true
|
|
42098
42252
|
});
|
|
@@ -43032,7 +43186,7 @@ async function handleEvidenceCommand(directory, args) {
|
|
|
43032
43186
|
return formatTaskEvidenceMarkdown(evidenceData);
|
|
43033
43187
|
}
|
|
43034
43188
|
async function handleEvidenceSummaryCommand(directory) {
|
|
43035
|
-
const { buildEvidenceSummary } = await import("./evidence-summary-service-
|
|
43189
|
+
const { buildEvidenceSummary } = await import("./evidence-summary-service-b15yes21.js");
|
|
43036
43190
|
const artifact = await buildEvidenceSummary(directory);
|
|
43037
43191
|
if (!artifact) {
|
|
43038
43192
|
return "No plan found. Run `/swarm plan` to check plan status.";
|
|
@@ -50031,7 +50185,7 @@ var _internals58 = {
|
|
|
50031
50185
|
// src/session/snapshot-writer.ts
|
|
50032
50186
|
import {
|
|
50033
50187
|
closeSync as closeSync10,
|
|
50034
|
-
existsSync as
|
|
50188
|
+
existsSync as existsSync40,
|
|
50035
50189
|
fsyncSync as fsyncSync2,
|
|
50036
50190
|
mkdirSync as mkdirSync21,
|
|
50037
50191
|
openSync as openSync10,
|
|
@@ -50051,7 +50205,7 @@ async function renameWithTransientRetry(tempPath, targetPath) {
|
|
|
50051
50205
|
} catch (error2) {
|
|
50052
50206
|
lastError = error2;
|
|
50053
50207
|
const code = error2.code;
|
|
50054
|
-
if (code === "ENOENT" && attempt > 0 && !
|
|
50208
|
+
if (code === "ENOENT" && attempt > 0 && !existsSync40(tempPath) && existsSync40(targetPath)) {
|
|
50055
50209
|
return;
|
|
50056
50210
|
}
|
|
50057
50211
|
if (code !== "EEXIST" && code !== "EBUSY" && code !== "EPERM") {
|
|
@@ -50926,7 +51080,7 @@ init_zod();
|
|
|
50926
51080
|
var import_proper_lockfile7 = __toESM(require_proper_lockfile(), 1);
|
|
50927
51081
|
import {
|
|
50928
51082
|
closeSync as closeSync11,
|
|
50929
|
-
existsSync as
|
|
51083
|
+
existsSync as existsSync41,
|
|
50930
51084
|
constants as FS_CONSTANTS,
|
|
50931
51085
|
fstatSync,
|
|
50932
51086
|
fsyncSync as fsyncSync3,
|
|
@@ -50938,7 +51092,7 @@ import {
|
|
|
50938
51092
|
readFileSync as readFileSync32,
|
|
50939
51093
|
renameSync as renameSync12,
|
|
50940
51094
|
rmSync as rmSync7,
|
|
50941
|
-
statSync as
|
|
51095
|
+
statSync as statSync20,
|
|
50942
51096
|
unlinkSync as unlinkSync12,
|
|
50943
51097
|
writeSync
|
|
50944
51098
|
} from "fs";
|
|
@@ -51187,7 +51341,7 @@ function activeLedgerDir(directory) {
|
|
|
51187
51341
|
return ledgerDir(directory);
|
|
51188
51342
|
const pointer = parseLedgerGenerationPointer(pointerValue, ledgerPointerPath(directory));
|
|
51189
51343
|
const target = path68.join(ledgerDir(directory), pointer.generationDir);
|
|
51190
|
-
if (!
|
|
51344
|
+
if (!existsSync41(target)) {
|
|
51191
51345
|
throw new HarnessStoreIntegrityError(target, "harness active ledger generation is missing");
|
|
51192
51346
|
}
|
|
51193
51347
|
return target;
|
|
@@ -51253,7 +51407,7 @@ function assertSafeArtifactPath(filePath, root) {
|
|
|
51253
51407
|
function readJsonFile(filePath, storeRoot) {
|
|
51254
51408
|
if (storeRoot)
|
|
51255
51409
|
assertSafeArtifactPath(filePath, storeRoot);
|
|
51256
|
-
if (!
|
|
51410
|
+
if (!existsSync41(filePath))
|
|
51257
51411
|
return null;
|
|
51258
51412
|
try {
|
|
51259
51413
|
const initial = lstatSync4(filePath);
|
|
@@ -51502,7 +51656,7 @@ function isCompactionRecord(record) {
|
|
|
51502
51656
|
}
|
|
51503
51657
|
function listSegmentPaths(directory) {
|
|
51504
51658
|
const activeDir = activeLedgerDir(directory);
|
|
51505
|
-
if (!
|
|
51659
|
+
if (!existsSync41(activeDir))
|
|
51506
51660
|
return [];
|
|
51507
51661
|
const segments = readDirFiles(activeDir).filter((name) => /^\d{6}\.jsonl$/.test(name)).sort();
|
|
51508
51662
|
for (let index = 0;index < segments.length; index++) {
|
|
@@ -51854,7 +52008,7 @@ function readProjectionAnchor(directory, segmentIndex) {
|
|
|
51854
52008
|
};
|
|
51855
52009
|
}
|
|
51856
52010
|
const previousSegmentPath = path68.join(activeLedgerDir(directory), segmentName(segmentIndex - 1));
|
|
51857
|
-
if (!
|
|
52011
|
+
if (!existsSync41(previousSegmentPath)) {
|
|
51858
52012
|
throw new HarnessStoreIntegrityError(previousSegmentPath, "harness ledger segment missing during projection replay");
|
|
51859
52013
|
}
|
|
51860
52014
|
const previousRecords = readSegmentRecords(previousSegmentPath, false).records;
|
|
@@ -51893,7 +52047,7 @@ function loadCurrentProjectionFast(directory, maxReplayRecords) {
|
|
|
51893
52047
|
const verifiedRecords = [];
|
|
51894
52048
|
if (storedHeadSegmentIndex > 0) {
|
|
51895
52049
|
const segmentPath = path68.join(activeLedgerDir(directory), stored.ledgerHeadSegment);
|
|
51896
|
-
if (!
|
|
52050
|
+
if (!existsSync41(segmentPath))
|
|
51897
52051
|
return null;
|
|
51898
52052
|
const parsed = readSegmentRecords(segmentPath, storedHeadSegmentIndex === segmentCount.count);
|
|
51899
52053
|
pointerSegmentRecords = parsed.records;
|
|
@@ -51996,7 +52150,7 @@ function buildHarnessHistoryPage(directory, current, limit, maxReplayRecords, in
|
|
|
51996
52150
|
let expectedHashAfter = current.ledgerHeadHash;
|
|
51997
52151
|
for (let segmentIndex = headSegmentIndex;segmentIndex >= 1 && records.length < safeLimit; segmentIndex--) {
|
|
51998
52152
|
const segmentPath = path68.join(activeLedgerDir(directory), segmentName(segmentIndex));
|
|
51999
|
-
if (!
|
|
52153
|
+
if (!existsSync41(segmentPath)) {
|
|
52000
52154
|
throw new HarnessStoreIntegrityError(segmentPath, "harness ledger segment missing during bounded history read");
|
|
52001
52155
|
}
|
|
52002
52156
|
const parsed = readSegmentRecords(segmentPath, segmentIndex === headSegmentIndex);
|
|
@@ -53062,11 +53216,11 @@ import {
|
|
|
53062
53216
|
copyFile as copyFile2,
|
|
53063
53217
|
mkdir as mkdir14,
|
|
53064
53218
|
readdir as readdir4,
|
|
53065
|
-
readFile as
|
|
53219
|
+
readFile as readFile15,
|
|
53066
53220
|
realpath as realpath4,
|
|
53067
53221
|
rm as rm2,
|
|
53068
53222
|
stat as stat5,
|
|
53069
|
-
writeFile as
|
|
53223
|
+
writeFile as writeFile8
|
|
53070
53224
|
} from "fs/promises";
|
|
53071
53225
|
import * as path70 from "path";
|
|
53072
53226
|
var HIVE_QUARANTINE_TOKEN_TTL_MS = 15 * 60 * 1000;
|
|
@@ -53857,8 +54011,8 @@ function emitMaintenanceTelemetry(payload) {
|
|
|
53857
54011
|
}
|
|
53858
54012
|
var _internals60 = {
|
|
53859
54013
|
emit,
|
|
53860
|
-
readFile:
|
|
53861
|
-
writeFile:
|
|
54014
|
+
readFile: readFile15,
|
|
54015
|
+
writeFile: writeFile8,
|
|
53862
54016
|
copyFile: copyFile2,
|
|
53863
54017
|
mkdir: mkdir14,
|
|
53864
54018
|
stat: stat5,
|
|
@@ -54175,14 +54329,14 @@ ${USAGE11}`;
|
|
|
54175
54329
|
}
|
|
54176
54330
|
|
|
54177
54331
|
// src/commands/knowledge.ts
|
|
54178
|
-
import { join as
|
|
54332
|
+
import { join as join59 } from "path";
|
|
54179
54333
|
init_schema();
|
|
54180
54334
|
|
|
54181
54335
|
// src/hooks/knowledge-migrator.ts
|
|
54182
54336
|
init_logger();
|
|
54183
54337
|
import { randomUUID as randomUUID10 } from "crypto";
|
|
54184
|
-
import { existsSync as
|
|
54185
|
-
import { mkdir as mkdir15, readFile as
|
|
54338
|
+
import { existsSync as existsSync43, readFileSync as readFileSync35 } from "fs";
|
|
54339
|
+
import { mkdir as mkdir15, readFile as readFile16, writeFile as writeFile9 } from "fs/promises";
|
|
54186
54340
|
import * as os9 from "os";
|
|
54187
54341
|
import * as path72 from "path";
|
|
54188
54342
|
init_knowledge_types();
|
|
@@ -54246,17 +54400,17 @@ var _internals62 = {
|
|
|
54246
54400
|
inferProjectName,
|
|
54247
54401
|
writeSentinel,
|
|
54248
54402
|
resolveLegacyHiveKnowledgePath,
|
|
54249
|
-
existsSync:
|
|
54403
|
+
existsSync: existsSync43,
|
|
54250
54404
|
readFileSync: readFileSync35,
|
|
54251
|
-
readFile:
|
|
54405
|
+
readFile: readFile16,
|
|
54252
54406
|
mkdir: mkdir15,
|
|
54253
|
-
writeFile:
|
|
54407
|
+
writeFile: writeFile9
|
|
54254
54408
|
};
|
|
54255
54409
|
async function migrateContextToKnowledge(directory, config) {
|
|
54256
54410
|
const sentinelPath = path72.join(directory, ".swarm", ".knowledge-migrated");
|
|
54257
54411
|
const contextPath = path72.join(directory, ".swarm", "context.md");
|
|
54258
54412
|
const knowledgePath = resolveSwarmKnowledgePath(directory);
|
|
54259
|
-
if (
|
|
54413
|
+
if (existsSync43(sentinelPath)) {
|
|
54260
54414
|
return {
|
|
54261
54415
|
migrated: false,
|
|
54262
54416
|
entriesMigrated: 0,
|
|
@@ -54265,7 +54419,7 @@ async function migrateContextToKnowledge(directory, config) {
|
|
|
54265
54419
|
skippedReason: "sentinel-exists"
|
|
54266
54420
|
};
|
|
54267
54421
|
}
|
|
54268
|
-
if (!
|
|
54422
|
+
if (!existsSync43(contextPath)) {
|
|
54269
54423
|
return {
|
|
54270
54424
|
migrated: false,
|
|
54271
54425
|
entriesMigrated: 0,
|
|
@@ -54274,7 +54428,7 @@ async function migrateContextToKnowledge(directory, config) {
|
|
|
54274
54428
|
skippedReason: "no-context-file"
|
|
54275
54429
|
};
|
|
54276
54430
|
}
|
|
54277
|
-
const contextContent = await
|
|
54431
|
+
const contextContent = await readFile16(contextPath, "utf-8");
|
|
54278
54432
|
if (contextContent.trim().length === 0) {
|
|
54279
54433
|
return {
|
|
54280
54434
|
migrated: false,
|
|
@@ -54357,7 +54511,7 @@ async function migrateHiveKnowledgeLegacy(config) {
|
|
|
54357
54511
|
const legacyHivePath = _internals62.resolveLegacyHiveKnowledgePath();
|
|
54358
54512
|
const canonicalHivePath = resolveHiveKnowledgePath2();
|
|
54359
54513
|
const sentinelPath = path72.join(path72.dirname(canonicalHivePath), ".hive-knowledge-migrated");
|
|
54360
|
-
if (
|
|
54514
|
+
if (existsSync43(sentinelPath)) {
|
|
54361
54515
|
return {
|
|
54362
54516
|
migrated: false,
|
|
54363
54517
|
entriesMigrated: 0,
|
|
@@ -54366,7 +54520,7 @@ async function migrateHiveKnowledgeLegacy(config) {
|
|
|
54366
54520
|
skippedReason: "sentinel-exists"
|
|
54367
54521
|
};
|
|
54368
54522
|
}
|
|
54369
|
-
if (!
|
|
54523
|
+
if (!existsSync43(legacyHivePath)) {
|
|
54370
54524
|
return {
|
|
54371
54525
|
migrated: false,
|
|
54372
54526
|
entriesMigrated: 0,
|
|
@@ -54568,7 +54722,7 @@ function truncateLesson2(text) {
|
|
|
54568
54722
|
}
|
|
54569
54723
|
function inferProjectName(directory) {
|
|
54570
54724
|
const packageJsonPath = path72.join(directory, "package.json");
|
|
54571
|
-
if (
|
|
54725
|
+
if (existsSync43(packageJsonPath)) {
|
|
54572
54726
|
try {
|
|
54573
54727
|
const pkg = JSON.parse(readFileSync35(packageJsonPath, "utf-8"));
|
|
54574
54728
|
if (pkg.name && typeof pkg.name === "string") {
|
|
@@ -54693,7 +54847,7 @@ async function handleKnowledgeRestoreCommand(directory, args) {
|
|
|
54693
54847
|
}
|
|
54694
54848
|
return `\u274C Entry ${fullId2} could not be unarchived${result.reason ? ` (${result.reason})` : ""}.`;
|
|
54695
54849
|
}
|
|
54696
|
-
const quarantinePath =
|
|
54850
|
+
const quarantinePath = join59(resolveKnowledgeStoreDir(directory), "knowledge-quarantined.jsonl");
|
|
54697
54851
|
const entries = await readKnowledge(quarantinePath);
|
|
54698
54852
|
const resolved = resolveEntryByPrefix(entries, inputId);
|
|
54699
54853
|
if ("error" in resolved) {
|
|
@@ -56058,13 +56212,13 @@ var _internals64 = {
|
|
|
56058
56212
|
};
|
|
56059
56213
|
|
|
56060
56214
|
// src/commands/link.ts
|
|
56061
|
-
import { mkdir as mkdir17, writeFile as
|
|
56215
|
+
import { mkdir as mkdir17, writeFile as writeFile10 } from "fs/promises";
|
|
56062
56216
|
import * as path75 from "path";
|
|
56063
56217
|
init_schema();
|
|
56064
56218
|
|
|
56065
56219
|
// src/knowledge/family-migration.ts
|
|
56066
56220
|
var import_proper_lockfile8 = __toESM(require_proper_lockfile(), 1);
|
|
56067
|
-
import { existsSync as
|
|
56221
|
+
import { existsSync as existsSync44, readFileSync as readFileSync37 } from "fs";
|
|
56068
56222
|
import { mkdir as mkdir16 } from "fs/promises";
|
|
56069
56223
|
import * as path74 from "path";
|
|
56070
56224
|
|
|
@@ -56173,7 +56327,7 @@ var MIGRATION_LOCK_RETRIES = {
|
|
|
56173
56327
|
// src/knowledge/family-migration.ts
|
|
56174
56328
|
var DEDUP_THRESHOLD = 0.6;
|
|
56175
56329
|
function readJsonl2(filePath) {
|
|
56176
|
-
if (!
|
|
56330
|
+
if (!existsSync44(filePath))
|
|
56177
56331
|
return [];
|
|
56178
56332
|
try {
|
|
56179
56333
|
const content = readFileSync37(filePath, "utf-8");
|
|
@@ -56193,7 +56347,7 @@ function readJsonl2(filePath) {
|
|
|
56193
56347
|
}
|
|
56194
56348
|
}
|
|
56195
56349
|
function readJson(filePath) {
|
|
56196
|
-
if (!
|
|
56350
|
+
if (!existsSync44(filePath))
|
|
56197
56351
|
return null;
|
|
56198
56352
|
try {
|
|
56199
56353
|
return JSON.parse(readFileSync37(filePath, "utf-8"));
|
|
@@ -56518,7 +56672,7 @@ ${formatStatus(directory)}`;
|
|
|
56518
56672
|
const config = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
|
|
56519
56673
|
const fingerprint = cohortConfigFingerprint(buildConfigFingerprintInput(config));
|
|
56520
56674
|
await mkdir17(linkDir, { recursive: true });
|
|
56521
|
-
await
|
|
56675
|
+
await writeFile10(path75.join(linkDir, "cohort-config.json"), JSON.stringify({ fingerprint, updated_at: new Date().toISOString() }, null, 2), "utf-8");
|
|
56522
56676
|
} catch {}
|
|
56523
56677
|
const relinkNote = existing ? `
|
|
56524
56678
|
(Re-linked from previous link "${existing.linkId}".)` : "";
|
|
@@ -56544,7 +56698,7 @@ var MIN_MAX_CYCLES = 1;
|
|
|
56544
56698
|
var MAX_MAX_CYCLES = 5;
|
|
56545
56699
|
async function readLatestLoopState(directory) {
|
|
56546
56700
|
try {
|
|
56547
|
-
const { readdirSync: readdirSync10, statSync:
|
|
56701
|
+
const { readdirSync: readdirSync10, statSync: statSync22, readFileSync: readFileSync38 } = await import("fs");
|
|
56548
56702
|
const loopDir = `${directory}/.swarm/loop`;
|
|
56549
56703
|
let latestMtime = 0;
|
|
56550
56704
|
let latestPath = null;
|
|
@@ -56555,7 +56709,7 @@ async function readLatestLoopState(directory) {
|
|
|
56555
56709
|
continue;
|
|
56556
56710
|
const statePath = `${loopDir}/${entry.name}/state.json`;
|
|
56557
56711
|
try {
|
|
56558
|
-
const mtime =
|
|
56712
|
+
const mtime = statSync22(statePath).mtimeMs;
|
|
56559
56713
|
if (mtime > latestMtime) {
|
|
56560
56714
|
latestMtime = mtime;
|
|
56561
56715
|
latestPath = statePath;
|
|
@@ -56701,7 +56855,7 @@ ${USAGE12}`;
|
|
|
56701
56855
|
|
|
56702
56856
|
// src/commands/memory.ts
|
|
56703
56857
|
init_loader();
|
|
56704
|
-
import { existsSync as
|
|
56858
|
+
import { existsSync as existsSync46, realpathSync as realpathSync9 } from "fs";
|
|
56705
56859
|
import * as path82 from "path";
|
|
56706
56860
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
56707
56861
|
// src/memory/evaluation.ts
|
|
@@ -57188,12 +57342,12 @@ init_logger();
|
|
|
57188
57342
|
// src/memory/reflection-service.ts
|
|
57189
57343
|
import {
|
|
57190
57344
|
closeSync as closeSync13,
|
|
57191
|
-
existsSync as
|
|
57345
|
+
existsSync as existsSync45,
|
|
57192
57346
|
fstatSync as fstatSync3,
|
|
57193
57347
|
openSync as openSync13,
|
|
57194
57348
|
readSync as readSync7,
|
|
57195
57349
|
realpathSync as realpathSync8,
|
|
57196
|
-
statSync as
|
|
57350
|
+
statSync as statSync23
|
|
57197
57351
|
} from "fs";
|
|
57198
57352
|
var import_proper_lockfile9 = __toESM(require_proper_lockfile(), 1);
|
|
57199
57353
|
|
|
@@ -62068,7 +62222,7 @@ var MAX_GRAPH_BYTES = 16 * 1024 * 1024;
|
|
|
62068
62222
|
var MAX_STORE_BYTES2 = 16 * 1024 * 1024;
|
|
62069
62223
|
function readReflectionDigest(directory) {
|
|
62070
62224
|
const filePath = validateSwarmPath(directory, "reflections/lessons.json");
|
|
62071
|
-
if (!
|
|
62225
|
+
if (!existsSync45(filePath))
|
|
62072
62226
|
return null;
|
|
62073
62227
|
let fd;
|
|
62074
62228
|
try {
|
|
@@ -62093,7 +62247,7 @@ function readDeadAnchorMemoryIds(directory) {
|
|
|
62093
62247
|
return new Set(Array.isArray(digest2?.deadAnchorMemoryIds) ? digest2.deadAnchorMemoryIds.filter((value) => typeof value === "string") : []);
|
|
62094
62248
|
}
|
|
62095
62249
|
// src/memory/consolidation-log.ts
|
|
62096
|
-
import { appendFile as appendFile4, mkdir as mkdir19, readFile as
|
|
62250
|
+
import { appendFile as appendFile4, mkdir as mkdir19, readFile as readFile20 } from "fs/promises";
|
|
62097
62251
|
import * as path81 from "path";
|
|
62098
62252
|
var LOG_RELATIVE_PATH = path81.join("memory", "consolidation-log.jsonl");
|
|
62099
62253
|
var LOG_BASENAME = "consolidation-log.jsonl";
|
|
@@ -62110,7 +62264,7 @@ async function readConsolidationLog(target) {
|
|
|
62110
62264
|
const filePath = resolveLogPath2(target);
|
|
62111
62265
|
let raw;
|
|
62112
62266
|
try {
|
|
62113
|
-
raw = await
|
|
62267
|
+
raw = await readFile20(filePath, "utf-8");
|
|
62114
62268
|
} catch {
|
|
62115
62269
|
return [];
|
|
62116
62270
|
}
|
|
@@ -62192,7 +62346,7 @@ async function handleMemoryStatusCommand(directory, _args) {
|
|
|
62192
62346
|
`- Provider: \`${config.provider}\``,
|
|
62193
62347
|
`- Storage: \`${storageDir}\``,
|
|
62194
62348
|
`- SQLite path: \`${sqlitePath}\``,
|
|
62195
|
-
`- SQLite database exists: \`${
|
|
62349
|
+
`- SQLite database exists: \`${existsSync46(sqlitePath)}\``,
|
|
62196
62350
|
`- Automatic destructive cleanup: \`disabled\``,
|
|
62197
62351
|
"",
|
|
62198
62352
|
"### Legacy JSONL"
|
|
@@ -62757,13 +62911,13 @@ function truncate2(value, maxLength) {
|
|
|
62757
62911
|
}
|
|
62758
62912
|
|
|
62759
62913
|
// src/commands/memory-link.ts
|
|
62760
|
-
import { mkdir as mkdir21, writeFile as
|
|
62914
|
+
import { mkdir as mkdir21, writeFile as writeFile12 } from "fs/promises";
|
|
62761
62915
|
import * as path84 from "path";
|
|
62762
62916
|
init_schema();
|
|
62763
62917
|
|
|
62764
62918
|
// src/memory/memory-family-migration.ts
|
|
62765
62919
|
var import_proper_lockfile10 = __toESM(require_proper_lockfile(), 1);
|
|
62766
|
-
import { copyFileSync as copyFileSync4, existsSync as
|
|
62920
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync47, readFileSync as readFileSync39, unlinkSync as unlinkSync15 } from "fs";
|
|
62767
62921
|
import { mkdir as mkdir20, rename as rename8 } from "fs/promises";
|
|
62768
62922
|
import * as path83 from "path";
|
|
62769
62923
|
init_logger();
|
|
@@ -62830,7 +62984,7 @@ var MIGRATED_MEMORY_FILENAMES = MEMORY_FAMILY.filter((m) => m.mergeStrategy !==
|
|
|
62830
62984
|
// src/memory/memory-family-migration.ts
|
|
62831
62985
|
var MAX_BACKUPS = 5;
|
|
62832
62986
|
function readJsonl3(filePath) {
|
|
62833
|
-
if (!
|
|
62987
|
+
if (!existsSync47(filePath))
|
|
62834
62988
|
return [];
|
|
62835
62989
|
try {
|
|
62836
62990
|
const content = readFileSync39(filePath, "utf-8");
|
|
@@ -62914,13 +63068,13 @@ function validateSerializedJsonl(serialized) {
|
|
|
62914
63068
|
}
|
|
62915
63069
|
function stageSqliteDb(sourceStoragePath, destDir) {
|
|
62916
63070
|
const sourceDbPath = path83.join(sourceStoragePath, "memory.db");
|
|
62917
|
-
if (!
|
|
63071
|
+
if (!existsSync47(sourceDbPath))
|
|
62918
63072
|
return null;
|
|
62919
63073
|
const stagedPath = path83.join(destDir, ".memory.db.stage");
|
|
62920
63074
|
copyFileSync4(sourceDbPath, stagedPath);
|
|
62921
63075
|
for (const suffix of ["-wal", "-shm"]) {
|
|
62922
63076
|
const sidecar = `${sourceDbPath}${suffix}`;
|
|
62923
|
-
if (
|
|
63077
|
+
if (existsSync47(sidecar)) {
|
|
62924
63078
|
try {
|
|
62925
63079
|
copyFileSync4(sidecar, `${stagedPath}${suffix}`);
|
|
62926
63080
|
} catch {}
|
|
@@ -62930,11 +63084,11 @@ function stageSqliteDb(sourceStoragePath, destDir) {
|
|
|
62930
63084
|
}
|
|
62931
63085
|
async function mergeStagedSqlite(destStoragePath, stagedPath) {
|
|
62932
63086
|
const destDbPath = path83.join(destStoragePath, "memory.db");
|
|
62933
|
-
if (!
|
|
63087
|
+
if (!existsSync47(destDbPath)) {
|
|
62934
63088
|
await rename8(stagedPath, destDbPath);
|
|
62935
63089
|
for (const suffix of ["-wal", "-shm"]) {
|
|
62936
63090
|
const stagedSidecar = `${stagedPath}${suffix}`;
|
|
62937
|
-
if (
|
|
63091
|
+
if (existsSync47(stagedSidecar)) {
|
|
62938
63092
|
try {
|
|
62939
63093
|
await rename8(stagedSidecar, `${destDbPath}${suffix}`);
|
|
62940
63094
|
} catch {}
|
|
@@ -62943,7 +63097,7 @@ async function mergeStagedSqlite(destStoragePath, stagedPath) {
|
|
|
62943
63097
|
return { merged: await countRowsSafe(destDbPath), skipped: 0 };
|
|
62944
63098
|
}
|
|
62945
63099
|
try {
|
|
62946
|
-
const { loadDatabaseCtor: loadDatabaseCtor2 } = await import("./sqlite-loader-
|
|
63100
|
+
const { loadDatabaseCtor: loadDatabaseCtor2 } = await import("./sqlite-loader-8zefc142.js");
|
|
62947
63101
|
const Db = loadDatabaseCtor2();
|
|
62948
63102
|
const db = new Db(destDbPath);
|
|
62949
63103
|
let attached = false;
|
|
@@ -63040,7 +63194,7 @@ async function mergeStagedSqlite(destStoragePath, stagedPath) {
|
|
|
63040
63194
|
}
|
|
63041
63195
|
async function countRowsSafe(dbPath) {
|
|
63042
63196
|
try {
|
|
63043
|
-
const { loadDatabaseCtor: loadDatabaseCtor2 } = await import("./sqlite-loader-
|
|
63197
|
+
const { loadDatabaseCtor: loadDatabaseCtor2 } = await import("./sqlite-loader-8zefc142.js");
|
|
63044
63198
|
const Db = loadDatabaseCtor2();
|
|
63045
63199
|
const db = new Db(dbPath);
|
|
63046
63200
|
try {
|
|
@@ -63072,7 +63226,7 @@ async function migrateMemoryFamily(destRoot, sourceRoot) {
|
|
|
63072
63226
|
const srcPath = path83.join(sourceStoragePath, member.filename);
|
|
63073
63227
|
const destPath = path83.join(destStoragePath, member.filename);
|
|
63074
63228
|
if (member.mergeStrategy === "sqlite-file-copy") {
|
|
63075
|
-
if (!
|
|
63229
|
+
if (!existsSync47(srcPath)) {
|
|
63076
63230
|
perMember.push({ filename: member.filename, merged: 0, skipped: 0 });
|
|
63077
63231
|
continue;
|
|
63078
63232
|
}
|
|
@@ -63086,7 +63240,7 @@ async function migrateMemoryFamily(destRoot, sourceRoot) {
|
|
|
63086
63240
|
continue;
|
|
63087
63241
|
}
|
|
63088
63242
|
if (member.mergeStrategy === "append-union") {
|
|
63089
|
-
if (!
|
|
63243
|
+
if (!existsSync47(srcPath)) {
|
|
63090
63244
|
perMember.push({ filename: member.filename, merged: 0, skipped: 0 });
|
|
63091
63245
|
continue;
|
|
63092
63246
|
}
|
|
@@ -63106,7 +63260,7 @@ async function migrateMemoryFamily(destRoot, sourceRoot) {
|
|
|
63106
63260
|
await mkdir20(backupDir, { recursive: true });
|
|
63107
63261
|
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
63108
63262
|
const sourceDbPath = path83.join(sourceStoragePath, "memory.db");
|
|
63109
|
-
if (
|
|
63263
|
+
if (existsSync47(sourceDbPath)) {
|
|
63110
63264
|
try {
|
|
63111
63265
|
copyFileSync4(sourceDbPath, path83.join(backupDir, `memory.db.pre-merge-${stamp}`));
|
|
63112
63266
|
} catch {}
|
|
@@ -63242,7 +63396,7 @@ ${formatStatus2(directory)}`;
|
|
|
63242
63396
|
await mkdir21(cohortRoot.cohortRoot, { recursive: true });
|
|
63243
63397
|
const fingerprintInput = buildMemoryCohortFingerprintInput(memoryConfig);
|
|
63244
63398
|
const fingerprint = computeMemoryCohortFingerprint(fingerprintInput);
|
|
63245
|
-
await
|
|
63399
|
+
await writeFile12(path84.join(cohortRoot.cohortRoot, "memory-cohort-config.json"), JSON.stringify({
|
|
63246
63400
|
fingerprint,
|
|
63247
63401
|
algorithm_version: FINGERPRINT_ALGORITHM_VERSION,
|
|
63248
63402
|
config: fingerprintInput,
|
|
@@ -76871,12 +77025,12 @@ Ensure this is a git repository with commit history.`;
|
|
|
76871
77025
|
|
|
76872
77026
|
// src/commands/skill-opt.ts
|
|
76873
77027
|
init_schema();
|
|
76874
|
-
import { copyFileSync as copyFileSync5, existsSync as
|
|
77028
|
+
import { copyFileSync as copyFileSync5, existsSync as existsSync63, mkdirSync as mkdirSync33, readFileSync as readFileSync50 } from "fs";
|
|
76875
77029
|
import * as path112 from "path";
|
|
76876
77030
|
|
|
76877
77031
|
// src/services/skill-optimizer/activation.ts
|
|
76878
77032
|
import {
|
|
76879
|
-
existsSync as
|
|
77033
|
+
existsSync as existsSync59,
|
|
76880
77034
|
mkdirSync as mkdirSync30,
|
|
76881
77035
|
readFileSync as readFileSync47,
|
|
76882
77036
|
renameSync as renameSync17,
|
|
@@ -76889,13 +77043,13 @@ import * as path106 from "path";
|
|
|
76889
77043
|
import { createHash as createHash32, randomUUID as randomUUID12 } from "crypto";
|
|
76890
77044
|
import {
|
|
76891
77045
|
closeSync as closeSync20,
|
|
76892
|
-
existsSync as
|
|
77046
|
+
existsSync as existsSync58,
|
|
76893
77047
|
fsyncSync as fsyncSync4,
|
|
76894
77048
|
mkdirSync as mkdirSync29,
|
|
76895
77049
|
openSync as openSync20,
|
|
76896
77050
|
readFileSync as readFileSync46,
|
|
76897
77051
|
renameSync as renameSync16,
|
|
76898
|
-
statSync as
|
|
77052
|
+
statSync as statSync27,
|
|
76899
77053
|
unlinkSync as unlinkSync22,
|
|
76900
77054
|
writeFileSync as writeFileSync18,
|
|
76901
77055
|
writeFileSync as writeFileSyncAsync
|
|
@@ -76956,7 +77110,7 @@ function stateProjectionPath(directory, skillSlug, candidateId2) {
|
|
|
76956
77110
|
}
|
|
76957
77111
|
function ensureCandidateDir(directory, skillSlug, candidateId2) {
|
|
76958
77112
|
const dir = candidateDir(directory, skillSlug, candidateId2);
|
|
76959
|
-
if (!
|
|
77113
|
+
if (!existsSync58(dir))
|
|
76960
77114
|
mkdirSync29(dir, { recursive: true });
|
|
76961
77115
|
return dir;
|
|
76962
77116
|
}
|
|
@@ -76984,8 +77138,8 @@ var _internals93 = {
|
|
|
76984
77138
|
readFileSync: readFileSync46,
|
|
76985
77139
|
renameSync: renameSync16,
|
|
76986
77140
|
unlinkSync: unlinkSync22,
|
|
76987
|
-
existsSync:
|
|
76988
|
-
statSync:
|
|
77141
|
+
existsSync: existsSync58,
|
|
77142
|
+
statSync: statSync27
|
|
76989
77143
|
};
|
|
76990
77144
|
async function appendEvent2(directory, eventInput) {
|
|
76991
77145
|
assertProjectRoot(directory);
|
|
@@ -76998,7 +77152,7 @@ async function appendEvent2(directory, eventInput) {
|
|
|
76998
77152
|
const filePath = ledgerPath2(directory, eventInput.skillSlug, eventInput.candidateId);
|
|
76999
77153
|
return _internals93.withEvidenceLock(directory, path105.join(".swarm", "evolution", "skills", eventInput.skillSlug, eventInput.candidateId, "lifecycle.jsonl"), "skill-opt-ledger", "append-skill-opt-event", async () => {
|
|
77000
77154
|
ensureCandidateDir(directory, eventInput.skillSlug, eventInput.candidateId);
|
|
77001
|
-
const existing =
|
|
77155
|
+
const existing = existsSync58(filePath) ? readFileSync46(filePath, "utf8") : "";
|
|
77002
77156
|
const events = parseEventsFromText(existing);
|
|
77003
77157
|
const nextSeq = events.length === 0 ? 1 : events[events.length - 1].seq + 1;
|
|
77004
77158
|
const lastEvent = events.length === 0 ? null : events[events.length - 1];
|
|
@@ -77056,7 +77210,7 @@ function parseEventsFromText(text) {
|
|
|
77056
77210
|
}
|
|
77057
77211
|
function replayCandidate(directory, skillSlug, candidateId2) {
|
|
77058
77212
|
const filePath = ledgerPath2(directory, skillSlug, candidateId2);
|
|
77059
|
-
if (!
|
|
77213
|
+
if (!existsSync58(filePath)) {
|
|
77060
77214
|
return {
|
|
77061
77215
|
events: [],
|
|
77062
77216
|
state: null,
|
|
@@ -77110,7 +77264,7 @@ function replayCandidate(directory, skillSlug, candidateId2) {
|
|
|
77110
77264
|
function quarantineSuffix(directory, skillSlug, badSuffix) {
|
|
77111
77265
|
assertProjectRoot(directory);
|
|
77112
77266
|
const dir = path105.join(directory, ".swarm", "evolution", "skills");
|
|
77113
|
-
if (!
|
|
77267
|
+
if (!existsSync58(dir))
|
|
77114
77268
|
mkdirSync29(dir, { recursive: true });
|
|
77115
77269
|
const hash2 = computeStateHash(badSuffix).slice(0, 12);
|
|
77116
77270
|
const stamp = Date.now();
|
|
@@ -77146,7 +77300,7 @@ function writeArtifact(directory, skillSlug, candidateId2, fileName, content) {
|
|
|
77146
77300
|
}
|
|
77147
77301
|
function readArtifact(directory, skillSlug, candidateId2, fileName) {
|
|
77148
77302
|
const target = path105.join(candidateDir(directory, skillSlug, candidateId2), fileName);
|
|
77149
|
-
if (!
|
|
77303
|
+
if (!existsSync58(target))
|
|
77150
77304
|
return null;
|
|
77151
77305
|
return readFileSync46(target, "utf8");
|
|
77152
77306
|
}
|
|
@@ -77238,7 +77392,7 @@ function writeSkillFileAtomic(targetPath, content) {
|
|
|
77238
77392
|
_internals94.renameSync(tempPath, targetPath);
|
|
77239
77393
|
} finally {
|
|
77240
77394
|
try {
|
|
77241
|
-
if (
|
|
77395
|
+
if (existsSync59(tempPath))
|
|
77242
77396
|
_internals94.unlinkSync(tempPath);
|
|
77243
77397
|
} catch {}
|
|
77244
77398
|
}
|
|
@@ -77250,7 +77404,7 @@ var _internals94 = {
|
|
|
77250
77404
|
};
|
|
77251
77405
|
async function activateCandidate(input) {
|
|
77252
77406
|
const skillPath = path106.join(input.directory, ".opencode", "skills", "generated", input.skillSlug, "SKILL.md");
|
|
77253
|
-
const incumbent =
|
|
77407
|
+
const incumbent = existsSync59(skillPath) ? readFileSync47(skillPath, "utf8") : "";
|
|
77254
77408
|
const currentHash = computeContentHash2(incumbent);
|
|
77255
77409
|
if (currentHash !== input.expectedContentHash) {
|
|
77256
77410
|
return {
|
|
@@ -77277,7 +77431,7 @@ async function activateCandidate(input) {
|
|
|
77277
77431
|
}
|
|
77278
77432
|
const rollbackSnapshotRef = writeArtifact(input.directory, input.skillSlug, input.candidateId, "rollback.md", incumbent);
|
|
77279
77433
|
const skillRoot = path106.dirname(skillPath);
|
|
77280
|
-
if (!
|
|
77434
|
+
if (!existsSync59(skillRoot))
|
|
77281
77435
|
mkdirSync30(skillRoot, { recursive: true });
|
|
77282
77436
|
writeSkillFileAtomic(skillPath, candidateContent);
|
|
77283
77437
|
await recordTransition({
|
|
@@ -77316,7 +77470,7 @@ async function rollbackCandidate(input) {
|
|
|
77316
77470
|
};
|
|
77317
77471
|
}
|
|
77318
77472
|
const skillPath = path106.join(input.directory, ".opencode", "skills", "generated", input.skillSlug, "SKILL.md");
|
|
77319
|
-
const beforeContent =
|
|
77473
|
+
const beforeContent = existsSync59(skillPath) ? readFileSync47(skillPath, "utf8") : "";
|
|
77320
77474
|
writeSkillFileAtomic(skillPath, snapshot);
|
|
77321
77475
|
await recordTransition({
|
|
77322
77476
|
directory: input.directory,
|
|
@@ -77335,7 +77489,7 @@ async function rollbackCandidate(input) {
|
|
|
77335
77489
|
|
|
77336
77490
|
// src/services/skill-optimizer/controller.ts
|
|
77337
77491
|
import { randomUUID as randomUUID13 } from "crypto";
|
|
77338
|
-
import { existsSync as
|
|
77492
|
+
import { existsSync as existsSync61, mkdirSync as mkdirSync31, readFileSync as readFileSync49, writeFileSync as writeFileSync20 } from "fs";
|
|
77339
77493
|
import * as path110 from "path";
|
|
77340
77494
|
|
|
77341
77495
|
// src/evaluation/pr-review-recovery.ts
|
|
@@ -77670,7 +77824,7 @@ var evaluationV1 = Object.freeze(Object.assign((options) => evaluateCandidateV1(
|
|
|
77670
77824
|
|
|
77671
77825
|
// src/security/protected-input-integrity.ts
|
|
77672
77826
|
import { createHash as createHash33 } from "crypto";
|
|
77673
|
-
import { lstat as lstat3, readdir as readdir8, readFile as
|
|
77827
|
+
import { lstat as lstat3, readdir as readdir8, readFile as readFile22, realpath as realpath7 } from "fs/promises";
|
|
77674
77828
|
import * as path108 from "path";
|
|
77675
77829
|
var LIMITS = {
|
|
77676
77830
|
files: 5000,
|
|
@@ -77688,7 +77842,7 @@ async function snapshotProtectedTree(root) {
|
|
|
77688
77842
|
if (rootStat.isFile()) {
|
|
77689
77843
|
if (rootStat.nlink > 1)
|
|
77690
77844
|
throw new Error("PROTECTED_INPUT_AMBIGUOUS:root");
|
|
77691
|
-
const content = await
|
|
77845
|
+
const content = await readFile22(canonicalRoot);
|
|
77692
77846
|
const afterRead = await lstat3(canonicalRoot);
|
|
77693
77847
|
if (`${afterRead.dev}:${afterRead.ino}:${afterRead.size}:${afterRead.mtimeMs}` !== `${rootStat.dev}:${rootStat.ino}:${rootStat.size}:${rootStat.mtimeMs}`)
|
|
77694
77848
|
throw new Error("PROTECTED_INPUT_REPLACED_DURING_READ:root");
|
|
@@ -77727,7 +77881,7 @@ async function snapshotProtectedTree(root) {
|
|
|
77727
77881
|
byteCount += stat8.size;
|
|
77728
77882
|
if (fileCount > LIMITS.files || byteCount > LIMITS.bytes || Date.now() - started > LIMITS.elapsedMs)
|
|
77729
77883
|
throw new Error("PROTECTED_INPUT_INTEGRITY_BUDGET_EXCEEDED");
|
|
77730
|
-
const contentHash = createHash33("sha256").update(await
|
|
77884
|
+
const contentHash = createHash33("sha256").update(await readFile22(absolute)).digest("hex");
|
|
77731
77885
|
const afterRead = await lstat3(absolute);
|
|
77732
77886
|
if (`${afterRead.dev}:${afterRead.ino}:${afterRead.size}:${afterRead.mtimeMs}` !== identityBefore)
|
|
77733
77887
|
throw new Error(`PROTECTED_INPUT_REPLACED_DURING_READ:${relative26}`);
|
|
@@ -77932,7 +78086,7 @@ async function deterministicSeed(input) {
|
|
|
77932
78086
|
}
|
|
77933
78087
|
|
|
77934
78088
|
// src/services/skill-optimizer/smoke.ts
|
|
77935
|
-
import { existsSync as
|
|
78089
|
+
import { existsSync as existsSync60, lstatSync as lstatSync14, readFileSync as readFileSync48, realpathSync as realpathSync18 } from "fs";
|
|
77936
78090
|
import * as path109 from "path";
|
|
77937
78091
|
|
|
77938
78092
|
// src/hooks/spawn-helper.ts
|
|
@@ -78041,7 +78195,7 @@ async function validateSkillSmoke(input) {
|
|
|
78041
78195
|
};
|
|
78042
78196
|
}
|
|
78043
78197
|
const skillRoot = path109.join(input.directory, ".opencode", "skills", "generated", input.skillSlug);
|
|
78044
|
-
if (
|
|
78198
|
+
if (existsSync60(skillRoot)) {
|
|
78045
78199
|
if (_internals97.isSymbolicLink(skillRoot)) {
|
|
78046
78200
|
return {
|
|
78047
78201
|
ok: false,
|
|
@@ -78127,7 +78281,7 @@ function checkFrontmatter(content) {
|
|
|
78127
78281
|
}
|
|
78128
78282
|
function readIncumbentContent(directory, skillSlug) {
|
|
78129
78283
|
const incumbent = path109.join(directory, ".opencode", "skills", "generated", skillSlug, "SKILL.md");
|
|
78130
|
-
if (!
|
|
78284
|
+
if (!existsSync60(incumbent))
|
|
78131
78285
|
return "";
|
|
78132
78286
|
try {
|
|
78133
78287
|
return readFileSync48(incumbent, "utf8");
|
|
@@ -78141,7 +78295,7 @@ var PROJECT_LOCK_PATH = path110.join(".swarm", "evolution", "skills", ".run.lock
|
|
|
78141
78295
|
var CONVERGENCE_FILE = path110.join(".swarm", "evolution", "skills", ".convergence.json");
|
|
78142
78296
|
async function prepareCandidatePayloads(inputRoot, candidateId2, skillSlug, baselineModel, candidateModel, baselineContent, candidateContent) {
|
|
78143
78297
|
const payloadSubdir = path110.join(inputRoot, "candidates", candidateId2);
|
|
78144
|
-
if (!
|
|
78298
|
+
if (!existsSync61(payloadSubdir))
|
|
78145
78299
|
mkdirSync31(payloadSubdir, { recursive: true });
|
|
78146
78300
|
const baselinePayloadRel = path110.join("candidates", candidateId2, "baseline.md");
|
|
78147
78301
|
const candidatePayloadRel = path110.join("candidates", candidateId2, "candidate.md");
|
|
@@ -78391,7 +78545,7 @@ async function runValidationWithTransientRetry(input, candidateContent, baseline
|
|
|
78391
78545
|
if (!input.dispatcher) {
|
|
78392
78546
|
throw new Error("no evaluation dispatcher available (cannot run validation)");
|
|
78393
78547
|
}
|
|
78394
|
-
const { createModelEvaluationExecutor: createModelEvaluationExecutor2 } = await import("./runner-
|
|
78548
|
+
const { createModelEvaluationExecutor: createModelEvaluationExecutor2 } = await import("./runner-d294h1by.js");
|
|
78395
78549
|
const executor = createModelEvaluationExecutor2(input.dispatcher, input.sessionId);
|
|
78396
78550
|
const result = await withProtectedSetIntegrity([evalInputRoot, ...protectedRoots(input.directory)], () => _internals98.evaluateCandidateV1({
|
|
78397
78551
|
projectRoot: input.directory,
|
|
@@ -78467,7 +78621,7 @@ async function runValidationWithTransientRetry(input, candidateContent, baseline
|
|
|
78467
78621
|
}
|
|
78468
78622
|
function readConvergenceState(directory) {
|
|
78469
78623
|
const file = path110.join(directory, CONVERGENCE_FILE);
|
|
78470
|
-
if (!
|
|
78624
|
+
if (!existsSync61(file))
|
|
78471
78625
|
return { nonImprovements: 0 };
|
|
78472
78626
|
try {
|
|
78473
78627
|
return JSON.parse(readFileSync49(file, "utf8"));
|
|
@@ -78478,7 +78632,7 @@ function readConvergenceState(directory) {
|
|
|
78478
78632
|
function writeConvergenceState(directory, nonImprovements) {
|
|
78479
78633
|
assertProjectRoot(directory);
|
|
78480
78634
|
const dir = path110.dirname(path110.join(directory, CONVERGENCE_FILE));
|
|
78481
|
-
if (!
|
|
78635
|
+
if (!existsSync61(dir))
|
|
78482
78636
|
mkdirSync31(dir, { recursive: true });
|
|
78483
78637
|
writeFileSync20(path110.join(directory, CONVERGENCE_FILE), JSON.stringify({ nonImprovements }), "utf8");
|
|
78484
78638
|
}
|
|
@@ -78535,7 +78689,7 @@ async function runOptimizationLoop(input) {
|
|
|
78535
78689
|
}
|
|
78536
78690
|
|
|
78537
78691
|
// src/services/skill-optimizer/skill-eval-tasks.ts
|
|
78538
|
-
import { existsSync as
|
|
78692
|
+
import { existsSync as existsSync62, mkdirSync as mkdirSync32, writeFileSync as writeFileSync21 } from "fs";
|
|
78539
78693
|
import * as path111 from "path";
|
|
78540
78694
|
var DEFAULT_SKILL_EVAL_TASKS = [
|
|
78541
78695
|
{
|
|
@@ -78577,7 +78731,7 @@ function buildSkillEvalTasks(args) {
|
|
|
78577
78731
|
const result = [];
|
|
78578
78732
|
for (const spec of tasks) {
|
|
78579
78733
|
const taskDir = path111.join(args.inputRoot, "skill-eval", spec.id);
|
|
78580
|
-
if (!
|
|
78734
|
+
if (!existsSync62(taskDir))
|
|
78581
78735
|
mkdirSync32(taskDir, { recursive: true });
|
|
78582
78736
|
const instructionPath = path111.join("skill-eval", spec.id, "instruction.md");
|
|
78583
78737
|
writeFileSync21(path111.join(args.inputRoot, instructionPath), `${spec.instruction}
|
|
@@ -78676,7 +78830,7 @@ ${JSON.stringify(result, null, 2)}
|
|
|
78676
78830
|
function readSkillOptConfigFromProject(directory) {
|
|
78677
78831
|
try {
|
|
78678
78832
|
const cfgPath = path112.join(directory, "opencode.json");
|
|
78679
|
-
if (!
|
|
78833
|
+
if (!existsSync63(cfgPath))
|
|
78680
78834
|
return { ...DEFAULT_SKILL_OPT_CONFIG };
|
|
78681
78835
|
const raw = JSON.parse(readFileSync50(cfgPath, "utf8"));
|
|
78682
78836
|
const block = raw?.skill_opt ?? raw?.swarm?.skill_opt;
|
|
@@ -78726,14 +78880,14 @@ async function handleSkillOptRun(directory, args, runtime = {}) {
|
|
|
78726
78880
|
}
|
|
78727
78881
|
const models = parsed.models.length > 0 ? parsed.models : ["default"];
|
|
78728
78882
|
const inputRoot = path112.join(directory, ".swarm", "evolution", "skills", "_eval-input");
|
|
78729
|
-
if (!
|
|
78883
|
+
if (!existsSync63(inputRoot))
|
|
78730
78884
|
mkdirSync33(inputRoot, { recursive: true });
|
|
78731
78885
|
const scorerDir = path112.join(inputRoot, "scoring");
|
|
78732
|
-
if (!
|
|
78886
|
+
if (!existsSync63(scorerDir))
|
|
78733
78887
|
mkdirSync33(scorerDir, { recursive: true });
|
|
78734
78888
|
const scorerSource = path112.join(directory, "evaluation-fixtures", "skill-eval", "scoring", "score-skill-eval.cjs");
|
|
78735
78889
|
const scorerDest = path112.join(scorerDir, "score-skill-eval.cjs");
|
|
78736
|
-
if (
|
|
78890
|
+
if (existsSync63(scorerSource)) {
|
|
78737
78891
|
copyFileSync5(scorerSource, scorerDest);
|
|
78738
78892
|
}
|
|
78739
78893
|
const scorerRelPath = path112.join("scoring", "score-skill-eval.cjs");
|
|
@@ -78907,7 +79061,7 @@ async function handleSpecifyCommand(_directory, args) {
|
|
|
78907
79061
|
|
|
78908
79062
|
// src/services/status-service.ts
|
|
78909
79063
|
import * as fsSync4 from "fs";
|
|
78910
|
-
import { readFile as
|
|
79064
|
+
import { readFile as readFile23 } from "fs/promises";
|
|
78911
79065
|
import * as path115 from "path";
|
|
78912
79066
|
init_loader();
|
|
78913
79067
|
init_schema();
|
|
@@ -79533,7 +79687,7 @@ async function getStatusData(directory, agents, sessionId, options) {
|
|
|
79533
79687
|
status.recentEscalations = await readRecentEscalations(directory);
|
|
79534
79688
|
status.pendingProposals = await countProposals(directory);
|
|
79535
79689
|
status.unactionableQueueDepth = await safeLineCount(resolveUnactionablePath(directory));
|
|
79536
|
-
status.insightCandidatesPending = await
|
|
79690
|
+
status.insightCandidatesPending = await countInsightCandidatesPending(directory);
|
|
79537
79691
|
try {
|
|
79538
79692
|
status.consensusReports = await countConsensusReportFiles(directory);
|
|
79539
79693
|
} catch {
|
|
@@ -80038,7 +80192,7 @@ async function safeLineCount(filePath) {
|
|
|
80038
80192
|
try {
|
|
80039
80193
|
if (!fsSync4.existsSync(filePath))
|
|
80040
80194
|
return 0;
|
|
80041
|
-
const content = await
|
|
80195
|
+
const content = await readFile23(filePath, "utf-8");
|
|
80042
80196
|
let n = 0;
|
|
80043
80197
|
for (const line of content.split(`
|
|
80044
80198
|
`)) {
|
|
@@ -80050,6 +80204,16 @@ async function safeLineCount(filePath) {
|
|
|
80050
80204
|
return 0;
|
|
80051
80205
|
}
|
|
80052
80206
|
}
|
|
80207
|
+
async function countInsightCandidatesPending(directory) {
|
|
80208
|
+
try {
|
|
80209
|
+
if (projectDbExists(directory)) {
|
|
80210
|
+
return countPendingInsightCandidatesDb(directory);
|
|
80211
|
+
}
|
|
80212
|
+
return await safeLineCount(validateSwarmPath(directory, "insight-candidates.jsonl"));
|
|
80213
|
+
} catch {
|
|
80214
|
+
return 0;
|
|
80215
|
+
}
|
|
80216
|
+
}
|
|
80053
80217
|
async function countProposals(directory) {
|
|
80054
80218
|
try {
|
|
80055
80219
|
const proposalsDir = validateSwarmPath(directory, "skills/proposals");
|
|
@@ -80516,7 +80680,7 @@ function buildDetailedHelp(commandName, entry) {
|
|
|
80516
80680
|
async function handleHelpCommand(ctx) {
|
|
80517
80681
|
const targetCommand = ctx.args.join(" ");
|
|
80518
80682
|
if (!targetCommand) {
|
|
80519
|
-
const { buildHelpText } = await import("./index-
|
|
80683
|
+
const { buildHelpText } = await import("./index-qkk2skff.js");
|
|
80520
80684
|
return buildHelpText();
|
|
80521
80685
|
}
|
|
80522
80686
|
const tokens = targetCommand.split(/\s+/);
|
|
@@ -80525,7 +80689,7 @@ async function handleHelpCommand(ctx) {
|
|
|
80525
80689
|
return _internals101.buildDetailedHelp(resolved.key, resolved.entry);
|
|
80526
80690
|
}
|
|
80527
80691
|
const similar = _internals101.findSimilarCommands(targetCommand);
|
|
80528
|
-
const { buildHelpText: fullHelp } = await import("./index-
|
|
80692
|
+
const { buildHelpText: fullHelp } = await import("./index-qkk2skff.js");
|
|
80529
80693
|
if (similar.length > 0) {
|
|
80530
80694
|
return `Command '/swarm ${targetCommand}' not found.
|
|
80531
80695
|
|
|
@@ -80856,7 +81020,7 @@ var COMMAND_REGISTRY = {
|
|
|
80856
81020
|
},
|
|
80857
81021
|
"guardrail explain": {
|
|
80858
81022
|
handler: async (ctx) => {
|
|
80859
|
-
const { handleGuardrailExplain } = await import("./guardrail-explain-
|
|
81023
|
+
const { handleGuardrailExplain } = await import("./guardrail-explain-kksdy032.js");
|
|
80860
81024
|
return handleGuardrailExplain(ctx.directory, ctx.args);
|
|
80861
81025
|
},
|
|
80862
81026
|
description: "Dry-run: show what the guardrails would do to a command or write target (executes nothing)",
|
|
@@ -80866,7 +81030,7 @@ var COMMAND_REGISTRY = {
|
|
|
80866
81030
|
},
|
|
80867
81031
|
"guardrail reset": {
|
|
80868
81032
|
handler: async (ctx) => {
|
|
80869
|
-
const { handleGuardrailReset } = await import("./guardrail-reset-
|
|
81033
|
+
const { handleGuardrailReset } = await import("./guardrail-reset-3b4gs357.js");
|
|
80870
81034
|
return handleGuardrailReset(ctx.args, ctx.sessionID);
|
|
80871
81035
|
},
|
|
80872
81036
|
description: "Reset one exact active invocation/action circuit after repair",
|
|
@@ -80875,7 +81039,7 @@ var COMMAND_REGISTRY = {
|
|
|
80875
81039
|
},
|
|
80876
81040
|
"guardrail-explain": {
|
|
80877
81041
|
handler: async (ctx) => {
|
|
80878
|
-
const { handleGuardrailExplain } = await import("./guardrail-explain-
|
|
81042
|
+
const { handleGuardrailExplain } = await import("./guardrail-explain-kksdy032.js");
|
|
80879
81043
|
return handleGuardrailExplain(ctx.directory, ctx.args);
|
|
80880
81044
|
},
|
|
80881
81045
|
description: "Dry-run: show what the guardrails would do to a command or write target (executes nothing)",
|
|
@@ -80885,7 +81049,7 @@ var COMMAND_REGISTRY = {
|
|
|
80885
81049
|
},
|
|
80886
81050
|
"guardrail-reset": {
|
|
80887
81051
|
handler: async (ctx) => {
|
|
80888
|
-
const { handleGuardrailReset } = await import("./guardrail-reset-
|
|
81052
|
+
const { handleGuardrailReset } = await import("./guardrail-reset-3b4gs357.js");
|
|
80889
81053
|
return handleGuardrailReset(ctx.args, ctx.sessionID);
|
|
80890
81054
|
},
|
|
80891
81055
|
description: "Reset one exact active invocation/action circuit after repair",
|
|
@@ -80895,7 +81059,7 @@ var COMMAND_REGISTRY = {
|
|
|
80895
81059
|
},
|
|
80896
81060
|
"guardrail-log": {
|
|
80897
81061
|
handler: async (ctx) => {
|
|
80898
|
-
const { handleGuardrailLog } = await import("./guardrail-log-
|
|
81062
|
+
const { handleGuardrailLog } = await import("./guardrail-log-7rxbd20p.js");
|
|
80899
81063
|
return handleGuardrailLog(ctx.directory, ctx.args);
|
|
80900
81064
|
},
|
|
80901
81065
|
description: "Read the guardrail decision log (use --blocks-only for blocks)",
|
|
@@ -86891,7 +87055,7 @@ function getDisplayFinalPromptPressure() {
|
|
|
86891
87055
|
async function rehydratePrSubscriptions(sessionID, directory) {
|
|
86892
87056
|
const map = new Map;
|
|
86893
87057
|
try {
|
|
86894
|
-
const { listActive: listActive2 } = await import("./pr-subscriptions-
|
|
87058
|
+
const { listActive: listActive2 } = await import("./pr-subscriptions-1a4gcnzv.js");
|
|
86895
87059
|
const records = await listActive2(directory);
|
|
86896
87060
|
for (const record of records) {
|
|
86897
87061
|
if (record.sessionID !== sessionID)
|
|
@@ -87337,7 +87501,7 @@ function isLaneOwnedByCurrentSession(branchName, expectedSessionId) {
|
|
|
87337
87501
|
return extracted === expectedSessionId;
|
|
87338
87502
|
}
|
|
87339
87503
|
async function inspectStandardWorktreeCollisionOwnership(identity) {
|
|
87340
|
-
const collisionOwnership = await import("./worktree-collision-ownership-
|
|
87504
|
+
const collisionOwnership = await import("./worktree-collision-ownership-7kj2ryt1.js");
|
|
87341
87505
|
return collisionOwnership.inspectStandardWorktreeCollisionOwnership(identity);
|
|
87342
87506
|
}
|
|
87343
87507
|
async function runRecoveryGit(directory, args, timeoutMs = 15000) {
|
|
@@ -87746,7 +87910,7 @@ async function precreateStandardWorktreeSession(args) {
|
|
|
87746
87910
|
const laneProfile = computeLaneRuntimeProfile(worktreeConfig.runtime_isolation, laneIndex, handle.worktreePath);
|
|
87747
87911
|
if (laneProfile) {
|
|
87748
87912
|
try {
|
|
87749
|
-
const { writeLaneProfileToDiskReal } = await import("./core-
|
|
87913
|
+
const { writeLaneProfileToDiskReal } = await import("./core-q5hv8e2w.js");
|
|
87750
87914
|
await writeLaneProfileToDiskReal(handle.worktreePath, laneProfile.laneIndex, laneProfile.envOverrides);
|
|
87751
87915
|
} catch {}
|
|
87752
87916
|
}
|
|
@@ -88671,7 +88835,7 @@ async function finishStandardWorktreeDispatch(directory, dispatch, config, callI
|
|
|
88671
88835
|
}
|
|
88672
88836
|
clearWorktreeMergeStatus(statusKey);
|
|
88673
88837
|
try {
|
|
88674
|
-
const { removeLaneProfileFromDiskReal } = await import("./core-
|
|
88838
|
+
const { removeLaneProfileFromDiskReal } = await import("./core-q5hv8e2w.js");
|
|
88675
88839
|
await removeLaneProfileFromDiskReal(dispatch.handle.worktreePath, dispatch.laneIndex);
|
|
88676
88840
|
} catch {}
|
|
88677
88841
|
const state = serializationStateBySessionID.get(dispatch.parentSessionID);
|