@chibitek/chibi 0.1.210 → 0.1.211

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.
Files changed (82) hide show
  1. package/dist/assets/{TerminalPanel-DxQoOfkY.js → TerminalPanel-Dro3aeVy.js} +1 -1
  2. package/dist/assets/{abnfDiagram-O67JEVCF-Ds2qYdjS.js → abnfDiagram-O67JEVCF-kzAr7vQ8.js} +1 -1
  3. package/dist/assets/{arc-1O9tchZk.js → arc-DKMhcYud.js} +1 -1
  4. package/dist/assets/{architectureDiagram-NJMV4G6O-CWuQ1x2F.js → architectureDiagram-NJMV4G6O-_XDnZ7Jz.js} +1 -1
  5. package/dist/assets/{blockDiagram-BEXU5L5S-CNcEkXEx.js → blockDiagram-BEXU5L5S-D5MoWro9.js} +1 -1
  6. package/dist/assets/{c4Diagram-YGBWAQC7-BKI_wi9I.js → c4Diagram-YGBWAQC7-CGvTMpGE.js} +1 -1
  7. package/dist/assets/channel-YcZdlysP.js +1 -0
  8. package/dist/assets/{chunk-2Q5K7J3B-gO88emfN.js → chunk-2Q5K7J3B-pjTwr5y0.js} +1 -1
  9. package/dist/assets/{chunk-3FUC2YCW-DbKNT_-r.js → chunk-3FUC2YCW-BR6zkd-l.js} +2 -2
  10. package/dist/assets/{chunk-5VM5RSS4-BbJCoZVg.js → chunk-5VM5RSS4-CfVFFBeH.js} +1 -1
  11. package/dist/assets/{chunk-GTNCS2PH-DXurSCcp.js → chunk-GTNCS2PH-TIoAkccw.js} +1 -1
  12. package/dist/assets/{chunk-GWA4HPMP-BWyt0I_m.js → chunk-GWA4HPMP-BNFBgzbt.js} +1 -1
  13. package/dist/assets/{chunk-JWPE2WC7-6iWSsogl.js → chunk-JWPE2WC7-B_3QFchU.js} +1 -1
  14. package/dist/assets/{chunk-NETBCI7D-CFoqO9Hw.js → chunk-NETBCI7D-Cj9q80P-.js} +1 -1
  15. package/dist/assets/{chunk-WEXAMYUT-BZEzAlNi.js → chunk-WEXAMYUT-DFZPGo9K.js} +1 -1
  16. package/dist/assets/{chunk-XXDRQBXY-W4hfC50f.js → chunk-XXDRQBXY-CekDrT9T.js} +1 -1
  17. package/dist/assets/{classDiagram-v2-NBCMYWYE-BsGmL9e7.js → classDiagram-v2-NBCMYWYE-C3R6Z4Qe.js} +1 -1
  18. package/dist/assets/{cose-bilkent-JH36ORCC-CYtTgIzk.js → cose-bilkent-JH36ORCC-C1CKyj0L.js} +1 -1
  19. package/dist/assets/{cynefin-OW5HDTMX-DLOi2Q2V.js → cynefin-OW5HDTMX-Deh9QGb0.js} +1 -1
  20. package/dist/assets/{cynefinDiagram-VND7K2PF-BXcXJ3hv.js → cynefinDiagram-VND7K2PF-BIlWyG_M.js} +1 -1
  21. package/dist/assets/{dagre-6A5THRUB-BdBOiuzt.js → dagre-6A5THRUB-Dx4bWOog.js} +1 -1
  22. package/dist/assets/{diagram-22UHCM2B-DCf3M4WE.js → diagram-22UHCM2B-DPxb-FUO.js} +1 -1
  23. package/dist/assets/{diagram-3UASUU5V-CzdF-UXi.js → diagram-3UASUU5V-BLPCNc4m.js} +1 -1
  24. package/dist/assets/{diagram-ATOU4E4O-_UmmlMOD.js → diagram-ATOU4E4O-DOCbp2Dw.js} +1 -1
  25. package/dist/assets/{diagram-CDSNMT55-DrQODVuX.js → diagram-CDSNMT55-62uSG-tn.js} +1 -1
  26. package/dist/assets/{diagram-MLGK6HIB-CE16iJlJ.js → diagram-MLGK6HIB-De1ZAWVZ.js} +1 -1
  27. package/dist/assets/{diagram-MPIPVDR6-DJuTbhbP.js → diagram-MPIPVDR6-CIGX9tku.js} +1 -1
  28. package/dist/assets/{ebnfDiagram-ZINNZB2B-f1VEI2Po.js → ebnfDiagram-ZINNZB2B-CegjStdk.js} +1 -1
  29. package/dist/assets/{elk-276RUBZZ-BRbs9WzY.js → elk-276RUBZZ-ClI52Pqm.js} +1 -1
  30. package/dist/assets/{erDiagram-OPXOYQCR-DvMp_cQr.js → erDiagram-OPXOYQCR-BQuzjt2-.js} +1 -1
  31. package/dist/assets/{flowDiagram-KWPJA3E3-CYS1A0fu.js → flowDiagram-KWPJA3E3-D1xbKgbB.js} +1 -1
  32. package/dist/assets/{ganttDiagram-FUAMR5RP-qya_JE9x.js → ganttDiagram-FUAMR5RP-CH1jGSZz.js} +1 -1
  33. package/dist/assets/{gitGraphDiagram-X574FWY7-ChMUJ3hH.js → gitGraphDiagram-X574FWY7-BvAUPEmQ.js} +1 -1
  34. package/dist/assets/{index-COH7BlyH.js → index-BcXDfnlQ.js} +157 -157
  35. package/dist/assets/{index-xE4Li_H2.js → index-DbkR_erP.js} +1 -1
  36. package/dist/assets/{infoDiagram-VRGFBTTK-B2VudqsE.js → infoDiagram-VRGFBTTK-CyMmMbMv.js} +1 -1
  37. package/dist/assets/{ishikawaDiagram-OU5B5YK6-Bdk47y0t.js → ishikawaDiagram-OU5B5YK6-Uw-hE1tO.js} +1 -1
  38. package/dist/assets/{journeyDiagram-ZHPQQLJL-A4StgNQ9.js → journeyDiagram-ZHPQQLJL-ClEDnNRB.js} +1 -1
  39. package/dist/assets/{kanban-definition-PNTS6WVX-DZo45dQw.js → kanban-definition-PNTS6WVX-erx0BEal.js} +1 -1
  40. package/dist/assets/{linear-D_rK-Ord.js → linear-CSSxpyL0.js} +1 -1
  41. package/dist/assets/{mermaid.core-C7CvDDvz.js → mermaid.core-n13K6vlC.js} +5 -5
  42. package/dist/assets/{mindmap-definition-NLK3R4M7-6fmVPMyc.js → mindmap-definition-NLK3R4M7-BcTEIqpD.js} +1 -1
  43. package/dist/assets/{pegDiagram-GJSIUBJH-CD4Qg24h.js → pegDiagram-GJSIUBJH-CJdsm3en.js} +1 -1
  44. package/dist/assets/{pieDiagram-5QR66LMP-DmzQ883B.js → pieDiagram-5QR66LMP-C7rk-ash.js} +1 -1
  45. package/dist/assets/{quadrantDiagram-O4NWA36T-BW37utPZ.js → quadrantDiagram-O4NWA36T-BSXOYov0.js} +1 -1
  46. package/dist/assets/{railroadDiagram-XR7U4H2S-CWXiMlAb.js → railroadDiagram-XR7U4H2S-Cmg_FtZY.js} +1 -1
  47. package/dist/assets/{requirementDiagram-PLB6GJNP-DHSfr9U3.js → requirementDiagram-PLB6GJNP-B_9aE6Mg.js} +1 -1
  48. package/dist/assets/{sankeyDiagram-IPEJSGJF-PebTt4eq.js → sankeyDiagram-IPEJSGJF-DyxaQPy3.js} +1 -1
  49. package/dist/assets/{sequenceDiagram-PO4LG4MO-DPwp8fia.js → sequenceDiagram-PO4LG4MO-D5CJeESq.js} +1 -1
  50. package/dist/assets/{sizeCapture-INFHLROL-BX_46o3S.js → sizeCapture-INFHLROL-9-Q4eosQ.js} +1 -1
  51. package/dist/assets/{stateDiagram-v2-GCMORJYK-W2e0RRrZ.js → stateDiagram-v2-GCMORJYK-jgsHnEQl.js} +1 -1
  52. package/dist/assets/{swimlanes-2SLR337P-CkyXpQX9.js → swimlanes-2SLR337P-MIVacUbv.js} +1 -1
  53. package/dist/assets/swimlanesDiagram-TC7HE7FX-Dekwo1KL.js +8 -0
  54. package/dist/assets/{timeline-definition-EJHVYXUP-BS-sCjlN.js → timeline-definition-EJHVYXUP-Ch8ins-D.js} +1 -1
  55. package/dist/assets/{usecaseDiagram-POWQR4AR-BQre-k6x.js → usecaseDiagram-POWQR4AR-BDwBIuhZ.js} +1 -1
  56. package/dist/assets/{vennDiagram-UO4OBE2U-CEWCsi_s.js → vennDiagram-UO4OBE2U-BiiDxcHO.js} +1 -1
  57. package/dist/assets/{wardleyDiagram-VNRHLVJA-CXUxqghG.js → wardleyDiagram-VNRHLVJA-D79CK2__.js} +1 -1
  58. package/dist/assets/{xychartDiagram-PMCCYNJV-DBgVMpwp.js → xychartDiagram-PMCCYNJV-CI7S0o-6.js} +1 -1
  59. package/dist/index.html +1 -1
  60. package/dist-server/container-mcp.js +81 -81
  61. package/dist-server/drivers/agents-proxy.js +81 -81
  62. package/dist-server/index.js +2533 -2147
  63. package/dist-server/openmausbot.js +625 -568
  64. package/dist-server/pair-cli.js +625 -568
  65. package/dist-server/server/auto-approve.js +12 -0
  66. package/dist-server/server/drivers/acp/custom.js +3 -1
  67. package/dist-server/server/drivers/acp/hermes.js +2 -1
  68. package/dist-server/server/drivers/hermes-context-floor.js +68 -0
  69. package/dist-server/server/god-mode-goal.js +78 -0
  70. package/dist-server/server/god-mode-run-host.js +69 -0
  71. package/dist-server/server/index.js +33 -33
  72. package/dist-server/server/model-fallback-repair.js +20 -0
  73. package/dist-server/server/personal-goal-runtime.js +29 -3
  74. package/dist-server/server/personal-goal-turn.js +2 -1
  75. package/dist-server/server/personal-goals.js +20 -2
  76. package/dist-server/shared/god-mode-run.js +173 -0
  77. package/dist-server/shared/personal-goal.js +42 -0
  78. package/dist-server/vps-container-mcp.js +81 -81
  79. package/package.json +1 -1
  80. package/dist/assets/channel-CT5xRPK0.js +0 -1
  81. package/dist/assets/swimlanesDiagram-TC7HE7FX-BH9Yry0J.js +0 -8
  82. package/dist-server/server/agents-token-file.js +0 -26
