robisie 0.1.0 → 0.1.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/CHANGELOG.md +79 -0
- package/README.md +109 -14
- package/dist/active-recovery.d.ts +58 -0
- package/dist/active-recovery.js +143 -0
- package/dist/agents.d.ts +34 -0
- package/dist/agents.js +77 -16
- package/dist/attempt-identity.d.ts +21 -0
- package/dist/attempt-identity.js +39 -0
- package/dist/ci-failure-result.d.ts +23 -0
- package/dist/ci-failure-result.js +90 -0
- package/dist/claude-headless.d.ts +7 -0
- package/dist/claude-headless.js +28 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.js +54 -14
- package/dist/commands.d.ts +18 -0
- package/dist/commands.js +195 -88
- package/dist/constants.d.ts +32 -0
- package/dist/constants.js +3 -3
- package/dist/context.d.ts +24 -0
- package/dist/context.js +22 -6
- package/dist/dependency-readiness.d.ts +13 -0
- package/dist/dependency-readiness.js +80 -0
- package/dist/dispatch-scope.d.ts +18 -0
- package/dist/dispatch-scope.js +46 -0
- package/dist/done-evidence.d.ts +31 -0
- package/dist/done-evidence.js +216 -0
- package/dist/engine-config.d.ts +65 -0
- package/dist/engine-config.js +139 -0
- package/dist/fsops.d.ts +87 -0
- package/dist/fsops.js +117 -24
- package/dist/helpers.d.ts +15 -0
- package/dist/helpers.js +268 -45
- package/dist/intent-rules/admission.d.ts +10 -0
- package/dist/intent-rules/admission.js +35 -0
- package/dist/intent-rules/done-when-roles.d.ts +21 -0
- package/dist/intent-rules/done-when-roles.js +101 -0
- package/dist/intent-rules/hooks.d.ts +29 -0
- package/dist/intent-rules/hooks.js +23 -0
- package/dist/k3-codex-role.d.ts +20 -0
- package/dist/k3-codex-role.js +68 -0
- package/dist/manifest.d.ts +41 -0
- package/dist/manifest.js +59 -14
- package/dist/mcp.d.ts +18 -0
- package/dist/mcp.js +117 -40
- package/dist/opencode-result.d.ts +19 -0
- package/dist/opencode-result.js +136 -0
- package/dist/opencode-review-guard.d.ts +1 -0
- package/dist/opencode-review-guard.js +19 -0
- package/dist/opencode-session-export.d.ts +5 -0
- package/dist/opencode-session-export.js +28 -0
- package/dist/outcome-moves.d.ts +15 -0
- package/dist/outcome-moves.js +39 -0
- package/dist/planer-client.d.ts +214 -0
- package/dist/planer-client.js +351 -0
- package/dist/restart-recovery.d.ts +47 -0
- package/dist/restart-recovery.js +70 -0
- package/dist/review-source-packet.d.ts +17 -0
- package/dist/review-source-packet.js +44 -0
- package/dist/role-registry.d.ts +25 -0
- package/dist/role-registry.js +91 -0
- package/dist/role-results.d.ts +15 -0
- package/dist/role-results.js +42 -0
- package/dist/roles.d.ts +30 -0
- package/dist/roles.js +20 -16
- package/dist/seed-validation.d.ts +28 -0
- package/dist/seed-validation.js +294 -0
- package/dist/selection-result.d.ts +44 -0
- package/dist/selection-result.js +144 -0
- package/dist/sparse-policy.d.ts +8 -0
- package/dist/sparse-policy.js +49 -0
- package/dist/tester-identity.d.ts +11 -0
- package/dist/tester-identity.js +53 -0
- package/dist/worker-env.d.ts +5 -0
- package/dist/worker-env.js +34 -0
- package/docs/ENGINE-API.md +88 -0
- package/docs/ENGINE-CONFIG.md +113 -0
- package/docs/README.en.md +142 -20
- package/docs/README.md +144 -20
- package/docs/RELEASE-0.1.0.md +81 -8
- package/docs/RELEASE-0.1.1.md +110 -0
- package/helpers/ceo-client-launcher-mcp.mjs +36 -8
- package/helpers/client-spawn-session.sh +181 -0
- package/helpers/client-spawn.sh +825 -0
- package/package.json +9 -4
- package/roles/ceo-client.md +3 -2
- package/roles/manager-builder-client.md +18 -4
- package/roles/quality-officer-client.md +20 -6
package/dist/agents.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { accessSync, constants, existsSync, statSync } from "node:fs";
|
|
2
|
-
import { delimiter, join } from "node:path";
|
|
2
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
3
3
|
import { HELPER_ENV, HELPER_SERVERS, KEY_ENV, MCP_SERVER_NAME, helperCommand, mcpUrl } from "./constants.js";
|
|
4
|
-
import { RobisieError } from "./context.js";
|
|
4
|
+
import { RobisieError, shellQuote } from "./context.js";
|
|
5
|
+
import { freeCopyPath } from "./fsops.js";
|
|
6
|
+
import { OPENCODE_REVIEW_GUARD } from "./opencode-review-guard.js";
|
|
5
7
|
import { renderClaudeAgent, renderCodexRole, renderOpenCodeAgent } from "./roles.js";
|
|
6
8
|
export const AGENT_IDS = ["claude", "codex", "opencode"];
|
|
7
9
|
export const AGENT_LABELS = { claude: "Claude Code", codex: "Codex CLI", opencode: "OpenCode" };
|
|
@@ -9,10 +11,17 @@ const BINARIES = { claude: "claude", codex: "codex", opencode: "opencode" };
|
|
|
9
11
|
export function isAgentId(value) {
|
|
10
12
|
return AGENT_IDS.includes(value);
|
|
11
13
|
}
|
|
14
|
+
function configRoot(ctx, name, fallback) {
|
|
15
|
+
const value = ctx.env[name];
|
|
16
|
+
if (value && !isAbsolute(value)) {
|
|
17
|
+
throw new RobisieError(`${name} musi wskazywać katalog ścieżką absolutną.`, `Ustaw ${name} na ścieżkę absolutną albo wykonaj \`unset ${name}\` i ponów polecenie.`);
|
|
18
|
+
}
|
|
19
|
+
return value || fallback;
|
|
20
|
+
}
|
|
12
21
|
/** Where each agent keeps its user-level configuration (the same places the agents themselves read). */
|
|
13
22
|
export function agentPaths(ctx) {
|
|
14
|
-
const codexHome = ctx
|
|
15
|
-
const configHome = ctx
|
|
23
|
+
const codexHome = configRoot(ctx, "CODEX_HOME", join(ctx.home, ".codex"));
|
|
24
|
+
const configHome = configRoot(ctx, "XDG_CONFIG_HOME", join(ctx.home, ".config"));
|
|
16
25
|
const opencodeDir = join(configHome, "opencode");
|
|
17
26
|
return {
|
|
18
27
|
// The package's own directory. Never ~/.robisie: on the owner's machine that belongs to the factory.
|
|
@@ -54,15 +63,27 @@ export function detectAgents(ctx) {
|
|
|
54
63
|
const dirs = { claude: paths.claudeDir, codex: paths.codexHome, opencode: paths.opencodeDir };
|
|
55
64
|
return AGENT_IDS.filter((id) => existsSync(dirs[id]) || agentOnPath(ctx, id));
|
|
56
65
|
}
|
|
66
|
+
const CODEX_TRUSTED_TOOLS = [
|
|
67
|
+
"append_detail",
|
|
68
|
+
"create_task",
|
|
69
|
+
"create_track",
|
|
70
|
+
"get_board",
|
|
71
|
+
"get_task",
|
|
72
|
+
"list_projects",
|
|
73
|
+
"list_tasks",
|
|
74
|
+
"move_task",
|
|
75
|
+
"reserve_task",
|
|
76
|
+
"update_task",
|
|
77
|
+
];
|
|
57
78
|
/** Every server name init writes into `[mcp_servers]`. */
|
|
58
79
|
const CODEX_SERVERS = [MCP_SERVER_NAME, ...HELPER_SERVERS].map((name) => name.replace(/[-]/g, "\\-")).join("|");
|
|
59
|
-
const CODEX_SERVER_KEY = `(?:"(
|
|
80
|
+
const CODEX_SERVER_KEY = `(?:"(${CODEX_SERVERS})"|'(${CODEX_SERVERS})'|(${CODEX_SERVERS}))`;
|
|
60
81
|
const TOML_ROBISIE_HEADER = new RegExp(`^\\s*\\[\\s*mcp_servers\\s*\\.\\s*${CODEX_SERVER_KEY}\\s*(?:\\.[^\\]]*)?\\]\\s*(?:#.*)?$`, "m");
|
|
61
82
|
const TOML_ANY_HEADER = /^\s*\[/;
|
|
62
83
|
const INLINE_TOP = new RegExp(`^\\s*mcp_servers\\s*\\.\\s*${CODEX_SERVER_KEY}\\s*[.=]`);
|
|
63
84
|
const INLINE_IN_TABLE = new RegExp(`^\\s*${CODEX_SERVER_KEY}\\s*[.=]`);
|
|
64
85
|
/** Keep a multiline string or array in its assignment, so its contents cannot look like server headers. */
|
|
65
|
-
function tomlStatements(text) {
|
|
86
|
+
export function tomlStatements(text) {
|
|
66
87
|
const lines = [];
|
|
67
88
|
let start = 0;
|
|
68
89
|
let depth = 0;
|
|
@@ -85,25 +106,43 @@ function tomlStatements(text) {
|
|
|
85
106
|
* Take over an `[mcp_servers.robisie]` table written earlier by hand or by `codex mcp add` (otherwise
|
|
86
107
|
* Codex would see the table twice and refuse the whole config). Backups retain the old configuration.
|
|
87
108
|
*/
|
|
88
|
-
export function removeCodexTables(text, removeInline = false) {
|
|
109
|
+
export function removeCodexTables(text, removeInline = false, codexHome) {
|
|
89
110
|
const lines = tomlStatements(text);
|
|
90
111
|
const kept = [];
|
|
91
112
|
let inRobisie = false;
|
|
113
|
+
let trailingComments = "";
|
|
92
114
|
let table = "";
|
|
115
|
+
const conflicts = new Set();
|
|
93
116
|
for (const line of lines) {
|
|
117
|
+
if (inRobisie && /^\s*(?:#[^\r\n]*)?\s*$/.test(line)) {
|
|
118
|
+
trailingComments += line;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
94
121
|
const header = /^\s*\[\s*([^\]]*?)\s*\]/.exec(line);
|
|
95
122
|
if (header)
|
|
96
123
|
table = (header[1] ?? "").replace(/\s+/g, "");
|
|
97
|
-
if (TOML_ANY_HEADER.test(line))
|
|
124
|
+
if (TOML_ANY_HEADER.test(line)) {
|
|
125
|
+
// Comments immediately before a foreign header belong to that preserved fragment.
|
|
126
|
+
if (inRobisie && !TOML_ROBISIE_HEADER.test(line))
|
|
127
|
+
kept.push(trailingComments);
|
|
98
128
|
inRobisie = TOML_ROBISIE_HEADER.test(line);
|
|
129
|
+
}
|
|
130
|
+
trailingComments = "";
|
|
99
131
|
if (inRobisie)
|
|
100
132
|
continue;
|
|
101
|
-
const inline =
|
|
133
|
+
const inline = table === "" ? INLINE_TOP.exec(line) : table === "mcp_servers" ? INLINE_IN_TABLE.exec(line) : null;
|
|
102
134
|
if (!inline)
|
|
103
135
|
kept.push(line);
|
|
104
|
-
else
|
|
105
|
-
|
|
106
|
-
|
|
136
|
+
else
|
|
137
|
+
conflicts.add(inline[1] ?? inline[2] ?? inline[3]);
|
|
138
|
+
}
|
|
139
|
+
if (conflicts.size && !removeInline) {
|
|
140
|
+
const config = codexHome ? join(codexHome, "config.toml") : "config.toml";
|
|
141
|
+
const profile = codexHome ? `CODEX_HOME=${shellQuote(codexHome)} ` : "";
|
|
142
|
+
const copy = codexHome
|
|
143
|
+
? `Zachowaj oryginał bez nadpisania wcześniejszej kopii: \`cp -p -n -- ${shellQuote(config)} ${shellQuote(freeCopyPath(config))}\`. Sprawdź, że kopia powstała i zawiera oryginalne bajty; dopiero wtedy kontynuuj. `
|
|
144
|
+
: "Zachowaj własną kopię config.toml. ";
|
|
145
|
+
throw new RobisieError(`W ${config} są już serwery ${[...conflicts].join(", ")} zapisane w formie, której nie umiem bezpiecznie przejąć.`, `${copy}Uruchom kolejno ${[...conflicts].map((name) => `\`${profile}codex mcp remove ${name}\``).join(", ")}, potem \`${profile}npx robisie init --agent codex --no-shell\` i \`${profile}npx robisie doctor\`.`);
|
|
107
146
|
}
|
|
108
147
|
return kept.join("");
|
|
109
148
|
}
|
|
@@ -116,6 +155,7 @@ function codexHelperTable(name) {
|
|
|
116
155
|
// Codex passes only a small default environment to stdio servers; the helpers need these three.
|
|
117
156
|
`env_vars = [${HELPER_ENV.map((name) => JSON.stringify(name)).join(", ")}]`,
|
|
118
157
|
"startup_timeout_sec = 60",
|
|
158
|
+
'default_tools_approval_mode = "approve"',
|
|
119
159
|
].join("\n");
|
|
120
160
|
}
|
|
121
161
|
/** Every file change `init` makes for one agent. */
|
|
@@ -136,8 +176,16 @@ export function planAgent(ctx, id, roles, key) {
|
|
|
136
176
|
kind: "block",
|
|
137
177
|
path: paths.codexConfig,
|
|
138
178
|
comment: "hash",
|
|
139
|
-
body: [
|
|
140
|
-
|
|
179
|
+
body: [
|
|
180
|
+
[
|
|
181
|
+
`[mcp_servers.${MCP_SERVER_NAME}]`,
|
|
182
|
+
`url = "${url}"`,
|
|
183
|
+
`bearer_token_env_var = "${KEY_ENV}"`,
|
|
184
|
+
...CODEX_TRUSTED_TOOLS.map((name) => `tools.${name}.approval_mode = "approve"`),
|
|
185
|
+
].join("\n"),
|
|
186
|
+
...HELPER_SERVERS.map(codexHelperTable),
|
|
187
|
+
].join("\n\n"),
|
|
188
|
+
clean: (text) => removeCodexTables(text, false, paths.codexHome),
|
|
141
189
|
},
|
|
142
190
|
...roleFiles.map(({ role, path }) => ({ kind: "file", path, content: renderCodexRole(role, roleFiles.find((r) => r.role.kind === "builder")?.path) })),
|
|
143
191
|
{
|
|
@@ -157,7 +205,7 @@ export function planAgent(ctx, id, roles, key) {
|
|
|
157
205
|
];
|
|
158
206
|
}
|
|
159
207
|
if (existsSync(paths.opencodeJsonc) && !existsSync(paths.opencodeJson)) {
|
|
160
|
-
throw new RobisieError(`OpenCode używa pliku ${paths.opencodeJsonc} (z komentarzami), którego nie zmieniam automatycznie.`,
|
|
208
|
+
throw new RobisieError(`OpenCode używa pliku ${paths.opencodeJsonc} (z komentarzami), którego nie zmieniam automatycznie.`, "Sam wpis zdalnego MCP w JSONC nie instaluje ról ani pomocników. Zachowaj konfigurację; człowiek przygotowuje wspierany opencode.json bez komentarzy zgodnie z ustawieniami OpenCode albo wybiera innego zainstalowanego dostawcę dla wszystkich trzech ról. Po przygotowaniu JSON ponów init dla OpenCode. Dla zainstalowanego Claude Code uruchom `npx robisie init --agent claude --role ceo=claude --role builder=claude --role quality=claude`. Potem uruchom `npx robisie doctor`. Przewodnik: [sekcja init](node_modules/robisie/docs/README.md#połączenie-agenta).");
|
|
161
209
|
}
|
|
162
210
|
return [
|
|
163
211
|
{ kind: "json", path: paths.opencodeJson, keyPath: ["mcp", MCP_SERVER_NAME], value: { type: "remote", url, enabled: true, headers: { Authorization: `Bearer {env:${KEY_ENV}}` } }, private: false },
|
|
@@ -168,6 +216,7 @@ export function planAgent(ctx, id, roles, key) {
|
|
|
168
216
|
return { kind: "json", path: paths.opencodeJson, keyPath: ["mcp", name], value: { type: "local", command: [command, ...args], enabled: true, environment, timeout: 60_000 }, private: false };
|
|
169
217
|
}),
|
|
170
218
|
...roles.map((role) => ({ kind: "file", path: join(paths.opencodeDir, "agents", role.file), content: renderOpenCodeAgent(role) })),
|
|
219
|
+
{ kind: "file", path: join(paths.opencodeDir, "plugins", "robisie-review-guard.js"), content: OPENCODE_REVIEW_GUARD },
|
|
171
220
|
];
|
|
172
221
|
}
|
|
173
222
|
/** Shell profile line that exports ROBISIE_KEY from the package's key file (roles and Codex/OpenCode read it). */
|
|
@@ -176,7 +225,19 @@ export function shellProfile(ctx) {
|
|
|
176
225
|
return null;
|
|
177
226
|
const shell = (ctx.env.SHELL ?? "").split("/").pop();
|
|
178
227
|
if (shell === "zsh")
|
|
179
|
-
return join(ctx
|
|
228
|
+
return join(configRoot(ctx, "ZDOTDIR", ctx.home), ".zshrc");
|
|
229
|
+
if (shell === "bash" && ctx.platform === "darwin") {
|
|
230
|
+
for (const name of [".bash_profile", ".bash_login", ".profile"]) {
|
|
231
|
+
const path = join(ctx.home, name);
|
|
232
|
+
try {
|
|
233
|
+
accessSync(path, constants.R_OK);
|
|
234
|
+
return path;
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
// Bash skips profiles it cannot read; keep looking in startup order.
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
180
241
|
if (shell === "bash")
|
|
181
242
|
return join(ctx.home, ctx.platform === "darwin" ? ".bash_profile" : ".bashrc");
|
|
182
243
|
return null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type AttemptActive = {
|
|
2
|
+
taskId: string;
|
|
3
|
+
jobId: string;
|
|
4
|
+
attempts: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function classifyStart(input: {
|
|
7
|
+
cardId: string;
|
|
8
|
+
seq: number;
|
|
9
|
+
attempt?: number;
|
|
10
|
+
jobId: unknown;
|
|
11
|
+
attempts: unknown;
|
|
12
|
+
actives: readonly AttemptActive[];
|
|
13
|
+
helperStatus: unknown;
|
|
14
|
+
}): {
|
|
15
|
+
ok: true;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function nextAttempt(details: Record<string, unknown> | null | undefined): number;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function classifyStart(input) {
|
|
2
|
+
const expected = input.attempt ?? input.seq; // P1-e: brak attempt → stary seq
|
|
3
|
+
if (!nonempty(input.jobId))
|
|
4
|
+
return { ok: false, reason: "brak jobId" };
|
|
5
|
+
if (!positiveInteger(input.attempts) || input.attempts !== expected)
|
|
6
|
+
return { ok: false, reason: "próba się nie zgadza" };
|
|
7
|
+
const active = input.actives.find(a => a.taskId === input.cardId);
|
|
8
|
+
if (!active)
|
|
9
|
+
return { ok: false, reason: "brak w state.actives" };
|
|
10
|
+
if (active.jobId !== input.jobId || active.attempts !== expected) {
|
|
11
|
+
return { ok: false, reason: "state.actives nie zgadza się z próbą/jobId" };
|
|
12
|
+
}
|
|
13
|
+
const status = typeof input.helperStatus === "string" ? input.helperStatus.trim().toLowerCase() : "";
|
|
14
|
+
if (status !== "queued" && status !== "running" && status !== "completed") {
|
|
15
|
+
return { ok: false, reason: `helper ${status || "brak"}` };
|
|
16
|
+
}
|
|
17
|
+
return { ok: true };
|
|
18
|
+
}
|
|
19
|
+
export function nextAttempt(details) {
|
|
20
|
+
const worker = details?.maszynista;
|
|
21
|
+
if (!record(worker))
|
|
22
|
+
return 1;
|
|
23
|
+
const previous = worker.attempts ?? worker.attempt;
|
|
24
|
+
if (worker.outcome === "MODEL_AT_CAPACITY" && positiveInteger(previous))
|
|
25
|
+
return previous;
|
|
26
|
+
// Karta po blokadzie wrocila do ready reka czlowieka/CR -> nowa seria prob (inaczej 4/3 = blokada po 1 probie).
|
|
27
|
+
if (worker.move === "blocked")
|
|
28
|
+
return 1;
|
|
29
|
+
return positiveInteger(previous) ? previous + 1 : 1;
|
|
30
|
+
}
|
|
31
|
+
function record(value) {
|
|
32
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
function positiveInteger(value) {
|
|
35
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
36
|
+
}
|
|
37
|
+
function nonempty(value) {
|
|
38
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
39
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type CiJobSteps = {
|
|
2
|
+
name: string;
|
|
3
|
+
diskTrusted?: boolean;
|
|
4
|
+
evidenceMissing?: boolean;
|
|
5
|
+
interruptedTrusted?: "cancelled" | "timed_out";
|
|
6
|
+
steps: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
conclusion: string | null;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
export declare function failedTestFiles(raw: string): string[];
|
|
12
|
+
export declare function normalizeCiLogTail(raw: string, maxLines?: number, maxChars?: number): string;
|
|
13
|
+
export declare function formatCiFailNote(failed: Array<{
|
|
14
|
+
name: string;
|
|
15
|
+
conclusion: string | null;
|
|
16
|
+
}>, jobs: CiJobSteps[], tails: Array<{
|
|
17
|
+
runId: string;
|
|
18
|
+
tail: string;
|
|
19
|
+
}>, maxChars?: number): string;
|
|
20
|
+
export declare const CI_DISK_HOLD_STEP = "Robisie disk HOLD v1";
|
|
21
|
+
export declare const CI_DISK_HOLD_JOBS: string[];
|
|
22
|
+
export declare function hasCiDiskHold(job: CiJobSteps): boolean;
|
|
23
|
+
export declare function classifyCiFailure(failedJobs: CiJobSteps[]): "disk" | "host" | "infra" | "code" | "unknown";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export function failedTestFiles(raw) {
|
|
2
|
+
const clean = raw.replace(/\x1b\[[0-9;]*[A-Za-z]/g, "");
|
|
3
|
+
return [...new Set(Array.from(clean.matchAll(/(?:^|[\t ])FAIL[\t ]+([^\s]+\.test\.(?:ts|tsx|mts|mjs|js))[\t ]+(?:>|\[)/gm), match => match[1]))];
|
|
4
|
+
}
|
|
5
|
+
export function normalizeCiLogTail(raw, maxLines = 40, maxChars = 1000) {
|
|
6
|
+
const lines = raw.split(/\r?\n/).map((line) => line
|
|
7
|
+
.replace(/\x1b\[[0-9;]*[A-Za-z]/g, "")
|
|
8
|
+
.replace(/^[^\t]*\t[^\t]*\t/, "")
|
|
9
|
+
.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z\s?/, "")
|
|
10
|
+
.trimEnd()).filter((line) => line.trim().length > 0);
|
|
11
|
+
const tail = lines.slice(-maxLines).join("\n");
|
|
12
|
+
return tail.length > maxChars ? `…${tail.slice(-(maxChars - 1))}` : tail;
|
|
13
|
+
}
|
|
14
|
+
export function formatCiFailNote(failed, jobs, tails, maxChars = 1400) {
|
|
15
|
+
const header = `CI: ${failed.map((run) => `${run.name}: ${run.conclusion}`).join(", ")}`;
|
|
16
|
+
const steps = jobs.flatMap((job) => {
|
|
17
|
+
const failedSteps = job.steps.filter((step) => step.conclusion === "failure");
|
|
18
|
+
return failedSteps.length > 0 ? failedSteps.map((step) => `${job.name} › ${step.name}`) : [job.name];
|
|
19
|
+
});
|
|
20
|
+
const marker = "…(ucięto)";
|
|
21
|
+
if (header.length >= maxChars)
|
|
22
|
+
return header.slice(0, maxChars);
|
|
23
|
+
let note = header;
|
|
24
|
+
const nonEmptyTails = tails.filter(({ tail }) => tail.length > 0);
|
|
25
|
+
const firstTail = nonEmptyTails[0];
|
|
26
|
+
const firstBlock = firstTail ? `\n--- ogon logu run ${firstTail.runId} ---\n${firstTail.tail}` : "";
|
|
27
|
+
const tailReserve = Math.min(firstBlock.length, 500) + (nonEmptyTails.length > 1 ? marker.length : 0);
|
|
28
|
+
if (steps.length > 0) {
|
|
29
|
+
const stepLine = `\nPadłe: ${steps.join(", ")}`;
|
|
30
|
+
const stepBudget = maxChars - note.length - tailReserve;
|
|
31
|
+
const stepMarker = firstTail ? "…(ucięto kroki)" : marker;
|
|
32
|
+
if (stepLine.length <= stepBudget)
|
|
33
|
+
note += stepLine;
|
|
34
|
+
else if (stepBudget >= stepMarker.length)
|
|
35
|
+
note += `${stepLine.slice(0, stepBudget - stepMarker.length)}${stepMarker}`;
|
|
36
|
+
}
|
|
37
|
+
for (const [index, { runId, tail }] of nonEmptyTails.entries()) {
|
|
38
|
+
const blockHeader = `\n--- ogon logu run ${runId} ---\n`;
|
|
39
|
+
const block = `${blockHeader}${tail}`;
|
|
40
|
+
if (note.length + block.length > maxChars) {
|
|
41
|
+
if (index === 0) {
|
|
42
|
+
const omittedMarker = nonEmptyTails.length > 1 ? marker : "";
|
|
43
|
+
const tailRoom = maxChars - note.length - blockHeader.length - omittedMarker.length;
|
|
44
|
+
if (tailRoom > 1) {
|
|
45
|
+
note += `${blockHeader}…${tail.slice(-(tailRoom - 1))}${omittedMarker}`;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (note.length + marker.length <= maxChars)
|
|
50
|
+
note += marker;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
note += block;
|
|
54
|
+
}
|
|
55
|
+
return note;
|
|
56
|
+
}
|
|
57
|
+
export const CI_DISK_HOLD_STEP = "Robisie disk HOLD v1";
|
|
58
|
+
export const CI_DISK_HOLD_JOBS = ["Verify (lint + build:check)", "Secret scan (gitleaks)", "check-agent-writes (ROB brief narrative discipline)", "check-postmortem-required (ROB_099 — bugfix postmortem gate)", "Deploy (wrangler → Cloudflare Workers)"];
|
|
59
|
+
export function hasCiDiskHold(job) {
|
|
60
|
+
return job.diskTrusted === true && CI_DISK_HOLD_JOBS.includes(job.name)
|
|
61
|
+
&& job.steps.some(step => step.name === CI_DISK_HOLD_STEP && step.conclusion === "failure");
|
|
62
|
+
}
|
|
63
|
+
export function classifyCiFailure(failedJobs) {
|
|
64
|
+
if (failedJobs.length === 0)
|
|
65
|
+
return "unknown";
|
|
66
|
+
const hostStep = /^(Set up runner|Complete runner|Set up job|Complete job)$/;
|
|
67
|
+
let sawFailedStep = false;
|
|
68
|
+
let sawNotStartedJob = false;
|
|
69
|
+
let sawDisk = false;
|
|
70
|
+
const diskPresent = failedJobs.some(hasCiDiskHold);
|
|
71
|
+
for (const job of failedJobs) {
|
|
72
|
+
if (job.evidenceMissing && job.interruptedTrusted && !diskPresent)
|
|
73
|
+
continue;
|
|
74
|
+
if (job.steps.length === 0 && !job.evidenceMissing)
|
|
75
|
+
sawNotStartedJob = true;
|
|
76
|
+
const failed = job.steps.filter((st) => st.conclusion === "failure");
|
|
77
|
+
if (failed.length === 0)
|
|
78
|
+
continue;
|
|
79
|
+
sawFailedStep = true;
|
|
80
|
+
const disk = hasCiDiskHold(job);
|
|
81
|
+
if (!failed.every((st) => hostStep.test(st.name) || disk && st.name === CI_DISK_HOLD_STEP))
|
|
82
|
+
return "code";
|
|
83
|
+
sawDisk ||= disk;
|
|
84
|
+
}
|
|
85
|
+
if (sawDisk)
|
|
86
|
+
return failedJobs.some(job => !job.interruptedTrusted && (job.evidenceMissing || job.steps.length > 0 && !job.steps.some(step => step.conclusion === "failure"))) ? "unknown" : "disk";
|
|
87
|
+
if (sawNotStartedJob)
|
|
88
|
+
return "infra";
|
|
89
|
+
return sawFailedStep ? "host" : "unknown";
|
|
90
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const HEADLESS_SYSTEM_PROMPT = "Jeste\u015B bezstanowym modu\u0142em fabryki Robisie wywo\u0142ywanym przez skrypt. Nie masz narz\u0119dzi ani dost\u0119pu do repozytorium, plik\u00F3w, tablicy ani historii \u2014 opierasz si\u0119 wy\u0142\u0105cznie na tre\u015Bci tej wiadomo\u015Bci. Odpowiadasz dok\u0142adnie w formacie, kt\u00F3rego \u017C\u0105da wiadomo\u015B\u0107.";
|
|
2
|
+
export declare const HEADLESS_CLAUDE_ENV: {
|
|
3
|
+
readonly CLAUDE_CODE_DISABLE_ATTACHMENTS: "1";
|
|
4
|
+
};
|
|
5
|
+
export declare function headlessClaudeArgs(model: string): string[];
|
|
6
|
+
/** Tokeny wejścia z koperty `--output-format json`; null, gdy koperta nie ma liczbowego `usage`. */
|
|
7
|
+
export declare function envelopeInputTokens(envelope: unknown): number | null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Jedno źródło argumentów `claude -p` dla automatu (selektor, agent zasiewu).
|
|
2
|
+
// Po co (Reksio-364, 2026-09-22, zmierzone): `--allowedTools ""` NIE odbiera narzędzi, a
|
|
3
|
+
// `--exclude-dynamic-system-prompt-sections` PRZENOSI `git status` do pierwszej wiadomości zamiast go
|
|
4
|
+
// usuwać; z cwd = repo model dostawał też personę Reksia (CLAUDE.local.md) i hooki SessionStart —
|
|
5
|
+
// 44 562 tokeny wejścia i 12 narzędzi. Z listą poniżej: 0 narzędzi, 0 instrukcji, 0 hooków, 1 234 tokeny.
|
|
6
|
+
// `--bare` odpada: wymaga ANTHROPIC_API_KEY, a fabryka działa na OAuth (plan Max).
|
|
7
|
+
export const HEADLESS_SYSTEM_PROMPT = "Jesteś bezstanowym modułem fabryki Robisie wywoływanym przez skrypt. Nie masz narzędzi ani dostępu do repozytorium, plików, tablicy ani historii — opierasz się wyłącznie na treści tej wiadomości. Odpowiadasz dokładnie w formacie, którego żąda wiadomość.";
|
|
8
|
+
// --tools "" does not stop CLI-side @file expansion before the model sees the prompt.
|
|
9
|
+
export const HEADLESS_CLAUDE_ENV = { CLAUDE_CODE_DISABLE_ATTACHMENTS: "1" };
|
|
10
|
+
export function headlessClaudeArgs(model) {
|
|
11
|
+
return [
|
|
12
|
+
"-p", "--model", model, "--disable-slash-commands",
|
|
13
|
+
"--tools", "", "--setting-sources", "", "--strict-mcp-config",
|
|
14
|
+
"--system-prompt", HEADLESS_SYSTEM_PROMPT, "--output-format", "json",
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
const TOKEN_FIELDS = ["input_tokens", "cache_creation_input_tokens", "cache_read_input_tokens"];
|
|
18
|
+
/** Tokeny wejścia z koperty `--output-format json`; null, gdy koperta nie ma liczbowego `usage`. */
|
|
19
|
+
export function envelopeInputTokens(envelope) {
|
|
20
|
+
if (typeof envelope !== "object" || envelope === null)
|
|
21
|
+
return null;
|
|
22
|
+
const usage = envelope.usage;
|
|
23
|
+
if (typeof usage !== "object" || usage === null)
|
|
24
|
+
return null;
|
|
25
|
+
const values = TOKEN_FIELDS.map((field) => usage[field])
|
|
26
|
+
.filter((value) => typeof value === "number");
|
|
27
|
+
return values.length === 0 ? null : values.reduce((sum, value) => sum + value, 0);
|
|
28
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type AgentId } from "./agents.js";
|
|
3
|
+
import { type Ctx } from "./context.js";
|
|
4
|
+
import { type RoleProviders } from "./manifest.js";
|
|
5
|
+
export interface ParsedArgs {
|
|
6
|
+
command: string;
|
|
7
|
+
help: boolean;
|
|
8
|
+
/** Positional argument (`robisie mcp <name>`). */
|
|
9
|
+
target: string | null;
|
|
10
|
+
agents: AgentId[] | null;
|
|
11
|
+
roles: Partial<RoleProviders>;
|
|
12
|
+
shell: boolean;
|
|
13
|
+
keyStdin: boolean;
|
|
14
|
+
engineConfig: string | null;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseArgs(argv: readonly string[]): ParsedArgs;
|
|
17
|
+
export declare function run(argv: readonly string[], ctx: Ctx): Promise<number>;
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { realpathSync } from "node:fs";
|
|
2
|
+
import { lstatSync, realpathSync } from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { AGENT_IDS, isAgentId } from "./agents.js";
|
|
5
|
-
import { doctor, init, uninstall } from "./commands.js";
|
|
5
|
+
import { doctor, init, recoveryStep, uninstall } from "./commands.js";
|
|
6
6
|
import { HELPER_SERVERS, PACKAGE_VERSION } from "./constants.js";
|
|
7
7
|
import { RobisieError, errorMessage, nodeCtx } from "./context.js";
|
|
8
8
|
import { isHelperServer, runHelper } from "./helpers.js";
|
|
9
9
|
import { ROLE_IDS, ROLE_STEP } from "./manifest.js";
|
|
10
|
+
import { doctorEngineConfig } from "./role-registry.js";
|
|
10
11
|
const HELP = `robisie ${PACKAGE_VERSION} — łączy Twojego agenta z tablicą robisie
|
|
11
12
|
|
|
12
13
|
npx robisie init klucz rob_… (z ${"ROBISIE_KEY"} albo z pytania) + konfiguracja MCP + role klienta
|
|
@@ -15,6 +16,10 @@ const HELP = `robisie ${PACKAGE_VERSION} — łączy Twojego agenta z tablicą r
|
|
|
15
16
|
npx robisie mcp <${HELPER_SERVERS.join("|")}>
|
|
16
17
|
pomocnik ról (serwer MCP stdio) — uruchamia go agent, nie Ty
|
|
17
18
|
|
|
19
|
+
Opcje doctor:
|
|
20
|
+
--engine-config <path> lokalnie i offline sprawdza K2 i rejestr wykonania czterech ról K7
|
|
21
|
+
--engine-config=<path> ta sama składnia; nie sprawdza uruchomienia dostawców
|
|
22
|
+
|
|
18
23
|
Opcje init:
|
|
19
24
|
--agent <${AGENT_IDS.join("|")}> wybrany dostawca (można powtórzyć albo podać po przecinku); razem z dostawcami mapy, bez --agent również wykryci
|
|
20
25
|
--role <rola=dostawca> wybór ceo, builder, quality → claude, codex, opencode (można powtórzyć)
|
|
@@ -29,13 +34,30 @@ export function parseArgs(argv) {
|
|
|
29
34
|
const roles = {};
|
|
30
35
|
let shell = true;
|
|
31
36
|
let keyStdin = false;
|
|
37
|
+
let engineConfig = null;
|
|
32
38
|
let target = null;
|
|
33
39
|
// Help wins over everything else, so `init --help` never starts an install.
|
|
34
|
-
if (
|
|
35
|
-
return { command, help: true, target, agents: null, roles, shell, keyStdin };
|
|
40
|
+
if (argv.includes("--help") || argv.includes("-h"))
|
|
41
|
+
return { command, help: true, target, agents: null, roles, shell, keyStdin, engineConfig };
|
|
36
42
|
while (args.length > 0) {
|
|
37
43
|
const arg = args.shift();
|
|
38
|
-
if (arg === "--no-shell"
|
|
44
|
+
if (command !== "init" && (arg === "--no-shell" || arg === "--key-stdin" ||
|
|
45
|
+
arg === "--agent" || arg.startsWith("--agent=") ||
|
|
46
|
+
arg === "--role" || arg.startsWith("--role="))) {
|
|
47
|
+
throw new RobisieError(`Opcja „${arg.split("=")[0]}” jest dostępna tylko dla polecenia init.`, "Zobacz `npx robisie help`.");
|
|
48
|
+
}
|
|
49
|
+
if (arg === "--engine-config" || arg.startsWith("--engine-config=")) {
|
|
50
|
+
const step = "Użyj `npx robisie doctor --engine-config <path>` z jedną niepustą ścieżką pliku.";
|
|
51
|
+
if (command !== "doctor")
|
|
52
|
+
throw new RobisieError("Opcja --engine-config jest dostępna tylko dla polecenia doctor.", step);
|
|
53
|
+
if (engineConfig !== null)
|
|
54
|
+
throw new RobisieError("Opcję --engine-config można podać tylko raz.", step);
|
|
55
|
+
const value = arg === "--engine-config" ? args.shift() ?? "" : arg.slice("--engine-config=".length);
|
|
56
|
+
if (!value.trim() || value.startsWith("-"))
|
|
57
|
+
throw new RobisieError("Opcja --engine-config wymaga ścieżki pliku.", step);
|
|
58
|
+
engineConfig = value;
|
|
59
|
+
}
|
|
60
|
+
else if (arg === "--no-shell")
|
|
39
61
|
shell = false;
|
|
40
62
|
else if (arg === "--key-stdin")
|
|
41
63
|
keyStdin = true;
|
|
@@ -45,9 +67,9 @@ export function parseArgs(argv) {
|
|
|
45
67
|
throw new RobisieError("Opcja --role wymaga przypisania rola=dostawca.", ROLE_STEP);
|
|
46
68
|
const [role, provider, extra] = value.split("=");
|
|
47
69
|
if (!ROLE_IDS.some((id) => id === role))
|
|
48
|
-
throw new RobisieError(
|
|
70
|
+
throw new RobisieError("Nieznana rola (--role).", ROLE_STEP);
|
|
49
71
|
if (extra !== undefined || !provider || !isAgentId(provider))
|
|
50
|
-
throw new RobisieError(
|
|
72
|
+
throw new RobisieError("Niepoprawny dostawca lub przypisanie (--role).", ROLE_STEP);
|
|
51
73
|
const id = role;
|
|
52
74
|
if (roles[id] && roles[id] !== provider)
|
|
53
75
|
throw new RobisieError(`Sprzeczne przypisania roli „${role}”: ${roles[id]} i ${provider}.`, ROLE_STEP);
|
|
@@ -58,11 +80,11 @@ export function parseArgs(argv) {
|
|
|
58
80
|
const ids = value.split(",").map((v) => v.trim());
|
|
59
81
|
// An empty value must not silently fall back to "every detected agent".
|
|
60
82
|
if (ids.some((id) => id === "") || value.startsWith("--")) {
|
|
61
|
-
throw new RobisieError("Opcja --agent wymaga nazwy agenta.",
|
|
83
|
+
throw new RobisieError("Opcja --agent wymaga nazwy agenta.", ROLE_STEP);
|
|
62
84
|
}
|
|
63
85
|
for (const id of ids) {
|
|
64
86
|
if (!isAgentId(id))
|
|
65
|
-
throw new RobisieError(
|
|
87
|
+
throw new RobisieError("Nieznany agent (--agent).", ROLE_STEP);
|
|
66
88
|
if (!agents.includes(id))
|
|
67
89
|
agents.push(id);
|
|
68
90
|
}
|
|
@@ -70,9 +92,9 @@ export function parseArgs(argv) {
|
|
|
70
92
|
else if (command === "mcp" && target === null && !arg.startsWith("-"))
|
|
71
93
|
target = arg;
|
|
72
94
|
else
|
|
73
|
-
throw new RobisieError(
|
|
95
|
+
throw new RobisieError("Nieznana opcja argumentów CLI.", "Zobacz `npx robisie help`.");
|
|
74
96
|
}
|
|
75
|
-
return { command, help: false, target, agents: agents.length > 0 ? agents : null, roles, shell, keyStdin };
|
|
97
|
+
return { command, help: false, target, agents: agents.length > 0 ? agents : null, roles, shell, keyStdin, engineConfig };
|
|
76
98
|
}
|
|
77
99
|
export async function run(argv, ctx) {
|
|
78
100
|
try {
|
|
@@ -86,12 +108,30 @@ export async function run(argv, ctx) {
|
|
|
86
108
|
await init(ctx, { agents: args.agents, roles: args.roles, shell: args.shell, keyStdin: args.keyStdin });
|
|
87
109
|
return 0;
|
|
88
110
|
case "doctor":
|
|
111
|
+
if (args.engineConfig !== null)
|
|
112
|
+
return doctorEngineConfig(ctx, args.engineConfig);
|
|
113
|
+
if (ctx.env.ROBISIE_KEY) {
|
|
114
|
+
try {
|
|
115
|
+
// Match the helper's directory rules without executing its code in doctor.
|
|
116
|
+
const selected = ctx.env.ROBISIE_PROJECT_CONTEXT || ctx.cwd;
|
|
117
|
+
if (!selected.startsWith("/") || selected.includes("\n"))
|
|
118
|
+
throw new Error("Invalid project-context path");
|
|
119
|
+
const selectedStat = lstatSync(selected);
|
|
120
|
+
const stat = lstatSync(realpathSync(selected));
|
|
121
|
+
if (selectedStat.isSymbolicLink() || !stat.isDirectory() || stat.isSymbolicLink()) {
|
|
122
|
+
throw new Error("Invalid project-context directory");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
throw new RobisieError("Nie mogę potwierdzić kontekstu projektu używanego przez pomocnik klienta.", "W katalogu projektu wykonaj `unset ROBISIE_PROJECT_CONTEXT`, potem `npx robisie doctor`. Albo ustaw istniejący absolutny rzeczywisty katalog: `export ROBISIE_PROJECT_CONTEXT='/absolutna/sciezka/do/projektu'` (zastąp ścieżkę katalogiem projektu), potem `npx robisie doctor`.");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
89
129
|
return await doctor(ctx);
|
|
90
130
|
case "uninstall":
|
|
91
131
|
return uninstall(ctx);
|
|
92
132
|
case "mcp":
|
|
93
133
|
if (!args.target || !isHelperServer(args.target)) {
|
|
94
|
-
throw new RobisieError(
|
|
134
|
+
throw new RobisieError("Nieznany pomocnik (mcp).", `Użyj jednego z: ${HELPER_SERVERS.join(", ")}.`);
|
|
95
135
|
}
|
|
96
136
|
return await runHelper(args.target);
|
|
97
137
|
case "--version":
|
|
@@ -104,13 +144,13 @@ export async function run(argv, ctx) {
|
|
|
104
144
|
ctx.out(HELP);
|
|
105
145
|
return 0;
|
|
106
146
|
default:
|
|
107
|
-
throw new RobisieError(
|
|
147
|
+
throw new RobisieError("Nieznane polecenie CLI.", "Zobacz `npx robisie help`.");
|
|
108
148
|
}
|
|
109
149
|
}
|
|
110
150
|
catch (error) {
|
|
111
151
|
if (error instanceof RobisieError) {
|
|
112
152
|
ctx.err(`✗ ${error.message}`);
|
|
113
|
-
ctx.err(`Następny krok: ${error.nextStep}`);
|
|
153
|
+
ctx.err(`Następny krok: ${recoveryStep(ctx, error.nextStep)}`);
|
|
114
154
|
}
|
|
115
155
|
else {
|
|
116
156
|
ctx.err(`✗ Coś poszło nie tak: ${errorMessage(error)}`);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type AgentId } from "./agents.js";
|
|
2
|
+
import { type Ctx } from "./context.js";
|
|
3
|
+
import { type RoleProviders } from "./manifest.js";
|
|
4
|
+
export interface InitOptions {
|
|
5
|
+
agents: AgentId[] | null;
|
|
6
|
+
roles?: Partial<RoleProviders>;
|
|
7
|
+
shell: boolean;
|
|
8
|
+
/** Read the key from piped stdin — only on request, so an open non-TTY stdin can never hang init. */
|
|
9
|
+
keyStdin: boolean;
|
|
10
|
+
rolesDir?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Advice chooses an executable CLI, not merely a leftover configuration directory. */
|
|
13
|
+
export declare function initRecoveryStep(ctx: Ctx, preferred?: AgentId): string;
|
|
14
|
+
export declare function recoveryStep(ctx: Ctx, step: string): string;
|
|
15
|
+
export declare function init(ctx: Ctx, options: InitOptions): Promise<void>;
|
|
16
|
+
/** Returns the process exit code: 0 = all good, 1 = something needs one action. */
|
|
17
|
+
export declare function doctor(ctx: Ctx): Promise<number>;
|
|
18
|
+
export declare function uninstall(ctx: Ctx): number;
|