toolroll 0.9.114 → 0.9.116
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 +54 -0
- package/dist/agent-state-words.js +1 -1
- package/dist/assignment-ui.js +1 -1
- package/dist/browser/terminal.css +1 -1
- package/dist/browser/terminal.js +1 -1
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +29 -28
- package/dist/chat-controls.js +1 -1
- package/dist/chat-quiet.js +2 -2
- package/dist/chat-voice.js +3 -3
- package/dist/check-levels.js +1 -1
- package/dist/claim.js +7 -2
- package/dist/cli.js +1 -0
- package/dist/code-map-cli.js +2 -1
- package/dist/coding-shipping-ui.js +2 -1
- package/dist/console-instance.js +21 -1
- package/dist/contracts/console-api.js +6 -2
- package/dist/contracts/engine-api.js +32 -4
- package/dist/demo-chat.js +1 -1
- package/dist/design/kit.css +3 -0
- package/dist/design/kit.js +1 -1
- package/dist/dispatch.js +19 -2
- package/dist/easy-start.js +23 -11
- package/dist/engine-reads.js +98 -7
- package/dist/export.js +16 -4
- package/dist/flexible-authority-end.js +94 -0
- package/dist/flexible-everyday-schema.js +76 -0
- package/dist/flexible-interactive-schema.js +133 -0
- package/dist/flexible-interactive.js +94 -0
- package/dist/flexible-laptop.js +38 -0
- package/dist/flexible-relay.js +9 -3
- package/dist/flexible-session.js +430 -10
- package/dist/flexible-ship.js +77 -12
- package/dist/flexible-sign-in.js +16 -1
- package/dist/flexible-start.js +17 -2
- package/dist/flexible-thread.js +1 -1
- package/dist/flexible-turns.js +9 -0
- package/dist/flexible-ui.js +3 -2
- package/dist/flexible.js +13 -0
- package/dist/flow-card-task.js +1 -1
- package/dist/home-groups.js +1 -1
- package/dist/lead-status.js +5 -3
- package/dist/lead-tools.js +1 -0
- package/dist/local-owner-acts.js +44 -1
- package/dist/local-owner.js +10 -0
- package/dist/needs-you.js +18 -6
- package/dist/operate-remote-arguments.js +1 -1
- package/dist/operate.js +250 -32
- package/dist/plan-problems-schema.js +4 -0
- package/dist/planner.js +17 -6
- package/dist/release-cli.js +2 -2
- package/dist/result-actions.js +1 -2
- package/dist/retention-ui.js +1 -1
- package/dist/scope.js +18 -7
- package/dist/server/chat.js +3 -3
- package/dist/server/console.css +15 -10
- package/dist/server/engine-api.js +161 -15
- package/dist/server/flows.js +4 -3
- package/dist/server/home.js +1 -1
- package/dist/server/kit.js +2 -2
- package/dist/server/render-chat.js +1 -1
- package/dist/server/render-pages.js +1 -1
- package/dist/server/render-tasks.js +21 -12
- package/dist/server/route-table.js +16 -0
- package/dist/server/settings-sections.js +6 -2
- package/dist/server/settings.js +22 -8
- package/dist/server/task-views.js +10 -4
- package/dist/server/tasks.js +51 -4
- package/dist/settings-kit.js +3 -3
- package/dist/skills-ui.js +3 -2
- package/dist/spend-report.js +2 -2
- package/dist/spend.js +3 -3
- package/dist/store.js +202 -7
- package/dist/subagent-admin.js +23 -10
- package/dist/subagent-backup-schema.js +36 -0
- package/dist/subagent-backup.js +92 -0
- package/dist/subagent-week.js +2 -2
- package/dist/subagent-work.js +70 -47
- package/dist/subagents-ui.js +6 -2
- package/dist/subagents.js +5 -2
- package/dist/subscription-chat.js +4 -0
- package/dist/surface.js +8 -1
- package/dist/task-status.js +13 -13
- package/dist/telegram-status.js +3 -3
- package/dist/terminal-safety.js +114 -0
- package/dist/toolroll-update.js +2 -1
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-launch.js +20 -1
- package/dist/tui.js +1 -1
- package/dist/work-index.js +23 -10
- package/dist/workspace-ui.js +5 -5
- package/dist/youiyoux-intake.js +1 -1
- package/package.json +2 -2
package/dist/store.js
CHANGED
|
@@ -30,6 +30,11 @@ import { V169_ADDED_COLUMNS, V169_SCHEMA, V169_STEPS } from "./task-sizing-schem
|
|
|
30
30
|
import { V170_ADDED_COLUMNS, V170_STEPS } from "./agent-said-schema.js";
|
|
31
31
|
import { V171_SCHEMA, V171_STEPS } from "./flexible-setting-schema.js";
|
|
32
32
|
import { V172_ADDED_COLUMNS, V172_OBJECTS, V172_SCHEMA, V172_STEPS } from "./flexible-sign-in-schema.js";
|
|
33
|
+
import { V173_ADDED_COLUMNS, V173_STEPS } from "./plan-problems-schema.js";
|
|
34
|
+
import { V175_OBJECTS, V175_SCHEMA, V175_STEPS } from "./flexible-interactive-schema.js";
|
|
35
|
+
import { V176_ADDED_COLUMNS, V176_STEPS, V176_SCHEMA, V176_OBJECTS } from "./subagent-backup-schema.js";
|
|
36
|
+
import { V174_OBJECTS, V174_SCHEMA, V174_STEPS } from "./flexible-everyday-schema.js";
|
|
37
|
+
import { endThreadAuthorityFor } from "./flexible-authority-end.js";
|
|
33
38
|
import { relayCancel } from "./flexible-relay-cancel.js";
|
|
34
39
|
import { endLapsedFlexible } from "./flexible.js";
|
|
35
40
|
import { refArchived, taskArchived, taskCancelled } from "./task-archive.js";
|
|
@@ -835,7 +840,7 @@ export function checkSuitesOf(value) {
|
|
|
835
840
|
}
|
|
836
841
|
}
|
|
837
842
|
const REGISTERED_AT_FILING = "again, as it was filed";
|
|
838
|
-
export const SCHEMA_VERSION =
|
|
843
|
+
export const SCHEMA_VERSION = 176;
|
|
839
844
|
export const V118_MERGED_TABLES = Object.freeze({ api_token: "person", coordinator_credential: "coordinator", lead_credential: "lead" });
|
|
840
845
|
const V118_REFERENCES = /REFERENCES (?:coordinator_credential\(cid\)|api_token\(id\))/g;
|
|
841
846
|
const V118_COORDINATOR_COLUMNS = [["task_ref", "coordinator_cid"], ["coordinator_event", "cid"], ["mcp_idempotency", "cid"], ["coordinator_proposal", "cid"]];
|
|
@@ -900,7 +905,7 @@ export const V115_DROPPED_TABLES = Object.freeze([
|
|
|
900
905
|
"fallback_config", "fallback_cycle", "fallback_transition",
|
|
901
906
|
]);
|
|
902
907
|
const V115_DROPPED_REFERENCES = /\s+REFERENCES (?:contestant|contest|tournament_terms|session_turn|attended_authorization|held_session|fallback_cycle|fallback_config|fallback_transition|routine|routine_fire)\(id\)(?: ON DELETE CASCADE)?/g;
|
|
903
|
-
export const UPDATE_SAFE_MIGRATIONS = Object.freeze([108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172]);
|
|
908
|
+
export const UPDATE_SAFE_MIGRATIONS = Object.freeze([108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176]);
|
|
904
909
|
export const V119_ADDED_COLUMNS = Object.freeze({
|
|
905
910
|
task_ref: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
|
|
906
911
|
run: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
|
|
@@ -1443,7 +1448,7 @@ export { V156_STEPS };
|
|
|
1443
1448
|
export { V157_STEPS };
|
|
1444
1449
|
export { V158_STEPS };
|
|
1445
1450
|
export { V159_STEPS };
|
|
1446
|
-
export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS, V164_STEPS, V165_STEPS, V166_STEPS, V167_STEPS, V168_STEPS, V169_STEPS, V170_STEPS, V171_STEPS, V172_STEPS };
|
|
1451
|
+
export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS, V164_STEPS, V165_STEPS, V166_STEPS, V167_STEPS, V168_STEPS, V169_STEPS, V170_STEPS, V171_STEPS, V172_STEPS, V173_STEPS, V174_STEPS, V175_STEPS, V176_STEPS };
|
|
1447
1452
|
export const RELEASE_ONCE_SCHEMA = `
|
|
1448
1453
|
CREATE TABLE IF NOT EXISTS release_authority (
|
|
1449
1454
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1796,7 +1801,7 @@ function readSubagentGrant(row) {
|
|
|
1796
1801
|
}
|
|
1797
1802
|
function readSubagentRow(row) {
|
|
1798
1803
|
return { id: Number(row["id"]), repo: String(row["repo"]), handle: String(row["handle"]), state: String(row["state"]), version: Number(row["version"]), soul: String(row["soul"]),
|
|
1799
|
-
model: row["model"] === null ? null : String(row["model"]), dailyTurns: Number(row["daily_turns"]), manager: String(row["manager"]), createdBy: String(row["created_by"]), createdAt: String(row["created_at"]),
|
|
1804
|
+
model: row["model"] === null ? null : String(row["model"]), codexBackupModel: typeof row["codex_backup_model"] === "string" ? row["codex_backup_model"] : null, authorityGeneration: Number(row["authority_generation"] ?? 0), dailyTurns: Number(row["daily_turns"]), manager: String(row["manager"]), createdBy: String(row["created_by"]), createdAt: String(row["created_at"]),
|
|
1800
1805
|
updatedBy: String(row["updated_by"]), updatedAt: String(row["updated_at"]), summaryAt: row["summary_at"] === null ? null : String(row["summary_at"]),
|
|
1801
1806
|
deskFlow: row["desk_flow"] === null || row["desk_flow"] === undefined ? null : Number(row["desk_flow"]),
|
|
1802
1807
|
weeklyAt: row["weekly_at"] === null || row["weekly_at"] === undefined ? null : String(row["weekly_at"]) };
|
|
@@ -4221,7 +4226,7 @@ function initializeStore(db, file, options = {}) {
|
|
|
4221
4226
|
throw new Error(`${file}: ${problem}; refusing to move chat history it cannot name`);
|
|
4222
4227
|
}
|
|
4223
4228
|
if (preflight === SCHEMA_VERSION && !findingSourcesStale(db)) {
|
|
4224
|
-
const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db) ?? flexibleTurnsShapeProblem(db) ?? flexibleLaunchShapeProblem(db) ?? flexibleRelayShapeProblem(db) ?? flexibleAnswersShapeProblem(db) ?? flexibleShipShapeProblem(db) ?? taskSizingShapeProblem(db) ?? agentSaidShapeProblem(db) ?? flexibleSettingShapeProblem(db) ?? flexibleSignInShapeProblem(db);
|
|
4229
|
+
const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db) ?? flexibleTurnsShapeProblem(db) ?? flexibleLaunchShapeProblem(db) ?? flexibleRelayShapeProblem(db) ?? flexibleAnswersShapeProblem(db) ?? flexibleShipShapeProblem(db) ?? taskSizingShapeProblem(db) ?? agentSaidShapeProblem(db) ?? flexibleSettingShapeProblem(db) ?? flexibleSignInShapeProblem(db) ?? planProblemsShapeProblem(db) ?? flexibleEverydayShapeProblem(db) ?? flexibleInteractiveShapeProblem(db) ?? subagentBackupShapeProblem(db);
|
|
4225
4230
|
if (missing !== null)
|
|
4226
4231
|
throw new Error(`${file}: refusing to open — ${missing}, though the schema says v${SCHEMA_VERSION}`);
|
|
4227
4232
|
db.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;");
|
|
@@ -4630,6 +4635,29 @@ CREATE INDEX IF NOT EXISTS run_checkpoint_by_task ON run_checkpoint (task_ref, i
|
|
|
4630
4635
|
if (signInDamaged !== null)
|
|
4631
4636
|
throw new Error(`${file}: refusing to open — ${signInDamaged}`);
|
|
4632
4637
|
step("flexible-sign-in");
|
|
4638
|
+
for (const [table, columns] of Object.entries(V173_ADDED_COLUMNS))
|
|
4639
|
+
for (const [column, { definition }] of Object.entries(columns))
|
|
4640
|
+
addColumn(db, table, column, definition);
|
|
4641
|
+
step("plan-problems-column");
|
|
4642
|
+
db.exec(V174_SCHEMA);
|
|
4643
|
+
const everydayDamaged = flexibleEverydayShapeProblem(db);
|
|
4644
|
+
if (everydayDamaged !== null)
|
|
4645
|
+
throw new Error(`${file}: refusing to open — ${everydayDamaged}`);
|
|
4646
|
+
step("flexible-everyday");
|
|
4647
|
+
db.exec(V175_SCHEMA);
|
|
4648
|
+
db.prepare("INSERT INTO flexible_thread_runtime (thread, runtime, chosen) SELECT id, 'stream-json', 1 FROM flexible_thread WHERE id NOT IN (SELECT thread FROM flexible_thread_runtime)").run();
|
|
4649
|
+
const interactiveDamaged = flexibleInteractiveShapeProblem(db);
|
|
4650
|
+
if (interactiveDamaged !== null)
|
|
4651
|
+
throw new Error(`${file}: refusing to open — ${interactiveDamaged}`);
|
|
4652
|
+
step("flexible-interactive");
|
|
4653
|
+
for (const [table, columns] of Object.entries(V176_ADDED_COLUMNS))
|
|
4654
|
+
for (const [column, { definition }] of Object.entries(columns))
|
|
4655
|
+
addColumn(db, table, column, definition);
|
|
4656
|
+
db.exec(V176_SCHEMA);
|
|
4657
|
+
const backupDamaged = subagentBackupShapeProblem(db);
|
|
4658
|
+
if (backupDamaged !== null)
|
|
4659
|
+
throw new Error(`${file}: refusing to open — ${backupDamaged}`);
|
|
4660
|
+
step("subagent-backup-columns");
|
|
4633
4661
|
if (!fresh)
|
|
4634
4662
|
reclaimDatabase(db, "migration");
|
|
4635
4663
|
const expectedMarker = preflight < 0 ? preflight : -preflight;
|
|
@@ -7167,6 +7195,7 @@ export class Store {
|
|
|
7167
7195
|
for (const id of subscriptions)
|
|
7168
7196
|
this.retirePushSubscription(id, "credential-rotation", now);
|
|
7169
7197
|
endLapsedFlexible(this, { signer: approver }, by, now);
|
|
7198
|
+
endThreadAuthorityFor(this, { person: approver, cause: "account-changed", at: now.toISOString() });
|
|
7170
7199
|
}
|
|
7171
7200
|
listApprovers() {
|
|
7172
7201
|
return this.db
|
|
@@ -13586,8 +13615,12 @@ export class Store {
|
|
|
13586
13615
|
}));
|
|
13587
13616
|
}
|
|
13588
13617
|
subagentTurnsSince(subagent, since) {
|
|
13589
|
-
|
|
13618
|
+
const legacy = Number(this.db.prepare("SELECT COUNT(*) AS n FROM subagent_event WHERE subagent = ? AND at >= ? AND kind IN ('decided','handled','handed','asked','failed')").get(subagent, since)?.["n"] ?? 0)
|
|
13590
13619
|
+ Number(this.db.prepare("SELECT COUNT(*) AS n FROM subagent_call WHERE subagent = ? AND created_at >= ?").get(subagent, since)?.["n"] ?? 0);
|
|
13620
|
+
const hasAttempts = this.db.prepare("SELECT 1 FROM subagent_turn WHERE subagent = ? AND at >= ? AND counted_attempt = 1 LIMIT 1").get(subagent, since) !== undefined;
|
|
13621
|
+
if (this.getSubagent(subagent)?.codexBackupModel === null && !hasAttempts)
|
|
13622
|
+
return legacy;
|
|
13623
|
+
return Math.max(legacy, Number(this.db.prepare("SELECT COUNT(*) AS n FROM subagent_turn WHERE subagent = ? AND at >= ?").get(subagent, since)?.["n"] ?? 0));
|
|
13591
13624
|
}
|
|
13592
13625
|
openSubagentQuestion(question, now) {
|
|
13593
13626
|
const { changes, lastInsertRowid } = this.db.prepare("INSERT OR IGNORE INTO subagent_question (subagent, card, entry, question, options_json, asked_of, state, created_at, tool_call, suggestion) VALUES (?, ?, ?, ?, ?, ?, 'open', ?, ?, ?)")
|
|
@@ -13735,7 +13768,7 @@ export class Store {
|
|
|
13735
13768
|
}
|
|
13736
13769
|
subagentTurns(subagent, since) {
|
|
13737
13770
|
return this.db.prepare("SELECT * FROM subagent_turn WHERE subagent = ? AND at >= ? ORDER BY id").all(subagent, since).map(row => ({
|
|
13738
|
-
id: Number(row["id"]), subagent: Number(row["subagent"]), card: row["card"] === null ? null : Number(row["card"]), model: String(row["model"]), ok: Number(row["ok"]) === 1, ms: Number(row["ms"]),
|
|
13771
|
+
id: Number(row["id"]), subagent: Number(row["subagent"]), card: row["card"] === null ? null : Number(row["card"]), model: String(row["model"]), provider: row["provider"] === "codex" ? "codex" : "claude", pending: Number(row["pending"]) === 1, modelReported: typeof row["model_reported"] === "string" ? row["model_reported"] : null, ok: Number(row["ok"]) === 1, ms: Number(row["ms"]),
|
|
13739
13772
|
costUsd: row["cost_usd"] === null ? null : Number(row["cost_usd"]), tokensIn: row["tokens_in"] === null ? null : Number(row["tokens_in"]), tokensOut: row["tokens_out"] === null ? null : Number(row["tokens_out"]), at: String(row["at"])
|
|
13740
13773
|
}));
|
|
13741
13774
|
}
|
|
@@ -16548,6 +16581,53 @@ export class Store {
|
|
|
16548
16581
|
flowFencePolicy(flow) {
|
|
16549
16582
|
return this.db.prepare("SELECT fence_policy FROM flow WHERE id = ?").get(flow)?.["fence_policy"] === 2 ? 2 : 1;
|
|
16550
16583
|
}
|
|
16584
|
+
setSubagentCodexBackup(id, model, by, now) {
|
|
16585
|
+
this.db.prepare("UPDATE subagent SET codex_backup_model = ?, updated_by = ?, updated_at = ? WHERE id = ?").run(model, by, now.toISOString(), id);
|
|
16586
|
+
this.addSubagentEvent({ subagent: id, kind: "note", said: model === null ? "Codex backup turned off." : `Codex backup enabled (${model}); every provider attempt counts toward the daily limit.`, by }, now);
|
|
16587
|
+
}
|
|
16588
|
+
reserveSubagentAttempt(input, now) {
|
|
16589
|
+
return this.transact(() => {
|
|
16590
|
+
const mate = this.getSubagent(input.subagent);
|
|
16591
|
+
if (mate === null || mate.state !== "active" || mate.codexBackupModel === null || mate.authorityGeneration !== input.authorityGeneration)
|
|
16592
|
+
return { ok: false, why: "The subagent or its backup is no longer enabled." };
|
|
16593
|
+
const card = this.getFlowCard(input.card);
|
|
16594
|
+
if (card === null || card.state !== "active" || card.entry !== input.cardEntry || card.stage !== input.stage || this.getFlow(card.flow)?.repo !== mate.repo || this.getFlow(card.flow)?.revision !== input.flowRevision || this.getFlow(card.flow)?.state !== "active")
|
|
16595
|
+
return { ok: false, why: "The card no longer belongs to this project." };
|
|
16596
|
+
if (this.db.prepare("SELECT 1 FROM subagent_turn WHERE subagent = ? AND card = ? AND card_entry = ? AND pending = 1").get(mate.id, input.card, input.cardEntry) !== undefined)
|
|
16597
|
+
return { ok: false, why: "An earlier attempt on this card is unfinished; inspect it before trying again." };
|
|
16598
|
+
if (input.provider === "claude") {
|
|
16599
|
+
const model = mate.model ?? (this.getChatConfig()?.provider === "claude-subscription" ? this.getChatConfig().model : "default");
|
|
16600
|
+
if (input.model !== model)
|
|
16601
|
+
return { ok: false, why: "The primary model changed." };
|
|
16602
|
+
}
|
|
16603
|
+
if (input.provider === "codex") {
|
|
16604
|
+
const parent = this.db.prepare("SELECT * FROM subagent_turn WHERE id = ? AND subagent = ? AND card = ? AND provider = 'claude' AND ok = 0 AND pending = 0 AND failure_kind IN ('usage-limit','unavailable') AND authority_generation = ? AND card_entry = ?").get(input.backupOf ?? -1, mate.id, input.card, mate.authorityGeneration, input.cardEntry);
|
|
16605
|
+
if (parent === undefined || mate.codexBackupModel !== input.model || input.billing !== "subscription")
|
|
16606
|
+
return { ok: false, why: "The approved backup or its primary attempt changed." };
|
|
16607
|
+
if (this.db.prepare("SELECT 1 FROM subagent_turn WHERE backup_of = ?").get(input.backupOf) !== undefined)
|
|
16608
|
+
return { ok: false, why: "This primary attempt already used its backup." };
|
|
16609
|
+
}
|
|
16610
|
+
const policy = this.agentPolicyRefusal(input.provider, input.model);
|
|
16611
|
+
if (policy !== null)
|
|
16612
|
+
return { ok: false, why: policy };
|
|
16613
|
+
const day = new Date(now);
|
|
16614
|
+
day.setHours(0, 0, 0, 0);
|
|
16615
|
+
if (this.subagentTurnsSince(mate.id, day.toISOString()) >= mate.dailyTurns)
|
|
16616
|
+
return { ok: false, why: "The daily turn limit is reached." };
|
|
16617
|
+
const budget = this.budgetGate(now)({ project: mate.repo, person: null, subagent: mate.id, agents: [{ provider: input.provider, billing: input.billing }] });
|
|
16618
|
+
if (budget.over !== null)
|
|
16619
|
+
return { ok: false, why: "A budget holds this provider attempt." };
|
|
16620
|
+
const row = this.db.prepare("INSERT INTO subagent_turn (subagent, card, card_entry, model, provider, billing, backup_of, pending, counted_attempt, authority_generation, ok, ms, at) VALUES (?, ?, ?, ?, ?, ?, ?, 1, 1, ?, 0, 0, ?)")
|
|
16621
|
+
.run(mate.id, input.card, input.cardEntry, input.model, input.provider, input.billing, input.backupOf ?? null, mate.authorityGeneration, now.toISOString());
|
|
16622
|
+
this.spendCache = null;
|
|
16623
|
+
return { ok: true, id: Number(row.lastInsertRowid) };
|
|
16624
|
+
});
|
|
16625
|
+
}
|
|
16626
|
+
settleSubagentAttempt(id, result) {
|
|
16627
|
+
this.db.prepare("UPDATE subagent_turn SET pending = 0, ok = ?, ms = ?, model_reported = ?, failure_kind = ?, cost_usd = ?, tokens_in = ?, tokens_out = ? WHERE id = ? AND pending = 1")
|
|
16628
|
+
.run(result.ok ? 1 : 0, Math.round(result.ms), result.modelReported ?? null, result.failureKind ?? null, result.costUsd ?? null, result.tokensIn ?? null, result.tokensOut ?? null, id);
|
|
16629
|
+
this.spendCache = null;
|
|
16630
|
+
}
|
|
16551
16631
|
}
|
|
16552
16632
|
function wholeNumber(value) {
|
|
16553
16633
|
if (value === null || value === undefined)
|
|
@@ -19027,3 +19107,118 @@ function flexibleSignInShapeProblem(db) {
|
|
|
19027
19107
|
}
|
|
19028
19108
|
return null;
|
|
19029
19109
|
}
|
|
19110
|
+
function planProblemsShapeProblem(db) {
|
|
19111
|
+
return hasColumn(db, "run", "plan_problems_json") ? null : "run.plan_problems_json is missing";
|
|
19112
|
+
}
|
|
19113
|
+
export function recordPlanProblems(store, runId, problems) {
|
|
19114
|
+
const kept = agentSaidTail(problems.slice(0, 8).join("\n"));
|
|
19115
|
+
while (kept.length > 0 && JSON.stringify(kept).length > 4096)
|
|
19116
|
+
kept.pop();
|
|
19117
|
+
if (kept.length === 0)
|
|
19118
|
+
return;
|
|
19119
|
+
store.handle.prepare("UPDATE run SET plan_problems_json = ? WHERE id = ? AND plan_problems_json IS NULL").run(JSON.stringify(kept), runId);
|
|
19120
|
+
}
|
|
19121
|
+
export function planProblemsOf(store, runId) {
|
|
19122
|
+
const row = store.handle.prepare("SELECT plan_problems_json FROM run WHERE id = ?").get(runId);
|
|
19123
|
+
const raw = row?.["plan_problems_json"];
|
|
19124
|
+
if (typeof raw !== "string")
|
|
19125
|
+
return null;
|
|
19126
|
+
try {
|
|
19127
|
+
const value = JSON.parse(raw);
|
|
19128
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
19129
|
+
return null;
|
|
19130
|
+
const lines = agentSaidTail(value.filter((one) => typeof one === "string").join("\n"));
|
|
19131
|
+
return lines.length === 0 ? null : lines;
|
|
19132
|
+
}
|
|
19133
|
+
catch {
|
|
19134
|
+
return null;
|
|
19135
|
+
}
|
|
19136
|
+
}
|
|
19137
|
+
export const PLANNER_INCIDENT_KINDS = new Set(["malformed-plan", "malformed-decision", "plan-attempts-exhausted"]);
|
|
19138
|
+
export const PLAN_AGAIN_ACTIONS = Object.freeze({ local: "task plan again (local owner)", person: "task plan again" });
|
|
19139
|
+
export function planAgain(store, input) {
|
|
19140
|
+
return store.transact(() => {
|
|
19141
|
+
const { taskId, incident, now } = input;
|
|
19142
|
+
const ref = store.lookupRef(taskId);
|
|
19143
|
+
const task = store.getTask(taskId);
|
|
19144
|
+
if (ref === null || task === null)
|
|
19145
|
+
return { ok: false, reason: "not-found", message: "That task is unavailable in your projects." };
|
|
19146
|
+
if (refArchived(store, ref.id))
|
|
19147
|
+
return { ok: false, reason: "archived", message: "This task is put away. Restore it first." };
|
|
19148
|
+
const row = store.handle.prepare(`SELECT incident.kind, incident.resolved_at, run.task_ref, run.role FROM incident JOIN run ON run.id = incident.run WHERE incident.id = ?`).get(incident);
|
|
19149
|
+
if (row === undefined || Number(row["task_ref"]) !== ref.id || row["role"] !== "planner" || !PLANNER_INCIDENT_KINDS.has(String(row["kind"]))) {
|
|
19150
|
+
return { ok: false, reason: "stale", message: "This task changed. Look at it again." };
|
|
19151
|
+
}
|
|
19152
|
+
const changed = { ok: false, reason: "stale", message: "This task changed. Look at it again." };
|
|
19153
|
+
if (task.state !== "queued" || ref.plan !== "requested")
|
|
19154
|
+
return changed;
|
|
19155
|
+
const approved = store.handle.prepare("SELECT 1 AS hit FROM task_scope WHERE task_id = ? AND approved_digest = digest AND approved_at IS NOT NULL").get(taskId);
|
|
19156
|
+
if (approved !== undefined)
|
|
19157
|
+
return changed;
|
|
19158
|
+
if (store.hasLiveClaim(ref.id, now))
|
|
19159
|
+
return { ok: false, reason: "refused", message: "The planner is already working on this task." };
|
|
19160
|
+
if (row["resolved_at"] !== null) {
|
|
19161
|
+
const again = store.handle.prepare(`SELECT detail FROM action_ledger WHERE task_id = ? AND action IN (?, ?) ORDER BY id DESC`).all(taskId, PLAN_AGAIN_ACTIONS.local, PLAN_AGAIN_ACTIONS.person)
|
|
19162
|
+
.some(one => { try {
|
|
19163
|
+
return JSON.parse(String(one["detail"] ?? "")).incident === incident;
|
|
19164
|
+
}
|
|
19165
|
+
catch {
|
|
19166
|
+
return false;
|
|
19167
|
+
} });
|
|
19168
|
+
if (!again)
|
|
19169
|
+
return changed;
|
|
19170
|
+
input.before?.();
|
|
19171
|
+
return { ok: true, replayed: true };
|
|
19172
|
+
}
|
|
19173
|
+
input.before?.();
|
|
19174
|
+
if (!store.resolveIncident(incident, input.by, now))
|
|
19175
|
+
throw new Error("plan again: the incident was open and couldn't be resolved");
|
|
19176
|
+
store.resetPlanStrikes(ref.id);
|
|
19177
|
+
store.recordAction({ at: now.toISOString(), actor: input.actor, repo: ref.repo, taskId, runId: null, action: input.action, outcome: "requested", source: "request",
|
|
19178
|
+
detail: JSON.stringify({ v: 1, incident, ...input.detail }) });
|
|
19179
|
+
return { ok: true, replayed: false };
|
|
19180
|
+
});
|
|
19181
|
+
}
|
|
19182
|
+
function flexibleEverydayShapeProblem(db) {
|
|
19183
|
+
const statements = V174_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
|
|
19184
|
+
for (const [type, name] of V174_OBJECTS) {
|
|
19185
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
19186
|
+
if (row === undefined)
|
|
19187
|
+
return `the interactive agent threads ${type} ${name} is missing`;
|
|
19188
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
19189
|
+
if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want.replace(/;$/, "")).trim())
|
|
19190
|
+
return `the interactive agent threads ${type} ${name} has an unknown shape`;
|
|
19191
|
+
}
|
|
19192
|
+
return null;
|
|
19193
|
+
}
|
|
19194
|
+
function flexibleInteractiveShapeProblem(db) {
|
|
19195
|
+
const statements = V175_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(one => one !== "");
|
|
19196
|
+
for (const [type, name] of V175_OBJECTS) {
|
|
19197
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
19198
|
+
if (row === undefined)
|
|
19199
|
+
return `the interactive agent threads ${type} ${name} is missing`;
|
|
19200
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
19201
|
+
if (want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(want.replace(/;$/, "")).trim())
|
|
19202
|
+
return `the interactive agent threads ${type} ${name} has an unknown shape`;
|
|
19203
|
+
}
|
|
19204
|
+
return null;
|
|
19205
|
+
}
|
|
19206
|
+
function subagentBackupShapeProblem(db) {
|
|
19207
|
+
for (const [table, columns] of Object.entries(V176_ADDED_COLUMNS)) {
|
|
19208
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?").get(table);
|
|
19209
|
+
for (const [column, { definition }] of Object.entries(columns)) {
|
|
19210
|
+
if (!hasColumn(db, table, column))
|
|
19211
|
+
return `the subagent backup column ${table}.${column} is missing`;
|
|
19212
|
+
if (row === undefined || !canonicalDdl(String(row["sql"])).includes(canonicalDdl(`, ${column} ${definition}`).trim()))
|
|
19213
|
+
return `the subagent backup column ${table}.${column} has an unknown shape`;
|
|
19214
|
+
}
|
|
19215
|
+
}
|
|
19216
|
+
const statements = V176_SCHEMA.split(/;\s*\n(?=CREATE )/).map(one => one.trim().replace(/;$/, "")).filter(Boolean);
|
|
19217
|
+
for (const [type, name] of V176_OBJECTS) {
|
|
19218
|
+
const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
|
|
19219
|
+
const want = statements.find(one => new RegExp(`^CREATE (?:UNIQUE )?${type.toUpperCase()} IF NOT EXISTS ${name}\\b`).test(one));
|
|
19220
|
+
if (row === undefined || want === undefined || canonicalDdl(String(row["sql"]).replace(/;$/, "")) !== canonicalDdl(want))
|
|
19221
|
+
return `the subagent backup ${type} ${name} has an unknown shape`;
|
|
19222
|
+
}
|
|
19223
|
+
return null;
|
|
19224
|
+
}
|
package/dist/subagent-admin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validModelId } from "./provider.js";
|
|
1
2
|
import { flowDefinitionOf } from "./flow-engine.js";
|
|
2
3
|
import { handleOf, parseSoul, SUBAGENT_TEMPLATES, subagentLabel } from "./subagents.js";
|
|
3
4
|
export const SUBAGENT_MODELS = ["default", "sonnet", "opus", "haiku"];
|
|
@@ -46,16 +47,28 @@ export function setSubagentState(store, mate, state, by, now) {
|
|
|
46
47
|
store.addSubagentEvent({ subagent: mate.id, kind: state === "paused" ? "paused" : "resumed", said: state === "paused" ? `${by} paused ${name}.` : `${by} set ${name} working again.`, by }, now);
|
|
47
48
|
return { ok: true, said: state === "paused" ? `${name} is paused. Its decisions go to people until you resume it.` : `${name} is working again.` };
|
|
48
49
|
}
|
|
49
|
-
export function subagentSettings(store, mate, change, by, now) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
export function subagentSettings(store, mate, change, by, now, options = {}) {
|
|
51
|
+
return store.transact(() => {
|
|
52
|
+
const current = store.getSubagent(mate.id);
|
|
53
|
+
if (current === null || current.state === "removed")
|
|
54
|
+
return { ok: false, said: "This teammate is no longer on the team." };
|
|
55
|
+
const model = change.model === undefined ? undefined : change.model === "default" ? null : SUBAGENT_MODELS.includes(change.model) ? change.model : undefined;
|
|
56
|
+
if (change.model !== undefined && model === undefined)
|
|
57
|
+
return { ok: false, said: "Choose one of the models listed." };
|
|
58
|
+
if (change.dailyTurns !== undefined && (!Number.isInteger(change.dailyTurns) || change.dailyTurns < 1 || change.dailyTurns > 2000))
|
|
59
|
+
return { ok: false, said: "A daily limit is 1 to 2,000 turns." };
|
|
60
|
+
if (change.manager !== undefined && !store.accountCanAccess(change.manager, current.repo))
|
|
61
|
+
return { ok: false, said: "Its manager must be someone on this project." };
|
|
62
|
+
const backup = change.codexBackupModel;
|
|
63
|
+
if (backup !== undefined && backup !== null && (!validModelId(backup) || ["default", "inherit", ""].includes(backup)))
|
|
64
|
+
return { ok: false, said: "Enter an exact Codex backup model ID, or leave it blank to turn the backup off." };
|
|
65
|
+
if (backup != null && backup !== current.codexBackupModel && (!store.accountCanAccess(by, current.repo) || options.proveBackup?.() !== true))
|
|
66
|
+
return { ok: false, said: "Enter your Toolroll password to enable or change the Codex backup. Nothing changed." };
|
|
67
|
+
store.updateSubagent(current.id, { ...(model === undefined ? {} : { model }), ...(change.dailyTurns === undefined ? {} : { dailyTurns: change.dailyTurns }), ...(change.manager === undefined ? {} : { manager: change.manager }) }, by, now);
|
|
68
|
+
if (backup !== undefined && backup !== current.codexBackupModel)
|
|
69
|
+
store.setSubagentCodexBackup(current.id, backup, by, now);
|
|
70
|
+
return { ok: true, said: "Saved." };
|
|
71
|
+
});
|
|
59
72
|
}
|
|
60
73
|
export const nameOf = (mate) => { const read = parseSoul(mate.soul); return read.ok ? read.soul.name : mate.handle; };
|
|
61
74
|
export const labelOf = (mate) => { const read = parseSoul(mate.soul); return read.ok ? subagentLabel(read.soul) : mate.handle; };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const V176_ADDED_COLUMNS = Object.freeze({
|
|
2
|
+
subagent: { authority_generation: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (authority_generation >= 0)", saved: "0" }, codex_backup_model: { definition: "TEXT", saved: "NULL" } },
|
|
3
|
+
subagent_turn: {
|
|
4
|
+
provider: { definition: "TEXT NOT NULL DEFAULT 'claude' CHECK (provider IN ('claude','codex'))", saved: "'claude'" },
|
|
5
|
+
card_entry: { definition: "INTEGER", saved: "NULL" },
|
|
6
|
+
model_reported: { definition: "TEXT", saved: "NULL" },
|
|
7
|
+
backup_of: { definition: "INTEGER REFERENCES subagent_turn(id)", saved: "NULL" },
|
|
8
|
+
authority_generation: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (authority_generation >= 0)", saved: "0" },
|
|
9
|
+
counted_attempt: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (counted_attempt IN (0,1))", saved: "0" },
|
|
10
|
+
failure_kind: { definition: "TEXT CHECK (failure_kind IN ('usage-limit','unavailable'))", saved: "NULL" },
|
|
11
|
+
pending: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (pending IN (0,1))", saved: "0" },
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
export const V176_STEPS = Object.freeze(["subagent-backup-columns"]);
|
|
15
|
+
export const V176_SCHEMA = `
|
|
16
|
+
CREATE UNIQUE INDEX IF NOT EXISTS subagent_backup_once ON subagent_turn(backup_of) WHERE backup_of IS NOT NULL;
|
|
17
|
+
CREATE TRIGGER IF NOT EXISTS subagent_authority_changed AFTER UPDATE OF state, soul, model, codex_backup_model, daily_turns, manager ON subagent
|
|
18
|
+
WHEN NEW.state IS NOT OLD.state OR NEW.soul IS NOT OLD.soul OR NEW.model IS NOT OLD.model
|
|
19
|
+
OR NEW.codex_backup_model IS NOT OLD.codex_backup_model OR NEW.daily_turns IS NOT OLD.daily_turns OR NEW.manager IS NOT OLD.manager
|
|
20
|
+
BEGIN
|
|
21
|
+
UPDATE subagent SET authority_generation = OLD.authority_generation + 1 WHERE id = NEW.id;
|
|
22
|
+
END;
|
|
23
|
+
CREATE TRIGGER IF NOT EXISTS subagent_policy_changed AFTER UPDATE ON org_policy
|
|
24
|
+
BEGIN
|
|
25
|
+
UPDATE subagent SET authority_generation = authority_generation + 1;
|
|
26
|
+
END;
|
|
27
|
+
CREATE TRIGGER IF NOT EXISTS subagent_policy_inserted AFTER INSERT ON org_policy
|
|
28
|
+
BEGIN
|
|
29
|
+
UPDATE subagent SET authority_generation = authority_generation + 1;
|
|
30
|
+
END;
|
|
31
|
+
CREATE TRIGGER IF NOT EXISTS subagent_policy_removed AFTER DELETE ON org_policy
|
|
32
|
+
BEGIN
|
|
33
|
+
UPDATE subagent SET authority_generation = authority_generation + 1;
|
|
34
|
+
END;
|
|
35
|
+
`;
|
|
36
|
+
export const V176_OBJECTS = Object.freeze([...V176_SCHEMA.matchAll(/CREATE (UNIQUE INDEX|TRIGGER) IF NOT EXISTS (\w+)/g)].map(one => [one[1] === "UNIQUE INDEX" ? "index" : "trigger", one[2]]));
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { claudeTurnRunner } from "./subagents.js";
|
|
3
|
+
import { TURN_MODEL_SCHEMA } from "./contracts/subagent-turn.js";
|
|
4
|
+
import { strictJsonParse } from "./converse.js";
|
|
5
|
+
import { performSubscriptionLeadRequest } from "./subscription-chat.js";
|
|
6
|
+
import { run } from "./exec.js";
|
|
7
|
+
import { ALL_CREDENTIAL_ENV } from "./provider.js";
|
|
8
|
+
import { claudeMachineBilling } from "./spend.js";
|
|
9
|
+
import { inEvalWorld } from "./eval-gate.js";
|
|
10
|
+
export async function subagentAttemptWithBackup(store, mate, card, request, runner = run, clock = () => new Date(), elapsedNow = () => performance.now()) {
|
|
11
|
+
const started = elapsedNow();
|
|
12
|
+
const remaining = () => Math.max(0, Math.min(request.timeoutMs, request.timeoutMs - (elapsedNow() - started)));
|
|
13
|
+
const failure = (said, provider = "claude", model = request.model) => ({ reply: { ok: false, said }, provider, model, backup: provider === "codex", authorize: () => said });
|
|
14
|
+
if (inEvalWorld())
|
|
15
|
+
return failure("Subagents don't run in an eval world.");
|
|
16
|
+
if (remaining() <= 0)
|
|
17
|
+
return failure("The original turn deadline elapsed.");
|
|
18
|
+
const originalFlow = store.getFlow(card.flow);
|
|
19
|
+
const flowRevision = request.flowRevision ?? originalFlow?.revision;
|
|
20
|
+
if (flowRevision === undefined)
|
|
21
|
+
return failure("The flow is no longer available.");
|
|
22
|
+
const freshnessProblem = (provider, model) => {
|
|
23
|
+
if (remaining() <= 0)
|
|
24
|
+
return "The original turn deadline elapsed before the answer could be used.";
|
|
25
|
+
const liveMate = store.getSubagent(mate.id), liveCard = store.getFlowCard(card.id), liveFlow = store.getFlow(card.flow);
|
|
26
|
+
if (liveMate?.state !== "active" || liveMate.authorityGeneration !== mate.authorityGeneration || liveCard?.state !== "active" || liveCard.entry !== card.entry || liveCard.stage !== card.stage || liveFlow?.revision !== flowRevision || liveFlow?.state !== "active")
|
|
27
|
+
return "The attempt's permission or card changed before its answer could be used.";
|
|
28
|
+
if (provider === "codex" && liveMate.codexBackupModel !== model)
|
|
29
|
+
return "The Codex backup's permission changed before its answer could be used.";
|
|
30
|
+
return store.agentPolicyRefusal(provider, model);
|
|
31
|
+
};
|
|
32
|
+
const primary = store.reserveSubagentAttempt({ subagent: mate.id, card: card.id, cardEntry: card.entry, stage: card.stage, authorityGeneration: mate.authorityGeneration, flowRevision, provider: "claude", model: request.model, billing: claudeMachineBilling(store.handle) }, clock());
|
|
33
|
+
if (!primary.ok)
|
|
34
|
+
return failure(primary.why);
|
|
35
|
+
let first;
|
|
36
|
+
try {
|
|
37
|
+
first = await claudeTurnRunner(runner)({ ...request, timeoutMs: remaining() });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
first = { ok: false, said: "Claude's attempt stopped without a decision." };
|
|
41
|
+
}
|
|
42
|
+
const primaryProblem = freshnessProblem("claude", request.model);
|
|
43
|
+
if (first.ok && primaryProblem !== null)
|
|
44
|
+
first = { ...first, ok: false, said: primaryProblem };
|
|
45
|
+
store.settleSubagentAttempt(primary.id, { ...first, ms: elapsedNow() - started, ...(!first.ok && first.backupReason !== undefined ? { failureKind: first.backupReason } : {}) });
|
|
46
|
+
if (!first.ok && primaryProblem !== null)
|
|
47
|
+
return failure(primaryProblem);
|
|
48
|
+
if (first.ok || first.backupReason === undefined || remaining() <= 0)
|
|
49
|
+
return { reply: first, provider: "claude", model: request.model, backup: false, authorize: () => freshnessProblem("claude", request.model) };
|
|
50
|
+
let signedIn = false;
|
|
51
|
+
try {
|
|
52
|
+
const status = await runner("codex", ["login", "status"], { timeoutMs: Math.min(15_000, remaining()), maxBuffer: 65_536, omitEnv: ALL_CREDENTIAL_ENV, processGroup: true });
|
|
53
|
+
const said = `${status.stdout}\n${status.stderr}`;
|
|
54
|
+
signedIn = status.code === 0 && !status.timedOut && !status.notFound && /^Logged in using ChatGPT\s*$/m.test(said) && !/api key|bedrock/i.test(said);
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
if (!signedIn || remaining() <= 0)
|
|
58
|
+
return failure(`${first.said} Codex backup needs a current ChatGPT sign-in.`);
|
|
59
|
+
const current = store.getSubagent(mate.id);
|
|
60
|
+
const model = current?.codexBackupModel;
|
|
61
|
+
if (model === null || model === undefined)
|
|
62
|
+
return failure(`${first.said} Codex backup is no longer enabled.`);
|
|
63
|
+
const backup = store.reserveSubagentAttempt({ subagent: mate.id, card: card.id, cardEntry: card.entry, stage: card.stage, authorityGeneration: mate.authorityGeneration, flowRevision, provider: "codex", model, billing: "subscription", backupOf: primary.id }, clock());
|
|
64
|
+
if (!backup.ok)
|
|
65
|
+
return failure(`${first.said} ${backup.why}`);
|
|
66
|
+
const began = elapsedNow();
|
|
67
|
+
let reply;
|
|
68
|
+
let modelReported = null;
|
|
69
|
+
try {
|
|
70
|
+
if (remaining() <= 0)
|
|
71
|
+
throw new Error("The original turn deadline elapsed.");
|
|
72
|
+
const answered = await performSubscriptionLeadRequest({ provider: "codex-subscription", model, system: "You decide one flow-card turn. Return exactly the supplied subagent decision schema. You have no native tools, repository or MCP access. The host validates any requested project-tool action separately.", dataDocument: request.prompt, history: [], tools: [], outputSchema: TURN_MODEL_SCHEMA, timeoutMs: remaining() }, runner);
|
|
73
|
+
if (!answered.ok)
|
|
74
|
+
reply = { ok: false, said: `Codex backup couldn't decide (${answered.problem}).` };
|
|
75
|
+
else {
|
|
76
|
+
modelReported = answered.answer.modelReported ?? null;
|
|
77
|
+
const parsed = strictJsonParse(Buffer.from(answered.answer.text, "utf8"), 65_536, 12);
|
|
78
|
+
const usage = { tokensIn: answered.answer.tokensIn, tokensOut: answered.answer.tokensOut,
|
|
79
|
+
...(answered.answer.reportedCostUsd == null ? {} : { costUsd: answered.answer.reportedCostUsd }) };
|
|
80
|
+
reply = parsed.ok ? { ok: true, value: parsed.value, ms: elapsedNow() - began, ...usage }
|
|
81
|
+
: { ok: false, said: "Codex backup's answer wasn't a decision.", ...usage };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
reply = { ok: false, said: "Codex backup stopped without a decision." };
|
|
86
|
+
}
|
|
87
|
+
const backupProblem = freshnessProblem("codex", model);
|
|
88
|
+
if (backupProblem !== null)
|
|
89
|
+
reply = { ...reply, ok: false, said: backupProblem };
|
|
90
|
+
store.settleSubagentAttempt(backup.id, { ...reply, ms: elapsedNow() - began, modelReported });
|
|
91
|
+
return { reply, provider: "codex", model: modelReported ?? model, backup: true, authorize: () => freshnessProblem("codex", model) };
|
|
92
|
+
}
|
package/dist/subagent-week.js
CHANGED
|
@@ -24,7 +24,7 @@ export function weekOf(store, mate, now, since = new Date(now.getTime() - WEEK_M
|
|
|
24
24
|
});
|
|
25
25
|
const moved = store.flowMovesOverridden(`${name} (AI)`, since).map(one => ({ said: `${one.by} moved “${one.title.slice(0, 80)}” after ${name} did`, at: one.at, href: flowCardHref(one.flow, one.card) }));
|
|
26
26
|
return {
|
|
27
|
-
since, turns: turns.length, failedTurns: turns.filter(one => !one.ok).length, costUsd: costs.length === 0 ? null : Math.round(costs.reduce((sum, one) => sum + one, 0) * 1e6) / 1e6,
|
|
27
|
+
since, turns: turns.length, pendingTurns: turns.filter(one => one.pending).length, failedTurns: turns.filter(one => !one.ok && !one.pending).length, costUsd: costs.length !== turns.length || costs.length === 0 ? null : Math.round(costs.reduce((sum, one) => sum + one, 0) * 1e6) / 1e6,
|
|
28
28
|
minutes: Math.round(turns.reduce((sum, one) => sum + one.ms, 0) / 60_000),
|
|
29
29
|
decided: count("decided"), handled: count("handled"), handed: count("handed"), asked: count("asked"),
|
|
30
30
|
calls: { made: calls.filter(one => one.state === "done" || one.state === "failed").length, approved: calls.filter(one => one.decidedBy !== null && one.state !== "denied" && one.state !== "refused").length,
|
|
@@ -41,7 +41,7 @@ export function weekWords(mate, week) {
|
|
|
41
41
|
const lines = [
|
|
42
42
|
`${name} decided ${week.decided}, handled ${week.handled}, handed ${week.handed} to people and asked ${week.asked} question${week.asked === 1 ? "" : "s"}.`,
|
|
43
43
|
`Tool calls: ${week.calls.made} made${week.calls.approved > 0 ? ` (${week.calls.approved} after a person approved)` : ""}${week.calls.denied > 0 ? `, ${week.calls.denied} turned down` : ""}${week.calls.refused > 0 ? `, ${week.calls.refused} outside its rules` : ""}${week.calls.undone > 0 ? `, ${week.calls.undone} undone` : ""}.`,
|
|
44
|
-
`${week.turns} turn${week.turns === 1 ? "" : "s"}${week.failedTurns > 0 ? ` (${week.failedTurns} failed)` : ""}, about ${week.minutes} minute${week.minutes === 1 ? "" : "s"} of thinking${week.costUsd === null ? "" : `, ${money(week.costUsd)} at API prices`}.`,
|
|
44
|
+
`${week.turns} turn${week.turns === 1 ? "" : "s"}${week.pendingTurns > 0 ? ` (${week.pendingTurns} unfinished)` : ""}${week.failedTurns > 0 ? ` (${week.failedTurns} failed)` : ""}, about ${week.minutes} minute${week.minutes === 1 ? "" : "s"} of thinking${week.costUsd === null ? "" : `, ${money(week.costUsd)} at API prices`}.`,
|
|
45
45
|
...(week.overrides.length === 0 ? ["Nobody overrode it."] : [`You overrode it ${week.overrides.length} time${week.overrides.length === 1 ? "" : "s"}:`, ...week.overrides.slice(0, 5).map(one => `• ${one.said}`)]),
|
|
46
46
|
];
|
|
47
47
|
return lines.join("\n");
|