@mmerterden/multi-agent-pipeline 20.41.0 → 20.43.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +8 -6
  3. package/README.tr.md +8 -6
  4. package/docs/architecture.md +3 -3
  5. package/docs/ecosystem.md +50 -13
  6. package/docs/facts.json +9 -9
  7. package/docs/features.md +9 -4
  8. package/install/claude.mjs +34 -1
  9. package/install/templates/claude-hooks.json +12 -1
  10. package/manifest.json +117 -90
  11. package/package.json +3 -2
  12. package/pipeline/commands/multi-agent/autopilot/SKILL.md +11 -0
  13. package/pipeline/commands/multi-agent/clean-disk/SKILL.md +134 -0
  14. package/pipeline/commands/multi-agent/review-priority/SKILL.md +143 -0
  15. package/pipeline/commands/multi-agent/setup/SKILL.md +1 -1
  16. package/pipeline/commands/multi-agent/sync/SKILL.md +4 -4
  17. package/pipeline/lib/args.mjs +131 -4
  18. package/pipeline/lib/bg-launch.mjs +5 -2
  19. package/pipeline/lib/credential-store.sh +11 -1
  20. package/pipeline/lib/hook-once.mjs +134 -0
  21. package/pipeline/lib/isotonic.mjs +73 -0
  22. package/pipeline/lib/low-disk.mjs +154 -0
  23. package/pipeline/lib/mcp-schema-load.mjs +90 -0
  24. package/pipeline/lib/md2confluence-v3.py +8 -7
  25. package/pipeline/lib/model-dispatch.sh +26 -2
  26. package/pipeline/lib/normalize-text.mjs +135 -0
  27. package/pipeline/lib/outbound-gate.mjs +21 -3
  28. package/pipeline/lib/plan-todos.sh +17 -4
  29. package/pipeline/lib/redact.mjs +12 -3
  30. package/pipeline/lib/risky-settings.mjs +198 -0
  31. package/pipeline/lib/route-state.sh +1 -0
  32. package/pipeline/lib/secret-patterns.generated.mjs +6 -2
  33. package/pipeline/lib/session-usage.mjs +232 -0
  34. package/pipeline/lib/source-digest.mjs +211 -0
  35. package/pipeline/lib/tdd-evidence.mjs +250 -17
  36. package/pipeline/lib/untrusted-fence.mjs +132 -1
  37. package/pipeline/multi-agent-refs/analysis/locked.md +1 -1
  38. package/pipeline/multi-agent-refs/cross-cli-contract.md +5 -5
  39. package/pipeline/multi-agent-refs/features/cost-analysis.md +37 -2
  40. package/pipeline/multi-agent-refs/features/doctor.md +66 -4
  41. package/pipeline/multi-agent-refs/features/model-fallback.md +25 -0
  42. package/pipeline/multi-agent-refs/features/plan-todos.md +4 -0
  43. package/pipeline/multi-agent-refs/features/review-priority.md +123 -0
  44. package/pipeline/multi-agent-refs/features/unattended-gates.md +5 -3
  45. package/pipeline/multi-agent-refs/features/usage-reporting.md +4 -2
  46. package/pipeline/multi-agent-refs/help/en.md +3 -1
  47. package/pipeline/multi-agent-refs/help/tr.md +3 -1
  48. package/pipeline/multi-agent-refs/outside-the-pipeline.md +6 -0
  49. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +1 -1
  50. package/pipeline/multi-agent-refs/phases/phase-2-dev.md +4 -4
  51. package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -2
  52. package/pipeline/multi-agent-refs/phases/phase-5-report.md +2 -0
  53. package/pipeline/multi-agent-refs/progress-contract.md +3 -1
  54. package/pipeline/multi-agent-refs/review-priority/rules/example.md +137 -0
  55. package/pipeline/office/toolkit.json +1 -1
  56. package/pipeline/rules/outside-the-pipeline.md +1 -1
  57. package/pipeline/schemas/doctor-report.schema.json +47 -0
  58. package/pipeline/schemas/plan-todos.schema.json +29 -1
  59. package/pipeline/schemas/prefs.schema.json +81 -0
  60. package/pipeline/schemas/route-config.schema.json +51 -0
  61. package/pipeline/schemas/secret-patterns.json +17 -1
  62. package/pipeline/schemas/toolkit-path-params.json +15 -1
  63. package/pipeline/scripts/_cost-advise.mjs +357 -0
  64. package/pipeline/scripts/_cost-budget.mjs +78 -0
  65. package/pipeline/scripts/_cost.mjs +29 -0
  66. package/pipeline/scripts/_decode_text.py +107 -0
  67. package/pipeline/scripts/_guard-probe.mjs +406 -0
  68. package/pipeline/scripts/_guard_rules.py +206 -0
  69. package/pipeline/scripts/_memory-policy.mjs +1 -25
  70. package/pipeline/scripts/_retrieval.mjs +148 -2
  71. package/pipeline/scripts/_secret-scan.mjs +6 -1
  72. package/pipeline/scripts/_stack-routing.mjs +1 -0
  73. package/pipeline/scripts/_test-gaming.mjs +346 -0
  74. package/pipeline/scripts/agent-guard.py +8 -1
  75. package/pipeline/scripts/argv-secret-scan.mjs +2 -1
  76. package/pipeline/scripts/autopilot-loop.mjs +407 -0
  77. package/pipeline/scripts/autopilot-runner.mjs +38 -25
  78. package/pipeline/scripts/capture-resume.sh +9 -1
  79. package/pipeline/scripts/cost-analyze.mjs +66 -4
  80. package/pipeline/scripts/cost-budget-check.mjs +5 -13
  81. package/pipeline/scripts/disk-cleaner.mjs +1432 -0
  82. package/pipeline/scripts/doctor.mjs +302 -47
  83. package/pipeline/scripts/evidence-gate.mjs +90 -0
  84. package/pipeline/scripts/gate-ledger.mjs +76 -21
  85. package/pipeline/scripts/gc-tmp.sh +5 -0
  86. package/pipeline/scripts/guard-probe-known-holes.json +3 -0
  87. package/pipeline/scripts/learnings-ledger.mjs +16 -12
  88. package/pipeline/scripts/note-agent-event.mjs +2 -0
  89. package/pipeline/scripts/note-mcp-failure.mjs +9 -2
  90. package/pipeline/scripts/note-skill-use.mjs +4 -1
  91. package/pipeline/scripts/pre-commit-check.sh +2 -2
  92. package/pipeline/scripts/pre-push-check.sh +8 -1
  93. package/pipeline/scripts/priority-review.mjs +912 -0
  94. package/pipeline/scripts/publish-staged.mjs +324 -0
  95. package/pipeline/scripts/route-learn.mjs +628 -0
  96. package/pipeline/scripts/run-scope-guard.mjs +55 -1
  97. package/pipeline/scripts/scan-agent-config.sh +1 -1
  98. package/pipeline/scripts/statusline.mjs +309 -0
  99. package/pipeline/scripts/test-integrity-gate.mjs +97 -2
  100. package/pipeline/scripts/triage-memory.mjs +12 -4
  101. package/pipeline/scripts/uninstall.mjs +1 -0
  102. package/pipeline/skills/.skill-manifest.json +17 -5
  103. package/pipeline/skills/.skills-index.json +36 -3
  104. package/pipeline/skills/shared/README.md +9 -6
  105. package/pipeline/skills/shared/core/multi-agent-clean-disk/SKILL.md +34 -0
  106. package/pipeline/skills/shared/core/multi-agent-review-priority/SKILL.md +36 -0
  107. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +4 -4
  108. package/pipeline/skills/shared/external/backlog/SKILL.md +1 -1
  109. package/pipeline/skills/shared/external/disk-cleaner/SKILL.md +111 -0
  110. package/pipeline/skills/shared/external/disk-cleaner/evals/evals.json +62 -0
  111. package/pipeline/skills/shared/external/disk-cleaner/scripts/disk-cleaner.mjs +1432 -0
  112. package/pipeline/skills/shared/external/localization-reuse-map/SKILL.md +1 -1
  113. package/pipeline/skills/skill-copies.json +4 -0
  114. package/pipeline/skills/skills-index.md +5 -2
