crewboss 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +633 -2
- package/bin/crewboss.js +14 -0
- package/package.json +43 -4
- package/src/agent.js +179 -0
- package/src/candidates.js +66 -0
- package/src/cli.js +531 -0
- package/src/collect.js +26 -0
- package/src/config.js +384 -0
- package/src/due.js +10 -0
- package/src/errors.js +47 -0
- package/src/events.js +243 -0
- package/src/fsutil.js +37 -0
- package/src/init.js +174 -0
- package/src/label.js +4 -0
- package/src/launchd.js +243 -0
- package/src/lock.js +62 -0
- package/src/mcp.js +293 -0
- package/src/memory.js +81 -0
- package/src/mods.js +354 -0
- package/src/node-command.js +34 -0
- package/src/personas.js +154 -0
- package/src/plugin.js +43 -0
- package/src/presence.js +160 -0
- package/src/process.js +37 -0
- package/src/quota.js +34 -0
- package/src/routines.js +401 -0
- package/src/rundir.js +43 -0
- package/src/runners/agy.js +26 -0
- package/src/runners/claude.js +39 -0
- package/src/runners/codex.js +26 -0
- package/src/runners/index.js +186 -0
- package/src/runners/opencode.js +28 -0
- package/src/schedule.js +21 -0
- package/src/server.js +773 -0
- package/src/session.js +40 -0
- package/src/store.js +615 -0
- package/src/task-schedule.js +6 -0
- package/src/task-time.js +30 -0
- package/src/tasks.js +129 -0
- package/src/trackers/command.js +126 -0
- package/src/trackers/file.js +160 -0
- package/src/trackers/index.js +16 -0
- package/src/trackers/local.js +57 -0
- package/src/units.js +117 -0
- package/src/warnings.js +19 -0
package/bin/crewboss.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { silenceSqliteExperimentalWarning } from '../src/warnings.js';
|
|
3
|
+
|
|
4
|
+
// A closed pipe (`crewboss … | head -1`) is not an error: stop quietly. Any other stdout error is rethrown.
|
|
5
|
+
process.stdout.on('error', (error) => {
|
|
6
|
+
if (error.code === 'EPIPE') process.exit(0);
|
|
7
|
+
throw error;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Before node:sqlite is loaded (through the CLI), so its ExperimentalWarning is dropped.
|
|
11
|
+
silenceSqliteExperimentalWarning();
|
|
12
|
+
const { main } = await import('../src/cli.js');
|
|
13
|
+
|
|
14
|
+
process.exitCode = await main(process.argv.slice(2));
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crewboss",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Run AI coding agents (Claude Code, Codex, agy, opencode) with personas, model tiers and fallback, and schedule routines that report findings to a task tracker",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"crewboss",
|
|
7
|
+
"ai",
|
|
8
|
+
"agents",
|
|
9
|
+
"claude",
|
|
10
|
+
"codex",
|
|
11
|
+
"opencode",
|
|
12
|
+
"cli",
|
|
13
|
+
"orchestrator",
|
|
14
|
+
"systemd",
|
|
15
|
+
"routines"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/PabloTheBlink/crewboss"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/PabloTheBlink/crewboss",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/PabloTheBlink/crewboss/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"bin": {
|
|
28
|
+
"crewboss": "bin/crewboss.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"bin",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22.13"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"provenance": true
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "node --test",
|
|
43
|
+
"prepublishOnly": "node --test"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/agent.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/** The `agent` command: launch one persona on one task and keep a trace of the run. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { formatCandidateLabel, parseModelArg, selectCandidates } from './candidates.js';
|
|
6
|
+
import { TIER_SIZES } from './config.js';
|
|
7
|
+
import {
|
|
8
|
+
assertCommunicationAllowed, communicationSection, NOTIFY_ENV, recordFinished, recordStarted, runEnv,
|
|
9
|
+
} from './events.js';
|
|
10
|
+
import { isDir, isFile, writeJson } from './fsutil.js';
|
|
11
|
+
import { agentScopes, memorySection } from './memory.js';
|
|
12
|
+
import { buildPrompt, loadConfiguredPersona, PERSONA_MODES } from './personas.js';
|
|
13
|
+
import { makeQuotaChecker } from './quota.js';
|
|
14
|
+
import { newRunDir } from './rundir.js';
|
|
15
|
+
import * as runners from './runners/index.js';
|
|
16
|
+
import { openStore } from './store.js';
|
|
17
|
+
|
|
18
|
+
function printSkipped(stderr, header, skipped) {
|
|
19
|
+
stderr.write(`${header}\n`);
|
|
20
|
+
for (const item of skipped) stderr.write(` - ${formatCandidateLabel(item.candidate)}: ${item.reason}\n`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Quote an argument for display only (the command is never run through a shell). */
|
|
24
|
+
const shellQuote = (arg) => (/^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`);
|
|
25
|
+
|
|
26
|
+
const reasonsOf = (skipped) => skipped.map((s) => `${formatCandidateLabel(s.candidate)}: ${s.reason}`).join('; ');
|
|
27
|
+
const skippedLine = (item) => {
|
|
28
|
+
const reason = item.reason === 'paid model not allowed without --allow-paid' ? 'paid; use --allow-paid' : item.reason;
|
|
29
|
+
return `Skipped: ${formatCandidateLabel(item.candidate)} (${reason})\n`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Load the persona, choose candidates (paid filter, quota), launch in the persona's mode
|
|
34
|
+
* (write by default; `mode` overrides it) with
|
|
35
|
+
* fallback within the tier, and write prompt.txt, agent.log, answer.md and choice.json.
|
|
36
|
+
* A forced --model is never retried. Every invocation is recorded in the local history.
|
|
37
|
+
* Resolves with the exit code.
|
|
38
|
+
*/
|
|
39
|
+
export async function runAgent(config, personaName, task, {
|
|
40
|
+
size = null,
|
|
41
|
+
mode = null,
|
|
42
|
+
model = null,
|
|
43
|
+
dir = null,
|
|
44
|
+
allowPaid = false,
|
|
45
|
+
dryRun = false,
|
|
46
|
+
runId = null,
|
|
47
|
+
attachment = null,
|
|
48
|
+
notify = process.env[NOTIFY_ENV] || null,
|
|
49
|
+
notifySource = null,
|
|
50
|
+
launch = runners.launch,
|
|
51
|
+
quota = undefined,
|
|
52
|
+
clock = undefined,
|
|
53
|
+
store = undefined,
|
|
54
|
+
stdout = process.stdout,
|
|
55
|
+
stderr = process.stderr,
|
|
56
|
+
} = {}) {
|
|
57
|
+
const persona = loadConfiguredPersona(config, personaName);
|
|
58
|
+
const workDir = path.resolve(config.root, dir || persona.dir);
|
|
59
|
+
if (!isDir(workDir)) throw new Error(`working directory not found: ${workDir}`);
|
|
60
|
+
const runMode = mode || persona.mode;
|
|
61
|
+
if (!PERSONA_MODES.includes(runMode)) throw new Error(`invalid mode: '${runMode}'`);
|
|
62
|
+
const tier = size || persona.size;
|
|
63
|
+
if (!TIER_SIZES.includes(tier)) throw new Error(`invalid size: '${tier}'`);
|
|
64
|
+
if (attachment && !isFile(attachment)) throw new Error(`attachment not found: ${attachment}`);
|
|
65
|
+
const forced = model ? parseModelArg(model) : null;
|
|
66
|
+
|
|
67
|
+
const history = store ?? openStore(config.root);
|
|
68
|
+
try {
|
|
69
|
+
const check = quota === undefined ? makeQuotaChecker(config.quota, config.root) : quota;
|
|
70
|
+
const { usable, skipped } = await selectCandidates(tier, config.tiers, {
|
|
71
|
+
allowPaid, forced, quota: check, warn: (message) => stderr.write(`${message}\n`),
|
|
72
|
+
});
|
|
73
|
+
if (!usable.length) {
|
|
74
|
+
const id = runId === null
|
|
75
|
+
? history.startRun({ kind: 'agent', name: persona.name, dryRun, workDir, notify })
|
|
76
|
+
: history.claimAgentRun(runId, persona.name, { dryRun, workDir, notify });
|
|
77
|
+
history.finishRun(id, { status: 'skipped', exitCode: 1, summary: `No usable agent candidate: ${reasonsOf(skipped)}` });
|
|
78
|
+
recordFinished(history, id);
|
|
79
|
+
printSkipped(stderr, `No usable agent candidate in tier '${tier}':`, skipped);
|
|
80
|
+
return 1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const runDir = newRunDir(path.join(config.logsDir, 'agents', persona.name));
|
|
84
|
+
const id = runId === null
|
|
85
|
+
? history.startRun({ kind: 'agent', name: persona.name, dryRun, logDir: runDir, workDir, notify })
|
|
86
|
+
: history.claimAgentRun(runId, persona.name, { dryRun, logDir: runDir, workDir, notify });
|
|
87
|
+
const memory = memorySection(history, agentScopes(persona.name), config.memoryMaxBytes);
|
|
88
|
+
const communication = communicationSection(config.preamble, { notify, claude: usable[0].tool === 'claude' });
|
|
89
|
+
let prompt = buildPrompt(persona, task, config.root, config.preamble, memory, communication);
|
|
90
|
+
if (attachment) prompt += `\n# Attachment\n\nRead the attached context file: ${attachment}\n`;
|
|
91
|
+
const promptPath = path.join(runDir, 'prompt.txt');
|
|
92
|
+
fs.writeFileSync(promptPath, prompt, 'utf8');
|
|
93
|
+
const choiceFile = path.join(runDir, 'choice.json');
|
|
94
|
+
const base = { tier, mode: runMode, forced: forced !== null };
|
|
95
|
+
const toolLists = { allowedTools: persona.allowedTools, disallowedTools: persona.disallowedTools, notify };
|
|
96
|
+
if (usable.some((c) => c.tool === 'claude')) {
|
|
97
|
+
try {
|
|
98
|
+
assertCommunicationAllowed(persona.disallowedTools, `persona '${persona.name}' disallowed_tools`);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
history.finishRun(id, { status: 'error', exitCode: 1, summary: err.message });
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Close the run in the history and tell the channel (not for dry runs, which launch nothing). */
|
|
105
|
+
const finish = (fields, answerPath = null) => {
|
|
106
|
+
history.finishRun(id, fields);
|
|
107
|
+
recordFinished(history, id, { answerPath });
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
if (dryRun) {
|
|
111
|
+
writeJson(choiceFile, { ...base, chosen: usable[0], skipped, dry_run: true });
|
|
112
|
+
history.finishRun(id, { status: 'ok', tool: usable[0].tool, model: usable[0].model, exitCode: 0, summary: 'dry run' });
|
|
113
|
+
const command = runners.buildCommand(usable[0], '<prompt>', { runDir, workDir, mode: runMode, attachment, ...toolLists });
|
|
114
|
+
for (const item of skipped) stdout.write(skippedLine(item));
|
|
115
|
+
stdout.write(`Choice: ${formatCandidateLabel(usable[0])} (tier: ${tier})\n`);
|
|
116
|
+
stdout.write(`Mode: ${runMode}\n`);
|
|
117
|
+
if (notify) stdout.write(`Notify: ${notify}${notifySource ? ` (from ${notifySource})` : ''}\n`);
|
|
118
|
+
stdout.write(`Prompt: ${promptPath}\n`);
|
|
119
|
+
stdout.write(`Command: ${command.map(shellQuote).join(' ')}\n`);
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
recordStarted(history, id, task);
|
|
124
|
+
for (const item of skipped) stderr.write(skippedLine(item));
|
|
125
|
+
let result;
|
|
126
|
+
try {
|
|
127
|
+
result = await runners.launchWithFallback(usable, prompt, runDir, workDir, {
|
|
128
|
+
mode: runMode,
|
|
129
|
+
attachment,
|
|
130
|
+
...toolLists,
|
|
131
|
+
env: runEnv(id, config),
|
|
132
|
+
checkStartup: !forced,
|
|
133
|
+
launcher: launch,
|
|
134
|
+
clock,
|
|
135
|
+
stdout,
|
|
136
|
+
stderr,
|
|
137
|
+
});
|
|
138
|
+
} catch (err) {
|
|
139
|
+
finish({ status: 'error', exitCode: 1, summary: err.message });
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
const allSkipped = [...skipped, ...result.skipped];
|
|
143
|
+
|
|
144
|
+
if (!result.chosen) {
|
|
145
|
+
writeJson(choiceFile, { ...base, chosen: null, skipped: allSkipped, exit_code: 1 });
|
|
146
|
+
finish({ status: 'error', exitCode: 1, summary: `No usable agent candidate left: ${reasonsOf(allSkipped)}` });
|
|
147
|
+
printSkipped(stderr, `No usable agent candidate left in tier '${tier}':`, allSkipped);
|
|
148
|
+
return 1;
|
|
149
|
+
}
|
|
150
|
+
let exitCode;
|
|
151
|
+
let summary = '';
|
|
152
|
+
if (result.error) {
|
|
153
|
+
stderr.write(`agent launch failed: ${result.error.message}\n`);
|
|
154
|
+
exitCode = 1;
|
|
155
|
+
summary = result.error.message;
|
|
156
|
+
} else {
|
|
157
|
+
exitCode = result.proc.returncode;
|
|
158
|
+
}
|
|
159
|
+
writeJson(choiceFile, {
|
|
160
|
+
...base,
|
|
161
|
+
chosen: result.chosen,
|
|
162
|
+
skipped: allSkipped,
|
|
163
|
+
start_time: result.startTime,
|
|
164
|
+
end_time: result.endTime,
|
|
165
|
+
exit_code: exitCode,
|
|
166
|
+
});
|
|
167
|
+
finish({
|
|
168
|
+
status: exitCode === 0 ? 'ok' : 'error',
|
|
169
|
+
tool: result.chosen.tool,
|
|
170
|
+
model: result.chosen.model,
|
|
171
|
+
exitCode,
|
|
172
|
+
summary: summary || (exitCode === 0 ? '' : `agent exited ${exitCode}`),
|
|
173
|
+
}, path.join(runDir, 'answer.md'));
|
|
174
|
+
stdout.write(`Answer: ${path.join(runDir, 'answer.md')}\n`);
|
|
175
|
+
return exitCode;
|
|
176
|
+
} finally {
|
|
177
|
+
if (!store) history.close();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Choose which tool:model candidates to try for a run. */
|
|
2
|
+
import { EFFORTS, validModel } from './config.js';
|
|
3
|
+
import { formatCandidateLabel } from './label.js';
|
|
4
|
+
import { quotaReason } from './quota.js';
|
|
5
|
+
import { TOOLS } from './runners/index.js';
|
|
6
|
+
|
|
7
|
+
export { formatCandidateLabel };
|
|
8
|
+
|
|
9
|
+
/** Parse `<tool>:<model>[@effort]` into a candidate. */
|
|
10
|
+
export function parseModelArg(arg) {
|
|
11
|
+
const colon = arg.indexOf(':');
|
|
12
|
+
if (colon === -1) throw new Error(`invalid --model format '${arg}', expected <tool>:<model>[@effort]`);
|
|
13
|
+
const tool = arg.slice(0, colon).trim();
|
|
14
|
+
const rest = arg.slice(colon + 1);
|
|
15
|
+
if (!TOOLS.has(tool)) {
|
|
16
|
+
throw new Error(`invalid tool '${tool}' in --model, expected one of ${[...TOOLS].sort().join(', ')}`);
|
|
17
|
+
}
|
|
18
|
+
let model = rest.trim();
|
|
19
|
+
let effort = null;
|
|
20
|
+
const at = rest.lastIndexOf('@');
|
|
21
|
+
if (at !== -1) {
|
|
22
|
+
model = rest.slice(0, at).trim();
|
|
23
|
+
effort = rest.slice(at + 1).trim();
|
|
24
|
+
if (!EFFORTS.includes(effort)) {
|
|
25
|
+
throw new Error(`invalid effort '${effort}' in --model, expected one of ${EFFORTS.join(', ')}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!validModel(model)) throw new Error(`invalid model '${model}' in --model`);
|
|
29
|
+
const candidate = { tool, model, paid: false };
|
|
30
|
+
if (effort) candidate.effort = effort;
|
|
31
|
+
return candidate;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Usable candidates in tier order, plus the skipped ones with their reason. Paid
|
|
36
|
+
* candidates need allowPaid; `quota` (see makeQuotaChecker) may skip any candidate.
|
|
37
|
+
* A forced candidate is always used: its quota is only reported through `warn`.
|
|
38
|
+
*/
|
|
39
|
+
export async function selectCandidates(size, tiers, {
|
|
40
|
+
allowPaid = false,
|
|
41
|
+
forced = null,
|
|
42
|
+
quota = null,
|
|
43
|
+
warn = (message) => process.stderr.write(`${message}\n`),
|
|
44
|
+
} = {}) {
|
|
45
|
+
if (forced) {
|
|
46
|
+
const reason = await quotaReason(quota, forced);
|
|
47
|
+
if (reason) warn(`warning: ${reason} for ${formatCandidateLabel(forced)}`);
|
|
48
|
+
return { usable: [forced], skipped: [] };
|
|
49
|
+
}
|
|
50
|
+
if (!(size in tiers)) throw new Error(`unknown tier size: '${size}'`);
|
|
51
|
+
const usable = [];
|
|
52
|
+
const skipped = [];
|
|
53
|
+
for (const candidate of tiers[size]) {
|
|
54
|
+
if (candidate.paid && !allowPaid) {
|
|
55
|
+
skipped.push({ candidate, reason: 'paid model not allowed without --allow-paid' });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const reason = await quotaReason(quota, candidate);
|
|
59
|
+
if (reason) {
|
|
60
|
+
skipped.push({ candidate, reason });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
usable.push(candidate);
|
|
64
|
+
}
|
|
65
|
+
return { usable, skipped };
|
|
66
|
+
}
|