omnius 1.0.476 → 1.0.478

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -26393,6 +26393,116 @@ var init_compaction_policy = __esm({
26393
26393
  }
26394
26394
  });
26395
26395
 
26396
+ // packages/memory/dist/evidence-retirement.js
26397
+ function extractDiagnosticSymbols(text2) {
26398
+ const symbols = /* @__PURE__ */ new Set();
26399
+ let count = 0;
26400
+ for (const line of text2.split("\n")) {
26401
+ if (!DIAG_LINE.test(line))
26402
+ continue;
26403
+ count += 1;
26404
+ let m2;
26405
+ QUOTED_SYMBOL.lastIndex = 0;
26406
+ while ((m2 = QUOTED_SYMBOL.exec(line)) !== null) {
26407
+ if (/^[A-Za-z_]/.test(m2[1]) && !m2[1].includes("/"))
26408
+ symbols.add(m2[1]);
26409
+ if (symbols.size >= 12)
26410
+ break;
26411
+ }
26412
+ }
26413
+ return { count, symbols: [...symbols] };
26414
+ }
26415
+ function isRetirableEvidence(message2, minChars) {
26416
+ if (message2.pinned)
26417
+ return false;
26418
+ if (typeof message2.content !== "string")
26419
+ return false;
26420
+ if (message2.content.length < minChars)
26421
+ return false;
26422
+ if (message2.role === "tool")
26423
+ return true;
26424
+ if (message2.role !== "system")
26425
+ return false;
26426
+ return EVIDENCE_MARKERS.some((m2) => message2.content.includes(m2));
26427
+ }
26428
+ function foldEvidenceOutcome(message2) {
26429
+ const text2 = message2.content;
26430
+ const diag = extractDiagnosticSymbols(text2);
26431
+ if (diag.count > 0) {
26432
+ const syms = diag.symbols.slice(0, 6);
26433
+ const exit = /exit_code:\s*(\d+)|Exit code (\d+)/.exec(text2);
26434
+ const code8 = exit ? exit[1] ?? exit[2] : void 0;
26435
+ return `${diag.count} diagnostic(s)${code8 ? ` (exit ${code8})` : ""}${syms.length ? `: ${syms.join(", ")}` : ""}`;
26436
+ }
26437
+ const fileHdr = /\[FILE CONTEXT[^\]]*\]/.exec(text2);
26438
+ if (fileHdr)
26439
+ return fileHdr[0].replace(/^\[|\]$/g, "").trim();
26440
+ if (text2.includes("[SHELL TRANSCRIPT]")) {
26441
+ const cmd = /command:\s*([^\n]+)/.exec(text2);
26442
+ const exit = /exit_code:\s*(\d+)|Exit code (\d+)/.exec(text2);
26443
+ const err = /(^|\n)\s*([^\n]*\berror\b[^\n]*)/i.exec(text2);
26444
+ const parts = [
26445
+ cmd ? `cmd: ${cmd[1].trim().slice(0, 80)}` : "",
26446
+ exit ? `exit ${exit[1] ?? exit[2]}` : "",
26447
+ err ? err[2].trim().slice(0, 100) : ""
26448
+ ].filter(Boolean);
26449
+ if (parts.length)
26450
+ return parts.join("; ");
26451
+ }
26452
+ const firstLine = text2.split("\n").map((l2) => l2.trim()).find((l2) => l2.length > 0 && !EVIDENCE_MARKERS.some((m2) => l2.startsWith(m2)));
26453
+ return (firstLine ?? "evidence").slice(0, 120);
26454
+ }
26455
+ function retirementStub(message2, outcome, originalChars) {
26456
+ const ref = message2.diskRef ? ` ref=${message2.diskRef}` : "";
26457
+ const tool = message2.toolName ? ` tool=${message2.toolName}` : "";
26458
+ const turn = typeof message2.turn === "number" ? ` turn=${message2.turn}` : "";
26459
+ return `[RETIRED EVIDENCE${tool}${turn} bytes=${originalChars}${ref}] outcome: ${outcome}
26460
+ (full evidence retired to disk — re-read the file or re-run the command to re-materialise if you need the detail)`;
26461
+ }
26462
+ function retireStaleEvidence(messages2, options2) {
26463
+ const keepRecentTurns = Math.max(0, options2.keepRecentTurns ?? 2);
26464
+ const minChars = Math.max(256, options2.minChars ?? 2e3);
26465
+ const summarize2 = options2.summarize ?? foldEvidenceOutcome;
26466
+ const staleBefore = options2.currentTurn - keepRecentTurns;
26467
+ let retiredCount = 0;
26468
+ let reclaimedChars = 0;
26469
+ const out = messages2.map((message2) => {
26470
+ if (typeof message2.turn !== "number" || message2.turn > staleBefore) {
26471
+ return message2;
26472
+ }
26473
+ if (!isRetirableEvidence(message2, minChars))
26474
+ return message2;
26475
+ const originalChars = message2.content.length;
26476
+ let outcome;
26477
+ try {
26478
+ outcome = summarize2(message2);
26479
+ } catch {
26480
+ outcome = "evidence";
26481
+ }
26482
+ const stub = retirementStub(message2, outcome, originalChars);
26483
+ if (stub.length >= originalChars)
26484
+ return message2;
26485
+ retiredCount += 1;
26486
+ reclaimedChars += originalChars - stub.length;
26487
+ return { ...message2, content: stub };
26488
+ });
26489
+ return { messages: out, retiredCount, reclaimedChars };
26490
+ }
26491
+ var DIAG_LINE, QUOTED_SYMBOL, EVIDENCE_MARKERS;
26492
+ var init_evidence_retirement = __esm({
26493
+ "packages/memory/dist/evidence-retirement.js"() {
26494
+ "use strict";
26495
+ DIAG_LINE = /\berror\b\s*:/i;
26496
+ QUOTED_SYMBOL = /['"`]([A-Za-z_][A-Za-z0-9_:.<>]{1,80})['"`]/g;
26497
+ EVIDENCE_MARKERS = [
26498
+ "[SHELL TRANSCRIPT]",
26499
+ "[FILE CONTEXT",
26500
+ "[RUN EVIDENCE]",
26501
+ "[TOOL RESULT]"
26502
+ ];
26503
+ }
26504
+ });
26505
+
26396
26506
  // packages/memory/dist/index.js
26397
26507
  var dist_exports = {};
26398
26508
  __export(dist_exports, {
@@ -26494,6 +26604,7 @@ __export(dist_exports, {
26494
26604
  extractTrace: () => extractTrace,
26495
26605
  findNeighbors: () => findNeighbors,
26496
26606
  fingerprintSignature: () => fingerprintSignature,
26607
+ foldEvidenceOutcome: () => foldEvidenceOutcome,
26497
26608
  freshNodeId: () => freshNodeId,
26498
26609
  generateEmbedding: () => generateEmbedding,
26499
26610
  generateEmbeddingBatch: () => generateEmbeddingBatch,
@@ -26503,6 +26614,7 @@ __export(dist_exports, {
26503
26614
  inferDomainFromEpisode: () => inferDomainFromEpisode,
26504
26615
  ingestContextFeedbackMarkdown: () => ingestContextFeedbackMarkdown,
26505
26616
  initDb: () => initDb,
26617
+ isRetirableEvidence: () => isRetirableEvidence,
26506
26618
  isSessionGist: () => isSessionGist,
26507
26619
  lightSleep: () => lightSleep,
26508
26620
  linkEpisode: () => linkEpisode,
@@ -26525,6 +26637,7 @@ __export(dist_exports, {
26525
26637
  reinforceGraphNodes: () => reinforceGraphNodes,
26526
26638
  remDream: () => remDream,
26527
26639
  resetCRLConfigStore: () => resetCRLConfigStore,
26640
+ retireStaleEvidence: () => retireStaleEvidence,
26528
26641
  retrieveByPPR: () => retrieveByPPR,
26529
26642
  runConsolidationCycle: () => runConsolidationCycle,
26530
26643
  runMemoryMaintenance: () => runMemoryMaintenance,
@@ -26609,6 +26722,7 @@ var init_dist = __esm({
26609
26722
  init_attention_select();
26610
26723
  init_context_folding();
26611
26724
  init_compaction_policy();
26725
+ init_evidence_retirement();
26612
26726
  }
26613
26727
  });
26614
26728
 
@@ -576954,9 +577068,235 @@ var init_coherence_gate = __esm({
576954
577068
  }
576955
577069
  });
576956
577070
 
577071
+ // packages/orchestrator/dist/spec-gate.js
577072
+ function definitionCount(source, name10) {
577073
+ const n2 = escapeRegExp2(name10);
577074
+ const patterns = [
577075
+ new RegExp(`}\\s*${n2}\\s*;`, "g"),
577076
+ // } Name; (typedef struct/enum)
577077
+ new RegExp(`\\b(?:struct|class|enum|union)\\s+${n2}\\s*[:{]`, "g"),
577078
+ new RegExp(`\\b(?:interface|type|class|enum)\\s+${n2}\\b`, "g"),
577079
+ new RegExp(`\\btypedef\\s+[^;{]+\\b${n2}\\s*;`, "g")
577080
+ ];
577081
+ let total = 0;
577082
+ for (const re of patterns)
577083
+ total += (source.match(re) ?? []).length;
577084
+ return total;
577085
+ }
577086
+ function hasField(source, symbol3, field) {
577087
+ const n2 = escapeRegExp2(symbol3);
577088
+ const block = source.match(new RegExp(`(?:struct|class|enum|union|interface)\\s+${n2}[^{]*{([\\s\\S]*?)}|{([\\s\\S]*?)}\\s*${n2}\\s*;`));
577089
+ const body = block?.[1] ?? block?.[2] ?? "";
577090
+ if (!body)
577091
+ return false;
577092
+ return new RegExp(`\\b${escapeRegExp2(field)}\\b`).test(body);
577093
+ }
577094
+ function hasSignature(source, fragment) {
577095
+ const norm = (s2) => s2.replace(/\s+/g, " ").trim();
577096
+ return norm(source).includes(norm(fragment));
577097
+ }
577098
+ function evaluateSpecGate(unit, contract, opts = {}) {
577099
+ const violations = [];
577100
+ const expected = new Set(opts.expectedSymbols ?? []);
577101
+ for (const spec of contract.symbols) {
577102
+ const count = definitionCount(unit.source, spec.name);
577103
+ const mustDefine = expected.has(spec.name);
577104
+ if (count === 0) {
577105
+ if (mustDefine) {
577106
+ violations.push({
577107
+ symbol: spec.name,
577108
+ kind: "missing_symbol",
577109
+ detail: `unit ${unit.path} must declare ${spec.kind} ${spec.name} but it is absent`
577110
+ });
577111
+ }
577112
+ continue;
577113
+ }
577114
+ if (count > 1) {
577115
+ violations.push({
577116
+ symbol: spec.name,
577117
+ kind: "duplicate_symbol",
577118
+ detail: `${spec.name} is defined ${count}× in ${unit.path}; the contract permits exactly one`
577119
+ });
577120
+ }
577121
+ for (const field of spec.fields ?? []) {
577122
+ if (!hasField(unit.source, spec.name, field)) {
577123
+ violations.push({
577124
+ symbol: spec.name,
577125
+ kind: "missing_field",
577126
+ detail: `${spec.name} is missing required member "${field}"`
577127
+ });
577128
+ }
577129
+ }
577130
+ if (spec.signature && !hasSignature(unit.source, spec.signature)) {
577131
+ violations.push({
577132
+ symbol: spec.name,
577133
+ kind: "signature_divergence",
577134
+ detail: `${spec.name} does not match the contract signature "${spec.signature}"`
577135
+ });
577136
+ }
577137
+ }
577138
+ const pass = violations.length === 0;
577139
+ return {
577140
+ pass,
577141
+ violations,
577142
+ summary: pass ? `spec gate PASS for ${unit.path}` : `spec gate FAIL for ${unit.path}: ${violations.length} violation(s) — ${violations.map((v) => `${v.symbol}:${v.kind}`).join(", ")}`
577143
+ };
577144
+ }
577145
+ function evaluateExecutorStep(input) {
577146
+ const spec = evaluateSpecGate(input.unit, input.contract, {
577147
+ expectedSymbols: input.expectedSymbols
577148
+ });
577149
+ if (input.convergenceTier === "abandon" || input.convergenceTier === "stalled") {
577150
+ return {
577151
+ decision: "replan",
577152
+ spec,
577153
+ reason: `convergence ${input.convergenceTier}: stop patching ${input.unit.path}; re-plan / regenerate from the locked contract`
577154
+ };
577155
+ }
577156
+ const boundaryOk = input.boundaryOk ?? true;
577157
+ if (spec.pass && boundaryOk) {
577158
+ return { decision: "accept", spec, reason: `${input.unit.path} accepted` };
577159
+ }
577160
+ return {
577161
+ decision: "reject_regenerate",
577162
+ spec,
577163
+ reason: spec.pass ? `${input.unit.path} passed the spec gate but failed to compile — regenerate` : spec.summary
577164
+ };
577165
+ }
577166
+ function escapeRegExp2(s2) {
577167
+ return s2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
577168
+ }
577169
+ var init_spec_gate = __esm({
577170
+ "packages/orchestrator/dist/spec-gate.js"() {
577171
+ "use strict";
577172
+ }
577173
+ });
577174
+
577175
+ // packages/orchestrator/dist/decomposition-orchestrator.js
577176
+ function decomposeToUnits(modules, contract, symbolSources = /* @__PURE__ */ new Map(), options2 = {}) {
577177
+ const maxUnits = Math.max(1, options2.maxUnits ?? 200);
577178
+ const units = [];
577179
+ const symbolsByPath = /* @__PURE__ */ new Map();
577180
+ for (const spec of contract.symbols) {
577181
+ const src2 = symbolSources.get(spec.name);
577182
+ if (!src2)
577183
+ continue;
577184
+ const arr = symbolsByPath.get(src2) ?? [];
577185
+ arr.push(spec);
577186
+ symbolsByPath.set(src2, arr);
577187
+ }
577188
+ let i2 = 0;
577189
+ for (const m2 of modules) {
577190
+ if (units.length >= maxUnits)
577191
+ break;
577192
+ const fileId = `unit-file-${++i2}`;
577193
+ const symbols = symbolsByPath.get(m2.path) ?? [];
577194
+ units.push({
577195
+ id: fileId,
577196
+ path: m2.path,
577197
+ content: `Implement ${m2.path} (delegate via sub_agent for isolated context)`,
577198
+ status: "pending",
577199
+ exitCriterion: symbols.length > 0 ? `${m2.path} compiles AND declares ${symbols.map((s2) => s2.name).join(", ")} matching the locked contract` : `${m2.path} compiles cleanly`
577200
+ });
577201
+ let j = 0;
577202
+ for (const s2 of symbols) {
577203
+ if (units.length >= maxUnits)
577204
+ break;
577205
+ units.push({
577206
+ id: `${fileId}-sym-${++j}`,
577207
+ parentId: fileId,
577208
+ path: m2.path,
577209
+ symbol: s2.name,
577210
+ content: `Declare ${s2.kind} ${s2.name} in ${m2.path} to match the locked contract`,
577211
+ status: "pending",
577212
+ exitCriterion: `${s2.name} declared exactly once with the contract shape; ${m2.path} compiles`
577213
+ });
577214
+ }
577215
+ }
577216
+ return units;
577217
+ }
577218
+ function evaluateUnitResult(input) {
577219
+ const expectedSymbols = input.unit.symbol ? [input.unit.symbol] : input.contract.symbols.filter((s2) => true).map((s2) => s2.name).filter((name10) => input.emittedSource.includes(name10));
577220
+ const spec = evaluateSpecGate({ path: input.unit.path, source: input.emittedSource }, input.contract, { expectedSymbols });
577221
+ const diagnostics = parseCompilerDiagnostics(String(input.buildOutput || ""));
577222
+ const structural = diagnostics.filter((d2) => d2.kind === "signature_mismatch" || d2.kind === "duplicate_definition" || d2.kind === "unknown_member" || d2.kind === "unknown_symbol" || d2.kind === "type_error");
577223
+ if (spec.pass && structural.length === 0) {
577224
+ const label = input.unit.symbol ?? input.unit.path;
577225
+ return {
577226
+ decision: "accept",
577227
+ foldSummary: `${label}: verified (declares ${expectedSymbols.join(", ") || "unit"}, compiles clean)`,
577228
+ violations: [],
577229
+ diagnosticsCount: 0
577230
+ };
577231
+ }
577232
+ const reasons = [];
577233
+ if (!spec.pass)
577234
+ reasons.push(spec.summary);
577235
+ if (structural.length > 0) {
577236
+ const syms = [...new Set(structural.map((d2) => d2.symbol).filter(Boolean))];
577237
+ reasons.push(`${structural.length} compiler diagnostic(s)${syms.length ? ` on ${syms.slice(0, 4).join(", ")}` : ""}`);
577238
+ }
577239
+ return {
577240
+ decision: "reject_regenerate",
577241
+ rejectReason: `Unit ${input.unit.path}${input.unit.symbol ? ` (${input.unit.symbol})` : ""} does not verify — regenerate against the locked contract: ${reasons.join("; ")}`,
577242
+ violations: spec.violations,
577243
+ diagnosticsCount: structural.length
577244
+ };
577245
+ }
577246
+ function buildUnitTodos(units) {
577247
+ return units.map((u) => ({
577248
+ id: u.id,
577249
+ content: u.content,
577250
+ status: u.status,
577251
+ ...u.parentId ? { parentId: u.parentId } : {}
577252
+ }));
577253
+ }
577254
+ var init_decomposition_orchestrator = __esm({
577255
+ "packages/orchestrator/dist/decomposition-orchestrator.js"() {
577256
+ "use strict";
577257
+ init_spec_gate();
577258
+ init_dist5();
577259
+ }
577260
+ });
577261
+
576957
577262
  // packages/orchestrator/dist/longhaul-integration.js
576958
577263
  import fs6 from "node:fs";
576959
577264
  import path7 from "node:path";
577265
+ function extractSymbols3(content, language) {
577266
+ const out = [];
577267
+ const seen = /* @__PURE__ */ new Set();
577268
+ const push = (name10, kind, body) => {
577269
+ if (!name10 || seen.has(name10))
577270
+ return;
577271
+ seen.add(name10);
577272
+ const fields = body ? extractFields(body) : [];
577273
+ out.push({ name: name10, kind, ...fields.length ? { fields } : {} });
577274
+ };
577275
+ if (language === "cpp" || language === "unknown") {
577276
+ for (const m2 of content.matchAll(/\{([\s\S]*?)\}\s*([A-Za-z_]\w*)\s*;/g))
577277
+ push(m2[2], "struct", m2[1]);
577278
+ for (const m2 of content.matchAll(/\b(struct|class|enum|union)\s+([A-Za-z_]\w*)\s*(?::[^{]*)?\{([\s\S]*?)\}/g))
577279
+ push(m2[2], m2[1] === "union" ? "struct" : m2[1], m2[3]);
577280
+ }
577281
+ if (language === "typescript" || language === "unknown") {
577282
+ for (const m2 of content.matchAll(/\b(interface|class|enum)\s+([A-Za-z_]\w*)\s*(?:extends[^{]*)?\{([\s\S]*?)\}/g))
577283
+ push(m2[2], m2[1], m2[3]);
577284
+ for (const m2 of content.matchAll(/\btype\s+([A-Za-z_]\w*)\s*=/g))
577285
+ push(m2[1], "type");
577286
+ }
577287
+ return out;
577288
+ }
577289
+ function extractFields(body) {
577290
+ const fields = [];
577291
+ for (const line of body.split(/[;,\n]/)) {
577292
+ const ts = line.match(/^\s*([A-Za-z_]\w*)\s*[?:]/);
577293
+ const c9 = line.match(/([A-Za-z_]\w*)\s*$/);
577294
+ const name10 = ts ? ts[1] : c9 ? c9[1] : void 0;
577295
+ if (name10 && !FIELD_STOPWORDS.test(name10) && !fields.includes(name10))
577296
+ fields.push(name10);
577297
+ }
577298
+ return fields.slice(0, 24);
577299
+ }
576960
577300
  function languageOf(p2) {
576961
577301
  if (/\.(c|cc|cpp|cxx|h|hh|hpp|hxx|ino)$/i.test(p2))
576962
577302
  return "cpp";
@@ -576964,12 +577304,14 @@ function languageOf(p2) {
576964
577304
  return "typescript";
576965
577305
  return "unknown";
576966
577306
  }
576967
- var JsonConvergenceStore, EDIT_TOOLS, LongHaulComponents;
577307
+ var JsonConvergenceStore, EDIT_TOOLS, LongHaulComponents, FIELD_STOPWORDS;
576968
577308
  var init_longhaul_integration = __esm({
576969
577309
  "packages/orchestrator/dist/longhaul-integration.js"() {
576970
577310
  "use strict";
576971
577311
  init_convergence_breaker();
576972
577312
  init_coherence_gate();
577313
+ init_spec_gate();
577314
+ init_decomposition_orchestrator();
576973
577315
  init_dist5();
576974
577316
  init_dist();
576975
577317
  init_dist();
@@ -577019,6 +577361,15 @@ var init_longhaul_integration = __esm({
577019
577361
  adaptiveEdit;
577020
577362
  coherenceGate;
577021
577363
  contextFolder;
577364
+ /**
577365
+ * WO-6: the locked contract — accumulated from COHERENT boundary units only.
577366
+ * A drifted/incoherent unit is never locked (WO-2 fires regenerate for it
577367
+ * instead), so this can only ever hold a self-consistent type spec. Gives the
577368
+ * breaker's "regenerate from the locked contract" guidance a real target.
577369
+ */
577370
+ locked = /* @__PURE__ */ new Map();
577371
+ /** WO-11: provenance — which file each locked symbol was declared in. */
577372
+ lockedSource = /* @__PURE__ */ new Map();
577022
577373
  constructor(options2) {
577023
577374
  this.convergenceBreaker = new ConvergenceBreaker({
577024
577375
  ...options2.convergence,
@@ -577069,6 +577420,91 @@ var init_longhaul_integration = __esm({
577069
577420
  return null;
577070
577421
  }
577071
577422
  }
577423
+ /**
577424
+ * WO-6: lock a boundary unit into the contract IFF it is coherent. A drifted
577425
+ * unit is never locked (WO-2 handles it), so the contract only ever holds
577426
+ * self-consistent symbol shapes. Returns the current contract size.
577427
+ */
577428
+ maybeLockContract(input) {
577429
+ try {
577430
+ if (!input.content)
577431
+ return this.locked.size;
577432
+ const lang = input.language ?? languageOf(input.path);
577433
+ const verdict = this.coherenceGate.evaluate({
577434
+ source: input.content,
577435
+ language: lang
577436
+ });
577437
+ if (verdict.regime === "regenerate")
577438
+ return this.locked.size;
577439
+ for (const s2 of extractSymbols3(input.content, lang)) {
577440
+ if (!this.locked.has(s2.name)) {
577441
+ this.locked.set(s2.name, s2);
577442
+ this.lockedSource.set(s2.name, input.path);
577443
+ }
577444
+ }
577445
+ return this.locked.size;
577446
+ } catch {
577447
+ return this.locked.size;
577448
+ }
577449
+ }
577450
+ /** WO-6: the accumulated locked contract (for the breaker's regenerate target). */
577451
+ lockedContract() {
577452
+ return { symbols: [...this.locked.values()] };
577453
+ }
577454
+ /** WO-11: map of locked symbol name → declaring file (for per-symbol units). */
577455
+ symbolSources() {
577456
+ return new Map(this.lockedSource);
577457
+ }
577458
+ /**
577459
+ * WO-11: extreme-granularity unit todo TREE for the TUI expanded-list mirror.
577460
+ * When the locked contract has symbols, each file expands into per-symbol
577461
+ * children; otherwise it degrades to the existing per-file granularity (safe
577462
+ * drop-in). Enriches as the contract fills across the run.
577463
+ */
577464
+ unitTreeTodos(modules) {
577465
+ try {
577466
+ const units = decomposeToUnits(modules, this.lockedContract(), this.symbolSources());
577467
+ return buildUnitTodos(units);
577468
+ } catch {
577469
+ return modules.map((m2, i2) => ({
577470
+ id: `unit-file-${i2 + 1}`,
577471
+ content: `Implement ${m2.path}`,
577472
+ status: "pending"
577473
+ }));
577474
+ }
577475
+ }
577476
+ /** WO-11: whether the contract is rich enough to expand into symbol children. */
577477
+ hasSymbolGranularity() {
577478
+ return this.lockedSource.size > 0;
577479
+ }
577480
+ /**
577481
+ * WO-11: compile-verify-FOLD gate for a delegated unit's result. Accept only
577482
+ * when it matches the contract AND compiles; else return the regenerate reason.
577483
+ */
577484
+ evaluateUnit(input) {
577485
+ return evaluateUnitResult({ ...input, contract: this.lockedContract() });
577486
+ }
577487
+ /**
577488
+ * WO-6: gate an emitted boundary unit against the locked contract. Returns
577489
+ * guidance naming symbols that diverge from (or duplicate) a locked shape, so
577490
+ * "regenerate from the locked contract" has a concrete target. Only fires for
577491
+ * symbols already locked from earlier coherent code — never invents violations.
577492
+ */
577493
+ specGateGuidance(input) {
577494
+ try {
577495
+ if (this.locked.size === 0 || !input.content)
577496
+ return null;
577497
+ const res = evaluateSpecGate({ path: input.path, source: input.content }, this.lockedContract());
577498
+ if (res.pass)
577499
+ return null;
577500
+ const relevant = res.violations.filter((v) => this.locked.has(v.symbol));
577501
+ if (relevant.length === 0)
577502
+ return null;
577503
+ return `${input.path} diverges from the LOCKED CONTRACT (established from earlier coherent code): ${relevant.map((v) => `${v.symbol} (${v.kind})`).join(", ")}. Do not redefine or reshape a locked symbol — reconcile this unit to the contract shape, or regenerate it against the contract.`;
577504
+ } catch {
577505
+ return null;
577506
+ }
577507
+ }
577072
577508
  /**
577073
577509
  * WO-1 (PyTy pattern): parse a failed build/verify command's own output for
577074
577510
  * named STRUCTURAL contract violations (signature mismatch / duplicate
@@ -577142,6 +577578,7 @@ var init_longhaul_integration = __esm({
577142
577578
  }
577143
577579
  }
577144
577580
  };
577581
+ FIELD_STOPWORDS = /^(struct|class|public|private|protected|const|unsigned|signed|static|typedef|enum|union|namespace|template|int|char|float|double|void|bool|long|short|size_t|uint\d+_t|int\d+_t|string|number|boolean|readonly)$/;
577145
577582
  }
577146
577583
  });
577147
577584
 
@@ -580561,6 +580998,8 @@ var init_agenticRunner = __esm({
580561
580998
  /** WO-1..WO-8 long-haul integration bundle (convergence, adaptive-edit,
580562
580999
  * coherence, folding). Constructed at run setup alongside the supervisor. */
580563
581000
  _longHaul = null;
581001
+ /** WO-11: decomposition modules (files) stashed for contract-enriched todo trees. */
581002
+ _decompModules = [];
580564
581003
  _focusTerminalLedgerRecorded = false;
580565
581004
  // Generic, cross-session failure→resolution learning: learns the token-level
580566
581005
  // change that turned a failed command into a working one (e.g. python→python3)
@@ -587621,7 +588060,23 @@ TASK: ${scrubbedTask}` : scrubbedTask;
587621
588060
  if (_decomp.modules.length > 0) {
587622
588061
  const _directive = buildDecompositionDirective(_decomp.modules, _decomp.strategy);
587623
588062
  messages2.push({ role: "system", content: _directive });
587624
- const _todos = buildDecompositionTodos(_decomp.modules);
588063
+ this._decompModules = _decomp.modules;
588064
+ if (this._longHaul) {
588065
+ const _wd = this.authoritativeWorkingDirectory();
588066
+ for (const _m of _decomp.modules) {
588067
+ try {
588068
+ const _abs = _pathResolve(_wd, _m.path);
588069
+ if (_fsExistsSync(_abs)) {
588070
+ this._longHaul.maybeLockContract({
588071
+ path: _m.path,
588072
+ content: _fsReadFileSync(_abs, "utf-8")
588073
+ });
588074
+ }
588075
+ } catch {
588076
+ }
588077
+ }
588078
+ }
588079
+ const _todos = this._longHaul && this._longHaul.hasSymbolGranularity() ? this._longHaul.unitTreeTodos(_decomp.modules) : buildDecompositionTodos(_decomp.modules);
587625
588080
  try {
587626
588081
  const sid = this._sessionId || process.env["OMNIUS_SESSION_ID"] || "default";
587627
588082
  const safe = sid.replace(/[^a-zA-Z0-9_.-]/g, "_");
@@ -589483,6 +589938,7 @@ If you're stuck, try a completely different approach. Do NOT repeat what failed
589483
589938
  messages2.push(...compacted);
589484
589939
  compacted = messages2;
589485
589940
  }
589941
+ this._retireStaleEvidenceInPlace(messages2, turn);
589486
589942
  if (turn > 0 && this._toolEvents.length > 0) {
589487
589943
  try {
589488
589944
  const _limits = this.contextLimits();
@@ -592538,6 +592994,16 @@ ${rec.guidance}` : rec.guidance;
592538
592994
 
592539
592995
  ${dir}` : dir;
592540
592996
  }
592997
+ lh.maybeLockContract({ path: editPath, content: writtenContent });
592998
+ const specDir = lh.specGateGuidance({
592999
+ path: editPath,
593000
+ content: writtenContent
593001
+ });
593002
+ if (specDir) {
593003
+ runtimeSystemGuidance = runtimeSystemGuidance ? `${runtimeSystemGuidance}
593004
+
593005
+ ${specDir}` : specDir;
593006
+ }
592541
593007
  }
592542
593008
  if (!result.success) {
592543
593009
  const diag = lh.diagnosticGuidance(result.output ?? result.error ?? "");
@@ -596288,6 +596754,80 @@ Actions: (1) list_directory on the parent directory to see what's there, (2) Che
596288
596754
  * Replaces both assistant messages AND their associated tool-result
596289
596755
  * messages in the turn range [startTurn, currentTurn].
596290
596756
  */
596757
+ /**
596758
+ * Staleness-based evidence retirement (WO-4 realized; operator's microcompaction
596759
+ * goal). The sibling `_evictCompletedTodoMessages` only fires when a todo
596760
+ * COMPLETES and — critically — SKIPS `system` messages. But the live
596761
+ * `myactuator` frame (turn 11) was dominated by a ~77 KB `system`
596762
+ * `[SHELL TRANSCRIPT]` pinned from turn 3: a stuck debug loop completes no
596763
+ * todos, so nothing retired it, and system-role evidence is exempt from the
596764
+ * todo evictor anyway.
596765
+ *
596766
+ * This pass fills that gap: it retires STALE, LARGE evidence bodies (tool
596767
+ * results and marker-gated `system` evidence blocks — `[SHELL TRANSCRIPT]`,
596768
+ * `[FILE CONTEXT`, `[RUN EVIDENCE]`) to a one-line world-state stub, keeping
596769
+ * the OUTCOME resident and moving the bytes out. It mirrors the evictor's safe
596770
+ * in-place, same-length-array style (no index shifting) and reuses the pure,
596771
+ * unit-tested `isRetirableEvidence` / `foldEvidenceOutcome` from @omnius/memory
596772
+ * for the decision — so directives, plans, the completion contract, ordinary
596773
+ * reasoning, and the base prompt are never touched (they carry no evidence
596774
+ * marker). Marker-gating is what makes touching `system` messages safe here.
596775
+ *
596776
+ * OPT-IN (`OMNIUS_EVIDENCE_RETIREMENT=1`) so it cannot perturb a live run until
596777
+ * the operator flips it on and validates — matching the runtime-harness
596778
+ * discipline we hold for anything that reshapes the model-visible frame. The
596779
+ * canonical message history is unaffected structurally (same length); full
596780
+ * evidence remains on disk (`.omnius/tool-results/`) and re-materialisable.
596781
+ */
596782
+ _retireStaleEvidenceInPlace(messages2, currentTurn) {
596783
+ if (process.env["OMNIUS_EVIDENCE_RETIREMENT"] !== "1")
596784
+ return;
596785
+ const keepRecent = Math.max(0, Number(process.env["OMNIUS_EVIDENCE_KEEP_TURNS"] ?? 2));
596786
+ const minChars = Math.max(512, Number(process.env["OMNIUS_EVIDENCE_MIN_CHARS"] ?? 2e3));
596787
+ const staleBefore = currentTurn - keepRecent;
596788
+ if (staleBefore <= 0)
596789
+ return;
596790
+ let turnCount = 0;
596791
+ let retired = 0;
596792
+ let reclaimed = 0;
596793
+ for (let i2 = 0; i2 < messages2.length; i2++) {
596794
+ const msg = messages2[i2];
596795
+ if (msg.role === "assistant") {
596796
+ turnCount++;
596797
+ if (turnCount > staleBefore)
596798
+ break;
596799
+ }
596800
+ const content = typeof msg.content === "string" ? msg.content : "";
596801
+ if (!content)
596802
+ continue;
596803
+ if (content.startsWith("[RETIRED EVIDENCE") || content.startsWith("[Todo context archived") || content.startsWith("[Tool result cleared")) {
596804
+ continue;
596805
+ }
596806
+ const rm4 = { role: msg.role, content };
596807
+ if (!isRetirableEvidence(rm4, minChars))
596808
+ continue;
596809
+ let outcome;
596810
+ try {
596811
+ outcome = foldEvidenceOutcome(rm4);
596812
+ } catch {
596813
+ outcome = "evidence";
596814
+ }
596815
+ const stub = `[RETIRED EVIDENCE turn<=${staleBefore} bytes=${content.length}] outcome: ${outcome}
596816
+ (full evidence retired to disk — re-read the file or re-run the command to re-materialise if you need the detail)`;
596817
+ if (stub.length >= content.length)
596818
+ continue;
596819
+ messages2[i2].content = stub;
596820
+ retired += 1;
596821
+ reclaimed += content.length - stub.length;
596822
+ }
596823
+ if (retired > 0) {
596824
+ this.emit({
596825
+ type: "status",
596826
+ content: `[evidence-retirement] retired ${retired} stale evidence block(s), reclaimed ~${Math.round(reclaimed / 4)} tokens (world-state outcomes retained; bytes on disk)`,
596827
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
596828
+ });
596829
+ }
596830
+ }
596291
596831
  _evictCompletedTodoMessages(startTurn, currentTurn, todoId, todoContent, messages2) {
596292
596832
  const placeholder = [
596293
596833
  `[Todo context archived: "${todoContent.slice(0, 120)}"`,
@@ -606839,110 +607379,6 @@ var init_conversational_scrutiny = __esm({
606839
607379
  }
606840
607380
  });
606841
607381
 
606842
- // packages/orchestrator/dist/spec-gate.js
606843
- function definitionCount(source, name10) {
606844
- const n2 = escapeRegExp2(name10);
606845
- const patterns = [
606846
- new RegExp(`}\\s*${n2}\\s*;`, "g"),
606847
- // } Name; (typedef struct/enum)
606848
- new RegExp(`\\b(?:struct|class|enum|union)\\s+${n2}\\s*[:{]`, "g"),
606849
- new RegExp(`\\b(?:interface|type|class|enum)\\s+${n2}\\b`, "g"),
606850
- new RegExp(`\\btypedef\\s+[^;{]+\\b${n2}\\s*;`, "g")
606851
- ];
606852
- let total = 0;
606853
- for (const re of patterns)
606854
- total += (source.match(re) ?? []).length;
606855
- return total;
606856
- }
606857
- function hasField(source, symbol3, field) {
606858
- const n2 = escapeRegExp2(symbol3);
606859
- const block = source.match(new RegExp(`(?:struct|class|enum|union|interface)\\s+${n2}[^{]*{([\\s\\S]*?)}|{([\\s\\S]*?)}\\s*${n2}\\s*;`));
606860
- const body = block?.[1] ?? block?.[2] ?? "";
606861
- if (!body)
606862
- return false;
606863
- return new RegExp(`\\b${escapeRegExp2(field)}\\b`).test(body);
606864
- }
606865
- function hasSignature(source, fragment) {
606866
- const norm = (s2) => s2.replace(/\s+/g, " ").trim();
606867
- return norm(source).includes(norm(fragment));
606868
- }
606869
- function evaluateSpecGate(unit, contract, opts = {}) {
606870
- const violations = [];
606871
- const expected = new Set(opts.expectedSymbols ?? []);
606872
- for (const spec of contract.symbols) {
606873
- const count = definitionCount(unit.source, spec.name);
606874
- const mustDefine = expected.has(spec.name);
606875
- if (count === 0) {
606876
- if (mustDefine) {
606877
- violations.push({
606878
- symbol: spec.name,
606879
- kind: "missing_symbol",
606880
- detail: `unit ${unit.path} must declare ${spec.kind} ${spec.name} but it is absent`
606881
- });
606882
- }
606883
- continue;
606884
- }
606885
- if (count > 1) {
606886
- violations.push({
606887
- symbol: spec.name,
606888
- kind: "duplicate_symbol",
606889
- detail: `${spec.name} is defined ${count}× in ${unit.path}; the contract permits exactly one`
606890
- });
606891
- }
606892
- for (const field of spec.fields ?? []) {
606893
- if (!hasField(unit.source, spec.name, field)) {
606894
- violations.push({
606895
- symbol: spec.name,
606896
- kind: "missing_field",
606897
- detail: `${spec.name} is missing required member "${field}"`
606898
- });
606899
- }
606900
- }
606901
- if (spec.signature && !hasSignature(unit.source, spec.signature)) {
606902
- violations.push({
606903
- symbol: spec.name,
606904
- kind: "signature_divergence",
606905
- detail: `${spec.name} does not match the contract signature "${spec.signature}"`
606906
- });
606907
- }
606908
- }
606909
- const pass = violations.length === 0;
606910
- return {
606911
- pass,
606912
- violations,
606913
- summary: pass ? `spec gate PASS for ${unit.path}` : `spec gate FAIL for ${unit.path}: ${violations.length} violation(s) — ${violations.map((v) => `${v.symbol}:${v.kind}`).join(", ")}`
606914
- };
606915
- }
606916
- function evaluateExecutorStep(input) {
606917
- const spec = evaluateSpecGate(input.unit, input.contract, {
606918
- expectedSymbols: input.expectedSymbols
606919
- });
606920
- if (input.convergenceTier === "abandon" || input.convergenceTier === "stalled") {
606921
- return {
606922
- decision: "replan",
606923
- spec,
606924
- reason: `convergence ${input.convergenceTier}: stop patching ${input.unit.path}; re-plan / regenerate from the locked contract`
606925
- };
606926
- }
606927
- const boundaryOk = input.boundaryOk ?? true;
606928
- if (spec.pass && boundaryOk) {
606929
- return { decision: "accept", spec, reason: `${input.unit.path} accepted` };
606930
- }
606931
- return {
606932
- decision: "reject_regenerate",
606933
- spec,
606934
- reason: spec.pass ? `${input.unit.path} passed the spec gate but failed to compile — regenerate` : spec.summary
606935
- };
606936
- }
606937
- function escapeRegExp2(s2) {
606938
- return s2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
606939
- }
606940
- var init_spec_gate = __esm({
606941
- "packages/orchestrator/dist/spec-gate.js"() {
606942
- "use strict";
606943
- }
606944
- });
606945
-
606946
607382
  // packages/orchestrator/dist/index.js
606947
607383
  var dist_exports3 = {};
606948
607384
  __export(dist_exports3, {
@@ -607026,6 +607462,7 @@ __export(dist_exports3, {
607026
607462
  buildRecentSteeringContext: () => buildRecentSteeringContext,
607027
607463
  buildSkillDescription: () => buildSkillDescription,
607028
607464
  buildSteeringPacket: () => buildSteeringPacket,
607465
+ buildUnitTodos: () => buildUnitTodos,
607029
607466
  checkMilestoneComplete: () => checkMilestoneComplete,
607030
607467
  chooseCheapModelRoute: () => chooseCheapModelRoute,
607031
607468
  claimAssertion: () => claimAssertion,
@@ -607059,6 +607496,7 @@ __export(dist_exports3, {
607059
607496
  criticalPathDepth: () => criticalPathDepth,
607060
607497
  debugArtifactRoot: () => debugArtifactRoot,
607061
607498
  decomposeSpec: () => decomposeSpec,
607499
+ decomposeToUnits: () => decomposeToUnits,
607062
607500
  defaultContextWindowDumpLocations: () => defaultContextWindowDumpLocations,
607063
607501
  deleteAgentTaskSidecar: () => deleteAgentTaskSidecar,
607064
607502
  deriveClaimsFromProposedText: () => deriveClaimsFromProposedText,
@@ -607071,6 +607509,7 @@ __export(dist_exports3, {
607071
607509
  discoverSystemOllamaModelStore: () => discoverSystemOllamaModelStore,
607072
607510
  evaluateExecutorStep: () => evaluateExecutorStep,
607073
607511
  evaluateSpecGate: () => evaluateSpecGate,
607512
+ evaluateUnitResult: () => evaluateUnitResult,
607074
607513
  executeBatch: () => executeBatch,
607075
607514
  executeHook: () => executeHook,
607076
607515
  expandContextReference: () => expandContextReference,
@@ -607302,6 +607741,7 @@ var init_dist8 = __esm({
607302
607741
  init_coherence_gate();
607303
607742
  init_spec_gate();
607304
607743
  init_longhaul_integration();
607744
+ init_decomposition_orchestrator();
607305
607745
  }
607306
607746
  });
607307
607747
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.476",
3
+ "version": "1.0.478",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "omnius",
9
- "version": "1.0.476",
9
+ "version": "1.0.478",
10
10
  "bundleDependencies": [
11
11
  "image-to-ascii"
12
12
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.476",
3
+ "version": "1.0.478",
4
4
  "description": "AI coding agent powered by open-source models (Ollama/vLLM) — interactive TUI with agentic tool-calling loop",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",