claude-flow 3.77.1 → 3.77.2
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/.claude/helpers/hook-handler.cjs +85 -5
- package/README.md +12 -2
- package/node_modules/@claude-flow/plugin-agent-federation/README.md +18 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.d.ts +4 -1
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.d.ts.map +1 -1
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.js +11 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.js.map +1 -1
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.d.ts +29 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.d.ts.map +1 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.js +96 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.js.map +1 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.d.ts.map +1 -1
- package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.js +3 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.js.map +1 -1
- package/package.json +8 -5
- package/v3/@claude-flow/cli/README.md +5 -0
- package/v3/@claude-flow/cli/bin/cli.js +8 -3
- package/v3/@claude-flow/cli/dist/src/commands/init.js +8 -1
- package/v3/@claude-flow/cli/dist/src/commands/session.js +2 -1
- package/v3/@claude-flow/cli/dist/src/commands/workflow.js +2 -1
- package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +85 -5
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-execute-core.js +26 -25
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +161 -157
- package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +257 -258
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +48 -29
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +6 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/locked-json-store.d.ts +20 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/locked-json-store.js +99 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/managed-agent-tools.js +51 -7
- package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.js +19 -9
- package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.js +299 -270
- package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.js +245 -215
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +5 -4
- package/v3/@claude-flow/cli/dist/src/missions/schemas.d.ts +38 -38
- package/v3/@claude-flow/cli/dist/src/mods/command-registry/schema.d.ts +210 -210
- package/v3/@claude-flow/cli/dist/src/services/managed-run-store.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-run-store.js +125 -3
- package/v3/@claude-flow/cli/dist/src/services/policy-runtime.d.ts +3 -0
- package/v3/@claude-flow/cli/dist/src/services/policy-runtime.js +3 -1
- package/v3/@claude-flow/cli/package.json +9 -6
- package/v3/@claude-flow/guidance/package.json +1 -0
- package/.claude/.proven-config-version +0 -1
- package/.claude/proven-config.json +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-flow",
|
|
3
|
-
"version": "3.77.
|
|
3
|
+
"version": "3.77.2",
|
|
4
4
|
"workspaces": [
|
|
5
5
|
"v3/@claude-flow/codex",
|
|
6
6
|
"v3/@claude-flow/mcp",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"bin": {
|
|
14
14
|
"claude-flow": "bin/cli.js"
|
|
15
15
|
},
|
|
16
|
-
"homepage": "https://
|
|
16
|
+
"homepage": "https://ruv.io",
|
|
17
17
|
"bugs": {
|
|
18
|
-
"url": "https://github.com/ruvnet/
|
|
18
|
+
"url": "https://github.com/ruvnet/ruflo/issues",
|
|
19
19
|
"email": "support@ruv.io"
|
|
20
20
|
},
|
|
21
21
|
"funding": {
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
},
|
|
176
176
|
"repository": {
|
|
177
177
|
"type": "git",
|
|
178
|
-
"url": "git+https://github.com/ruvnet/
|
|
178
|
+
"url": "git+https://github.com/ruvnet/ruflo.git"
|
|
179
179
|
},
|
|
180
180
|
"keywords": [
|
|
181
181
|
"ruvflow",
|
|
@@ -210,7 +210,10 @@
|
|
|
210
210
|
"hive-mind",
|
|
211
211
|
"distributed-systems",
|
|
212
212
|
"consensus",
|
|
213
|
-
"self-learning"
|
|
213
|
+
"self-learning",
|
|
214
|
+
"local-vector-search",
|
|
215
|
+
"rvf",
|
|
216
|
+
"mcp-server"
|
|
214
217
|
],
|
|
215
218
|
"author": "RuvNet <ruv@ruv.io> (https://ruv.io)",
|
|
216
219
|
"license": "MIT",
|
|
@@ -52,6 +52,11 @@ User --> Ruflo (CLI/MCP) --> Router --> Swarm --> Agents --> Memory --> LLM Prov
|
|
|
52
52
|
|
|
53
53
|
## Quick Start
|
|
54
54
|
|
|
55
|
+
|
|
56
|
+
<a href="https://github.com/ruvnet/ruflo/blob/main/docs/recipes/rvf-mcp-search.md"><img src="https://raw.githubusercontent.com/ruvnet/ruflo/main/docs/assets/readme/rvf-mcp-search.svg" width="720" alt="Search a portable RVF index locally through stdio MCP"></a>
|
|
57
|
+
|
|
58
|
+
[Optional recipe: local vector search with RVF and MCP](https://github.com/ruvnet/ruflo/blob/main/docs/recipes/rvf-mcp-search.md) · [Ruvnet ecosystem](https://ruv.io)
|
|
59
|
+
|
|
55
60
|
There are **two different install paths** with very different surface areas. Pick based on what you need (#1744):
|
|
56
61
|
|
|
57
62
|
| | **Claude Code Plugin** | **CLI install (`npx ruflo init`)** |
|
|
@@ -377,9 +377,14 @@ if (isHarness) {
|
|
|
377
377
|
try {
|
|
378
378
|
const { shutdownBridge } = await import('../dist/src/memory/memory-bridge.js');
|
|
379
379
|
if (typeof shutdownBridge === 'function') await shutdownBridge();
|
|
380
|
-
} catch {
|
|
381
|
-
// Cleanup is best-effort
|
|
382
|
-
//
|
|
380
|
+
} catch (error) {
|
|
381
|
+
// Cleanup is best-effort for everything except a failed persist: when
|
|
382
|
+
// the sql.js save is refused (#4733), the command's writes never reached
|
|
383
|
+
// disk, so it must not exit 0. Other teardown errors stay silent.
|
|
384
|
+
if (error?.code === 'AGENTDB_LOCK_UNRECOVERABLE') {
|
|
385
|
+
console.error(`Error: ${error.message}`);
|
|
386
|
+
process.exitCode = 1;
|
|
387
|
+
}
|
|
383
388
|
}
|
|
384
389
|
})
|
|
385
390
|
.catch((error) => {
|
|
@@ -1045,6 +1045,13 @@ const initAction = async (ctx) => {
|
|
|
1045
1045
|
dryRun: ctx.flags.dryRun === true || ctx.flags['dry-run'] === true,
|
|
1046
1046
|
});
|
|
1047
1047
|
}
|
|
1048
|
+
// #4994 — only the Grok path implements a preview. For every other mode
|
|
1049
|
+
// --dry-run used to be silently ignored and a real init ran (project scaffold,
|
|
1050
|
+
// $HOME/.codex, mods enable). Refuse to write anything instead.
|
|
1051
|
+
if (ctx.flags.dryRun === true || ctx.flags['dry-run'] === true) {
|
|
1052
|
+
output.printWarning('--dry-run: nothing was written. A file preview is only available with --grok; remove --dry-run to run init.');
|
|
1053
|
+
return { success: true, data: { dryRun: true, written: [] } };
|
|
1054
|
+
}
|
|
1048
1055
|
if (codexMode && !dualMode) {
|
|
1049
1056
|
return initCodexAction(ctx, { codexMode, dualMode: false, force, minimal, full });
|
|
1050
1057
|
}
|
|
@@ -1860,7 +1867,7 @@ export const initCommand = {
|
|
|
1860
1867
|
},
|
|
1861
1868
|
{
|
|
1862
1869
|
name: 'dry-run',
|
|
1863
|
-
description: '
|
|
1870
|
+
description: 'List the files init would write (--grok); for other modes write nothing and exit',
|
|
1864
1871
|
type: 'boolean',
|
|
1865
1872
|
default: false,
|
|
1866
1873
|
},
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { output } from '../output.js';
|
|
6
6
|
import { confirm, input, select } from '../prompt.js';
|
|
7
7
|
import { callMCPTool, MCPClientError } from '../mcp-client.js';
|
|
8
|
+
import { localCliContext } from '../mcp-tools/path-containment.js';
|
|
8
9
|
import * as fs from 'fs';
|
|
9
10
|
import * as path from 'path';
|
|
10
11
|
import { stringify as stringifyYaml } from 'yaml';
|
|
@@ -672,7 +673,7 @@ const importCommand = {
|
|
|
672
673
|
inputPath: absolutePath,
|
|
673
674
|
name: sessionName,
|
|
674
675
|
activate
|
|
675
|
-
});
|
|
676
|
+
}, localCliContext());
|
|
676
677
|
const failure = toolError(result);
|
|
677
678
|
if (failure) {
|
|
678
679
|
spinner.fail('Failed to import session');
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { output } from '../output.js';
|
|
6
6
|
import { select, confirm } from '../prompt.js';
|
|
7
7
|
import { callMCPTool, MCPClientError } from '../mcp-client.js';
|
|
8
|
+
import { localCliContext } from '../mcp-tools/path-containment.js';
|
|
8
9
|
// Workflow templates
|
|
9
10
|
const WORKFLOW_TEMPLATES = [
|
|
10
11
|
{ value: 'development', label: 'Development', hint: 'Standard development workflow' },
|
|
@@ -203,7 +204,7 @@ const validateCommand = {
|
|
|
203
204
|
const result = await callMCPTool('workflow_validate', {
|
|
204
205
|
file,
|
|
205
206
|
strict,
|
|
206
|
-
});
|
|
207
|
+
}, localCliContext());
|
|
207
208
|
if (ctx.flags.format === 'json') {
|
|
208
209
|
output.printJson(result);
|
|
209
210
|
return { success: result.valid, data: result };
|
|
@@ -478,7 +478,8 @@ module.exports = commands;
|
|
|
478
478
|
}
|
|
479
479
|
// Literal-word root guard mirrored in the mod and both shipped classic helpers.
|
|
480
480
|
const ROOT_DELETE_CHECK_SOURCE = String.raw `function hasRootDelete(command, depth = 0) {
|
|
481
|
-
// mask has one letter per character of word: 'u' unquoted, 'q' quoted or escaped
|
|
481
|
+
// mask has one letter per character of word: 'u' unquoted, 'd' double-quoted, 'q' otherwise quoted or escaped
|
|
482
|
+
// (only unquoted braces expand; a parameter's default expands unquoted or double-quoted).
|
|
482
483
|
let word = '', mask = '', quote = '', started = false, redirect = false
|
|
483
484
|
let ansiNul = false // a NUL inside $'...' ends that string, as in bash
|
|
484
485
|
let inRm = false, optionsEnded = false, recursive = false, force = false, root = false
|
|
@@ -511,9 +512,11 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw `function hasRootDelete(command, dep
|
|
|
511
512
|
}
|
|
512
513
|
// Past the rescan bound (or the brace budget), a string is judged by its tokens: an rm and a possible root operand
|
|
513
514
|
// anywhere in it deny. Quote characters are dropped first, so r"m" is still rm; a path token with braces may expand to /.
|
|
515
|
+
const looseTokens = (text) => text.replace(/["'\\]/g, '').split(/[\s;&|()\x60$]+/)
|
|
516
|
+
const isRm = (t) => t === 'rm' || t.endsWith('/rm')
|
|
514
517
|
const looseRootDelete = (text) => {
|
|
515
|
-
const tokens = text
|
|
516
|
-
return tokens.some(
|
|
518
|
+
const tokens = looseTokens(text)
|
|
519
|
+
return tokens.some(isRm) && tokens.some(t => isRoot(t) || (t.includes('/') && /[{}]/.test(t)))
|
|
517
520
|
}
|
|
518
521
|
// Bash brace expansion of one word ({a,b} lists, nested or glued to text), and nothing else: no {1..3} sequences, and
|
|
519
522
|
// nothing inside parameter braces after a dollar sign. Only unquoted braces and commas count. Iterative and bounded:
|
|
@@ -574,10 +577,42 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw `function hasRootDelete(command, dep
|
|
|
574
577
|
} else root = root || isRoot(w)
|
|
575
578
|
return inRm && recursive && force && root
|
|
576
579
|
}
|
|
580
|
+
// The word as the shell reads it with its parameters unset: a default (dollar-brace X:-word, X-word, X:=word or
|
|
581
|
+
// X=word) becomes its word, taken literally, and an alternate (X:+word, X+word) becomes nothing. Undefined when the
|
|
582
|
+
// word has neither. Linear: nested parameters are frames on a stack, not recursion.
|
|
583
|
+
const unsetDefaults = (text, marks) => {
|
|
584
|
+
if (!text.includes('$' + '{')) return undefined
|
|
585
|
+
const frames = [{ out: '', outMarks: '', op: '', nest: 0 }]
|
|
586
|
+
const param = /!?(?:[a-z_][a-z0-9_]*(?:\[[^\]]*\])?|[0-9]+|[@*#?$!-]):?([-=+])/y
|
|
587
|
+
let found = false
|
|
588
|
+
for (let k = 0; k < text.length; k++) {
|
|
589
|
+
const top = frames[frames.length - 1], c = text[k], live = marks[k] !== 'q'
|
|
590
|
+
if (live && c === '$' && text[k + 1] === '{' && marks[k + 1] !== 'q') {
|
|
591
|
+
param.lastIndex = k + 2
|
|
592
|
+
const m = param.exec(text)
|
|
593
|
+
if (m) { frames.push({ out: '', outMarks: '', op: m[1], nest: 0 }); k = param.lastIndex - 1; found = true; continue }
|
|
594
|
+
}
|
|
595
|
+
if (live && c === '}' && frames.length > 1 && top.nest === 0) {
|
|
596
|
+
frames.pop()
|
|
597
|
+
const parent = frames[frames.length - 1]
|
|
598
|
+
if (top.op !== '+') { parent.out += top.out; parent.outMarks += 'q'.repeat(top.out.length) }
|
|
599
|
+
continue
|
|
600
|
+
}
|
|
601
|
+
if (live && c === '{') top.nest++
|
|
602
|
+
else if (live && c === '}' && top.nest > 0) top.nest--
|
|
603
|
+
top.out += c; top.outMarks += marks[k]
|
|
604
|
+
}
|
|
605
|
+
return found && frames.length === 1 ? [frames[0].out, frames[0].outMarks] : undefined
|
|
606
|
+
}
|
|
577
607
|
const finishWord = () => {
|
|
578
608
|
if (!started) return false
|
|
579
609
|
const text = word, marks = mask
|
|
580
610
|
word = ''; mask = ''; started = false
|
|
611
|
+
// A default is a word the shell may use instead: rm -rf with a default of / deletes the root when it is unset.
|
|
612
|
+
const unset = unsetDefaults(text, marks)
|
|
613
|
+
return judgeWord(text, marks) || (unset !== undefined && judgeWord(unset[0], unset[1]))
|
|
614
|
+
}
|
|
615
|
+
const judgeWord = (text, marks) => {
|
|
581
616
|
// Literal shell strings (e.g. sh -c 'rm -rf /', or sh -c '{rm,-rf,/}') also carried the old guard.
|
|
582
617
|
// Bound rescanning to four levels; beyond that judge the string by its tokens.
|
|
583
618
|
if (/[\s;&|()\x60{]/.test(text)) {
|
|
@@ -610,6 +645,38 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw `function hasRootDelete(command, dep
|
|
|
610
645
|
}
|
|
611
646
|
return [j, depth < 4 ? hasRootDelete(body, depth + 1) : looseRootDelete(body)]
|
|
612
647
|
}
|
|
648
|
+
// The index of the parenthesis closing the one at open, past quoted and ANSI-C quoted text, escapes, comments and
|
|
649
|
+
// backtick substitutions, or -1. After one never closes none is looked for again in this scan (the shell rejects the
|
|
650
|
+
// command), so the scan stays linear and the rest is read as before, with ( and ) as separators, but a command
|
|
651
|
+
// with an rm in it is refused. A case pattern's ) is still read as the close.
|
|
652
|
+
let unclosedParen = false
|
|
653
|
+
const closeParen = (open) => {
|
|
654
|
+
if (unclosedParen) return -1
|
|
655
|
+
let level = 0
|
|
656
|
+
for (let j = open; j < command.length; j++) {
|
|
657
|
+
const c = command[j]
|
|
658
|
+
if (c === '\\') j++
|
|
659
|
+
else if (c === '$' && command[j + 1] === "'") {
|
|
660
|
+
for (j += 2; j < command.length && command[j] !== "'"; j++) if (command[j] === '\\') j++
|
|
661
|
+
} else if (c === '#' && /[\s;&|()<>]/.test(command[j - 1])) {
|
|
662
|
+
while (j + 1 < command.length && command[j + 1] !== '\n') j++
|
|
663
|
+
} else if (c === "'" || c === '"' || c === '\x60') {
|
|
664
|
+
for (j++; j < command.length && command[j] !== c; j++) if (c !== "'" && command[j] === '\\') j++
|
|
665
|
+
} else if (c === '(') level++
|
|
666
|
+
else if (c === ')' && --level === 0) return j
|
|
667
|
+
}
|
|
668
|
+
unclosedParen = true
|
|
669
|
+
return -1
|
|
670
|
+
}
|
|
671
|
+
// A $(...) substitution from its dollar sign: the body is scanned as written and its output taken as empty, as a
|
|
672
|
+
// backtick one's is. $((...)) is arithmetic, a number: its body is still scanned (it may hold a substitution) and
|
|
673
|
+
// a digit stands in the word for it. Returns the closing parenthesis, whether the body deletes the root, and the
|
|
674
|
+
// text the word keeps.
|
|
675
|
+
const parenSubstitution = (at) => {
|
|
676
|
+
const end = closeParen(at + 1)
|
|
677
|
+
const body = command.slice(at + 2, end)
|
|
678
|
+
return [end, depth < 4 ? hasRootDelete(body, depth + 1) : looseRootDelete(body), command[at + 2] === '(' ? '0' : '']
|
|
679
|
+
}
|
|
613
680
|
const finishCommand = () => {
|
|
614
681
|
const denied = inRm && recursive && force && root
|
|
615
682
|
inRm = optionsEnded = recursive = force = root = false
|
|
@@ -639,12 +706,19 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw `function hasRootDelete(command, dep
|
|
|
639
706
|
if (command[end + 1] === '#') { word += '\u0001'; mask += 'q' }
|
|
640
707
|
i = end
|
|
641
708
|
}
|
|
709
|
+
else if (quote === '"' && char === '$' && command[i + 1] === '(' && closeParen(i + 1) > i) {
|
|
710
|
+
const [end, denied, kept] = parenSubstitution(i)
|
|
711
|
+
if (denied) return true
|
|
712
|
+
word += kept; mask += 'q'.repeat(kept.length)
|
|
713
|
+
if (command[end + 1] === '#') { word += '\u0001'; mask += 'q' }
|
|
714
|
+
i = end
|
|
715
|
+
}
|
|
642
716
|
else if (quote === '"' && char === '\\' && i + 1 < command.length &&
|
|
643
717
|
(command[i + 1] === '"' || command[i + 1] === '\\' || command[i + 1] === '$' ||
|
|
644
718
|
command.charCodeAt(i + 1) === 96 || command[i + 1] === '\n')) {
|
|
645
719
|
const next = command[++i]
|
|
646
720
|
if (next !== '\n') { word += next; mask += 'q' }
|
|
647
|
-
} else { word += char; mask += 'q' }
|
|
721
|
+
} else { word += char; mask += quote === '"' ? 'd' : 'q' }
|
|
648
722
|
continue
|
|
649
723
|
}
|
|
650
724
|
if (char === '\\' && i + 1 < command.length) {
|
|
@@ -657,6 +731,12 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw `function hasRootDelete(command, dep
|
|
|
657
731
|
const [end, denied] = substitution(i + 1, false)
|
|
658
732
|
if (denied) return true
|
|
659
733
|
i = end; started = true
|
|
734
|
+
} else if (char === '$' && command[i + 1] === '(' && closeParen(i + 1) > i) {
|
|
735
|
+
// $(...) is a command substitution too, and the rm being parsed keeps its state across it.
|
|
736
|
+
const [end, denied, kept] = parenSubstitution(i)
|
|
737
|
+
if (denied) return true
|
|
738
|
+
word += kept; mask += 'q'.repeat(kept.length)
|
|
739
|
+
i = end; started = true
|
|
660
740
|
} else if (char === '$' && (command[i + 1] === "'" || command[i + 1] === '"')) {
|
|
661
741
|
// ANSI-C ($'...': escapes decoded) and locale ($"...") quoting: the $ is not part of the word.
|
|
662
742
|
quote = command[i + 1] === "'" ? "$'" : '"'; started = true; i++
|
|
@@ -675,7 +755,7 @@ const ROOT_DELETE_CHECK_SOURCE = String.raw `function hasRootDelete(command, dep
|
|
|
675
755
|
word += char; mask += 'u'; started = true
|
|
676
756
|
}
|
|
677
757
|
}
|
|
678
|
-
return finishWord() || finishCommand()
|
|
758
|
+
return finishWord() || finishCommand() || (unclosedParen && looseTokens(command).some(isRm))
|
|
679
759
|
}
|
|
680
760
|
|
|
681
761
|
// A fork bomb's definition as bash reads it, whatever the spacing or the name: f(){ f|f& }, function f { f|f& },
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* keeps the wire from agent_spawn → ProviderManager (real) in one
|
|
8
8
|
* place rather than duplicated.
|
|
9
9
|
*/
|
|
10
|
-
import { existsSync,
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
import { getProjectCwd } from './types.js';
|
|
13
|
+
import { saved, unchanged, updateJsonStore } from './locked-json-store.js';
|
|
13
14
|
import { appendAgentExecution, summarizeAgentExecutions } from './agent-health-metrics.js';
|
|
14
15
|
import { configManager } from '../services/config-file-manager.js';
|
|
15
16
|
const STORAGE_DIR = '.claude-flow';
|
|
@@ -17,11 +18,6 @@ const AGENT_DIR = 'agents';
|
|
|
17
18
|
const AGENT_FILE = 'store.json';
|
|
18
19
|
function getAgentDir() { return join(getProjectCwd(), STORAGE_DIR, AGENT_DIR); }
|
|
19
20
|
function getAgentPath() { return join(getAgentDir(), AGENT_FILE); }
|
|
20
|
-
function ensureAgentDir() {
|
|
21
|
-
const dir = getAgentDir();
|
|
22
|
-
if (!existsSync(dir))
|
|
23
|
-
mkdirSync(dir, { recursive: true });
|
|
24
|
-
}
|
|
25
21
|
function loadAgentStore() {
|
|
26
22
|
try {
|
|
27
23
|
if (existsSync(getAgentPath()))
|
|
@@ -30,9 +26,9 @@ function loadAgentStore() {
|
|
|
30
26
|
catch { /* fall through */ }
|
|
31
27
|
return { agents: {}, version: '3.0.0' };
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
/** Same file and lock as agent-tools.ts's agent writes. */
|
|
30
|
+
function updateAgentStore(mutate) {
|
|
31
|
+
return updateJsonStore(getAgentPath(), loadAgentStore, mutate, 'agents');
|
|
36
32
|
}
|
|
37
33
|
// #1906/#2232 — Current model ids (Claude 4.x family):
|
|
38
34
|
// Opus 4.8 → claude-opus-4-8 (current, the `opus` alias)
|
|
@@ -490,12 +486,21 @@ export function resolveAnthropicModel(input) {
|
|
|
490
486
|
// Tracks overlapping calls in this process; persisted state remains authoritative.
|
|
491
487
|
const activeExecutions = new Map();
|
|
492
488
|
export async function executeAgentTask(input) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
489
|
+
// Check the agent and mark it busy in one locked step; the provider call
|
|
490
|
+
// below runs without the lock.
|
|
491
|
+
const claimed = await updateAgentStore((store) => {
|
|
492
|
+
const found = store.agents[input.agentId];
|
|
493
|
+
if (!found)
|
|
494
|
+
return unchanged('Agent not found');
|
|
495
|
+
if (found.status === 'terminated')
|
|
496
|
+
return unchanged('Agent has been terminated');
|
|
497
|
+
found.status = 'busy';
|
|
498
|
+
found.taskCount = (found.taskCount || 0) + 1;
|
|
499
|
+
return saved(found);
|
|
500
|
+
});
|
|
501
|
+
if (typeof claimed === 'string')
|
|
502
|
+
return { success: false, agentId: input.agentId, error: claimed };
|
|
503
|
+
const agent = claimed;
|
|
499
504
|
// ADR-149 iter 13 — first-call dispatch prefers `agent.modelId` (the
|
|
500
505
|
// cost-optimal pick from the neural backend) over `MODEL_MAP[agent.model]`
|
|
501
506
|
// when present. Before this fix the first attempt always used the tier
|
|
@@ -538,9 +543,6 @@ export async function executeAgentTask(input) {
|
|
|
538
543
|
`Respond directly and stay focused on the task. If you need information you don't have, state that explicitly.`;
|
|
539
544
|
const initialModelId = agent.modelId;
|
|
540
545
|
const initialModel = agent.model;
|
|
541
|
-
agent.status = 'busy';
|
|
542
|
-
agent.taskCount = (agent.taskCount || 0) + 1;
|
|
543
|
-
saveAgentStore(store);
|
|
544
546
|
const executionKey = JSON.stringify([getAgentPath(), input.agentId, agent.createdAt]);
|
|
545
547
|
activeExecutions.set(executionKey, (activeExecutions.get(executionKey) || 0) + 1);
|
|
546
548
|
try {
|
|
@@ -707,13 +709,12 @@ export async function executeAgentTask(input) {
|
|
|
707
709
|
// Silent — bandit feedback must never block routing.
|
|
708
710
|
}
|
|
709
711
|
const remaining = (activeExecutions.get(executionKey) || 1) - 1;
|
|
710
|
-
const persistCompletion = (out) => {
|
|
712
|
+
const persistCompletion = (out) => updateAgentStore((latest) => {
|
|
711
713
|
// Awaited provider/feedback work may have overlapped registration, updates,
|
|
712
714
|
// termination or deletion. Never replace that newer registry snapshot.
|
|
713
|
-
const latest = loadAgentStore();
|
|
714
715
|
const current = latest.agents[input.agentId];
|
|
715
716
|
if (!current || current.createdAt !== agent.createdAt)
|
|
716
|
-
return;
|
|
717
|
+
return unchanged(undefined);
|
|
717
718
|
if (current.status === 'busy')
|
|
718
719
|
current.status = remaining > 0 ? 'busy' : 'idle';
|
|
719
720
|
if (agent.modelId !== initialModelId && current.modelId === initialModelId) {
|
|
@@ -739,8 +740,8 @@ export async function executeAgentTask(input) {
|
|
|
739
740
|
if (mayUpdateStoredHealth) {
|
|
740
741
|
current.health = summarizeAgentExecutions(current.executionHistory).health ?? current.health;
|
|
741
742
|
}
|
|
742
|
-
|
|
743
|
-
};
|
|
743
|
+
return saved(undefined);
|
|
744
|
+
});
|
|
744
745
|
if (result.success) {
|
|
745
746
|
const out = {
|
|
746
747
|
success: true,
|
|
@@ -753,10 +754,10 @@ export async function executeAgentTask(input) {
|
|
|
753
754
|
durationMs: result.durationMs ?? Date.now() - startedAt,
|
|
754
755
|
...(fallbackHistory.length > 0 ? { fallbackHistory } : {}),
|
|
755
756
|
};
|
|
756
|
-
persistCompletion(out);
|
|
757
|
+
await persistCompletion(out);
|
|
757
758
|
return out;
|
|
758
759
|
}
|
|
759
|
-
persistCompletion();
|
|
760
|
+
await persistCompletion();
|
|
760
761
|
// No-provider-configured error → surface the same actionable message
|
|
761
762
|
// the router built, with a #2042-aware remediation pointer.
|
|
762
763
|
const noProvider = (result.error || '').includes('No LLM provider configured');
|