@@ -4,6 +4,9 @@ import { createHash, randomUUID } from "node:crypto";
4
4
  import { z } from "zod";
5
5
  import { writeFileAtomic } from "./atomic.js";
6
6
  import { parseGroupGoalDecision } from "./group-goal-run.js";
7
+ import { GOD_MODE_ACTIONS, GOD_MODE_STOP_KINDS, godModeRunInstructions } from "../shared/god-mode-run.js";
8
+ import { beginGodModeTurn, godModeRunLive, newGodModeRun, settleGodModeTurn } from "./god-mode-goal.js";
9
+ const godModeLog = z.object({ at: z.number(), stop: z.enum(GOD_MODE_STOP_KINDS), action: z.enum(GOD_MODE_ACTIONS), detail: z.string() });
7
10
  const goalSchema = z.object({
8
11
  id: z.string(), botId: z.string(), threadId: z.string(), objective: z.string(),
9
12
  criteria: z.array(z.string()), maxTurns: z.number().int().positive().max(1000),
@@ -14,6 +17,9 @@ const goalSchema = z.object({
14
17
  trigger: z.union([z.object({ kind: z.literal("owner") }), z.object({ kind: z.literal("user"), email: z.string().optional(), label: z.string().optional() })]).optional(),
15
18
  receiptMessageId: z.string().optional(), missing: z.number(), noProgress: z.number(),
16
19
  repeated: z.number(), lastReply: z.string(), lastBlocker: z.string(), blockers: z.number(),
20
+ /** A GOD MODE run (server/god-mode-goal.ts): bounded by time, not turns. */
21
+ godMode: z.object({ startedAt: z.number(), endsAt: z.number(), attempts: z.number(), failures: z.number(),
22
+ log: z.array(godModeLog) }).optional(),
17
23
  });
18
24
  const terminal = (goal) => goal.status === "completed" || goal.status === "stopped";
19
25
  /** A single durable objective per conversation. No provider, timer or authority lives here. */
@@ -33,7 +39,7 @@ export class PersonalGoals {
33
39
  this.loadError = "Saved goal state could not be read. It has been preserved for recovery; goals are paused.";
34
40
  }
35
41
  for (const goal of this.records)
36
- if (goal.status === "working") {
42
+ if (goal.status === "working" && !godModeRunLive(goal, Date.now())) {
37
43
  goal.status = "paused";
38
44
  goal.detail = "Atomic restarted. Use /goal resume to continue.";
39
45
  goal.updatedAt = Date.now();
@@ -46,6 +52,8 @@ export class PersonalGoals {
46
52
  save() { writeFileAtomic(this.path, JSON.stringify(this.records), { mode: 0o600 }); }
47
53
  touch(goal) { goal.updatedAt = Date.now(); goal.detail = redactSecretsInText(goal.detail); this.changed(goal); this.save(); }
48
54
  get(threadId) { return this.records.findLast((goal) => goal.threadId === threadId); }
55
+ /** GOD MODE runs still inside their time, e.g. after a restart. */
56
+ liveGodModeRuns() { return this.records.filter((goal) => godModeRunLive(goal, Date.now())); }
49
57
  byId(id) { return this.records.find((goal) => goal.id === id); }
50
58
  start(botId, threadId, input) {
51
59
  if (this.loadError)
@@ -53,7 +61,8 @@ export class PersonalGoals {
53
61
  const previous = this.get(threadId);
54
62
  if (previous && !terminal(previous))
55
63
  throw new Error("This conversation already has a goal. Resume it or stop it first.");
56
- const goal = goalSchema.parse({ ...input, objective: redactSecretsInText(input.objective), criteria: input.criteria.map(redactSecretsInText), id: randomUUID(), botId, threadId,
64
+ const { godModeMs, ...plain } = input;
65
+ const goal = goalSchema.parse({ ...plain, ...(godModeMs ? { godMode: newGodModeRun(Date.now(), godModeMs) } : {}), objective: redactSecretsInText(input.objective), criteria: input.criteria.map(redactSecretsInText), id: randomUUID(), botId, threadId,
57
66
  tokensUsed: 0, turnCount: 0, status: "working", detail: "Starting goal.",
58
67
  createdAt: Date.now(), updatedAt: Date.now(), missing: 0, noProgress: 0, repeated: 0, lastReply: "", lastBlocker: "", blockers: 0 });
59
68
  this.records.push(goal);
@@ -95,6 +104,10 @@ export class PersonalGoals {
95
104
  const goal = this.byId(id);
96
105
  if (!goal || goal.status !== "working")
97
106
  return false;
107
+ if (goal.godMode && !beginGodModeTurn(goal, Date.now())) {
108
+ this.touch(goal);
109
+ return false;
110
+ }
98
111
  if (goal.turnCount >= goal.maxTurns || (goal.tokenBudget !== undefined && goal.tokensUsed >= goal.tokenBudget)) {
99
112
  goal.status = "limit-reached";
100
113
  goal.detail = "Goal budget reached.";
@@ -167,6 +180,9 @@ export class PersonalGoals {
167
180
  else {
168
181
  goal.detail = decision?.detail ?? "Continue the objective and report a valid goal status.";
169
182
  }
183
+ // A GOD MODE run never stops on a failure, a question or a blocker.
184
+ if (goal.godMode && goal.status !== "completed")
185
+ settleGodModeTurn(goal, Date.now(), result, decision);
170
186
  if (goal.status === "working") {
171
187
  if (goal.turnCount >= goal.maxTurns || (goal.tokenBudget !== undefined && goal.tokensUsed >= goal.tokenBudget)) {
172
188
  goal.status = "limit-reached";
@@ -181,6 +197,8 @@ export class PersonalGoals {
181
197
  }
182
198
  }
183
199
  export function personalGoalInstructions(goal) {
200
+ if (goal.godMode)
201
+ return godModeRunInstructions({ ...goal, godMode: goal.godMode }, Date.now());
184
202
  return [
185
203
  "You are pursuing this conversation's durable goal. Complete authorized work; ordinary turn completion does not end the goal.",
186
204
  `Objective: ${goal.objective}`,
@@ -0,0 +1,173 @@
1
+ // A GOD MODE run: GOD MODE and Goal combined, for a fixed time.
2
+ //
3
+ // Erick, 2026-11-22: "2 hours, non stop, approve ALL permissions, bypass
4
+ // permissions, do not ask for anything if there is a way to do it". A run
5
+ // keeps working on one goal until the goal is done or the time is up. Every
6
+ // place a turn would otherwise stop to ask the person becomes the next
7
+ // attempt instead (godModeRunStop). The few things no run may do on its own
8
+ // (godModeHardLimit) are refused to the bot, which keeps working another way;
9
+ // they are never turned into a question either.
10
+ //
11
+ // Pure: a run is a goal with a deadline (server/personal-goals.ts keeps it,
12
+ // server/god-mode-goal.ts applies this policy), and the client shows the
13
+ // countdown from the same record.
14
+ export const GOD_MODE_RUN_DEFAULT_MS = 2 * 60 * 60_000;
15
+ export const GOD_MODE_RUN_MAX_MS = 8 * 60 * 60_000;
16
+ export const GOD_MODE_RUN_MIN_MS = 5 * 60_000;
17
+ /** Every place a turn can stop or ask the person. */
18
+ export const GOD_MODE_STOP_KINDS = [
19
+ "tool-permission", "paid-key", "provider-restriction", "owner-restriction", "approval-switch",
20
+ "question", "turn-failed", "check-in", "turn-ended", "computer-unavailable",
21
+ ];
22
+ export const GOD_MODE_ACTIONS = ["approved", "continued", "switched", "answered", "blocked"];
23
+ export const HARD_LIMIT_TEXT = {
24
+ money: "GOD MODE never moves money or buys anything.",
25
+ "delete-user-data": "GOD MODE never deletes data outside the task.",
26
+ "production-deploy": "GOD MODE never deploys to production.",
27
+ "force-push": "GOD MODE never force pushes.",
28
+ "local-postgres": "RULE #1: no local Postgres. Use the cloud Supabase database.",
29
+ };
30
+ const MONEY_TOOL = /(?:^|_|\b)(?:purchase|checkout|buy|pay(?:ment)?s?|transfer|send_money|payout|refund|charge|receive_payment|create_invoice|trade|swap|withdraw|deposit)(?:_|\b|$)/i;
31
+ const MONEY_COMMAND = /\b(?:stripe\s+(?:charges|payouts|transfers|refunds|payment_intents)\s+create|gh\s+sponsor|npm\s+fund\b.*--pay)\b/i;
32
+ const FORCE_PUSH = /\bgit\b[^\n;&|]*\bpush\b[^\n;&|]*(?:\s--force(?:-with-lease)?\b|\s-[a-zA-Z]*f\b|\s\+[^\s]+)/;
33
+ const PRODUCTION_DEPLOY = new RegExp([
34
+ String.raw `\bvercel\b[^\n;&|]*(?:--prod\b|\bpromote\b)`,
35
+ String.raw `\brailway\s+(?:up|redeploy)\b`,
36
+ String.raw `\bfly(?:ctl)?\s+deploy\b`,
37
+ String.raw `\bnetlify\s+deploy\b[^\n;&|]*--prod\b`,
38
+ String.raw `\bsupabase\s+(?:db\s+push|functions\s+deploy)\b`,
39
+ String.raw `\bheroku\b[^\n;&|]*\brelease\b`,
40
+ String.raw `\bgit\s+push\b[^\n;&|]*\bproduction\b`,
41
+ String.raw `\bpnpm\s+release(?::[a-z]+)?\b`,
42
+ String.raw `\bkubectl\b[^\n;&|]*\b(?:apply|rollout)\b[^\n;&|]*\bprod`,
43
+ ].join("|"), "i");
44
+ const PRODUCTION_DEPLOY_TOOL = /(?:^|__)(?:deploy|redeploy|accept-deploy|create-deployment|promote)(?:[-_]|$)/i;
45
+ const LOCAL_POSTGRES = new RegExp([
46
+ String.raw `postgres(?:ql)?://[^\s'"]*@(?:localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0)\b`,
47
+ String.raw `\bDATABASE_URL\s*=\s*['"]?[^\s'"]*(?:localhost|127\.0\.0\.1)`,
48
+ String.raw `\b(?:psql|pg_dump|pg_restore|createdb|dropdb)\b[^\n;&|]*(?:-h\s*|--host[= ])(?:localhost|127\.0\.0\.1)`,
49
+ String.raw `\b(?:initdb|pg_ctl(?:cluster)?|postgres\s+-D)\b`,
50
+ String.raw `\bbrew\s+services\s+(?:start|run|restart)\s+postgres`,
51
+ String.raw `\bdocker\b[^\n;&|]*\b(?:run|compose\s+up)\b[^\n;&|]*\b(?:postgres|supabase\/postgres|pgvector)\b`,
52
+ String.raw `\bsupabase\s+(?:start|db\s+start|db\s+reset)\b`,
53
+ ].join("|"), "i");
54
+ const DELETE_DATA_COMMAND = new RegExp([
55
+ String.raw `\brm\s+(?:-[a-zA-Z]*[rf][a-zA-Z]*\s+)+(?:--\s+)?(?:~|\$HOME|\/(?:\s|$|Users\b|home\b|\*)|\.\.(?:\/|\s|$))`,
56
+ String.raw `\b(?:drop\s+(?:database|schema|table)|truncate\s+table)\b`,
57
+ String.raw `\bdelete\s+from\s+\w+\s*(?:;|$)`,
58
+ String.raw `\bgit\s+(?:clean\s+-[a-zA-Z]*f[a-zA-Z]*d|reset\s+--hard\s+origin)\b`,
59
+ String.raw `\b(?:diskutil\s+erase|mkfs\b|shred\b)`,
60
+ ].join("|"), "i");
61
+ const DELETE_DATA_TOOL = /(?:^|__|[-_])(?:delete|destroy|purge|shred|empty_trash|drop)(?:[-_]|$)/i;
62
+ /** The command text or arguments of a tool call, as one string to check. */
63
+ export function toolCallText(input) {
64
+ if (typeof input === "string")
65
+ return input;
66
+ if (!input || typeof input !== "object")
67
+ return "";
68
+ try {
69
+ return JSON.stringify(input);
70
+ }
71
+ catch {
72
+ return "";
73
+ }
74
+ }
75
+ /** Which hard limit a tool call crosses, or null when a run may approve it.
76
+ * `workspace` is the run's own folder: deleting inside it is the task. */
77
+ export function godModeHardLimit(tool, input, workspace) {
78
+ const name = tool.replace(/^mcp__[^_]+__/, "");
79
+ const text = toolCallText(input);
80
+ if (LOCAL_POSTGRES.test(text))
81
+ return "local-postgres";
82
+ if (FORCE_PUSH.test(text))
83
+ return "force-push";
84
+ if (PRODUCTION_DEPLOY.test(text) || PRODUCTION_DEPLOY_TOOL.test(tool))
85
+ return "production-deploy";
86
+ if (MONEY_TOOL.test(name) || MONEY_COMMAND.test(text))
87
+ return "money";
88
+ if (DELETE_DATA_TOOL.test(tool) || DELETE_DATA_COMMAND.test(text)) {
89
+ if (workspace && deletesOnlyInside(text, workspace))
90
+ return null;
91
+ return "delete-user-data";
92
+ }
93
+ return null;
94
+ }
95
+ /** An `rm` whose every target is inside the run's folder. */
96
+ function deletesOnlyInside(text, workspace) {
97
+ const match = /\brm\s+((?:-[a-zA-Z]+\s+)*)(.+)/.exec(text);
98
+ if (!match)
99
+ return false;
100
+ const targets = match[2].split(/\s+/).filter(Boolean).map((target) => target.replace(/^['"]|['"]$/g, ""));
101
+ const root = workspace.replace(/\/+$/, "");
102
+ return targets.length > 0 && targets.every((target) => target.startsWith(`${root}/`) ||
103
+ (!target.startsWith("/") && !target.startsWith("~") && !target.startsWith("$") && !target.split("/").includes("..")));
104
+ }
105
+ /** What a running GOD MODE run does where a turn would stop. Nothing here
106
+ * returns "ask the person": a hard limit is refused to the bot, everything
107
+ * else goes on. */
108
+ export function godModeRunStop(stop) {
109
+ const detail = stop.detail ? ` ${stop.detail}` : "";
110
+ switch (stop.kind) {
111
+ case "tool-permission": {
112
+ const limit = godModeHardLimit(stop.tool ?? "", stop.input, stop.workspace);
113
+ if (limit)
114
+ return { action: "blocked", limit, note: `${HARD_LIMIT_TEXT[limit]} Refused ${stop.tool ?? "a tool"}; keep working another way.` };
115
+ return { action: "approved", note: `approved ${stop.tool ?? "tool"} (GOD MODE run)` };
116
+ }
117
+ case "paid-key":
118
+ return { action: "approved", note: `kept going on a pay-per-use key for this run.${detail}` };
119
+ case "provider-restriction":
120
+ case "owner-restriction":
121
+ case "approval-switch":
122
+ return { action: "switched", note: `moved to another engine for this run.${detail}` };
123
+ case "question":
124
+ return { action: "answered", note: GOD_MODE_QUESTION_ANSWER };
125
+ case "computer-unavailable":
126
+ return { action: "continued", note: `the computer is not available; doing it another way.${detail}` };
127
+ case "turn-failed":
128
+ case "check-in":
129
+ case "turn-ended":
130
+ return { action: "continued", note: `started the next attempt.${detail}` };
131
+ }
132
+ }
133
+ /** The answer a run gives a bot's question: Erick is not there to answer. */
134
+ export const GOD_MODE_QUESTION_ANSWER = "GOD MODE run: the person is away and will not answer. Pick the option that best finishes the goal, say which you picked, and keep going.";
135
+ /** The instruction every attempt of a run carries, in place of the
136
+ * ordinary goal's "approval requirements still apply ... ask". */
137
+ export function godModeRunInstructions(run, now) {
138
+ const minutes = Math.max(0, Math.round((run.godMode.endsAt - now) / 60_000));
139
+ return [
140
+ "GOD MODE run. Work non stop until the goal is done. Do not ask the person anything: they are away and every tool and permission is approved.",
141
+ `Objective: ${run.objective}`,
142
+ run.criteria.length ? `Completion criteria: ${JSON.stringify(run.criteria)}. Supply one non-empty evidence string per criterion when completed.` : "",
143
+ `Time left: about ${minutes} minutes. Attempt ${run.godMode.attempts + 1}.`,
144
+ `Progress: ${run.detail}`,
145
+ "If one way is blocked, find another way: another tool, another approach, another engine. A failure is the start of the next attempt, not a reason to stop.",
146
+ "Hard limits, never crossed: no moving money or buying anything, no deleting data outside this task, no production deploys, no force pushes, no local Postgres database (cloud Supabase only). Skip that step, say so, and finish the rest.",
147
+ 'End with a private envelope: <openmaus-goal>{"status":"continue","next":"self","instruction":"next concrete step","detail":"progress"}</openmaus-goal>',
148
+ 'Or status completed with detail, and for criteria "evidence":["verification for criterion 1", ...]. Never claim completion from intent alone; verify first.',
149
+ "Write useful visible results before the envelope. Never show or explain the envelope.",
150
+ ].filter(Boolean).join("\n");
151
+ }
152
+ /** The pause before the next attempt after `failures` failed ones in a row:
153
+ * none after a good turn, then 5 s doubling to at most a minute, so an engine
154
+ * that fails at once cannot spin the run through its turns. */
155
+ export function godModeRetryDelayMs(failures) {
156
+ if (failures <= 0)
157
+ return 0;
158
+ return Math.min(60_000, 5_000 * 2 ** (failures - 1));
159
+ }
160
+ /** A requested length, clamped; default two hours. */
161
+ export function godModeRunDuration(requested) {
162
+ if (typeof requested !== "number" || !Number.isFinite(requested))
163
+ return GOD_MODE_RUN_DEFAULT_MS;
164
+ return Math.min(GOD_MODE_RUN_MAX_MS, Math.max(GOD_MODE_RUN_MIN_MS, Math.round(requested)));
165
+ }
166
+ /** "1:59:30" for the countdown. */
167
+ export function formatGodModeCountdown(ms) {
168
+ const total = Math.max(0, Math.ceil(ms / 1000));
169
+ const hours = Math.floor(total / 3600);
170
+ const minutes = Math.floor((total % 3600) / 60);
171
+ const seconds = total % 60;
172
+ return `${hours}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
173
+ }
@@ -1,4 +1,7 @@
1
1
  export function parseGoalCommand(text) {
2
+ const godMode = parseGodModeCommand(text);
3
+ if (godMode !== undefined)
4
+ return godMode;
2
5
  const match = /^\/goal(?:\s+([\s\S]*))?$/i.exec(text.trim());
3
6
  if (!match)
4
7
  return null;
@@ -41,3 +44,42 @@ export function parseGoalCommand(text) {
41
44
  return { action: "start", objective: rest, maxTurns: maxTurns ?? 20, tokenBudget, criteria };
42
45
  }
43
46
  export const GOAL_HELP = 'Start: /goal [--turns 20] [--tokens N] [--done "criterion"] objective\nControls: /goal status, /goal pause, /goal resume [--turns N] [--tokens N], /goal stop. Resume budgets are total ceilings, not additional allowances. Token limits are checked between turns; a running turn can exceed the limit.';
47
+ /** `/godmode [--hours N | --minutes N] [--done "criterion"] objective`: a goal
48
+ * that runs non stop under GOD MODE until it is done or the time is up
49
+ * (default two hours). `/godmode stop` and `/godmode status` control it like
50
+ * `/goal`. Undefined when the text is not a /godmode command. */
51
+ function parseGodModeCommand(text) {
52
+ const match = /^\/god-?mode(?:\s+([\s\S]*))?$/i.exec(text.trim());
53
+ if (!match)
54
+ return undefined;
55
+ let rest = (match[1] ?? "").trim();
56
+ const control = /^(status|stop|help)$/i.exec(rest);
57
+ if (control)
58
+ return { action: control[1].toLowerCase() };
59
+ let godModeMs = 2 * 60 * 60_000;
60
+ const criteria = [];
61
+ while (rest.startsWith("--")) {
62
+ const flag = /^--(hours|minutes|done)\s+(?:"([^"\n]+)"|'([^'\n]+)'|(\S+))(?:\s|$)/.exec(rest);
63
+ if (!flag)
64
+ throw new Error('Use --hours N, --minutes N, or --done "completion criterion" before the goal.');
65
+ const value = flag[2] ?? flag[3] ?? flag[4];
66
+ if (flag[1] === "done")
67
+ criteria.push(value);
68
+ else {
69
+ const number = Number(value);
70
+ if (!Number.isFinite(number) || number <= 0)
71
+ throw new Error("The run length must be a positive number.");
72
+ godModeMs = Math.round(number * (flag[1] === "hours" ? 60 * 60_000 : 60_000));
73
+ if (godModeMs < 5 * 60_000 || godModeMs > 8 * 60 * 60_000)
74
+ throw new Error("A GOD MODE run lasts between 5 minutes and 8 hours.");
75
+ }
76
+ rest = rest.slice(flag[0].length).trim();
77
+ }
78
+ if (!rest)
79
+ return { action: "help" };
80
+ if (rest.length > 20_000 || criteria.length > 20 || criteria.some((item) => item.length > 2000))
81
+ throw new Error("Goal or completion criteria are too long.");
82
+ // Turns are only a loop guard here: the run is bounded by its time.
83
+ return { action: "start", objective: rest, maxTurns: 1000, criteria, godModeMs };
84
+ }
85
+ export const GOD_MODE_HELP = 'GOD MODE run: /godmode [--hours 2] [--done "criterion"] goal. It works non stop until the goal is done or the time is up, approves every tool, keeps going on pay-per-use keys, and switches engines when one is blocked. It never moves money, deletes data outside the task, deploys to production, force pushes or uses a local Postgres. Stop it with /godmode stop or the Stop button.';