claude-flow 3.71.1 → 3.71.3
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/.proven-config-version +1 -0
- package/.claude/helpers/auto-memory-hook.mjs +209 -55
- package/.claude/proven-config.json +42 -0
- package/.claude/security-scans/scan-all-quick.json +201 -0
- package/.claude/settings.json +2 -1
- package/README.md +2 -0
- package/package.json +1 -1
- package/v3/@claude-flow/cli/README.md +2 -0
- package/v3/@claude-flow/cli/catalog-manifest.json +2 -2
- package/v3/@claude-flow/cli/dist/src/commands/daemon.js +20 -1
- package/v3/@claude-flow/cli/dist/src/commands/embeddings.js +6 -6
- package/v3/@claude-flow/cli/dist/src/commands/hive-mind-worker.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/hive-mind-worker.js +20 -0
- package/v3/@claude-flow/cli/dist/src/commands/hive-mind.js +27 -4
- package/v3/@claude-flow/cli/dist/src/commands/init.js +4 -0
- package/v3/@claude-flow/cli/dist/src/commands/session.js +10 -7
- package/v3/@claude-flow/cli/dist/src/init/executor.js +15 -5
- package/v3/@claude-flow/cli/dist/src/init/settings-generator.js +4 -0
- package/v3/@claude-flow/cli/dist/src/init/types.d.ts +2 -0
- package/v3/@claude-flow/cli/dist/src/init/types.js +4 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +3 -3
- package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +23 -10
- package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.js +22 -2
- package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +2 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +11 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.js +42 -4
- package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.js +11 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/terminal-tools.js +5 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.js +22 -3
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +29 -5
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +32 -10
- package/v3/@claude-flow/cli/dist/src/missions/schemas.d.ts +124 -124
- package/v3/@claude-flow/cli/dist/src/mods/command-registry/schema.d.ts +189 -189
- package/v3/@claude-flow/cli/dist/src/mods/headless-plugins.d.ts +16 -0
- package/v3/@claude-flow/cli/dist/src/mods/headless-plugins.js +30 -1
- package/v3/@claude-flow/cli/dist/src/services/claims-store.js +5 -2
- package/v3/@claude-flow/cli/dist/src/services/daemon-autostart.d.ts +24 -0
- package/v3/@claude-flow/cli/dist/src/services/daemon-autostart.js +55 -1
- package/v3/@claude-flow/cli/dist/src/services/headless-worker-executor.d.ts +15 -0
- package/v3/@claude-flow/cli/dist/src/services/headless-worker-executor.js +28 -0
- package/v3/@claude-flow/cli/package.json +1 -1
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Tool definitions for session management with file persistence.
|
|
5
5
|
*/
|
|
6
|
-
import { existsSync, readFileSync, readdirSync, unlinkSync, statSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync, unlinkSync, statSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { randomUUID } from 'node:crypto';
|
|
8
8
|
import { gunzipSync } from 'node:zlib';
|
|
9
|
-
import { join } from 'node:path';
|
|
9
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
10
10
|
import { getProjectCwd } from './types.js';
|
|
11
11
|
import { mkdirRestricted, readFileMaybeEncrypted, writeFileRestricted, } from '../fs-secure.js';
|
|
12
12
|
import { validateIdentifier, validateText } from './validate-input.js';
|
|
@@ -351,6 +351,41 @@ function isSessionRecordLike(value) {
|
|
|
351
351
|
const v = value;
|
|
352
352
|
return 'data' in v || 'stats' in v || 'sessionId' in v || 'savedAt' in v;
|
|
353
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* SECURITY: `outputPath` comes from MCP tool input. Resolve it against the
|
|
356
|
+
* project root and require the real (symlink-resolved) parent directory to stay
|
|
357
|
+
* inside the real project root, and refuse an existing symlink as the target,
|
|
358
|
+
* so session_export cannot write files elsewhere on the host. The CLI's
|
|
359
|
+
* `session export` writes its own file and does not pass outputPath.
|
|
360
|
+
*/
|
|
361
|
+
function containedExportPath(outputPath) {
|
|
362
|
+
if (!outputPath || outputPath.includes('\0'))
|
|
363
|
+
return null;
|
|
364
|
+
try {
|
|
365
|
+
const root = realpathSync(getProjectCwd());
|
|
366
|
+
const abs = resolve(root, outputPath);
|
|
367
|
+
const parent = realpathSync(dirname(abs));
|
|
368
|
+
const target = join(parent, basename(abs));
|
|
369
|
+
const rel = relative(root, target);
|
|
370
|
+
if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel))
|
|
371
|
+
return null;
|
|
372
|
+
const existing = lstatOrNull(target);
|
|
373
|
+
if (existing && (existing.isSymbolicLink() || !existing.isFile()))
|
|
374
|
+
return null;
|
|
375
|
+
return target;
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function lstatOrNull(p) {
|
|
382
|
+
try {
|
|
383
|
+
return lstatSync(p);
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
354
389
|
export const sessionTools = [
|
|
355
390
|
{
|
|
356
391
|
name: 'session_save',
|
|
@@ -705,9 +740,12 @@ export const sessionTools = [
|
|
|
705
740
|
let path = null;
|
|
706
741
|
const outputPath = input.outputPath ? String(input.outputPath) : null;
|
|
707
742
|
if (outputPath) {
|
|
743
|
+
const target = containedExportPath(outputPath);
|
|
744
|
+
if (!target)
|
|
745
|
+
return { sessionId, error: 'outputPath must be a file inside the project directory (no symlinks)' };
|
|
708
746
|
try {
|
|
709
|
-
writeFileSync(
|
|
710
|
-
path =
|
|
747
|
+
writeFileSync(target, JSON.stringify(session, null, 2), 'utf-8');
|
|
748
|
+
path = target;
|
|
711
749
|
}
|
|
712
750
|
catch (e) {
|
|
713
751
|
return { sessionId, error: `Could not write ${outputPath}: ${e.message}` };
|
|
@@ -117,6 +117,10 @@ export const taskTools = [
|
|
|
117
117
|
const vDesc = validateText(input.description, 'description');
|
|
118
118
|
if (!vDesc.valid)
|
|
119
119
|
return { success: false, error: vDesc.error };
|
|
120
|
+
if (input.assignTo !== undefined && (!Array.isArray(input.assignTo)
|
|
121
|
+
|| !input.assignTo.every(id => validateIdentifier(id, 'assignTo').valid))) {
|
|
122
|
+
return { success: false, error: 'assignTo must be an array of agent ids' };
|
|
123
|
+
}
|
|
120
124
|
const store = loadTaskStore();
|
|
121
125
|
const taskId = `task-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
122
126
|
const task = {
|
|
@@ -134,6 +138,13 @@ export const taskTools = [
|
|
|
134
138
|
};
|
|
135
139
|
store.tasks[taskId] = task;
|
|
136
140
|
saveTaskStore(store);
|
|
141
|
+
// Assigning at creation must mark the workers busy, as task_assign and task_update do;
|
|
142
|
+
// otherwise they read idle while holding the task, and task_complete or task_cancel,
|
|
143
|
+
// which only release a worker whose currentTask is this task, never free them either.
|
|
144
|
+
updateAgents(task.assignedTo, (agent) => {
|
|
145
|
+
agent.status = 'busy';
|
|
146
|
+
agent.currentTask = taskId;
|
|
147
|
+
});
|
|
137
148
|
return {
|
|
138
149
|
taskId,
|
|
139
150
|
type: task.type,
|
|
@@ -132,6 +132,11 @@ export const terminalTools = [
|
|
|
132
132
|
const store = loadTerminalStore();
|
|
133
133
|
const sessionId = input.sessionId;
|
|
134
134
|
const command = input.command;
|
|
135
|
+
// An explicit sessionId must name a stored session; only fall back to
|
|
136
|
+
// (or create) the default session when no sessionId was given.
|
|
137
|
+
if (sessionId && !store.sessions[sessionId]) {
|
|
138
|
+
return { success: false, error: 'Session not found' };
|
|
139
|
+
}
|
|
135
140
|
// Find or create default session
|
|
136
141
|
let session = sessionId ? store.sessions[sessionId] : Object.values(store.sessions).find(s => s.status === 'active');
|
|
137
142
|
if (!session) {
|
|
@@ -55,18 +55,37 @@ function ensureWorkflowDir() {
|
|
|
55
55
|
mkdirSync(dir, { recursive: true });
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* SECURITY: record maps are keyed by ids taken from MCP tool input, and
|
|
60
|
+
* validateIdentifier accepts names like `__proto__` and `constructor`. On a
|
|
61
|
+
* plain object those resolve to Object.prototype or a built-in, which a handler
|
|
62
|
+
* would then write into. Null-prototype maps only ever return own records.
|
|
63
|
+
*/
|
|
64
|
+
function withRecordMaps(store, keys) {
|
|
65
|
+
const maps = store;
|
|
66
|
+
for (const key of keys) {
|
|
67
|
+
const map = maps[key];
|
|
68
|
+
if (map && typeof map === 'object' && !Array.isArray(map))
|
|
69
|
+
Object.setPrototypeOf(map, null);
|
|
70
|
+
else
|
|
71
|
+
maps[key] = Object.create(null);
|
|
72
|
+
}
|
|
73
|
+
return store;
|
|
74
|
+
}
|
|
75
|
+
const WORKFLOW_MAPS = ['workflows', 'templates'];
|
|
58
76
|
function loadWorkflowStore() {
|
|
59
77
|
try {
|
|
60
78
|
const path = getWorkflowPath();
|
|
61
79
|
if (existsSync(path)) {
|
|
62
|
-
const data = readFileSync(path, 'utf-8');
|
|
63
|
-
|
|
80
|
+
const data = JSON.parse(readFileSync(path, 'utf-8'));
|
|
81
|
+
if (data && typeof data === 'object' && !Array.isArray(data))
|
|
82
|
+
return withRecordMaps(data, WORKFLOW_MAPS);
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
85
|
catch {
|
|
67
86
|
// Return default store on error
|
|
68
87
|
}
|
|
69
|
-
return { workflows: {}, templates: {}, version: '3.0.0' };
|
|
88
|
+
return withRecordMaps({ workflows: {}, templates: {}, version: '3.0.0' }, WORKFLOW_MAPS);
|
|
70
89
|
}
|
|
71
90
|
function saveWorkflowStore(store) {
|
|
72
91
|
ensureWorkflowDir();
|
|
@@ -1540,15 +1540,39 @@ export async function bridgeListEntries(options) {
|
|
|
1540
1540
|
// List
|
|
1541
1541
|
const entries = [];
|
|
1542
1542
|
try {
|
|
1543
|
-
|
|
1544
|
-
const
|
|
1545
|
-
|
|
1543
|
+
const columns = 'id, key, namespace, content, embedding, access_count, created_at, updated_at, provenance_type, expires_at, tags';
|
|
1544
|
+
const listLimit = options.includeEmbedding ? Math.min(safeLimit, MAX_LIST_EMBEDDINGS) : safeLimit;
|
|
1545
|
+
// #4686: sort only row identities first, then fetch the payload for the
|
|
1546
|
+
// page. The old query sorted full `content`/`embedding` payloads for
|
|
1547
|
+
// every row and discarded all but the requested page.
|
|
1548
|
+
const pagedSql = `
|
|
1549
|
+
SELECT ${columns}
|
|
1550
|
+
FROM memory_entries
|
|
1551
|
+
WHERE _rowid_ IN (
|
|
1552
|
+
SELECT _rowid_
|
|
1553
|
+
FROM memory_entries
|
|
1554
|
+
WHERE ${statusFilter} ${extraFilter}
|
|
1555
|
+
ORDER BY updated_at DESC
|
|
1556
|
+
LIMIT ? OFFSET ?
|
|
1557
|
+
)
|
|
1558
|
+
ORDER BY updated_at DESC
|
|
1559
|
+
`;
|
|
1560
|
+
const originalSql = `
|
|
1561
|
+
SELECT ${columns}
|
|
1546
1562
|
FROM memory_entries
|
|
1547
1563
|
WHERE ${statusFilter} ${extraFilter}
|
|
1548
1564
|
ORDER BY updated_at DESC
|
|
1549
1565
|
LIMIT ? OFFSET ?
|
|
1550
|
-
|
|
1551
|
-
|
|
1566
|
+
`;
|
|
1567
|
+
let rows;
|
|
1568
|
+
try {
|
|
1569
|
+
rows = ctx.db.prepare(pagedSql).all(...filterParams, listLimit, safeOffset);
|
|
1570
|
+
}
|
|
1571
|
+
catch {
|
|
1572
|
+
// WITHOUT ROWID/legacy tables have no _rowid_: preserve the original
|
|
1573
|
+
// query rather than failing the page.
|
|
1574
|
+
rows = ctx.db.prepare(originalSql).all(...filterParams, listLimit, safeOffset);
|
|
1575
|
+
}
|
|
1552
1576
|
for (const row of rows) {
|
|
1553
1577
|
let tags = [];
|
|
1554
1578
|
if (row.tags) {
|
|
@@ -3115,16 +3115,38 @@ export async function listEntries(options) {
|
|
|
3115
3115
|
const total = countRows[0]?.[0] || 0;
|
|
3116
3116
|
// Get entries. ADR-472: embedding rows are capped at MAX_LIST_EMBEDDINGS.
|
|
3117
3117
|
const listLimit = options.includeEmbedding ? Math.min(safeLimit, MAX_LIST_EMBEDDINGS) : safeLimit;
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3118
|
+
const columns = 'id, key, namespace, content, embedding, access_count, created_at, updated_at, provenance_type, expires_at, tags';
|
|
3119
|
+
// #4686: page row identities first so the temporary sort B-tree does not
|
|
3120
|
+
// carry full content/embedding payloads for rows outside the page.
|
|
3121
|
+
const pagedSql = `SELECT ${columns} FROM memory_entries
|
|
3122
|
+
WHERE _rowid_ IN (
|
|
3123
|
+
SELECT _rowid_ FROM memory_entries WHERE ${whereSql}
|
|
3124
|
+
ORDER BY updated_at DESC LIMIT ? OFFSET ?
|
|
3125
|
+
)
|
|
3126
|
+
ORDER BY updated_at DESC`;
|
|
3127
|
+
const originalSql = `SELECT ${columns} FROM memory_entries WHERE ${whereSql}
|
|
3128
|
+
ORDER BY updated_at DESC LIMIT ? OFFSET ?`;
|
|
3129
|
+
let listRows = [];
|
|
3130
|
+
const runList = (sql) => {
|
|
3131
|
+
const stmt = db.prepare(sql);
|
|
3132
|
+
try {
|
|
3133
|
+
stmt.bind([...whereParams, listLimit, safeOffset]);
|
|
3134
|
+
const rows = [];
|
|
3135
|
+
while (stmt.step())
|
|
3136
|
+
rows.push(stmt.get());
|
|
3137
|
+
return rows;
|
|
3138
|
+
}
|
|
3139
|
+
finally {
|
|
3140
|
+
stmt.free();
|
|
3141
|
+
}
|
|
3142
|
+
};
|
|
3143
|
+
try {
|
|
3144
|
+
listRows = runList(pagedSql);
|
|
3145
|
+
}
|
|
3146
|
+
catch {
|
|
3147
|
+
// Legacy WITHOUT ROWID tables have no _rowid_: keep the original query.
|
|
3148
|
+
listRows = runList(originalSql);
|
|
3149
|
+
}
|
|
3128
3150
|
const entries = [];
|
|
3129
3151
|
for (const row of listRows) {
|
|
3130
3152
|
const [id, key, ns, content, embedding, accessCount, createdAt, updatedAt, provenanceTypeVal, expiresAtVal, tagsJson] = row;
|