monomind 1.11.14 → 1.13.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.
- package/.claude/agents/generated/channel-intelligence-director.md +87 -0
- package/.claude/agents/generated/chief-growth-officer.md +88 -0
- package/.claude/agents/generated/content-seo-strategist.md +90 -0
- package/.claude/agents/generated/developer-community-strategist.md +91 -0
- package/.claude/agents/generated/outreach-partnership-strategist.md +90 -0
- package/.claude/agents/generated/social-media-strategist.md +91 -0
- package/.claude/agents/generated/video-visual-strategist.md +90 -0
- package/.claude/commands/mastermind/master.md +1 -1
- package/.claude/helpers/auto-memory-hook.mjs +13 -4
- package/.claude/helpers/control-start.cjs +5 -0
- package/.claude/helpers/event-logger.cjs +114 -0
- package/.claude/helpers/handlers/adr-draft-handler.cjs +19 -5
- package/.claude/helpers/handlers/agent-start-handler.cjs +13 -4
- package/.claude/helpers/handlers/compact-handler.cjs +2 -0
- package/.claude/helpers/handlers/edit-handler.cjs +1 -1
- package/.claude/helpers/handlers/gates-handler.cjs +3 -0
- package/.claude/helpers/handlers/graph-status-handler.cjs +14 -8
- package/.claude/helpers/handlers/loops-status-handler.cjs +5 -2
- package/.claude/helpers/handlers/route-handler.cjs +24 -10
- package/.claude/helpers/handlers/session-handler.cjs +11 -4
- package/.claude/helpers/handlers/session-restore-handler.cjs +35 -19
- package/.claude/helpers/handlers/task-handler.cjs +13 -5
- package/.claude/helpers/hook-handler.cjs +40 -0
- package/.claude/helpers/intelligence.cjs +130 -53
- package/.claude/helpers/loop-tracker.cjs +15 -3
- package/.claude/helpers/memory-palace.cjs +461 -0
- package/.claude/helpers/memory.cjs +138 -14
- package/.claude/helpers/metrics-db.mjs +87 -0
- package/.claude/helpers/router.cjs +300 -42
- package/.claude/helpers/session.cjs +89 -30
- package/.claude/helpers/statusline.cjs +148 -4
- package/.claude/helpers/toggle-statusline.cjs +73 -0
- package/.claude/helpers/token-tracker.cjs +934 -0
- package/.claude/helpers/utils/micro-agents.cjs +20 -4
- package/.claude/helpers/utils/monograph.cjs +39 -4
- package/.claude/helpers/utils/telemetry.cjs +3 -3
- package/.claude/scheduled_tasks.lock +1 -1
- package/.claude/settings.json +92 -1
- package/.claude/skills/mastermind/_protocol.md +25 -15
- package/.claude/skills/mastermind/architect.md +3 -3
- package/.claude/skills/mastermind/autodev.md +4 -2
- package/.claude/skills/mastermind/idea.md +10 -0
- package/.claude/skills/mastermind/ops.md +3 -3
- package/.claude/skills/mastermind/runorg.md +153 -86
- package/package.json +20 -3
- package/packages/@monomind/cli/dist/src/agents/registry-builder.js +2 -0
- package/packages/@monomind/cli/dist/src/autopilot-state.js +10 -5
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.js +13 -0
- package/packages/@monomind/cli/dist/src/benchmarks/metric-evaluators.js +20 -9
- package/packages/@monomind/cli/dist/src/browser/actions.js +10 -3
- package/packages/@monomind/cli/dist/src/browser/browser.js +12 -2
- package/packages/@monomind/cli/dist/src/browser/cdp.js +21 -3
- package/packages/@monomind/cli/dist/src/browser/har.js +27 -5
- package/packages/@monomind/cli/dist/src/commands/agent.js +11 -8
- package/packages/@monomind/cli/dist/src/commands/analyze.js +36 -21
- package/packages/@monomind/cli/dist/src/commands/autopilot.js +12 -4
- package/packages/@monomind/cli/dist/src/commands/benchmark.js +51 -8
- package/packages/@monomind/cli/dist/src/commands/browse.js +5 -2
- package/packages/@monomind/cli/dist/src/commands/claims.js +29 -11
- package/packages/@monomind/cli/dist/src/commands/cleanup.js +25 -5
- package/packages/@monomind/cli/dist/src/commands/config.js +15 -7
- package/packages/@monomind/cli/dist/src/commands/daemon.js +6 -0
- package/packages/@monomind/cli/dist/src/commands/deployment.js +34 -19
- package/packages/@monomind/cli/dist/src/commands/doctor.js +192 -23
- package/packages/@monomind/cli/dist/src/commands/guidance.js +15 -2
- package/packages/@monomind/cli/dist/src/commands/hive-mind.js +37 -14
- package/packages/@monomind/cli/dist/src/commands/hooks.js +42 -25
- package/packages/@monomind/cli/dist/src/commands/init.js +9 -4
- package/packages/@monomind/cli/dist/src/commands/issues.js +29 -26
- package/packages/@monomind/cli/dist/src/commands/mcp.js +11 -5
- package/packages/@monomind/cli/dist/src/commands/memory.js +10 -0
- package/packages/@monomind/cli/dist/src/commands/migrate.js +5 -5
- package/packages/@monomind/cli/dist/src/commands/monograph.js +18 -5
- package/packages/@monomind/cli/dist/src/commands/monovector/backup.js +8 -2
- package/packages/@monomind/cli/dist/src/commands/monovector/benchmark.js +20 -7
- package/packages/@monomind/cli/dist/src/commands/monovector/import.js +15 -0
- package/packages/@monomind/cli/dist/src/commands/monovector/migrate.js +4 -1
- package/packages/@monomind/cli/dist/src/commands/monovector/optimize.js +11 -0
- package/packages/@monomind/cli/dist/src/commands/monovector/setup.js +11 -1
- package/packages/@monomind/cli/dist/src/commands/neural.js +1 -1
- package/packages/@monomind/cli/dist/src/commands/performance.js +20 -7
- package/packages/@monomind/cli/dist/src/commands/platforms.js +90 -8
- package/packages/@monomind/cli/dist/src/commands/plugins.js +12 -5
- package/packages/@monomind/cli/dist/src/commands/process.js +33 -10
- package/packages/@monomind/cli/dist/src/commands/progress.js +5 -3
- package/packages/@monomind/cli/dist/src/commands/providers.js +5 -5
- package/packages/@monomind/cli/dist/src/commands/replay.js +8 -2
- package/packages/@monomind/cli/dist/src/commands/route.js +27 -7
- package/packages/@monomind/cli/dist/src/commands/security.js +4 -0
- package/packages/@monomind/cli/dist/src/commands/session.js +12 -1
- package/packages/@monomind/cli/dist/src/commands/start.js +11 -4
- package/packages/@monomind/cli/dist/src/commands/status.js +7 -4
- package/packages/@monomind/cli/dist/src/commands/swarm.js +27 -13
- package/packages/@monomind/cli/dist/src/commands/task.js +26 -11
- package/packages/@monomind/cli/dist/src/commands/tokens.js +7 -2
- package/packages/@monomind/cli/dist/src/commands/transfer-store.js +36 -22
- package/packages/@monomind/cli/dist/src/commands/update.js +15 -3
- package/packages/@monomind/cli/dist/src/commands/workflow.js +39 -6
- package/packages/@monomind/cli/dist/src/consensus/audit-writer.js +18 -7
- package/packages/@monomind/cli/dist/src/consensus/vote-signer.js +25 -8
- package/packages/@monomind/cli/dist/src/index.js +7 -3
- package/packages/@monomind/cli/dist/src/init/executor.js +14 -11
- package/packages/@monomind/cli/dist/src/init/shared-instructions-generator.js +20 -4
- package/packages/@monomind/cli/dist/src/init/statusline-generator.js +36 -15
- package/packages/@monomind/cli/dist/src/mcp-tools/a2a-tools.js +98 -13
- package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.js +16 -3
- package/packages/@monomind/cli/dist/src/mcp-tools/analyze-tools.js +80 -17
- package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.js +84 -22
- package/packages/@monomind/cli/dist/src/mcp-tools/claims-tools.js +35 -7
- package/packages/@monomind/cli/dist/src/mcp-tools/config-tools.js +82 -17
- package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.js +37 -4
- package/packages/@monomind/cli/dist/src/mcp-tools/daa-tools.js +49 -7
- package/packages/@monomind/cli/dist/src/mcp-tools/embeddings-tools.js +45 -18
- package/packages/@monomind/cli/dist/src/mcp-tools/github-tools.js +75 -25
- package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +32 -10
- package/packages/@monomind/cli/dist/src/mcp-tools/hive-mind-tools.js +91 -20
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +188 -29
- package/packages/@monomind/cli/dist/src/mcp-tools/memory-tools.js +25 -7
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.js +11 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +476 -62
- package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +44 -9
- package/packages/@monomind/cli/dist/src/mcp-tools/performance-tools.js +45 -10
- package/packages/@monomind/cli/dist/src/mcp-tools/progress-tools.js +7 -4
- package/packages/@monomind/cli/dist/src/mcp-tools/request-tracker.js +15 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/security-tools.js +61 -9
- package/packages/@monomind/cli/dist/src/mcp-tools/session-tools.js +45 -14
- package/packages/@monomind/cli/dist/src/mcp-tools/swarm-tools.js +15 -3
- package/packages/@monomind/cli/dist/src/mcp-tools/system-tools.js +14 -7
- package/packages/@monomind/cli/dist/src/mcp-tools/task-tools.js +52 -10
- package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.js +40 -6
- package/packages/@monomind/cli/dist/src/mcp-tools/transfer-tools.js +37 -4
- package/packages/@monomind/cli/dist/src/mcp-tools/workflow-tools.js +29 -6
- package/packages/@monomind/cli/dist/src/memory/ewc-consolidation.js +26 -10
- package/packages/@monomind/cli/dist/src/memory/intelligence.js +80 -19
- package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +21 -2
- package/packages/@monomind/cli/dist/src/memory/memory-initializer.js +67 -3
- package/packages/@monomind/cli/dist/src/memory/sona-optimizer.js +14 -4
- package/packages/@monomind/cli/dist/src/monovector/command-outcomes.js +43 -7
- package/packages/@monomind/cli/dist/src/monovector/coverage-router.js +8 -4
- package/packages/@monomind/cli/dist/src/monovector/coverage-tools.js +6 -3
- package/packages/@monomind/cli/dist/src/monovector/diff-classifier.js +13 -0
- package/packages/@monomind/cli/dist/src/monovector/route-outcomes.d.ts +2 -1
- package/packages/@monomind/cli/dist/src/monovector/route-outcomes.js +46 -4
- package/packages/@monomind/cli/dist/src/plugins/manager.js +8 -3
- package/packages/@monomind/cli/dist/src/plugins/store/discovery.js +46 -2
- package/packages/@monomind/cli/dist/src/plugins/store/search.js +5 -4
- package/packages/@monomind/cli/dist/src/production/circuit-breaker.js +17 -3
- package/packages/@monomind/cli/dist/src/production/error-handler.js +3 -0
- package/packages/@monomind/cli/dist/src/production/monitoring.js +20 -3
- package/packages/@monomind/cli/dist/src/production/rate-limiter.js +13 -4
- package/packages/@monomind/cli/dist/src/production/retry.js +17 -9
- package/packages/@monomind/cli/dist/src/routing/embed-worker.js +6 -2
- package/packages/@monomind/cli/dist/src/routing/embedder.js +0 -0
- package/packages/@monomind/cli/dist/src/routing/llm-caller.js +13 -2
- package/packages/@monomind/cli/dist/src/routing/route-layer-factory.js +18 -3
- package/packages/@monomind/cli/dist/src/services/claim-service.d.ts +1 -0
- package/packages/@monomind/cli/dist/src/services/claim-service.js +8 -0
- package/packages/@monomind/cli/dist/src/services/config-file-manager.js +14 -2
- package/packages/@monomind/cli/dist/src/services/headless-worker-executor.js +18 -2
- package/packages/@monomind/cli/dist/src/services/worker-daemon.js +348 -17
- package/packages/@monomind/cli/dist/src/transfer/anonymization/index.d.ts +0 -3
- package/packages/@monomind/cli/dist/src/transfer/anonymization/index.js +16 -1
- package/packages/@monomind/cli/dist/src/transfer/export.js +8 -0
- package/packages/@monomind/cli/dist/src/transfer/ipfs/upload.js +33 -3
- package/packages/@monomind/cli/dist/src/transfer/serialization/cfp.js +8 -2
- package/packages/@monomind/cli/dist/src/transfer/storage/gcs.js +37 -3
- package/packages/@monomind/cli/dist/src/transfer/store/discovery.js +45 -3
- package/packages/@monomind/cli/dist/src/transfer/store/download.js +5 -0
- package/packages/@monomind/cli/dist/src/transfer/store/publish.js +13 -1
- package/packages/@monomind/cli/dist/src/transfer/store/registry.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/transfer/store/registry.js +30 -5
- package/packages/@monomind/cli/dist/src/transfer/store/search.js +20 -5
- package/packages/@monomind/cli/dist/src/update/checker.js +59 -7
- package/packages/@monomind/cli/dist/src/update/executor.js +50 -3
- package/packages/@monomind/cli/dist/src/update/index.js +18 -1
- package/packages/@monomind/cli/dist/src/update/rate-limiter.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/update/rate-limiter.js +79 -7
- package/packages/@monomind/cli/dist/src/update/validator.js +52 -1
- package/packages/@monomind/cli/package.json +2 -3
|
@@ -151,13 +151,26 @@ export const benchmarkCommand = {
|
|
|
151
151
|
],
|
|
152
152
|
action: async (ctx) => {
|
|
153
153
|
const config = getConnectionConfig(ctx);
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
const
|
|
154
|
+
// Clamp numeric inputs to safe ranges to prevent DoS via OOM
|
|
155
|
+
const numVectors = Math.min(Math.max(1, parseInt(ctx.flags.vectors || '10000', 10)), 1_000_000);
|
|
156
|
+
const dimensions = Math.min(Math.max(1, parseInt(ctx.flags.dimensions || '1536', 10)), 65536);
|
|
157
|
+
const numQueries = Math.min(Math.max(1, parseInt(ctx.flags.queries || '100', 10)), 10_000);
|
|
158
|
+
const topK = Math.min(Math.max(1, parseInt(ctx.flags.k || '10', 10)), 10_000);
|
|
159
|
+
// Validate metric and indexType against allowlists to prevent SQL injection
|
|
160
|
+
const VALID_METRICS = ['cosine', 'l2', 'inner'];
|
|
161
|
+
const VALID_INDEX_TYPES = ['hnsw', 'ivfflat', 'none'];
|
|
162
|
+
const rawMetric = ctx.flags.metric || 'cosine';
|
|
163
|
+
const rawIndexType = ctx.flags.index || 'hnsw';
|
|
164
|
+
const metric = VALID_METRICS.includes(rawMetric) ? rawMetric : 'cosine';
|
|
165
|
+
const indexType = VALID_INDEX_TYPES.includes(rawIndexType) ? rawIndexType : 'hnsw';
|
|
166
|
+
const batchSize = Math.min(Math.max(1, parseInt(ctx.flags['batch-size'] || '1000', 10)), 100_000);
|
|
167
|
+
// Validate schema identifier against safe pattern to prevent SQL injection
|
|
168
|
+
const rawSchema = config.schema || 'monomind';
|
|
169
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]{0,62}$/.test(rawSchema)) {
|
|
170
|
+
output.printError('Invalid schema name. Only alphanumeric characters and underscores are allowed.');
|
|
171
|
+
return { success: false, exitCode: 1 };
|
|
172
|
+
}
|
|
173
|
+
config.schema = rawSchema;
|
|
161
174
|
const cleanup = ctx.flags.cleanup !== false;
|
|
162
175
|
output.writeln();
|
|
163
176
|
output.writeln(output.bold('MonoVector Performance Benchmark'));
|
|
@@ -184,6 +184,21 @@ export const importCommand = {
|
|
|
184
184
|
output.printError(`Input file not found: ${inputFile}`);
|
|
185
185
|
return { success: false, message: 'File not found' };
|
|
186
186
|
}
|
|
187
|
+
// Symlink guard: a symlink could redirect to /etc/passwd or a huge file.
|
|
188
|
+
// lstatSync checks the link itself, not the target — so symlinks are rejected
|
|
189
|
+
// regardless of what they point to (TOCTOU-safe for the check + read pair).
|
|
190
|
+
const lstat = fs.lstatSync(inputFile);
|
|
191
|
+
if (lstat.isSymbolicLink()) {
|
|
192
|
+
output.printError(`Symlinks are not allowed as input files: ${inputFile}`);
|
|
193
|
+
return { success: false, message: 'Symlink not allowed' };
|
|
194
|
+
}
|
|
195
|
+
// Size guard: without this, a user can pass a multi-GB file and exhaust the
|
|
196
|
+
// Node heap before JSON.parse ever runs, crashing the CLI with an OOM.
|
|
197
|
+
const MAX_IMPORT_FILE_BYTES = 50 * 1024 * 1024; // 50 MB
|
|
198
|
+
if (lstat.size > MAX_IMPORT_FILE_BYTES) {
|
|
199
|
+
output.printError(`Input file too large: ${inputFile} (max 50 MB)`);
|
|
200
|
+
return { success: false, message: 'Input file too large' };
|
|
201
|
+
}
|
|
187
202
|
try {
|
|
188
203
|
output.printInfo(`Reading: ${inputFile}`);
|
|
189
204
|
const content = fs.readFileSync(inputFile, 'utf-8');
|
|
@@ -130,10 +130,13 @@ const MIGRATIONS = [
|
|
|
130
130
|
`,
|
|
131
131
|
},
|
|
132
132
|
];
|
|
133
|
+
const IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_]{0,63}$/;
|
|
133
134
|
/**
|
|
134
135
|
* Get PostgreSQL connection config from context
|
|
135
136
|
*/
|
|
136
137
|
function getConnectionConfig(ctx) {
|
|
138
|
+
const rawSchema = ctx.flags.schema || 'monomind';
|
|
139
|
+
const schema = IDENTIFIER_RE.test(rawSchema) ? rawSchema : 'monomind';
|
|
137
140
|
return {
|
|
138
141
|
host: ctx.flags.host || process.env.PGHOST || 'localhost',
|
|
139
142
|
port: parseInt(ctx.flags.port || process.env.PGPORT || '5432', 10),
|
|
@@ -141,7 +144,7 @@ function getConnectionConfig(ctx) {
|
|
|
141
144
|
user: ctx.flags.user || process.env.PGUSER || 'postgres',
|
|
142
145
|
password: ctx.flags.password || process.env.PGPASSWORD || '',
|
|
143
146
|
ssl: ctx.flags.ssl || process.env.PGSSLMODE === 'require',
|
|
144
|
-
schema
|
|
147
|
+
schema,
|
|
145
148
|
};
|
|
146
149
|
}
|
|
147
150
|
/**
|
|
@@ -121,6 +121,17 @@ export const optimizeCommand = {
|
|
|
121
121
|
output.printError('Database name is required. Use --database or -d flag, or set PGDATABASE env.');
|
|
122
122
|
return { success: false, exitCode: 1 };
|
|
123
123
|
}
|
|
124
|
+
// Validate schema identifier to prevent SQL injection
|
|
125
|
+
const IDENT_RE = /^[a-zA-Z_][a-zA-Z0-9_]{0,62}$/;
|
|
126
|
+
if (!IDENT_RE.test(config.schema)) {
|
|
127
|
+
output.printError('Invalid schema name. Only alphanumeric characters and underscores are allowed.');
|
|
128
|
+
return { success: false, exitCode: 1 };
|
|
129
|
+
}
|
|
130
|
+
// Validate --index flag if provided
|
|
131
|
+
if (specificIndex !== undefined && !IDENT_RE.test(specificIndex)) {
|
|
132
|
+
output.printError('Invalid index name. Only alphanumeric characters and underscores are allowed.');
|
|
133
|
+
return { success: false, exitCode: 1 };
|
|
134
|
+
}
|
|
124
135
|
const spinner = output.createSpinner({ text: 'Connecting to PostgreSQL...', spinner: 'dots' });
|
|
125
136
|
spinner.start();
|
|
126
137
|
const recommendations = [];
|
|
@@ -685,13 +685,23 @@ export const setupCommand = {
|
|
|
685
685
|
{ command: 'monomind monovector setup --force', description: 'Overwrite existing files' },
|
|
686
686
|
],
|
|
687
687
|
action: async (ctx) => {
|
|
688
|
-
const
|
|
688
|
+
const rawOutputDir = ctx.flags.output || './monovector-postgres';
|
|
689
689
|
const printOnly = ctx.flags.print;
|
|
690
690
|
const force = ctx.flags.force;
|
|
691
691
|
output.writeln();
|
|
692
692
|
output.writeln(output.bold('MonoVector PostgreSQL Setup'));
|
|
693
693
|
output.writeln(output.dim('='.repeat(50)));
|
|
694
694
|
output.writeln();
|
|
695
|
+
// Guard against path traversal: resolve to absolute and ensure it stays within
|
|
696
|
+
// the current working directory or the user's home directory.
|
|
697
|
+
const resolvedOutput = path.resolve(rawOutputDir);
|
|
698
|
+
const safeBases = [process.cwd(), process.env.HOME || process.env.USERPROFILE || ''].filter(Boolean);
|
|
699
|
+
const withinSafeBase = safeBases.some(base => resolvedOutput.startsWith(base + path.sep) || resolvedOutput === base);
|
|
700
|
+
if (!withinSafeBase) {
|
|
701
|
+
output.printError(`Output path must be within the current directory or home directory: ${resolvedOutput}`);
|
|
702
|
+
return { success: false, exitCode: 1 };
|
|
703
|
+
}
|
|
704
|
+
const outputDir = resolvedOutput;
|
|
695
705
|
if (printOnly) {
|
|
696
706
|
// Print to stdout
|
|
697
707
|
output.writeln(output.bold('=== docker-compose.yml ==='));
|
|
@@ -940,7 +940,7 @@ const importCommand = {
|
|
|
940
940
|
}
|
|
941
941
|
const patternsFile = path.join(memoryDir, 'patterns.json');
|
|
942
942
|
let existingPatterns = [];
|
|
943
|
-
if (merge && fs.existsSync(patternsFile)) {
|
|
943
|
+
if (merge && fs.existsSync(patternsFile) && fs.statSync(patternsFile).size <= 50 * 1024 * 1024) {
|
|
944
944
|
existingPatterns = JSON.parse(fs.readFileSync(patternsFile, 'utf8'));
|
|
945
945
|
}
|
|
946
946
|
// Merge or replace
|
|
@@ -20,14 +20,18 @@ const benchmarkCommand = {
|
|
|
20
20
|
{ command: 'monomind performance benchmark -i 1000', description: 'Run with 1000 iterations' },
|
|
21
21
|
],
|
|
22
22
|
action: async (ctx) => {
|
|
23
|
-
const
|
|
23
|
+
const suiteRaw = ctx.flags.suite || 'all';
|
|
24
|
+
const VALID_SUITES = new Set(['all', 'wasm', 'neural', 'memory', 'search']);
|
|
25
|
+
const suite = VALID_SUITES.has(suiteRaw) ? suiteRaw : 'all';
|
|
24
26
|
const MAX_ITERATIONS = 10_000;
|
|
25
27
|
const MAX_WARMUP = 500;
|
|
26
28
|
const iterationsRaw = parseInt(ctx.flags.iterations || '100', 10);
|
|
27
29
|
const warmupRaw = parseInt(ctx.flags.warmup || '10', 10);
|
|
28
30
|
const iterations = Number.isFinite(iterationsRaw) ? Math.min(Math.max(1, iterationsRaw), MAX_ITERATIONS) : 100;
|
|
29
31
|
const warmup = Number.isFinite(warmupRaw) ? Math.min(Math.max(0, warmupRaw), MAX_WARMUP) : 10;
|
|
30
|
-
const
|
|
32
|
+
const outputFormatRaw = ctx.flags.output || 'text';
|
|
33
|
+
const VALID_OUTPUT_FORMATS = new Set(['text', 'json', 'csv']);
|
|
34
|
+
const outputFormat = VALID_OUTPUT_FORMATS.has(outputFormatRaw) ? outputFormatRaw : 'text';
|
|
31
35
|
output.writeln();
|
|
32
36
|
output.writeln(output.bold('Performance Benchmark (Real Measurements)'));
|
|
33
37
|
output.writeln(output.dim('─'.repeat(60)));
|
|
@@ -235,8 +239,11 @@ const profileCommand = {
|
|
|
235
239
|
{ command: 'monomind performance profile -d 60', description: 'Profile for 60 seconds' },
|
|
236
240
|
],
|
|
237
241
|
action: async (ctx) => {
|
|
238
|
-
const
|
|
239
|
-
const
|
|
242
|
+
const typeRaw = ctx.flags.type || 'all';
|
|
243
|
+
const VALID_PROFILE_TYPES = new Set(['cpu', 'memory', 'io', 'all']);
|
|
244
|
+
const type = VALID_PROFILE_TYPES.has(typeRaw) ? typeRaw : 'all';
|
|
245
|
+
const durationRaw = parseInt(ctx.flags.duration || '30', 10);
|
|
246
|
+
const duration = Number.isFinite(durationRaw) ? Math.min(Math.max(1, durationRaw), 300) : 30;
|
|
240
247
|
output.writeln();
|
|
241
248
|
output.writeln(output.bold('Performance Profiler'));
|
|
242
249
|
output.writeln(output.dim('─'.repeat(50)));
|
|
@@ -308,8 +315,12 @@ const metricsCommand = {
|
|
|
308
315
|
{ command: 'monomind performance metrics -f prometheus', description: 'Export as Prometheus format' },
|
|
309
316
|
],
|
|
310
317
|
action: async (ctx) => {
|
|
311
|
-
const
|
|
312
|
-
const
|
|
318
|
+
const timeframeRaw = ctx.flags.timeframe || '24h';
|
|
319
|
+
const VALID_TIMEFRAMES = new Set(['1h', '24h', '7d', '30d']);
|
|
320
|
+
const timeframe = VALID_TIMEFRAMES.has(timeframeRaw) ? timeframeRaw : '24h';
|
|
321
|
+
const formatRaw = ctx.flags.format || 'text';
|
|
322
|
+
const VALID_FORMATS = new Set(['text', 'json', 'prometheus']);
|
|
323
|
+
const format = VALID_FORMATS.has(formatRaw) ? formatRaw : 'text';
|
|
313
324
|
output.writeln();
|
|
314
325
|
output.writeln(output.bold(`Performance Metrics (${timeframe})`));
|
|
315
326
|
output.writeln(output.dim('─'.repeat(50)));
|
|
@@ -491,7 +502,9 @@ const optimizeCommand = {
|
|
|
491
502
|
{ command: 'monomind performance optimize --apply', description: 'Apply all optimizations' },
|
|
492
503
|
],
|
|
493
504
|
action: async (ctx) => {
|
|
494
|
-
const
|
|
505
|
+
const targetRaw = ctx.flags.target || 'all';
|
|
506
|
+
const VALID_TARGETS = new Set(['memory', 'cpu', 'latency', 'all']);
|
|
507
|
+
const target = VALID_TARGETS.has(targetRaw) ? targetRaw : 'all';
|
|
495
508
|
if (ctx.flags.apply) {
|
|
496
509
|
output.printWarning('Optimization application is not yet implemented. Showing recommendations only.');
|
|
497
510
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* github.com/monoes/monomind
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync, writeFileSync, mkdirSync, readFileSync } from 'fs';
|
|
8
|
-
import { join, dirname } from 'path';
|
|
7
|
+
import { existsSync, writeFileSync, mkdirSync, readFileSync, statSync } from 'fs';
|
|
8
|
+
import { join, dirname, resolve } from 'path';
|
|
9
9
|
import { output } from '../output.js';
|
|
10
10
|
export const SUPPORTED_PLATFORMS = [
|
|
11
11
|
'claude', 'gemini', 'cursor', 'vscode', 'copilot',
|
|
@@ -43,15 +43,63 @@ Graph is at \`.monomind/monograph.db\`. Rebuild with: \`npx monograph build\`
|
|
|
43
43
|
${MONOMIND_BLOCK_END}
|
|
44
44
|
`;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Maximum size for a platform config file we will read or append to.
|
|
48
|
+
* Platform config files (CLAUDE.md, .cursorrules, etc.) are never legitimately
|
|
49
|
+
* larger than a few hundred KB — a 1 MB cap prevents OOM when the flag points
|
|
50
|
+
* at an enormous file such as a binary or a DB dump.
|
|
51
|
+
*/
|
|
52
|
+
const MAX_CONFIG_FILE_BYTES = 1 * 1024 * 1024; // 1 MB
|
|
53
|
+
/**
|
|
54
|
+
* Resolve and validate the user-supplied --path flag.
|
|
55
|
+
*
|
|
56
|
+
* SECURITY: the flag is attacker-controlled. Without validation an adversary can
|
|
57
|
+
* pass --path /etc to overwrite system files, or --path "../../.." to escape
|
|
58
|
+
* the project. We resolve to an absolute path and reject anything that isn't
|
|
59
|
+
* a directory (or doesn't exist yet under a parent that does exist).
|
|
60
|
+
* We do NOT further restrict the path to cwd because a legitimate use case is
|
|
61
|
+
* "install into another repo at an absolute path", but we do require the
|
|
62
|
+
* resolved path to be a directory (or the parent to exist) so that the caller
|
|
63
|
+
* cannot aim the flag at a file.
|
|
64
|
+
*/
|
|
65
|
+
function resolveRepoPath(rawPath) {
|
|
66
|
+
// Prevent shell-injection via null bytes or unusual separators
|
|
67
|
+
if (rawPath.includes('\0'))
|
|
68
|
+
throw new Error('Invalid path: contains null byte');
|
|
69
|
+
const resolved = resolve(rawPath);
|
|
70
|
+
// If the path exists it must be a directory
|
|
71
|
+
if (existsSync(resolved)) {
|
|
72
|
+
const st = statSync(resolved);
|
|
73
|
+
if (!st.isDirectory())
|
|
74
|
+
throw new Error(`--path must be a directory, got a file: ${resolved}`);
|
|
75
|
+
}
|
|
76
|
+
return resolved;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validate that fullPath is contained within repoRoot (path traversal defence).
|
|
80
|
+
* relPath comes from our own PLATFORM_CONFIG_FILES map, but we validate anyway
|
|
81
|
+
* to guard against future changes that introduce dynamic paths.
|
|
82
|
+
*/
|
|
83
|
+
function assertWithinRoot(fullPath, repoRoot) {
|
|
84
|
+
if (!fullPath.startsWith(repoRoot + '/') && fullPath !== repoRoot) {
|
|
85
|
+
throw new Error(`Path escapes repository root: ${fullPath}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
46
88
|
function installPlatform(platform, repoPath) {
|
|
47
89
|
const files = PLATFORM_CONFIG_FILES[platform];
|
|
48
90
|
const instructions = getMonomindInstructions();
|
|
49
91
|
const written = [];
|
|
50
92
|
for (const relPath of files) {
|
|
51
|
-
const fullPath = join(repoPath, relPath);
|
|
93
|
+
const fullPath = resolve(join(repoPath, relPath));
|
|
94
|
+
assertWithinRoot(fullPath, repoPath);
|
|
52
95
|
const dir = dirname(fullPath);
|
|
53
96
|
mkdirSync(dir, { recursive: true });
|
|
54
97
|
if (existsSync(fullPath)) {
|
|
98
|
+
// Guard against reading oversized files (e.g. the flag points at a data file)
|
|
99
|
+
const fileStat = statSync(fullPath);
|
|
100
|
+
if (fileStat.size > MAX_CONFIG_FILE_BYTES) {
|
|
101
|
+
throw new Error(`Config file too large to read (${fileStat.size} bytes): ${relPath}`);
|
|
102
|
+
}
|
|
55
103
|
const existing = readFileSync(fullPath, 'utf8');
|
|
56
104
|
if (existing.includes(MONOMIND_BLOCK_START))
|
|
57
105
|
continue;
|
|
@@ -69,9 +117,15 @@ function uninstallPlatform(platform, repoPath) {
|
|
|
69
117
|
const blockRe = new RegExp(`\\n?${MONOMIND_BLOCK_START}[\\s\\S]*?${MONOMIND_BLOCK_END}\\n?`, 'g');
|
|
70
118
|
const cleaned = [];
|
|
71
119
|
for (const relPath of files) {
|
|
72
|
-
const fullPath = join(repoPath, relPath);
|
|
120
|
+
const fullPath = resolve(join(repoPath, relPath));
|
|
121
|
+
assertWithinRoot(fullPath, repoPath);
|
|
73
122
|
if (!existsSync(fullPath))
|
|
74
123
|
continue;
|
|
124
|
+
// Guard against reading oversized files
|
|
125
|
+
const fileStat = statSync(fullPath);
|
|
126
|
+
if (fileStat.size > MAX_CONFIG_FILE_BYTES) {
|
|
127
|
+
throw new Error(`Config file too large to read (${fileStat.size} bytes): ${relPath}`);
|
|
128
|
+
}
|
|
75
129
|
const content = readFileSync(fullPath, 'utf8');
|
|
76
130
|
writeFileSync(fullPath, content.replace(blockRe, ''), 'utf8');
|
|
77
131
|
cleaned.push(relPath);
|
|
@@ -81,7 +135,14 @@ function uninstallPlatform(platform, repoPath) {
|
|
|
81
135
|
async function handleInstall(ctx) {
|
|
82
136
|
const platform = ctx.flags['platform'];
|
|
83
137
|
const all = ctx.flags['all'];
|
|
84
|
-
|
|
138
|
+
let repoPath;
|
|
139
|
+
try {
|
|
140
|
+
repoPath = resolveRepoPath(ctx.flags['path'] ?? '.');
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
output.error(`Invalid --path: ${err instanceof Error ? err.message : String(err)}`);
|
|
144
|
+
return { success: false, exitCode: 1 };
|
|
145
|
+
}
|
|
85
146
|
if (!platform && !all) {
|
|
86
147
|
output.error('Specify --platform <name> or --all');
|
|
87
148
|
output.info(`Supported platforms: ${SUPPORTED_PLATFORMS.join(', ')}`);
|
|
@@ -98,7 +159,14 @@ async function handleInstall(ctx) {
|
|
|
98
159
|
}
|
|
99
160
|
let totalFiles = 0;
|
|
100
161
|
for (const p of targets) {
|
|
101
|
-
|
|
162
|
+
let written;
|
|
163
|
+
try {
|
|
164
|
+
written = installPlatform(p, repoPath);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
output.error(`[${p}] Install failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
102
170
|
if (written.length > 0) {
|
|
103
171
|
output.success(`[${p}] Installed Monograph context → ${written.join(', ')}`);
|
|
104
172
|
totalFiles += written.length;
|
|
@@ -113,7 +181,14 @@ async function handleInstall(ctx) {
|
|
|
113
181
|
async function handleUninstall(ctx) {
|
|
114
182
|
const platform = ctx.flags['platform'];
|
|
115
183
|
const all = ctx.flags['all'];
|
|
116
|
-
|
|
184
|
+
let repoPath;
|
|
185
|
+
try {
|
|
186
|
+
repoPath = resolveRepoPath(ctx.flags['path'] ?? '.');
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
output.error(`Invalid --path: ${err instanceof Error ? err.message : String(err)}`);
|
|
190
|
+
return { success: false, exitCode: 1 };
|
|
191
|
+
}
|
|
117
192
|
if (!platform && !all) {
|
|
118
193
|
output.error('Specify --platform <name> or --all');
|
|
119
194
|
output.info(`Supported platforms: ${SUPPORTED_PLATFORMS.join(', ')}`);
|
|
@@ -130,7 +205,14 @@ async function handleUninstall(ctx) {
|
|
|
130
205
|
}
|
|
131
206
|
let totalFiles = 0;
|
|
132
207
|
for (const p of targets) {
|
|
133
|
-
|
|
208
|
+
let cleaned;
|
|
209
|
+
try {
|
|
210
|
+
cleaned = uninstallPlatform(p, repoPath);
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
output.error(`[${p}] Uninstall failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
134
216
|
if (cleaned.length > 0) {
|
|
135
217
|
output.success(`[${p}] Removed Monograph context from ${cleaned.join(', ')}`);
|
|
136
218
|
totalFiles += cleaned.length;
|
|
@@ -187,14 +187,16 @@ const installCommand = {
|
|
|
187
187
|
{ command: 'monomind plugins install -n ./my-plugin --dev', description: 'Install local plugin' },
|
|
188
188
|
],
|
|
189
189
|
action: async (ctx) => {
|
|
190
|
-
const
|
|
190
|
+
const rawName = ctx.flags.name;
|
|
191
191
|
const version = ctx.flags.version || 'latest';
|
|
192
192
|
const registryName = ctx.flags.registry;
|
|
193
193
|
const verify = ctx.flags.verify !== false;
|
|
194
|
-
if (!
|
|
194
|
+
if (!rawName) {
|
|
195
195
|
output.printError('Plugin name is required');
|
|
196
196
|
return { success: false, exitCode: 1 };
|
|
197
197
|
}
|
|
198
|
+
// Cap plugin name and version to prevent DoS/injection
|
|
199
|
+
const name = typeof rawName === 'string' ? rawName.slice(0, 214) : '';
|
|
198
200
|
// Check if it's a local path
|
|
199
201
|
const isLocalPath = name.startsWith('./') || name.startsWith('/') || name.startsWith('../');
|
|
200
202
|
output.writeln();
|
|
@@ -620,16 +622,21 @@ const searchCommand = {
|
|
|
620
622
|
{ command: 'monomind plugins search -q security --verified', description: 'Search verified security plugins' },
|
|
621
623
|
],
|
|
622
624
|
action: async (ctx) => {
|
|
623
|
-
const
|
|
625
|
+
const rawQuery = ctx.flags.query;
|
|
624
626
|
const category = ctx.flags.category;
|
|
625
627
|
const type = ctx.flags.type;
|
|
626
628
|
const verified = ctx.flags.verified;
|
|
627
|
-
const
|
|
629
|
+
const rawLimit = ctx.flags.limit;
|
|
628
630
|
const registryName = ctx.flags.registry;
|
|
629
|
-
if (!
|
|
631
|
+
if (!rawQuery) {
|
|
630
632
|
output.printError('Search query is required');
|
|
631
633
|
return { success: false, exitCode: 1 };
|
|
632
634
|
}
|
|
635
|
+
// Cap query length and limit to prevent DoS
|
|
636
|
+
const query = typeof rawQuery === 'string' ? rawQuery.slice(0, 200) : '';
|
|
637
|
+
const limit = typeof rawLimit === 'number' && Number.isFinite(rawLimit)
|
|
638
|
+
? Math.max(1, Math.min(Math.floor(rawLimit), 100))
|
|
639
|
+
: 20;
|
|
633
640
|
const spinner = output.createSpinner({ text: 'Searching plugin registry...', spinner: 'dots' });
|
|
634
641
|
spinner.start();
|
|
635
642
|
try {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* CLI Process Management Command
|
|
3
3
|
* Background process management, daemon mode, and monitoring
|
|
4
4
|
*/
|
|
5
|
-
import { writeFileSync, readFileSync, unlinkSync, existsSync, mkdirSync } from 'node:fs';
|
|
5
|
+
import { writeFileSync, readFileSync, statSync, unlinkSync, existsSync, mkdirSync } from 'node:fs';
|
|
6
6
|
import { dirname, resolve } from 'node:path';
|
|
7
7
|
// Helper functions for PID file management
|
|
8
8
|
function writePidFile(pidFile, pid, port) {
|
|
@@ -35,13 +35,22 @@ function writePidFile(pidFile, pid, port) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
const MAX_PID_FILE_BYTES = 4 * 1024; // 4 KB — a PID file should never be this large
|
|
38
39
|
function readPidFile(pidFile) {
|
|
39
40
|
try {
|
|
40
41
|
const path = resolve(pidFile);
|
|
41
42
|
if (!existsSync(path))
|
|
42
43
|
return null;
|
|
44
|
+
// Guard against oversized PID files before reading into memory
|
|
45
|
+
if (statSync(path).size > MAX_PID_FILE_BYTES)
|
|
46
|
+
return null;
|
|
43
47
|
const data = readFileSync(path, 'utf-8');
|
|
44
|
-
return JSON.parse(data)
|
|
48
|
+
return JSON.parse(data, (key, value) => {
|
|
49
|
+
// Prototype pollution guard
|
|
50
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype')
|
|
51
|
+
return undefined;
|
|
52
|
+
return value;
|
|
53
|
+
});
|
|
45
54
|
}
|
|
46
55
|
catch {
|
|
47
56
|
return null;
|
|
@@ -270,9 +279,10 @@ const monitorCommand = {
|
|
|
270
279
|
// Try to read agent and task counts from local store files
|
|
271
280
|
let agentCount = 0;
|
|
272
281
|
const taskCounts = { running: 0, queued: 0, completed: 0, failed: 0 };
|
|
282
|
+
const MAX_PROCESS_STORE_BYTES = 50 * 1024 * 1024; // 50 MB
|
|
273
283
|
try {
|
|
274
284
|
const agentStorePath = resolve('.monomind/agents/store.json');
|
|
275
|
-
if (existsSync(agentStorePath)) {
|
|
285
|
+
if (existsSync(agentStorePath) && statSync(agentStorePath).size <= MAX_PROCESS_STORE_BYTES) {
|
|
276
286
|
const agentStore = JSON.parse(readFileSync(agentStorePath, 'utf-8'));
|
|
277
287
|
const agents = Array.isArray(agentStore) ? agentStore : Object.values(agentStore.agents || agentStore || {});
|
|
278
288
|
agentCount = agents.length;
|
|
@@ -281,7 +291,7 @@ const monitorCommand = {
|
|
|
281
291
|
catch { /* no agent store */ }
|
|
282
292
|
try {
|
|
283
293
|
const taskStorePath = resolve('.monomind/tasks/store.json');
|
|
284
|
-
if (existsSync(taskStorePath)) {
|
|
294
|
+
if (existsSync(taskStorePath) && statSync(taskStorePath).size <= MAX_PROCESS_STORE_BYTES) {
|
|
285
295
|
const taskStore = JSON.parse(readFileSync(taskStorePath, 'utf-8'));
|
|
286
296
|
const tasks = Array.isArray(taskStore) ? taskStore : Object.values(taskStore.tasks || taskStore || {});
|
|
287
297
|
for (const t of tasks) {
|
|
@@ -607,12 +617,22 @@ const logsCommand = {
|
|
|
607
617
|
{ command: 'monomind process logs --since 1h --grep "error"', description: 'Search logs' },
|
|
608
618
|
],
|
|
609
619
|
action: async (ctx) => {
|
|
610
|
-
const
|
|
611
|
-
const
|
|
620
|
+
const VALID_SOURCES = new Set(['daemon', 'workers', 'tasks', 'all']);
|
|
621
|
+
const VALID_LEVELS = new Set(['debug', 'info', 'warn', 'error']);
|
|
622
|
+
const MAX_TAIL = 10_000; // cap to prevent huge in-memory slice
|
|
623
|
+
const MAX_GREP_LEN = 256; // cap regex/pattern length
|
|
624
|
+
const MAX_SINCE_LEN = 64; // cap timestamp/duration string
|
|
625
|
+
const rawSource = ctx.flags?.source || 'all';
|
|
626
|
+
const source = VALID_SOURCES.has(rawSource) ? rawSource : 'all';
|
|
627
|
+
const rawTail = Number(ctx.flags?.tail ?? 50);
|
|
628
|
+
const tail = Number.isFinite(rawTail) && rawTail > 0 ? Math.min(rawTail, MAX_TAIL) : 50;
|
|
612
629
|
const follow = ctx.flags?.follow === true;
|
|
613
|
-
const
|
|
614
|
-
const
|
|
615
|
-
const
|
|
630
|
+
const rawLevel = ctx.flags?.level || 'info';
|
|
631
|
+
const level = VALID_LEVELS.has(rawLevel) ? rawLevel : 'info';
|
|
632
|
+
const rawSince = ctx.flags?.since;
|
|
633
|
+
const since = rawSince ? String(rawSince).slice(0, MAX_SINCE_LEN) : undefined;
|
|
634
|
+
const rawGrep = ctx.flags?.grep;
|
|
635
|
+
const grep = rawGrep ? String(rawGrep).slice(0, MAX_GREP_LEN) : undefined;
|
|
616
636
|
console.log(`\n📜 Process Logs (${source})\n`);
|
|
617
637
|
console.log(` Level: ${level}+ | Lines: ${tail}${since ? ` | Since: ${since}` : ''}${grep ? ` | Filter: ${grep}` : ''}`);
|
|
618
638
|
console.log('─'.repeat(70));
|
|
@@ -629,7 +649,10 @@ const logsCommand = {
|
|
|
629
649
|
.filter(f => source === 'all' || f.includes(source));
|
|
630
650
|
for (const file of logFiles) {
|
|
631
651
|
try {
|
|
632
|
-
const
|
|
652
|
+
const logFilePath = resolve(logsDir, file);
|
|
653
|
+
if (statSync(logFilePath).size > 10 * 1024 * 1024)
|
|
654
|
+
continue; // skip files > 10 MB
|
|
655
|
+
const content = readFileSync(logFilePath, 'utf-8');
|
|
633
656
|
const lines = content.split('\n').filter(l => l.trim());
|
|
634
657
|
for (const line of lines) {
|
|
635
658
|
// Filter by log level if detectable
|
|
@@ -158,7 +158,8 @@ const watchCommand = {
|
|
|
158
158
|
},
|
|
159
159
|
],
|
|
160
160
|
action: async (ctx) => {
|
|
161
|
-
const
|
|
161
|
+
const rawInterval = ctx.flags.interval || 5000;
|
|
162
|
+
const interval = Number.isFinite(rawInterval) ? Math.max(500, Math.min(rawInterval, 3_600_000)) : 5000; // min 500ms, max 1h
|
|
162
163
|
output.writeln(output.highlight(`Watching progress (interval: ${interval}ms). Press Ctrl+C to stop.`));
|
|
163
164
|
output.writeln();
|
|
164
165
|
let lastProgress = 0;
|
|
@@ -180,8 +181,9 @@ const watchCommand = {
|
|
|
180
181
|
};
|
|
181
182
|
await check();
|
|
182
183
|
const timer = setInterval(check, interval);
|
|
183
|
-
// Handle Ctrl+C
|
|
184
|
-
|
|
184
|
+
// Handle Ctrl+C — use once so repeated calls don't accumulate SIGINT handlers
|
|
185
|
+
// (which would trigger MaxListenersExceededWarning and a memory leak).
|
|
186
|
+
process.once('SIGINT', () => {
|
|
185
187
|
clearInterval(timer);
|
|
186
188
|
output.writeln();
|
|
187
189
|
output.writeln(output.dim('Stopped watching.'));
|
|
@@ -59,10 +59,10 @@ const configureCommand = {
|
|
|
59
59
|
],
|
|
60
60
|
action: async (ctx) => {
|
|
61
61
|
try {
|
|
62
|
-
const provider = ctx.flags.provider || (ctx.args && ctx.args[0]) || '';
|
|
63
|
-
const apiKey = ctx.flags.key;
|
|
64
|
-
const model = ctx.flags.model;
|
|
65
|
-
const endpoint = ctx.flags.endpoint;
|
|
62
|
+
const provider = (ctx.flags.provider || (ctx.args && ctx.args[0]) || '').slice(0, 64);
|
|
63
|
+
const apiKey = ctx.flags.key?.slice(0, 256);
|
|
64
|
+
const model = ctx.flags.model?.slice(0, 128);
|
|
65
|
+
const endpoint = ctx.flags.endpoint?.slice(0, 512);
|
|
66
66
|
if (!provider) {
|
|
67
67
|
output.printError('Provider name is required. Use -p <name> or pass as first argument.');
|
|
68
68
|
return { success: false, exitCode: 1 };
|
|
@@ -127,7 +127,7 @@ const testCommand = {
|
|
|
127
127
|
],
|
|
128
128
|
action: async (ctx) => {
|
|
129
129
|
try {
|
|
130
|
-
const provider = ctx.flags.provider || (ctx.args && ctx.args[0]) || '';
|
|
130
|
+
const provider = (ctx.flags.provider || (ctx.args && ctx.args[0]) || '').slice(0, 64);
|
|
131
131
|
const testAll = ctx.flags.all;
|
|
132
132
|
output.writeln();
|
|
133
133
|
output.writeln(output.bold('Provider Connectivity Test'));
|
|
@@ -10,7 +10,8 @@ const showSubcommand = {
|
|
|
10
10
|
{ name: 'json', type: 'boolean', description: 'Output as JSON', default: false },
|
|
11
11
|
],
|
|
12
12
|
action: async (ctx) => {
|
|
13
|
-
|
|
13
|
+
// Cap session ID to prevent DoS via oversized string and unbounded output reflection.
|
|
14
|
+
const sessionId = (ctx.args[0] || '').slice(0, 128);
|
|
14
15
|
if (!sessionId) {
|
|
15
16
|
output.error('Session ID is required: replay show <sessionId>');
|
|
16
17
|
return { success: false, message: 'Missing session ID' };
|
|
@@ -40,7 +41,12 @@ const listSubcommand = {
|
|
|
40
41
|
try {
|
|
41
42
|
const { ReplayReader } = await import('../observability/replay-reader.js');
|
|
42
43
|
const reader = new ReplayReader();
|
|
43
|
-
const
|
|
44
|
+
const rawLimit = ctx.flags['limit'];
|
|
45
|
+
// Cap limit to prevent DoS
|
|
46
|
+
const limit = typeof rawLimit === 'number' && Number.isFinite(rawLimit)
|
|
47
|
+
? Math.max(1, Math.min(Math.floor(rawLimit), 500))
|
|
48
|
+
: 20;
|
|
49
|
+
const data = await reader.list(limit);
|
|
44
50
|
const asJson = ctx.flags['json'];
|
|
45
51
|
output.writeln(asJson ? JSON.stringify(data, null, 2) : 'Available replays listed');
|
|
46
52
|
return { success: true, data };
|
|
@@ -90,15 +90,20 @@ const routeTaskCommand = {
|
|
|
90
90
|
{ command: 'monomind route task "review code" --agent reviewer', description: 'Force specific agent' },
|
|
91
91
|
],
|
|
92
92
|
action: async (ctx) => {
|
|
93
|
-
const
|
|
93
|
+
const rawTask = ctx.args[0];
|
|
94
94
|
const forceAgent = ctx.flags.agent;
|
|
95
95
|
const useExploration = ctx.flags.explore;
|
|
96
96
|
const jsonOutput = ctx.flags.json;
|
|
97
|
-
if (!
|
|
97
|
+
if (!rawTask) {
|
|
98
98
|
output.printError('Task description is required');
|
|
99
99
|
output.writeln(output.dim('Usage: monomind route task "task description"'));
|
|
100
100
|
return { success: false, exitCode: 1 };
|
|
101
101
|
}
|
|
102
|
+
if (rawTask.length > 4096) {
|
|
103
|
+
output.printError('Task description too long (max 4096 characters)');
|
|
104
|
+
return { success: false, exitCode: 1 };
|
|
105
|
+
}
|
|
106
|
+
const taskDescription = rawTask;
|
|
102
107
|
const spinner = output.createSpinner({ text: 'Analyzing task...', spinner: 'dots' });
|
|
103
108
|
spinner.start();
|
|
104
109
|
try {
|
|
@@ -349,14 +354,24 @@ const feedbackCommand = {
|
|
|
349
354
|
{ command: 'monomind route feedback -t "write tests" -a tester -r -0.5', description: 'Negative feedback' },
|
|
350
355
|
],
|
|
351
356
|
action: async (ctx) => {
|
|
352
|
-
const
|
|
357
|
+
const rawFeedbackTask = ctx.flags.task;
|
|
353
358
|
const agentId = ctx.flags.agent;
|
|
354
359
|
const reward = ctx.flags.reward;
|
|
355
|
-
const
|
|
356
|
-
if (!
|
|
360
|
+
const rawNextTask = ctx.flags['next-task'];
|
|
361
|
+
if (!rawFeedbackTask || !agentId) {
|
|
357
362
|
output.printError('Task description and agent are required');
|
|
358
363
|
return { success: false, exitCode: 1 };
|
|
359
364
|
}
|
|
365
|
+
if (rawFeedbackTask.length > 4096) {
|
|
366
|
+
output.printError('Task description too long (max 4096 characters)');
|
|
367
|
+
return { success: false, exitCode: 1 };
|
|
368
|
+
}
|
|
369
|
+
if (agentId.length > 128) {
|
|
370
|
+
output.printError('Agent ID too long (max 128 characters)');
|
|
371
|
+
return { success: false, exitCode: 1 };
|
|
372
|
+
}
|
|
373
|
+
const taskDescription = rawFeedbackTask;
|
|
374
|
+
const nextTask = rawNextTask && rawNextTask.length > 4096 ? undefined : rawNextTask;
|
|
360
375
|
// Validate agent
|
|
361
376
|
const agent = getAgentType(agentId);
|
|
362
377
|
if (!agent) {
|
|
@@ -776,13 +791,18 @@ const semanticRouteCommand = {
|
|
|
776
791
|
{ command: 'monomind route semantic -t "write unit tests" --debug', description: 'Show all route scores' },
|
|
777
792
|
],
|
|
778
793
|
action: async (ctx) => {
|
|
779
|
-
const
|
|
794
|
+
const rawSemanticTask = ctx.flags.task;
|
|
780
795
|
const debug = ctx.flags.debug;
|
|
781
796
|
const jsonOutput = ctx.flags.json;
|
|
782
|
-
if (!
|
|
797
|
+
if (!rawSemanticTask) {
|
|
783
798
|
output.printError('Task description is required. Use --task or -t flag.');
|
|
784
799
|
return { success: false, exitCode: 1 };
|
|
785
800
|
}
|
|
801
|
+
if (rawSemanticTask.length > 4096) {
|
|
802
|
+
output.printError('Task description too long (max 4096 characters)');
|
|
803
|
+
return { success: false, exitCode: 1 };
|
|
804
|
+
}
|
|
805
|
+
const taskDescription = rawSemanticTask;
|
|
786
806
|
const spinner = output.createSpinner({ text: 'Computing semantic route...', spinner: 'dots' });
|
|
787
807
|
spinner.start();
|
|
788
808
|
try {
|