@oh-my-matrix/autopilot 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +105 -10
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +308 -92
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/autopilot-state.d.ts +17 -0
  7. package/dist/src/autopilot-state.d.ts.map +1 -1
  8. package/dist/src/autopilot-state.js +52 -8
  9. package/dist/src/autopilot-state.js.map +1 -1
  10. package/dist/src/command-runner.d.ts +2 -6
  11. package/dist/src/command-runner.d.ts.map +1 -1
  12. package/dist/src/command-runner.js +4 -34
  13. package/dist/src/command-runner.js.map +1 -1
  14. package/dist/src/completion-detector.d.ts.map +1 -1
  15. package/dist/src/completion-detector.js +16 -8
  16. package/dist/src/completion-detector.js.map +1 -1
  17. package/dist/src/effort-injection.d.ts +21 -2
  18. package/dist/src/effort-injection.d.ts.map +1 -1
  19. package/dist/src/effort-injection.js +33 -9
  20. package/dist/src/effort-injection.js.map +1 -1
  21. package/dist/src/event-shape.contract.d.ts +21 -0
  22. package/dist/src/event-shape.contract.d.ts.map +1 -0
  23. package/dist/src/event-shape.contract.js +10 -0
  24. package/dist/src/event-shape.contract.js.map +1 -0
  25. package/dist/src/logger.d.ts.map +1 -1
  26. package/dist/src/logger.js +42 -7
  27. package/dist/src/logger.js.map +1 -1
  28. package/dist/src/model-routing.d.ts +36 -0
  29. package/dist/src/model-routing.d.ts.map +1 -0
  30. package/dist/src/model-routing.js +106 -0
  31. package/dist/src/model-routing.js.map +1 -0
  32. package/dist/src/orchestrator.d.ts +34 -1
  33. package/dist/src/orchestrator.d.ts.map +1 -1
  34. package/dist/src/orchestrator.js +113 -12
  35. package/dist/src/orchestrator.js.map +1 -1
  36. package/dist/src/projection.d.ts +8 -2
  37. package/dist/src/projection.d.ts.map +1 -1
  38. package/dist/src/projection.js +15 -1
  39. package/dist/src/projection.js.map +1 -1
  40. package/dist/src/stall-detector.d.ts +4 -1
  41. package/dist/src/stall-detector.d.ts.map +1 -1
  42. package/dist/src/stall-detector.js +7 -3
  43. package/dist/src/stall-detector.js.map +1 -1
  44. package/dist/src/tool-error-tracker.d.ts +16 -0
  45. package/dist/src/tool-error-tracker.d.ts.map +1 -1
  46. package/dist/src/tool-error-tracker.js +16 -0
  47. package/dist/src/tool-error-tracker.js.map +1 -1
  48. package/dist/src/types.d.ts +67 -5
  49. package/dist/src/types.d.ts.map +1 -1
  50. package/dist/src/types.js +45 -1
  51. package/dist/src/types.js.map +1 -1
  52. package/dist/src/workflow-config.d.ts.map +1 -1
  53. package/dist/src/workflow-config.js +108 -14
  54. package/dist/src/workflow-config.js.map +1 -1
  55. package/openclaw.plugin.json +34 -2
  56. package/package.json +23 -13
  57. package/LICENSE +0 -21
  58. package/dist/src/audit-persister.d.ts +0 -25
  59. package/dist/src/audit-persister.d.ts.map +0 -1
  60. package/dist/src/audit-persister.js +0 -162
  61. package/dist/src/audit-persister.js.map +0 -1
  62. package/dist/src/permission-policy.d.ts +0 -36
  63. package/dist/src/permission-policy.d.ts.map +0 -1
  64. package/dist/src/permission-policy.js +0 -265
  65. package/dist/src/permission-policy.js.map +0 -1
package/README.md CHANGED
@@ -14,23 +14,118 @@ npm install @oh-my-matrix/autopilot
14
14
  npm install openclaw@">=2026.5.28" @oh-my-matrix/permission-policy