@@ -13,6 +13,14 @@
13
13
  * required gate for that HEAD passed. A gate the run skipped leaves no entry,
14
14
  * and a missing entry blocks the commit the same way a failing one does.
15
15
  *
16
+ * The build and test gates (DIGEST_BOUND) also record `sourceDigest`, the
17
+ * digest of the working tree's content (lib/source-digest.mjs). An edit made
18
+ * after the build leaves HEAD where it was, so for those gates the digest
19
+ * decides: an entry whose digest is the tree's current one counts whatever
20
+ * HEAD it names, and one whose digest differs is stale, which blocks the
21
+ * commit like a missing entry and is reported as `stale`. An entry without a
22
+ * digest, or a tree git cannot digest, is judged by sha as before.
23
+ *
16
24
  * Entries are written while the quality gates are active (lib/unattended.mjs,
17
25
  * gatesActive): MULTI_AGENT_UNATTENDED=1, or a run in autopilot mode. A run
18
26
  * that is neither writes only the gates in ATTENDED_RECORDED, each entry marked
@@ -69,6 +77,7 @@ import { dirname, join } from "node:path";
69
77
  import { decisionEntry, withDecision } from "../lib/decisions.mjs";
70
78
  import { invokedDirectly } from "../lib/invoked-directly.mjs";
