@claude-flow/cli 3.56.9 → 3.57.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 (101) hide show
  1. package/.claude/helpers/.helpers-version +1 -1
  2. package/.claude/helpers/helpers.manifest.json +3 -3
  3. package/.claude/helpers/intelligence.cjs +51 -9
  4. package/.claude/helpers/router.cjs +0 -0
  5. package/.claude/skills/verification-quality/SKILL.md +14 -11
  6. package/README.md +1 -1
  7. package/catalog-manifest.json +2 -2
  8. package/dist/src/autopilot-state.d.ts +2 -0
  9. package/dist/src/autopilot-state.js +36 -8
  10. package/dist/src/command-resolution.d.ts +15 -0
  11. package/dist/src/command-resolution.js +25 -0
  12. package/dist/src/commands/agent.js +17 -17
  13. package/dist/src/commands/claims.js +6 -8
  14. package/dist/src/commands/daemon.js +94 -33
  15. package/dist/src/commands/doctor.js +95 -18
  16. package/dist/src/commands/memory.js +14 -2
  17. package/dist/src/commands/policy.js +6 -1
  18. package/dist/src/commands/security-code-patterns.d.ts +2 -2
  19. package/dist/src/commands/security-code-patterns.js +61 -3
  20. package/dist/src/commands/security.d.ts +24 -0
  21. package/dist/src/commands/security.js +81 -35
  22. package/dist/src/commands/tui.d.ts +9 -0
  23. package/dist/src/commands/tui.js +29 -3
  24. package/dist/src/config/proven-config-refresh.d.ts +9 -0
  25. package/dist/src/config/proven-config-refresh.js +24 -3
  26. package/dist/src/funnel/local-signals.js +2 -1
  27. package/dist/src/index.js +11 -47
  28. package/dist/src/init/settings-generator.js +4 -58
  29. package/dist/src/init/types.js +1 -1
  30. package/dist/src/mcp-tools/agent-execute-core.d.ts +2 -0
  31. package/dist/src/mcp-tools/agent-execute-core.js +15 -0
  32. package/dist/src/mcp-tools/agent-health-metrics.d.ts +22 -0
  33. package/dist/src/mcp-tools/agent-health-metrics.js +33 -0
  34. package/dist/src/mcp-tools/agent-tools.js +45 -22
  35. package/dist/src/mcp-tools/agentbbs-federation.d.ts +1 -1
  36. package/dist/src/mcp-tools/agentbbs-federation.js +7 -2
  37. package/dist/src/mcp-tools/agentdb-tools.js +25 -2
  38. package/dist/src/mcp-tools/aidefence-known-misses.d.ts +22 -0
  39. package/dist/src/mcp-tools/aidefence-known-misses.js +57 -0
  40. package/dist/src/mcp-tools/analyze-tools.js +10 -11
  41. package/dist/src/mcp-tools/autopilot-tools.js +2 -2
  42. package/dist/src/mcp-tools/browser-intent-tools.js +6 -2
  43. package/dist/src/mcp-tools/embeddings-tools.js +29 -7
  44. package/dist/src/mcp-tools/hooks-tools.js +4 -0
  45. package/dist/src/mcp-tools/memory-tools.d.ts +1 -1
  46. package/dist/src/mcp-tools/memory-tools.js +100 -25
  47. package/dist/src/mcp-tools/metaharness-tools.js +1 -1
  48. package/dist/src/mcp-tools/neural-tools.js +48 -54
  49. package/dist/src/mcp-tools/policy-tools.js +5 -3
  50. package/dist/src/mcp-tools/ruvllm-tools.js +6 -0
  51. package/dist/src/mcp-tools/security-tools.js +55 -17
  52. package/dist/src/mcp-tools/workflow-tools.js +66 -17
  53. package/dist/src/memory/intelligence.d.ts +5 -1
  54. package/dist/src/memory/intelligence.js +158 -35
  55. package/dist/src/memory/memory-bridge.js +10 -3
  56. package/dist/src/memory/memory-initializer.js +2 -1
  57. package/dist/src/memory/search-defaults.d.ts +54 -0
  58. package/dist/src/memory/search-defaults.js +37 -0
  59. package/dist/src/memory/sona-optimizer.d.ts +28 -0
  60. package/dist/src/memory/sona-optimizer.js +59 -2
  61. package/dist/src/memory/stats-file-lock.d.ts +7 -0
  62. package/dist/src/memory/stats-file-lock.js +53 -0
  63. package/dist/src/mods/command-registry/schema.d.ts +24 -24
  64. package/dist/src/ruvector/agent-wasm.d.ts +10 -0
  65. package/dist/src/ruvector/agent-wasm.js +27 -1
  66. package/dist/src/ruvector/diff-classifier.d.ts +2 -4
  67. package/dist/src/ruvector/diff-classifier.js +202 -69
  68. package/dist/src/ruvector/ruvllm-wasm.d.ts +4 -0
  69. package/dist/src/ruvector/ruvllm-wasm.js +12 -1
  70. package/dist/src/services/distill-oracle.d.ts +1 -1
  71. package/dist/src/services/distill-oracle.js +2 -2
  72. package/dist/src/services/policy-anchor-log.d.ts +13 -0
  73. package/dist/src/services/policy-anchor-log.js +242 -0
  74. package/dist/src/services/policy-archive-scan.d.ts +7 -0
  75. package/dist/src/services/policy-archive-scan.js +50 -0
  76. package/dist/src/services/policy-ledger-anchor.d.ts +14 -8
  77. package/dist/src/services/policy-ledger-anchor.js +356 -40
  78. package/dist/src/services/policy-ledger-audit.d.ts +22 -0
  79. package/dist/src/services/policy-ledger-audit.js +260 -0
  80. package/dist/src/services/policy-ledger-record.d.ts +3 -0
  81. package/dist/src/services/policy-ledger-record.js +22 -0
  82. package/dist/src/services/policy-runtime.d.ts +2 -1
  83. package/dist/src/services/policy-runtime.js +267 -40
  84. package/dist/src/services/worker-daemon.d.ts +11 -0
  85. package/dist/src/services/worker-daemon.js +37 -0
  86. package/dist/src/transfer/store/discovery.js +16 -17
  87. package/dist/src/transfer/store/types.d.ts +4 -0
  88. package/node_modules/@claude-flow/codex/dist/cli.js +0 -0
  89. package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js +0 -0
  90. package/node_modules/@claude-flow/security/dist/policy/engine.d.ts +17 -1
  91. package/node_modules/@claude-flow/security/dist/policy/engine.d.ts.map +1 -1
  92. package/node_modules/@claude-flow/security/dist/policy/engine.js +99 -24
  93. package/node_modules/@claude-flow/security/dist/policy/engine.js.map +1 -1
  94. package/node_modules/@claude-flow/security/dist/policy/types.d.ts +14 -1
  95. package/node_modules/@claude-flow/security/dist/policy/types.d.ts.map +1 -1
  96. package/node_modules/@claude-flow/security/dist/policy/types.js +3 -1
  97. package/node_modules/@claude-flow/security/dist/policy/types.js.map +1 -1
  98. package/package.json +5 -5
  99. package/plugins/ruflo-console/dist/tui.mjs +162 -161
  100. package/plugins/ruflo-metaharness/hooks/screen.ts +7 -1
  101. package/plugins/ruflo-metaharness/scripts/_darwin.mjs +4 -4