15
15
  ```
16
16
 
17
- ## Use
18
-
19
- Registers as an OpenClaw plugin (`openclaw.plugin.json`) with hooks including
20
- `before_tool_call`, `after_tool_call`, `before_compaction`, `agent_turn_prepare`,
21
- `before_agent_run`, and `llm_output`. Enable it in your OpenClaw runtime and configure
22
- behaviour via `WORKFLOW.md` (destructive-git policy, retry, evidence gates).
23
-
24
17
  ## What it does
25
18
 
26
- - **Continuation engine** — resumes long tasks across turns with a retry queue.
19
+ - **Continuation engine** — resumes long tasks across turns with exponential-backoff retry.
27
20
  - **Stall / completion detection** — surfaces when a run is stuck or genuinely done.
28
- - **Evidence gate** — blocks completion until success criteria are verified.
21
+ - **Evidence gate** — blocks completion until validation commands pass (opt-in via `trustWorkspace`).
22
+ - **Orchestrator reducer** — pure-function state machine (7 states, immutable transitions).
29
23
  - **Projection + goal manager** — preserves run state and goal across compaction.
24
+ - **Model routing** — cost-aware tier selection per execution phase (budget/standard/premium).
30
25
  - **Permission-policy integration** — coordinates the run-scoped policy with
31
26
  [`@oh-my-matrix/permission-policy`](../permission-policy).
32
27
 
28
+ ## Plugin config
29
+
30
+ Set via `openclaw.plugin.json` or host `pluginConfig`:
31
+
32
+ | Key | Type | Default | Description |
33
+ |-----|------|---------|-------------|
34
+ | `maxAttemptsPerTurn` | number | `5` | Max revise attempts within a single turn |
35
+ | `maxTotalContinuations` | number | `50` | Max total continuations across all turns |
36
+ | `toolErrorThreshold` | number | `3` | Consecutive identical tool errors before pause |
37
+ | `excludedAgents` | string[] | `[]` | Agent IDs to skip (no autopilot hooks) |
38
+ | `highRiskTools` | string[] | — | Additional tools to block for subagents |
39
+ | `tokenBudget` | number | — | Total token budget; pauses when exceeded |
40
+ | `maxConcurrentAutopilot` | number | `5` | Max simultaneous autopilot runs |
41
+ | `thinkingIntensity` | `'low'\|'medium'\|'high'` | `'high'` | Graduated thinking effort injection |
42
+ | `trustWorkspace` | boolean | `false` | Enable workspace-sourced validation commands |
43
+ | `modelRouting` | object | — | Tier→model mapping (see Model routing below) |
44
+
45
+ ## Gateway methods
46
+
47
+ | Method | Params | Description |
48
+ |--------|--------|-------------|
49
+ | `autopilot.activate` | `{ sessionKey, goal?, maxTotalContinuations?, tokenBudget?, trustWorkspace? }` | Start or re-activate a run. Returns `{ ok, runId, projection }` |
50
+ | `autopilot.stop` | `{ sessionKey }` | Stop a running session (sets `blockedReason: 'user_stopped'`) |
51
+ | `autopilot.resume` | `{ sessionKey }` | Resume from `paused` status (resumable blocked reasons only) |
52
+ | `autopilot.status` | `{ sessionKey }` | Query current projection for a session |
53
+ | `autopilot.setGoal` | `{ sessionKey, goal }` | Update the run goal mid-flight |
54
+ | `autopilot.cleanup` | — | Clear all internal state (all runs, maps, intervals) |
55
+
56
+ ## WORKFLOW.md format
57
+
58
+ Place a `WORKFLOW.md` with YAML front matter in the workspace root to configure per-workspace behavior:
59
+
60
+ ```yaml
61
+ ---
62
+ autopilot:
63
+ version: 1
64
+ permission_mode: guarded_yolo
65
+ max_concurrent: 3
66
+ max_retries: 5
67
+ stall_timeout_ms: 60000
68
+ max_retry_backoff_ms: 120000
69
+ workspace:
70
+ root: .matrix/worktrees
71
+ cleanup: delete_on_done
72
+ branch_prefix: auto
73
+ validation:
74
+ commands:
75
+ - id: test
76
+ command: pnpm test
77
+ timeout_ms: 30000
78
+ required: true
79
+ destructive_git:
80
+ allow: false
81
+ model_routing:
82
+ default_tier: standard
83
+ initial_turn_tier: premium
84
+ validation_tier: budget
85
+ model_ids:
86
+ budget: claude-haiku-4-5-20251001
87
+ standard: claude-sonnet-4-6
88
+ premium: claude-opus-4-6
89
+ ---
90
+ ```
91
+
92
+ Validation command binaries are allowlisted (npm, pnpm, node, vitest, tsc, go, cargo, python, etc.); disallowed binaries (curl, wget, bash, sh) are dropped with a warning.
93
+
94
+ ## AutopilotProjection fields
95
+
96
+ The `autopilot.status` gateway returns a projection object:
97
+
98
+ | Field | Type | Description |
99
+ |-------|------|-------------|
100
+ | `status` | `'idle'\|'running'\|'paused'\|'done'` | Current run status |
101
+ | `orchestrationState` | `'unclaimed'\|'claimed'\|'running'\|'retry_queued'\|'released'\|'blocked'\|'done'` | Orchestrator state |
102
+ | `enabled` | boolean | Whether autopilot is active |
103
+ | `turnAttempts` / `totalContinuations` | number | Current turn / total counters |
104
+ | `pauseReason` | string? | Why the run paused |
105
+ | `blockedReason` | string? | Why the run is blocked |
106
+ | `canStop` | boolean | Whether stop is meaningful |
107
+ | `lastGoal` | string? | Truncated goal text |
108
+ | `totalTokensUsed` / `inputTokensUsed` / `outputTokensUsed` | number | Token accounting |
109
+ | `estimatedCostUsd` | number | Estimated API cost (Claude Sonnet pricing) |
110
+ | `evidenceStatus` | string? | Evidence gate status |
111
+ | `workspacePath` / `workspaceBranch` | string? | Workspace info |
112
+ | `thinkingIntensity` / `modelTier` / `recommendedModelId` | string? | Current routing |
113
+
114
+ ## Environment variables
115
+
116
+ No environment variables are required. The plugin reads all configuration from `pluginConfig` and `WORKFLOW.md`.
117
+
118
+ ## Troubleshooting
119
+
120
+ **Run stuck at `claimed`?** — The host must emit `agent_turn_prepare` before `before_agent_finalize` for the orchestrator to advance through `running` → `released` → `done`.
121
+
122
+ **Evidence gate always skipped?** — Set `trustWorkspace: true` in the activate payload or plugin config. Without it, workspace-sourced validation commands are not executed (security: untrusted workspaces cannot reach RCE).
123
+
124
+ **"audit plugin not loaded" warning?** — Normal if `@openclaw/matrixassistant-audit` is not installed. Autopilot works without it (degraded but safe).
125
+
126
+ **Token budget not enforcing?** — Budget enforcement happens at the `before_agent_finalize` turn boundary (`continuation-engine.ts`). Subagent tokens are counted toward the parent run's budget.
127
+
33
128
  ## Status
34
129
 
35
- v2.1.1. Tested with `vitest` (500+ tests). See the project
130
+ v3.0.0. Tested with `vitest` (677 tests, 91%+ statement coverage). See the project
36
131
  [changelog](https://github.com/TeFuirnever/oh-my-matrix/blob/master/CHANGELOG.md).
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { AutopilotState } from './src/types';
2
2
  import type { OpenClawPluginApi } from 'openclaw/dist/plugin-sdk/plugin-runtime';
3
+ export type { AutopilotProjection } from './src/projection';
3
4
  export declare const id = "autopilot";
4
5
  export declare const name = "Autopilot Continuous Mode";
5
- export declare const version = "2.0.0";
6
+ export declare const version = "3.0.0";
6
7
  export declare function _resetForTest(): void;
7
8
  /** Test-only: inject a mock audit_setMode so the closed-over _auditSetMode reference is replaceable. */
8
9
  export declare function _setAuditSetModeForTest(fn: ((mode: 'active' | 'monitor' | 'passive') => void) | null): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,cAAc,EAA+B,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,yCAAyC,CAAC;AA+BlG,eAAO,MAAM,EAAE,cAAc,CAAC;AAC9B,eAAO,MAAM,IAAI,8BAA8B,CAAC;AAChD,eAAO,MAAM,OAAO,UAAU,CAAC;AAgD/B,wBAAgB,aAAa,IAAI,IAAI,CASpC;AAED,wGAAwG;AACxG,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAK3G;AAED,wBAAgB,wBAAwB;;;;;EAOvC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,cAAc,CAAC,oBAAoB,CAAC,CAAC;IACzD,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CACjC,GAAG,cAAc,GAAG,SAAS,CAiD7B;AAyDD,+EAA+E;AAC/E,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAMD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,CAwyBrD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,cAAc,EAA+B,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAuZ,MAAM,yCAAyC,CAAC;AActe,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAsB5D,eAAO,MAAM,EAAE,cAAc,CAAC;AAC9B,eAAO,MAAM,IAAI,8BAA8B,CAAC;AAGhD,eAAO,MAAM,OAAO,UAAU,CAAC;AA4G/B,wBAAgB,aAAa,IAAI,IAAI,CAWpC;AAED,wGAAwG;AACxG,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAK3G;AAED,wBAAgB,wBAAwB;;;;;EAOvC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,cAAc,CAAC,oBAAoB,CAAC,CAAC;IACzD,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CACjC,GAAG,cAAc,GAAG,SAAS,CAmD7B;AA6FD,+EAA+E;AAC/E,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAMD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,CAo7BrD"}