71
79
  import { readRegularFile, readRegularJson } from "../lib/regular-file.mjs";
80
+ import { sourceDigest } from "../lib/source-digest.mjs";
72
81
  import { writeFileSafe } from "../lib/safe-write.mjs";
73
82
  import { globalPref } from "../lib/prefs-value.mjs";
74
83
  import { modeEntry } from "../lib/run-completion.mjs";
@@ -137,6 +146,35 @@ export function trailingFailures(gates, gate) {
137
146
 
138
147
  export const ATTENDED_COMMIT_EVIDENCE = ["evidence-gate/build", "evidence-gate/test"];
139
148
 
149
+ /** Gates whose entries carry the working tree's source digest. */
150
+ export const DIGEST_BOUND = new Set(["evidence-gate/build", "evidence-gate/test"]);
151
+
152
+ /** The digest of the tree at `dir`, or null when it cannot be read. */
153
+ export function currentDigestOf(dir) {
154
+ return sourceDigest(dir)?.digest ?? null;
155
+ }
156
+
157
+ /**
158
+ * Latest entry per gate among those that speak for the current content: a
159
+ * digest-bound entry with a digest is matched on the digest when the current
160
+ * one is known, every other entry on its sha. Also names the digest-bound
161
+ * gates whose only candidates were recorded on other content.
162
+ */
163
+ function evidenceFor(gates, { sha, currentDigest = null, sameTree = null }) {
164
+ const onSha = (s) => s === sha || (sameTree ? sameTree(s) : false);
165
+ const byDigest = (e) =>
166
+ DIGEST_BOUND.has(e.gate) && Boolean(currentDigest) && typeof e.sourceDigest === "string";
167
+ const latest = latestWhere(gates, (e) =>
168
+ byDigest(e) ? e.sourceDigest === currentDigest : onSha(e.sha),
169
+ );
170
+ const stale = new Set();
171
+ for (const e of Array.isArray(gates) ? gates : []) {
172
+ if (e && byDigest(e) && e.sourceDigest !== currentDigest && !latest.has(e.gate))
173
+ stale.add(e.gate);
174
+ }
175
+ return { latest, stale };
176
+ }
177
+
140
178
  /** Asked for too once the run is in its commit phase: the review verdict. */
141
179
  export const ATTENDED_REVIEW_EVIDENCE = "review-decision";
142
180
  export const ATTENDED_REVIEW_FROM_PHASE = 4;
@@ -159,16 +197,14 @@ export const ATTENDED_COMMIT_MODES = ["off", "warn", "block", "auto"];
159
197
  * @param {string} sha
160
198
  * @returns {string[]}
161
199
  */
162
- export function attendedEvidenceGaps(state, sha, { sameTree } = {}) {
200
+ export function attendedEvidenceGaps(state, sha, { sameTree, currentDigest = null } = {}) {
163
201
  const wanted = [...ATTENDED_COMMIT_EVIDENCE];
164
202
  if (Number(state?.currentPhase) >= ATTENDED_REVIEW_FROM_PHASE)
165
203
  wanted.push(ATTENDED_REVIEW_EVIDENCE);
166
204
  const asked = (Array.isArray(state?.gates) ? state.gates : []).filter((e) =>
167
205
  wanted.includes(e?.gate),
168
206
  );
169
- const latest = sameTree
170
- ? latestByGateWhere(asked, (s) => s === sha || sameTree(s))
171
- : latestByGate(asked, sha);
207
+ const { latest } = evidenceFor(asked, { sha, currentDigest, sameTree });
172
208
  return wanted.filter((g) => {
173
209
  const e = latest.get(g);
174
210
  return !e || !PASSING.has(e.verdict);
@@ -494,11 +530,13 @@ export async function record(
494
530
  const wt = ctx.state?.worktreePath;
495
531
  shaRepo = typeof wt === "string" && existsSync(wt) ? wt : process.cwd();
496
532
  }
533
+ const digest = DIGEST_BOUND.has(gate) ? currentDigestOf(shaRepo) : null;
497
534
  const entry = {
498
535
  gate,
499
536
  verdict,
500
537
  at: new Date().toISOString(),
501
538
  sha: headSha(shaRepo),
539
+ ...(digest ? { sourceDigest: digest } : {}),
502
540
  detail: detail && typeof detail === "object" ? detail : { value: detail },
503
541
  ...(attended ? { attended: true } : {}),
504
542
  };
@@ -613,9 +651,14 @@ export function latestByGate(gates, sha) {
613
651
 
614
652
  /** latestByGate over the entries whose sha `accept` takes. */
615
653
  export function latestByGateWhere(gates, accept) {
654
+ return latestWhere(gates, (e) => accept(e.sha));
655
+ }
656
+
657
+ /** Latest entry per gate over the entries `accept` takes. */
658
+ function latestWhere(gates, accept) {
616
659
  const out = new Map();
617
660
  (Array.isArray(gates) ? gates : []).forEach((e, i) => {
618
- if (!e || typeof e !== "object" || typeof e.gate !== "string" || !accept(e.sha)) return;
661
+ if (!e || typeof e !== "object" || typeof e.gate !== "string" || !accept(e)) return;
619
662
  const prev = out.get(e.gate);
620
663
  const t = Date.parse(e.at) || 0;
621
664
  if (!prev || t > prev.t || (t === prev.t && i > prev.i)) out.set(e.gate, { e, t, i });
@@ -628,24 +671,31 @@ export function latestByGateWhere(gates, accept) {
628
671
  *
629
672
  * @param {object} state
630
673
  * @param {string} sha
631
- * @param {{mandatory?: string[]}} [opts]
632
- * @returns {{ok: boolean, missing: string[], failing: object[], sha: string}}
674
+ * @param {{mandatory?: string[], currentDigest?: string|null}} [opts]
675
+ * @returns {{ok: boolean, missing: string[], failing: object[], stale: string[], sha: string}}
633
676
  */
634
- export function checkCommit(state, sha, { mandatory = MANDATORY_AT_COMMIT } = {}) {
677
+ export function checkCommit(
678
+ state,
679
+ sha,
680
+ { mandatory = MANDATORY_AT_COMMIT, currentDigest = null } = {},
681
+ ) {
635
682
  // An entry written while the gates were off says what an attended run
636
683
  // observed; it never stands in for a verdict the unattended contract requires.
637
684
  const gated = (Array.isArray(state?.gates) ? state.gates : []).filter(
638
685
  (e) => !(e && e.attended === true),
639
686
  );
640
- const latest = latestByGate(gated, sha);
687
+ const { latest, stale: staleSet } = evidenceFor(gated, { sha, currentDigest });
641
688
  const missing = [];
642
689
  const failing = [];
690
+ const stale = [];
643
691
  for (const g of mandatory) {
644
692
  const e = latest.get(g);
645
- if (!e) missing.push(g);
693
+ if (!e && staleSet.has(g)) stale.push(g);
694
+ else if (!e) missing.push(g);
646
695
  else if (!PASSING.has(e.verdict)) failing.push(e);
647
696
  }
648
- return { ok: missing.length === 0 && failing.length === 0, missing, failing, sha };
697
+ const ok = missing.length === 0 && failing.length === 0 && stale.length === 0;
698
+ return { ok, missing, failing, stale, sha };
649
699
  }
650
700
 
651
701
  // ---------------------------------------------------------------------------
@@ -705,23 +755,25 @@ async function main(argv) {
705
755
  return 3;
706
756
  }
707
757
  const state = readJson(path);
708
- const sha =
709
- opts.sha ||
710
- headSha(
711
- opts.repo || !(state?.worktreePath && existsSync(state.worktreePath))
712
- ? repo
713
- : state.worktreePath,
714
- );
758
+ const tree =
759
+ opts.repo || !(state?.worktreePath && existsSync(state.worktreePath))
760
+ ? repo
761
+ : state.worktreePath;
762
+ const sha = opts.sha || headSha(tree);
715
763
  if (!state || !sha) {
716
764
  process.stderr.write(`gate-ledger: cannot read ${path} or resolve HEAD\n`);
717
765
  return 3;
718
766
  }
719
- const r = checkCommit(state, sha);
767
+ const r = checkCommit(state, sha, { currentDigest: currentDigestOf(tree) });
720
768
  if (opts.json) writeFileSync(1, `${JSON.stringify({ statePath: path, ...r }, null, 2)}\n`);
721
769
  if (!r.ok) {
722
770
  const lines = [
723
771
  `gate-ledger: the unattended commit on ${sha.slice(0, 12)} is not backed by the gate ledger (${path})`,
724
772
  ...r.missing.map((g) => ` missing: ${g} has no entry for this HEAD`),
773
+ ...r.stale.map(
774
+ (g) =>
775
+ ` stale: ${g} was recorded on other source; a file changed after it ran, so run it again`,
776
+ ),
725
777
  ...r.failing.map(
726
778
  (e) =>
727
779
  ` failing: ${e.gate} -> ${e.verdict}${e.detail?.reason ? ` (${e.detail.reason})` : ""}`,
@@ -765,7 +817,10 @@ async function main(argv) {
765
817
  const bound =
766
818
  (session && state.hostSessionId === session) || (launched && state.sessionId === launched);
767
819
  const gateMode = effectiveCommitMode(pref, Boolean(bound));
768
- const missing = attendedEvidenceGaps(state, sha, { sameTree: sameTreeAs(repo) });
820
+ const missing = attendedEvidenceGaps(state, sha, {
821
+ sameTree: sameTreeAs(repo),
822
+ currentDigest: currentDigestOf(repo),
823
+ });
769
824
  if (opts.json)
770
825
  writeFileSync(1, `${JSON.stringify({ statePath: path, sha, gateMode, missing })}\n`);
771
826
  if (!missing.length) return 0;
@@ -773,7 +828,7 @@ async function main(argv) {
773
828
  writeFileSync(
774
829
  2,
775
830
  `${[
776
- `pre-commit-check: ${verb}: the run's gate ledger (${path}) has no passing ${missing.join(" / ")} for HEAD ${sha.slice(0, 12)}.`,
831
+ `pre-commit-check: ${verb}: the run's gate ledger (${path}) has no passing ${missing.join(" / ")} for HEAD ${sha.slice(0, 12)} and the source as it is now; an edit after the build or the tests makes their verdict stale.`,
777
832
  " Run the build and the tests through evidence-gate.mjs (Phase 2 Gate 1), and in the commit phase the review verdict (review-decision-gate.mjs), so the commit rests on recorded evidence.",
778
833
  gateMode === "block"
779
834
  ? " This session drives the run, so the commit waits for the evidence; prefs.global.attendedCommitGate.mode warn lets it through."
@@ -123,6 +123,11 @@ NAME_ARGS=(
123
123
  -o \( -name '*-wiki' -type d \)
124
124
  )
125
125
 
126
+ # `multi-agent-*` also covers lib/hook-once.mjs's claim directory
127
+ # (multi-agent-hook-once-<uid>). Its claims prune themselves after ten
128
+ # minutes; a sweep here removes the directory once no hook has claimed in it
129
+ # for the grace window.
130
+ #
126
131
  # `complaint-analysis-*` needs its own entry: find matches the basename against
127
132
  # the whole glob, so `analysis-*` never matched it. Same for the other three,
128
133
  # which were writing into $ROOT with nothing sweeping them (phase-0-init.md,
@@ -0,0 +1,3 @@
1
+ {
2
+ "holes": []
3
+ }
@@ -165,7 +165,7 @@ import {
165
165
  import { createInterface } from "node:readline";
166
166
  import { homedir } from "node:os";
167
167
  import { join, dirname, basename } from "node:path";
168
- import { bm25, recencyRank, rrf, tokens, recallConfig } from "./_retrieval.mjs";
168
+ import { bm25, mmr, multiQuery, recencyRank, rrf, tokens, recallConfig } from "./_retrieval.mjs";
169
169
  import { checkedSlug, repoName } from "../lib/slug.mjs";
170
170
  import {
171
171
  GLOBAL_LEDGER_SLUG,
@@ -943,15 +943,15 @@ function cmdBrief() {
943
943
  // pass no task text, and as the rollback path.
944
944
  ordered = capGlobalShare(newestFirst(pool), max);
945
945
  } else {
946
- const relevance = bm25(
947
- tokens(task),
948
- pool.map((r) => ({
949
- statement: r.statement || "",
950
- diagnosis: r.diagnosis || "",
951
- scope: r.scope === "global" ? "" : r.scope || "",
952
- })),
953
- { fieldWeights: { statement: 3, diagnosis: 2, scope: 1 } },
954
- );
946
+ const docs = pool.map((r) => ({
947
+ statement: r.statement || "",
948
+ diagnosis: r.diagnosis || "",
949
+ scope: r.scope === "global" ? "" : r.scope || "",
950
+ }));
951
+ const fieldWeights = { statement: 3, diagnosis: 2, scope: 1 };
952
+ const relevance = cfg.multiQuery
953
+ ? multiQuery(task, docs, { fieldWeights })
954
+ : bm25(tokens(task), docs, { fieldWeights });
955
955
  const fresh = recencyRank(pool, { halfLifeDays: cfg.halfLifeDays });
956
956
  const matched = new Set(relevance.filter((x) => x.score > 0).map((x) => x.index));
957
957
  // Entries recorded useful at least twice rank by their strength as well;
@@ -959,8 +959,12 @@ function cmdBrief() {
959
959
  const earned = pool
960
960
  .map((r, index) => ({ index, score: strengthOf.get(r) || 0 }))
961
961
  .sort((a, b) => b.score - a.score);
962
- const fused = rrf([relevance, fresh, earned], { k: [10, 60, 60], weights: [3, 1, 1] }).filter(
963
- (x) => matched.has(x.index),
962
+ const fused = mmr(
963
+ rrf([relevance, fresh, earned], { k: [10, 60, 60], weights: [3, 1, 1] }).filter((x) =>
964
+ matched.has(x.index),
965
+ ),
966
+ docs.map((d) => tokens(`${d.statement} ${d.diagnosis}`)),
967
+ { lambda: cfg.mmrLambda, limit: max },
964
968
  );
965
969
  ordered = capGlobalShare(
966
970
  fused.map((x) => pool[x.index]),
@@ -29,6 +29,7 @@ import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
29
29
  import { homedir } from "node:os";
30
30
  import { join } from "node:path";
31
31
 
32
+ import { claimHookEvent } from "../lib/hook-once.mjs";
32
33
  import { invokedDirectly } from "../lib/invoked-directly.mjs";
33
34
  import { findActiveRun } from "./_active-run.mjs";
34
35
  import { memoryExcluded } from "./_memory-policy.mjs";
@@ -143,6 +144,7 @@ function main() {
143
144
  } catch {
144
145
  return;
145
146
  }
147
+ if (!claimHookEvent("note-agent-event", payload)) return;
146
148
  record(payload);
147
149
  }
148
150
 
@@ -10,8 +10,9 @@
10
10
  * server the MCP server, from the tool name mcp__<server>__<tool>
11
11
  * tool the tool, from the same name
12
12
  * ts when the hook ran
13
- * errorClass one of ERROR_CLASSES, chosen from the error text: a JSON-RPC
14
- * code first, then a message that opens with "invalid" or
13
+ * errorClass one of ERROR_CLASSES: the host's interrupt flag first, then
14
+ * a refusal by the user or the permission layer, then a JSON-RPC
15
+ * code, then a message that opens with "invalid" or
15
16
  * "validation", then an HTTP status, then fixed wording
16
17
  * patterns; the text itself is never stored
17
18
  *
@@ -48,6 +49,7 @@ import { join } from "node:path";
48
49
  import { parseArgs } from "../lib/args.mjs";
49
50
  import { exitOnHelp } from "../lib/cli-help.mjs";
50
51
  import { installFatalHandlers } from "../lib/fatal.mjs";
52
+ import { claimHookEvent } from "../lib/hook-once.mjs";
51
53
  import { invokedDirectly } from "../lib/invoked-directly.mjs";
52
54
  import { findPrefs, globalPref } from "../lib/prefs-value.mjs";
53
55
  import { redact } from "../lib/redact.mjs";
@@ -120,6 +122,10 @@ function statusClass(status) {
120
122
  * the server failing, and invalid-input is not counted against a server.
121
123
  */
122
124
  const CLASS_PATTERNS = [
125
+ [
126
+ "disk-full",
127
+ /ENOSPC|no space left on device|disk (?:is )?full|not enough (?:free )?(?:disk )?space|out of disk space/i,
128
+ ],
123
129
  ["timeout", /timed out|deadline exceeded|ETIMEDOUT|timeout (?:error|exceeded|after)/i],
124
130
  ["rate-limit", /rate.?limit|too many requests/i],
125
131
  ["auth", /unauthori[sz]ed|forbidden|authenticat|expired token|token expired|invalid token/i],
@@ -339,6 +345,7 @@ async function hookMain() {
339
345
  } catch {
340
346
  return;
341
347
  }
348
+ if (!claimHookEvent("note-mcp-failure", payload)) return;
342
349
  record(payload);
343
350
  }
344
351
 
@@ -48,6 +48,7 @@ import { basename, dirname, join, resolve } from "node:path";
48
48
 
49
49
  import { exitOnHelp } from "../lib/cli-help.mjs";
50
50
  import { installFatalHandlers } from "../lib/fatal.mjs";
51
+ import { claimHookEvent } from "../lib/hook-once.mjs";
51
52
  import { invokedDirectly } from "../lib/invoked-directly.mjs";
52
53
  import { globalPref } from "../lib/prefs-value.mjs";
53
54
  import { redact } from "../lib/redact.mjs";
@@ -165,7 +166,8 @@ async function rowRepo(cwd, env) {
165
166
 
166
167
  /**
167
168
  * The log's size: 0 when nothing is there, null when a link, a FIFO, a
168
- * directory or anything but a regular file stands at the name.
169
+ * directory or anything but a regular file stands at the name. Any other
170
+ * stat error is thrown to the caller.
169
171
  */
170
172
  function logSize(file, opts) {
171
173
  try {
@@ -332,6 +334,7 @@ async function main() {
332
334
  } catch {
333
335
  return;
334
336
  }
337
+ if (!claimHookEvent("note-skill-use", payload)) return;
335
338
  await record(payload);
336
339
  }
337
340
 
@@ -96,10 +96,10 @@ SECRET_PATTERN_ERES=(
96
96
  '"type"[[:space:]]*:[[:space:]]*"service_account"'
97
97
  '(^|[^A-Za-z0-9_])eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}([^A-Za-z0-9_]|$)'
98
98
  '-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----'
99
- '(^|[^A-Za-z0-9_])[a-z][a-z0-9+.-]*://[^[:space:]/:@]+:[^[:space:]/@]+@'
99
+ '(^|[^A-Za-z0-9_])[a-z][a-z0-9+.-]{0,31}://[^[:space:]/:@]{1,255}:[^[:space:]/@]+@'
100
100
  '(^|[^A-Za-z0-9_])Authorization:[[:space:]]*(Bearer|Basic)[[:space:]]+[A-Za-z0-9._~+/=-]{16,}'
101
101
  )
102
- SECRET_PATTERNS_ERE='((^|[^A-Za-z0-9_])gh[pousr]_[A-Za-z0-9]{36,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])github_pat_[A-Za-z0-9_]{50,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])xox[abprs]-[A-Za-z0-9-]{10,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])(AKIA|ASIA)[0-9A-Z]{16})|((^|[^A-Za-z0-9_])AIza[0-9A-Za-z_-]{35}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])sk-(proj-)?[A-Za-z0-9_-]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])sk-ant-[A-Za-z0-9_-]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])fig[a-z]_[A-Za-z0-9_-]{20,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])npm_[A-Za-z0-9]{36}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])glpat-[A-Za-z0-9_-]{20,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])[sr]k_live_[A-Za-z0-9]{20,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])pplx-[A-Za-z0-9]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])hf_[A-Za-z0-9]{30,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])gsk_[A-Za-z0-9]{40,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])sk-or-v1-[A-Za-z0-9]{40,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])xapp-[0-9]+-[A-Za-z0-9]{8,}-[0-9]{8,}-[A-Za-z0-9]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}([^A-Za-z0-9_-]|$))|((^|[^A-Za-z0-9_])SK[0-9a-f]{32}([^A-Za-z0-9_]|$))|("type"[[:space:]]*:[[:space:]]*"service_account")|((^|[^A-Za-z0-9_])eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}([^A-Za-z0-9_]|$))|(-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----)|((^|[^A-Za-z0-9_])[a-z][a-z0-9+.-]*://[^[:space:]/:@]+:[^[:space:]/@]+@)'
102
+ SECRET_PATTERNS_ERE='((^|[^A-Za-z0-9_])gh[pousr]_[A-Za-z0-9]{36,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])github_pat_[A-Za-z0-9_]{50,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])xox[abprs]-[A-Za-z0-9-]{10,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])(AKIA|ASIA)[0-9A-Z]{16})|((^|[^A-Za-z0-9_])AIza[0-9A-Za-z_-]{35}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])sk-(proj-)?[A-Za-z0-9_-]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])sk-ant-[A-Za-z0-9_-]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])fig[a-z]_[A-Za-z0-9_-]{20,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])npm_[A-Za-z0-9]{36}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])glpat-[A-Za-z0-9_-]{20,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])[sr]k_live_[A-Za-z0-9]{20,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])pplx-[A-Za-z0-9]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])hf_[A-Za-z0-9]{30,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])gsk_[A-Za-z0-9]{40,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])sk-or-v1-[A-Za-z0-9]{40,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])xapp-[0-9]+-[A-Za-z0-9]{8,}-[0-9]{8,}-[A-Za-z0-9]{32,}([^A-Za-z0-9_]|$))|((^|[^A-Za-z0-9_])SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}([^A-Za-z0-9_-]|$))|((^|[^A-Za-z0-9_])SK[0-9a-f]{32}([^A-Za-z0-9_]|$))|("type"[[:space:]]*:[[:space:]]*"service_account")|((^|[^A-Za-z0-9_])eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}([^A-Za-z0-9_]|$))|(-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----)|((^|[^A-Za-z0-9_])[a-z][a-z0-9+.-]{0,31}://[^[:space:]/:@]{1,255}:[^[:space:]/@]+@)'
103
103
  SECRET_PATTERNS_ERE_ICASE='(aws_?secret_?access_?key["'\'']?[[:space:]]*[:=][[:space:]]*["'\'']?[A-Za-z0-9/+=]{40}([^A-Za-z0-9/+=]|$))|(aws_?session_?token["'\'']?[[:space:]]*[:=][[:space:]]*["'\'']?[A-Za-z0-9/+=]{100,})|((^|[^A-Za-z0-9_])Authorization:[[:space:]]*(Bearer|Basic)[[:space:]]+[A-Za-z0-9._~+/=-]{16,})'
104
104
  # END GENERATED: secret-patterns
105
105
 
@@ -44,6 +44,8 @@
44
44
 
45
45
  set -uo pipefail
46
46
 
47
+ LOW_DISK="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" 2>/dev/null && pwd)/low-disk.mjs"
48
+
47
49
  # Git runs the hook from the top of the worktree being pushed; the script itself
48
50
  # may live in a different checkout of the same repository. Measure the former.
49
51
  REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || (cd "$(dirname "$0")/../.." && pwd))"
@@ -114,12 +116,16 @@ echo "→ Running local CI gate (primary - GitHub Actions is not executing)"
114
116
  echo ""
115
117
 
116
118
  FAILED=0
119
+ # Every step's output is kept, so a failed gate can be checked for a full
120
+ # disk: a gate that dies with ENOSPC is not a code defect.
121
+ GATE_LOG="$(mktemp "${TMPDIR:-/tmp}/pre-push-gate-XXXXXX")"
122
+ trap 'rm -f "$GATE_LOG"' EXIT
117
123
 
118
124
  run_step() {
119
125
  local name="$1"
120
126
  shift
121
127
  echo "→ $name"
122
- if "$@"; then
128
+ if { "$@" 2>&1; } | tee -a "$GATE_LOG"; then
123
129
  echo " ✓ $name passed"
124
130
  else
125
131
  echo " ✗ $name FAILED" >&2
@@ -166,6 +172,7 @@ fi
166
172
  if [ "$FAILED" -gt 0 ]; then
167
173
  echo "" >&2
168
174
  echo "✗ $FAILED gate(s) failed. Fix before pushing." >&2
175
+ node "$LOW_DISK" --scan "$GATE_LOG" >&2 || true
169
176
  echo " To bypass (emergencies only): git push --no-verify" >&2
170
177
  exit 1
171
178
  fi