@@ -0,0 +1,242 @@
1
+ /** Streaming reader/writer for the existing version-1 anchor JSON object.
2
+ * Every entry is still parsed and authenticated by the caller. This bounds
3
+ * memory without weakening historical validation or changing the log format.
4
+ */
5
+ import { closeSync, constants, fstatSync, openSync, readSync, writeSync } from 'node:fs';
6
+ import { TextDecoder } from 'node:util';
7
+ export const ATOMIC_JSON_WRITER = Symbol('policy-atomic-json-writer');
8
+ const CHUNK_BYTES = 64 * 1024;
9
+ const VALUE_LIMIT = 16 * 1024 * 1024;
10
+ const STRING_STRUCTURE = /["\\]/g;
11
+ const VALUE_STRUCTURE = /["\\{}\[\]]/g;
12
+ class JsonReader {
13
+ fd;
14
+ buffer = Buffer.allocUnsafe(CHUNK_BYTES);
15
+ decoder = new TextDecoder('utf-8', { fatal: true });
16
+ text = '';
17
+ cursor = 0;
18
+ position = 0;
19
+ ended = false;
20
+ constructor(file) {
21
+ this.fd = openSync(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
22
+ try {
23
+ if (!fstatSync(this.fd).isFile())
24
+ throw new Error('policy-anchor-log-corrupt');
25
+ }
26
+ catch (error) {
27
+ closeSync(this.fd);
28
+ throw error;
29
+ }
30
+ }
31
+ close() { closeSync(this.fd); }
32
+ peek() {
33
+ while (this.cursor >= this.text.length && !this.ended) {
34
+ const count = readSync(this.fd, this.buffer, 0, this.buffer.length, this.position);
35
+ this.position += count;
36
+ this.text = this.decoder.decode(this.buffer.subarray(0, count), { stream: count !== 0 });
37
+ this.cursor = 0;
38
+ if (!count)
39
+ this.ended = true;
40
+ }
41
+ return this.text[this.cursor] ?? '';
42
+ }
43
+ next() { const character = this.peek(); if (character)
44
+ this.cursor++; return character; }
45
+ whitespace() { while (/[ \t\r\n]/.test(this.peek()) && this.peek())
46
+ this.next(); }
47
+ expect(character) { this.whitespace(); if (this.next() !== character)
48
+ throw new Error('policy-anchor-log-corrupt'); }
49
+ value() {
50
+ this.whitespace();
51
+ const first = this.peek();
52
+ if (!first)
53
+ throw new Error('policy-anchor-log-corrupt');
54
+ const compound = first === '{' || first === '[';
55
+ const string = first === '"';
56
+ const parts = [];
57
+ let bytes = 0;
58
+ let depth = 0;
59
+ let quoted = false;
60
+ let escaped = false;
61
+ for (;;) {
62
+ if (!this.peek()) {
63
+ if (quoted || depth !== 0 || !parts.length)
64
+ throw new Error('policy-anchor-log-corrupt');
65
+ break;
66
+ }
67
+ const start = this.cursor;
68
+ let end = start;
69
+ let complete = false;
70
+ // Scan the available segment directly. Avoid per-character method,
71
+ // regular-expression and string-concatenation overhead on mature logs.
72
+ for (; end < this.text.length; end++) {
73
+ if (!escaped && (quoted || compound)) {
74
+ const markers = quoted ? STRING_STRUCTURE : VALUE_STRUCTURE;
75
+ markers.lastIndex = end;
76
+ const next = markers.exec(this.text);
77
+ if (!next) {
78
+ end = this.text.length;
79
+ break;
80
+ }
81
+ end = next.index;
82
+ }
83
+ const code = this.text.charCodeAt(end);
84
+ if (!quoted && depth === 0 && (parts.length > 0 || end > start) && !compound && !string
85
+ && (code === 32 || code === 9 || code === 10 || code === 13 || code === 44 || code === 125 || code === 93)) {
86
+ complete = true;
87
+ break;
88
+ }
89
+ if (quoted) {
90
+ if (escaped)
91
+ escaped = false;
92
+ else if (code === 92)
93
+ escaped = true;
94
+ else if (code === 34) {
95
+ quoted = false;
96
+ if (string && depth === 0) {
97
+ end++;
98
+ complete = true;
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ else if (code === 34)
104
+ quoted = true;
105
+ else if (code === 123 || code === 91)
106
+ depth++;
107
+ else if (code === 125 || code === 93) {
108
+ depth--;
109
+ if (depth < 0)
110
+ throw new Error('policy-anchor-log-corrupt');
111
+ if (compound && depth === 0) {
112
+ end++;
113
+ complete = true;
114
+ break;
115
+ }
116
+ }
117
+ }
118
+ const segment = this.text.slice(start, end);
119
+ bytes += Buffer.byteLength(segment);
120
+ if (bytes > VALUE_LIMIT)
121
+ throw new Error('policy-anchor-log-record-too-large');
122
+ if (segment)
123
+ parts.push(segment);
124
+ this.cursor = end;
125
+ if (complete)
126
+ break;
127
+ }
128
+ // JSON.parse validates the complete bounded token's grammar, including
129
+ // bracket kinds, escapes, control characters and scalar spellings.
130
+ return JSON.parse(parts.join(''));
131
+ }
132
+ }
133
+ /** Supports property order/whitespace from ordinary JSON writers. Unknown
134
+ * root values remain bounded and syntax-checked; duplicate known keys fail. */
135
+ export function* anchorEntries(file) {
136
+ const reader = new JsonReader(file);
137
+ let version;
138
+ let seenVersion = false;
139
+ let seenEntries = false;
140
+ try {
141
+ reader.expect('{');
142
+ reader.whitespace();
143
+ if (reader.peek() === '}')
144
+ throw new Error('policy-anchor-log-corrupt');
145
+ for (;;) {
146
+ const key = reader.value();
147
+ if (typeof key !== 'string')
148
+ throw new Error('policy-anchor-log-corrupt');
149
+ reader.expect(':');
150
+ if (key === 'entries') {
151
+ if (seenEntries)
152
+ throw new Error('policy-anchor-log-corrupt');
153
+ seenEntries = true;
154
+ reader.expect('[');
155
+ reader.whitespace();
156
+ if (reader.peek() !== ']') {
157
+ for (;;) {
158
+ yield reader.value();
159
+ reader.whitespace();
160
+ if (reader.peek() === ']')
161
+ break;
162
+ reader.expect(',');
163
+ }
164
+ }
165
+ reader.expect(']');
166
+ }
167
+ else {
168
+ const value = reader.value();
169
+ if (key === 'version') {
170
+ if (seenVersion)
171
+ throw new Error('policy-anchor-log-corrupt');
172
+ seenVersion = true;
173
+ version = value;
174
+ }
175
+ }
176
+ reader.whitespace();
177
+ if (reader.peek() === '}')
178
+ break;
179
+ reader.expect(',');
180
+ }
181
+ reader.expect('}');
182
+ reader.whitespace();
183
+ if (reader.peek() || !seenEntries || !seenVersion || version !== 1)
184
+ throw new Error('policy-anchor-log-corrupt');
185
+ }
186
+ finally {
187
+ reader.close();
188
+ }
189
+ }
190
+ function writeText(fd, text) {
191
+ const bytes = Buffer.from(text);
192
+ let count = 0;
193
+ while (count < bytes.length) {
194
+ const next = writeSync(fd, bytes, count, bytes.length - count);
195
+ if (!next)
196
+ throw new Error('policy-anchor-log-short-write');
197
+ count += next;
198
+ }
199
+ }
200
+ /** Serialization callback runs inside the runtime's existing durable atomic
201
+ * writer. Failure removes the temporary file; no partial log is published. */
202
+ export function appendedAnchorLog(file, next, validate) {
203
+ return { [ATOMIC_JSON_WRITER](fd) {
204
+ let pending = '';
205
+ let pendingBytes = 0;
206
+ const flush = () => { if (pendingBytes)
207
+ writeText(fd, pending); pending = ''; pendingBytes = 0; };
208
+ const emit = (text) => {
209
+ const bytes = Buffer.byteLength(text);
210
+ if (pendingBytes + bytes > CHUNK_BYTES)
211
+ flush();
212
+ if (bytes >= CHUNK_BYTES)
213
+ writeText(fd, text);
214
+ else {
215
+ pending += text;
216
+ pendingBytes += bytes;
217
+ }
218
+ };
219
+ emit('{"version":1,"entries":[\n');
220
+ let count = 0;
221
+ let previous = null;
222
+ if (file) {
223
+ for (const entry of anchorEntries(file)) {
224
+ if (!validate(entry, count, previous))
225
+ throw new Error('policy-anchor-log-corrupt');
226
+ if (count)
227
+ emit(',\n');
228
+ emit(JSON.stringify(entry));
229
+ count++;
230
+ previous = entry.hash;
231
+ }
232
+ }
233
+ if (!validate(next, count, previous))
234
+ throw new Error('policy-anchor-log-corrupt');
235
+ if (count)
236
+ emit(',\n');
237
+ emit(JSON.stringify(next));
238
+ emit('\n]}\n');
239
+ flush();
240
+ } };
241
+ }
242
+ //# sourceMappingURL=policy-anchor-log.js.map
@@ -0,0 +1,7 @@
1
+ export interface ReverseRecord {
2
+ bytes: Buffer;
3
+ offset: number;
4
+ terminated: boolean;
5
+ }
6
+ export declare function reverseArchiveRecords(fd: number, size: number, limit: number): Generator<ReverseRecord>;
7
+ //# sourceMappingURL=policy-archive-scan.d.ts.map
@@ -0,0 +1,50 @@
1
+ /** Fixed-chunk reverse archive scan used by the synchronous anchor gate.
2
+ * Memory follows the largest single line, never the entire archive/window.
3
+ */
4
+ import { readSync } from 'node:fs';
5
+ const CHUNK_BYTES = 64 * 1024;
6
+ export function* reverseArchiveRecords(fd, size, limit) {
7
+ let position = size;
8
+ let parts = [];
9
+ let partBytes = 0;
10
+ let terminated = false;
11
+ while (position > 0) {
12
+ const count = Math.min(CHUNK_BYTES, position);
13
+ position -= count;
14
+ const chunk = Buffer.allocUnsafe(count);
15
+ let read = 0;
16
+ while (read < count) {
17
+ const next = readSync(fd, chunk, read, count - read, position + read);
18
+ if (!next)
19
+ throw new Error('policy-ledger-archive-changed');
20
+ read += next;
21
+ }
22
+ let end = chunk.length;
23
+ for (;;) {
24
+ const newline = chunk.lastIndexOf(10, end - 1);
25
+ if (newline < 0)
26
+ break;
27
+ const piece = chunk.subarray(newline + 1, end);
28
+ if (piece.length + partBytes > limit)
29
+ throw new Error(`policy-ledger-archive-record-too-large:${limit}`);
30
+ const bytes = parts.length ? Buffer.concat([piece, ...parts], piece.length + partBytes) : Buffer.from(piece);
31
+ yield { bytes, offset: position + newline + 1, terminated };
32
+ terminated = true;
33
+ parts = [];
34
+ partBytes = 0;
35
+ end = newline;
36
+ if (end === 0)
37
+ break;
38
+ }
39
+ if (end > 0) {
40
+ if (partBytes + end > limit)
41
+ throw new Error(`policy-ledger-archive-record-too-large:${limit}`);
42
+ const piece = Buffer.from(chunk.subarray(0, end));
43
+ parts.unshift(piece);
44
+ partBytes += piece.length;
45
+ }
46
+ }
47
+ if (partBytes > 0)
48
+ yield { bytes: Buffer.concat(parts, partBytes), offset: 0, terminated };
49
+ }
50
+ //# sourceMappingURL=policy-archive-scan.js.map
@@ -1,4 +1,5 @@
1
- import type { PolicyState } from '@claude-flow/security';
1
+ import { type AtomicJsonSource } from './policy-anchor-log.js';
2
+ import { type PolicyState } from '@claude-flow/security/policy/index';
2
3
  export type AnchorEvent = 'append' | 'migrated-from-state' | 'establish-anchor';
3
4
  export interface AnchorEntry {
4
5
  seq: number;
@@ -8,6 +9,15 @@ export interface AnchorEntry {
8
9
  ts: number;
9
10
  event: AnchorEvent;
10
11
  by?: string;
12
+ /**
13
+ * How much of the archive this anchor claims (`state.retainedFrom` at
14
+ * anchor time) and the hash of its newest archived receipt (#3892 Blocker
15
+ * 1). Absent on anchors written before this field existed, or for a
16
+ * ledger that has never been pruned — both resolve to a vacuous pass so
17
+ * the unpruned baseline stays byte-for-byte identical (see `entryHash`).
18
+ */
19
+ archivedThrough?: number;
20
+ archiveHeadHash?: string | null;
11
21
  hash: string;
12
22
  }
13
23
  export type AnchorAssessment = {
@@ -21,6 +31,7 @@ export type AnchorAssessment = {
21
31
  error: string;
22
32
  };
23
33
  export type AnchorWriter = (file: string, value: unknown) => Promise<void>;
34
+ export type StreamingAnchorWriter = (file: string, value: AtomicJsonSource) => Promise<void>;
24
35
  export declare const anchorLogPath: (projectRoot: string) => string;
25
36
  /**
26
37
  * Directory holding per-project trust material (anchor mirror, HMAC key).
@@ -30,19 +41,14 @@ export declare const anchorLogPath: (projectRoot: string) => string;
30
41
  * user who already has trust state under the legacy ~/.config keeps using it.
31
42
  */
32
43
  export declare function policyTrustRoot(): string;
33
- /**
34
- * How the stored anchors relate to `state`; read-only. `rebuild` is the
35
- * explicit-establish path: an unreadable log or mirror is treated as absent, but
36
- * whatever readable anchor remains must still agree with the chain, so it can
37
- * never bless a truncation the anchors still remember.
38
- */
44
+ /** Convert archive record-limit/UTF8 failures into structured gate failures. */
39
45
  export declare function assessAnchors(projectRoot: string, state: PolicyState, rebuild?: boolean): AnchorAssessment;
40
46
  /**
41
47
  * Append an entry for the current state if the newest entry does not already
42
48
  * describe it. Must run under the policy lock. Throws if the log is corrupt:
43
49
  * only an explicit establish may replace a corrupt log.
44
50
  */
45
- export declare function recordAnchor(projectRoot: string, state: PolicyState, write: AnchorWriter, event?: AnchorEvent, by?: string): Promise<void>;
51
+ export declare function recordAnchor(projectRoot: string, state: PolicyState, write: AnchorWriter, event?: AnchorEvent, by?: string, writeLog?: StreamingAnchorWriter, assessedTip?: AnchorEntry): Promise<void>;
46
52
  export declare function anchorPosture(projectRoot: string): {
47
53
  log: boolean;
48
54
  mirror: boolean;