archal 0.9.20 → 0.10.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 (90) hide show
  1. package/README.md +59 -159
  2. package/agents/openclaw/Dockerfile +2 -1
  3. package/agents/openclaw/README.md +10 -17
  4. package/agents/openclaw/drive.mjs +21 -31
  5. package/agents/openclaw/extract-openclaw-response-text.mjs +49 -0
  6. package/agents/openclaw/scenarios/acceptance/github-escalation-and-cleanup.md +43 -0
  7. package/agents/openclaw/scenarios/acceptance/jira-linear-release-triage.md +39 -0
  8. package/agents/openclaw/scenarios/acceptance/multi-clone-customer-risk-review.md +45 -0
  9. package/agents/openclaw/scenarios/acceptance/slack-incident-handoff.md +42 -0
  10. package/agents/openclaw/scenarios/acceptance/stripe-dunning-remediation.md +40 -0
  11. package/agents/openclaw/scenarios/close-stale-issues.md +35 -0
  12. package/agents/openclaw/workspace/TOOLS.md +19 -0
  13. package/clone-assets/calcom/tools.json +1705 -153
  14. package/clone-assets/clickup/tools.json +2528 -541
  15. package/clone-assets/customerio/tools.json +2108 -144
  16. package/clone-assets/github/tools.json +1 -2
  17. package/clone-assets/gitlab/tools.json +10087 -398
  18. package/clone-assets/hubspot/tools.json +198 -0
  19. package/clone-assets/linear/tools.json +41 -1
  20. package/clone-assets/sentry/tools.json +2264 -188
  21. package/clone-assets/stripe/tools.json +114 -0
  22. package/clone-assets/webflow/tools.json +1895 -125
  23. package/dist/{autoloop-worker-types-BEb_E44z.d.cts → autoloop-worker-types-CHaclqtD.d.cts} +23 -59
  24. package/dist/cli.cjs +107175 -126959
  25. package/dist/commands/{autoloop-hosted-worker.cjs → autoloop-hosted-control-plane-client.cjs} +25657 -42736
  26. package/dist/commands/{autoloop-hosted-worker.d.cts → autoloop-hosted-control-plane-client.d.cts} +32 -42
  27. package/dist/commands/autoloop-pr-verification.cjs +607 -522
  28. package/dist/commands/autoloop-pr-verification.d.cts +3 -1
  29. package/dist/commands/autoloop-result-parser.cjs +2474 -2373
  30. package/dist/commands/autoloop-result-parser.d.cts +159 -2
  31. package/dist/commands/autoloop-worker.cjs +14565 -12240
  32. package/dist/commands/autoloop-worker.d.cts +10 -5
  33. package/dist/eval-shim.mjs +216 -0
  34. package/dist/index.cjs +15 -2
  35. package/dist/index.d.cts +3 -1
  36. package/dist/layer-1-ziaLpfLr.d.cts +62 -0
  37. package/dist/metafile-cjs.json +1 -0
  38. package/dist/reporter-entry.js +3 -0
  39. package/dist/{replay.cjs → sdk/index.cjs} +42979 -40973
  40. package/dist/sdk/index.d.cts +626 -0
  41. package/dist/vitest/{chunk-6CBYFCFK.js → chunk-2PDHTPZC.js} +289 -89
  42. package/dist/vitest/{chunk-ARVS45PP.js → chunk-7L4BBB6M.js} +123 -274
  43. package/dist/vitest/index.cjs +500 -816
  44. package/dist/vitest/index.d.ts +16 -81
  45. package/dist/vitest/index.js +40 -409
  46. package/dist/vitest/runtime/hosted-session-reaper.cjs +143 -293
  47. package/dist/vitest/runtime/hosted-session-reaper.js +1 -1
  48. package/dist/vitest/runtime/setup-files.js +2 -2
  49. package/manifest.json +9 -0
  50. package/package.json +14 -13
  51. package/skills/archal-agent/SKILL.md +0 -1
  52. package/skills/autoloop/SKILL.md +288 -273
  53. package/skills/autoloop/references/hosted-sources.md +49 -17
  54. package/skills/autoloop/references/trace-schema-mapping.md +83 -52
  55. package/skills/eval/SKILL.md +16 -48
  56. package/skills/free-account/SKILL.md +103 -0
  57. package/skills/install-agent/SKILL.md +16 -35
  58. package/skills/onboard/SKILL.md +13 -70
  59. package/skills/scenario/SKILL.md +30 -27
  60. package/skills/seed/SKILL.md +7 -6
  61. package/skills/vitest/SKILL.md +3 -2
  62. package/agents/github-octokit/.archal.json +0 -8
  63. package/agents/github-octokit/Dockerfile +0 -8
  64. package/agents/github-octokit/README.md +0 -113
  65. package/agents/github-octokit/agent.mjs +0 -54
  66. package/agents/github-octokit/package.json +0 -9
  67. package/agents/github-octokit/scenarios/test-repo-access.md +0 -27
  68. package/agents/google-workspace-local-tools/Dockerfile +0 -6
  69. package/agents/google-workspace-local-tools/README.md +0 -58
  70. package/agents/google-workspace-local-tools/agent.mjs +0 -196
  71. package/agents/google-workspace-local-tools/archal-harness.json +0 -7
  72. package/agents/google-workspace-local-tools/run-input.yaml +0 -16
  73. package/agents/google-workspace-local-tools/scenario.md +0 -29
  74. package/agents/hermes/.archal.json +0 -8
  75. package/agents/hermes/Dockerfile +0 -46
  76. package/agents/hermes/README.md +0 -87
  77. package/agents/hermes/SOUL.md +0 -27
  78. package/agents/hermes/config.yaml +0 -34
  79. package/agents/hermes/drive.mjs +0 -113
  80. package/agents/hermes/scenarios/stripe-customers-read-only.md +0 -32
  81. package/agents/pagination-test/README.md +0 -24
  82. package/agents/pagination-test/scenario.md +0 -24
  83. package/agents/replay-capsule-harness/README.md +0 -29
  84. package/agents/replay-capsule-harness/observability-install-offline-e2e.mts +0 -1517
  85. package/agents/replay-capsule-harness/replay-capsule-e2e.mjs +0 -104
  86. package/dist/harness.cjs +0 -63
  87. package/dist/harness.d.cts +0 -20
  88. package/dist/replay.d.cts +0 -4625
  89. package/dist/scenarios.cjs +0 -80343
  90. package/dist/scenarios.d.cts +0 -562
@@ -7,12 +7,13 @@ argument-hint: "[repo, trace source, or failure description]"
7
7
 
8
8
  # Archal Autoloop
9
9
 
10
- You help users connect real agent traces to Archal. Your job is to wire the repo,
11
- trace source, harness contract, scenario contract, and GitHub PR path without
12
- guessing or leaking secrets.
10
+ You help users connect real agent traces to Archal, then drive the loop that
11
+ turns a production failure into a verified reproduction and, when the user
12
+ opts in, a fix PR. Your job is to wire the repo, trace source, harness, and
13
+ scenario without guessing or leaking secrets.
13
14
 
14
- Autoloop is not a replacement for `archal run`. It uses the same harness and clone
15
- routing ideas, but the trigger is a trace that already happened.
15
+ Autoloop is not a replacement for `archal run`. It uses the same harness and
16
+ clone routing, but the trigger is a trace that already happened.
16
17
 
17
18
  Autoloop is also not arbitrary production trace replay. It can reproduce a
18
19
  failure only when the trace, scenario contract, and seed templates contain
@@ -21,331 +22,351 @@ is thin, block and name the missing data instead of claiming reproduction.
21
22
 
22
23
  ## Product mental model
23
24
 
24
- Autoloop does this loop:
25
+ Autoloop runs this loop:
25
26
 
26
27
  1. Import a trace and its child spans from a read-only source.
27
28
  2. Grade whether the trace contains a real failure.
28
29
  3. Build a reproduction scenario and clone seed from trace evidence plus
29
30
  repo-owned seed templates.
30
31
  4. Run the reproduction against service clones through the customer harness.
31
- 5. If reproduced, patch the repo and open a GitHub issue or PR.
32
+ 5. If reproduced, patch the repo and open a GitHub PR.
32
33
 
33
34
  Steps 1-4 are **autoloop**: ingest -> grade -> find the failed trace ->
34
35
  reproduce on clones. Step 5 (writing the fix and opening the PR) is **autofix**,
35
36
  a separate opt-in step that is *not* part of autoloop until it is turned on.
36
- Both are per-agent toggles, switchable from the agents tab, the CLI, or by asking
37
- the Archal copilot in chat.
38
37
 
39
- The CLI maps these toggles to `--execution-policy`: `reproduce` runs autoloop
40
- only with autofix off, while `fix` turns autofix on (autoloop plus the fix/PR
41
- step). Narrower policies stop earlier:
38
+ ## Consent breakpoints (do these before you touch anything)
42
39
 
43
- | Policy | Stops after | Autofix |
44
- |--------|-------------|---------|
45
- | `observe` | import | off |
46
- | `grade` | grading | off |
47
- | `reproduce` | reproduction | off |
48
- | `fix` | PR or blocked fix status | on |
40
+ Autoloop can act on the user's real repository and reads their production
41
+ traces. Before you register a source or start a loop, walk the three
42
+ breakpoints below **in order**. Each is a hard STOP: ask the question, wait for
43
+ an explicit answer, and only then proceed. Do not batch them, do not assume a
44
+ default, and do not start the loop until all three are answered.
49
45
 
50
- Do not invent or promote separate top-level judge, reproduce, fix, or
51
- trace-replay commands. The public command is `archal autoloop`. Local stop
52
- command is `archal detach` for file-backed trace directories.
46
+ ### Breakpoint 1 - PR-opening consent
53
47
 
54
- ## Discover first
48
+ STOP. Before anything else, state the consequence plainly and ask the user to
49
+ choose:
55
50
 
56
- Before changing anything, inspect the repo:
51
+ > Autoloop can open fix PRs on your repo automatically. With **Autofix ON**,
52
+ > every imported production failure that reproduces gets a fix PR opened on
53
+ > your repo. With **Autofix OFF**, autoloop stops after reproducing the failure
54
+ > and opens no PRs; you (or your agent) take over from the reproduction.
55
+ > Which do you want?
57
56
 
58
- 1. `package.json` and scripts: how is the agent run? What tests should a fix PR
59
- pass?
60
- 2. Existing Archal files:
61
- - `.archal.json`
62
- - `.archal/harness.*`
63
- - `archal/harness.json`
64
- - `archal/scenario.md`
65
- - `archal/run-input.yaml`
66
- - `archal/seeds/*.json`
67
- - `scenarios/*.md`
68
- 3. Service SDKs and likely clones:
69
- - `stripe` -> `stripe`
70
- - `@octokit/rest`, `octokit` -> `github`
71
- - `@slack/web-api`, `@slack/bolt` -> `slack`
72
- - `jira`, `jira-client`, `jira.js` -> `jira`
73
- - `@linear/sdk` -> `linear`
74
- - `@supabase/supabase-js`, `pg` -> `supabase`
75
- - `googleapis` -> `google-workspace`
76
- 4. GitHub remote:
77
- ```bash
78
- git remote get-url origin
79
- ```
80
- Hosted sources and `--execution-policy fix` need a GitHub remote.
81
- 5. Trace source shape, if available:
82
- - provider: local files, Postgres, Supabase
83
- - or local/client-ingested sources normalized through `archal trace-source`
84
- such as file, HTTP/OTel, Langfuse, Braintrust, S3/GCS, or custom JSON
85
- - trace table and span table names
86
- - id columns
87
- - parent span column
88
- - timestamp/cursor columns
89
- - status, workspace, trace group, and agent filters
90
-
91
- Never print secrets while inspecting. If you need to show a database URL, show
92
- only the env var name or secret reference.
93
-
94
- ## Preconditions
95
-
96
- You need these before a full hosted Autoloop setup:
97
-
98
- - Archal CLI installed in the repo or reachable with `npx archal`
99
- - authenticated user (`archal login`) or `ARCHAL_TOKEN=archal_ws_...`
100
- - GitHub App installed on the target repo
101
- - repo origin that resolves to `github.com/<owner>/<repo>`
102
- - read-only trace source credential
103
- - headless harness command
104
- - `archal/scenario.md` for the trace family
105
- - optional but strongly recommended `archal/seeds/*.json`
106
- - model/provider keys required by the user's agent and tests
107
-
108
- If any prerequisite is missing, make the smallest safe change and explain what
109
- is still required. Do not continue into a fake reproduction.
110
-
111
- ## Safe setup flow
112
-
113
- ### 1. Install and authenticate
114
-
115
- Prefer project-local install:
57
+ Map the answer explicitly and never rely on the CLI default:
116
58
 
117
- ```bash
118
- npm install -D archal
119
- npx archal login
120
- npx archal usage
121
- ```
59
+ | User wants | Pass | Autofix |
60
+ |------------|------|---------|
61
+ | Fix PRs opened automatically | `--execution-policy fix` | ON |
62
+ | Reproduce only, no PRs | `--execution-policy reproduce` | OFF |
122
63
 
123
- In CI or a customer repo, use:
64
+ The bare `archal autoloop` default is `fix`, which opens PRs. **Never let that
65
+ default stand in silently.** Always pass an explicit `--execution-policy` that
66
+ matches the user's answer. The reproduce-only promise is real: with
67
+ `--execution-policy reproduce`, autoloop grades and replays against clones and
68
+ then stops, with no fix and no PR.
124
69
 
125
- ```bash
126
- export ARCHAL_TOKEN=archal_ws_...
127
- npx archal usage
128
- ```
70
+ ### Breakpoint 2 - GitHub App install (only if the user chose fix PRs)
129
71
 
130
- Use a workspace API key for automated runs. Do not commit it.
72
+ If the user chose **reproduce only**, skip this breakpoint and note that the
73
+ fix path stays off.
131
74
 
132
- ### 2. Add or verify `archal/harness.json`
75
+ If the user chose **fix PRs**, STOP and explain, then wait for confirmation:
133
76
 
134
- Minimal shape:
77
+ > The fix-PR path needs the **Archal GitHub App** installed on the target repo
78
+ > and linked to your Archal workspace. The app is granted least-privilege
79
+ > access: write to repository contents (to push a fix branch) and to pull
80
+ > requests (to open the PR), plus read-only access to Actions, checks, commit
81
+ > statuses, and metadata so it can watch its own PR's checks. It gets **no**
82
+ > issue access, and it opens a PR from a fix branch rather than pushing to your
83
+ > default branch. Install it from the Archal dashboard's integrations /
84
+ > connect-repo flow, then tell me once it is installed (or say you'd rather stay
85
+ > reproduce-only).
135
86
 
136
- ```json
137
- {
138
- "version": 1,
139
- "local": {
140
- "command": "node",
141
- "args": ["agent.mjs"]
142
- }
143
- }
144
- ```
87
+ Do not proceed to a `fix` policy until the user confirms. Verify the install
88
+ with the machine check before starting the loop:
145
89
 
146
- The command must be headless and repeatable. It should run the real agent path,
147
- not a hand-authored mock. During reproduction, Archal invokes this command
148
- through `archal run`, so the agent should read the task from `AGENT_TASK` and
149
- print its final answer to stdout. If the project already has `.archal.json` for
150
- `archal run`, align the Autoloop harness with that command.
90
+ ```bash
91
+ npx archal autoloop --repo . --execution-policy fix --check --json
92
+ ```
151
93
 
152
- ### 3. Add or verify `archal/scenario.md`
94
+ The `GitHub App auth` check must pass (a repo-scoped PR token can be minted). A
95
+ failing check tells you exactly what is missing; relay that, don't guess.
153
96
 
154
- The scenario describes the standing task and checks for this trace family.
97
+ ### Breakpoint 3 - read-only database connection string
155
98
 
156
- Required sections:
99
+ STOP whenever the trace source is a database (Postgres or Supabase). Do not
100
+ accept a privileged or default connection string. Walk the user through
101
+ creating a **read-only** role scoped to the trace tables, then:
157
102
 
158
- ```md
159
- # Scenario title
103
+ - The credential is passed by **environment variable name**, not value:
104
+ `--database-url-env <ENV_VAR_NAME>`. Never put the URL inline in a command,
105
+ never echo it, never commit it.
106
+ - In hosted production, prefer a secret reference:
107
+ `--database-url-secret-ref <ref>` (the ref must not contain a plaintext
108
+ credential).
160
109
 
161
- ## Setup
162
- Trace-family context and the starting state Archal should reconstruct.
110
+ Ask the user to confirm the role is read-only and the URL lives in an env var
111
+ or secret ref before you run any `--source` command. See
112
+ `references/hosted-sources.md` for the read-only-role and flag detail.
163
113
 
164
- ## Prompt
165
- The task the agent should complete.
114
+ ## Discover first
166
115
 
167
- ## Expected Behavior
168
- The answer key for grading and reproduction.
116
+ Before changing anything, inspect the repo:
169
117
 
170
- ## Success Criteria
171
- - [D] Deterministic clone-state check
172
- - [P] Probabilistic trace/output check
118
+ 1. `package.json` and scripts: how is the agent run? What tests should a fix PR
119
+ pass?
120
+ 2. Auth: `archal usage` must pass. For hosted sources, CI, or headless agents,
121
+ use a workspace API key in `ARCHAL_TOKEN`, created by an owner/admin with
122
+ `archal workspace api-key create <label>`.
123
+ 3. GitHub remote: `git remote get-url origin`. Hosted sources and the `fix`
124
+ policy need an origin that resolves to `github.com/<owner>/<repo>`.
125
+ 4. Docker: high-fidelity reproduction needs Docker or sandbox mode available.
126
+ If Docker is unavailable, stop before claiming clone-backed reproduction.
127
+ 5. Existing Archal files: `.archal.json`, `archal/harness.json`,
128
+ `archal/scenario.md`, `archal/seeds/*.json`, `scenarios/*.md`.
129
+ 6. Service SDKs and likely clones: `stripe` -> `stripe`; `@octokit/rest`,
130
+ `octokit` -> `github`; `@slack/web-api`, `@slack/bolt` -> `slack`;
131
+ `jira.js` -> `jira`; `@linear/sdk` -> `linear`; `@supabase/supabase-js`,
132
+ `pg` -> `supabase`; `googleapis` -> `google-workspace`.
133
+ 7. Trace source shape: provider (local files, Postgres, Supabase), trace/span
134
+ table names, id columns, parent-span column, cursor columns, and any
135
+ workspace/agent/status/group filters.
136
+
137
+ Never print secrets while inspecting. Show only the env var name or secret
138
+ reference, never a database URL.
139
+
140
+ ## Setup files
141
+
142
+ ### `archal/harness.json`
173
143
 
174
- ## Config
175
- clones: stripe, slack
176
- timeout: 120
144
+ ```json
145
+ { "version": 1, "local": { "command": "node", "args": ["agent.mjs"] } }
177
146
  ```
178
147
 
179
- Keep model-visible instructions realistic. Do not tell the tested agent that it
180
- is in Archal, a clone-backed environment, or a special replay.
148
+ The command must be headless and repeatable, and run the real agent path (not a
149
+ mock). During reproduction Archal invokes it through `archal run`, so the agent
150
+ reads its task from `AGENT_TASK` and prints its final answer to stdout. Align it
151
+ with the `agent` command in `.archal.json` if one exists.
181
152
 
182
- ### 4. Add seed templates when trace evidence is thin
153
+ ### `archal/scenario.md`
183
154
 
184
- Recommended:
155
+ Describes the standing task and checks for this trace family. Required sections:
156
+ `# Title`, `## Setup`, `## Prompt`, `## Expected Behavior`,
157
+ `## Success Criteria` (`[D]` deterministic, `[P]` probabilistic), `## Config`
158
+ (`clones:`, `timeout:`). Keep model-visible instructions realistic: do not tell
159
+ the tested agent it is in Archal, a clone-backed environment, or a replay.
185
160
 
186
- ```text
187
- archal/seeds/
188
- stripe-billing-support.json
189
- jira-escalations.json
190
- ```
161
+ ### Seed templates (when trace evidence is thin)
191
162
 
192
- Seed templates should contain stable service state for the task family. Autoloop
193
- can then fill in trace-specific identifiers. This is much safer than expecting
194
- weak traces to reconstruct full service state.
163
+ Put stable service state for the task family under `archal/seeds/*.json` (e.g.
164
+ `stripe-billing-support.json`). Autoloop fills in trace-specific identifiers.
165
+ This is far safer than expecting a weak trace to reconstruct full service state.
195
166
 
196
- ## Hosted database source
167
+ ## Register the loop
197
168
 
198
- Use this when traces live in Postgres or Supabase. Create a read-only DB user,
199
- keep the URL in `TRACE_DATABASE_URL` (or a secret ref in hosted production), then
200
- `--check` the source and re-run without `--check` to register it. Registration
201
- posts the source config to Archal and returns; hosted workers own polling after
202
- that, so local `archal detach` does not disable it.
169
+ ### Local trace directory (pilot / exported files)
203
170
 
204
- See `references/hosted-sources.md` for the full check, register, and
205
- `--database-url-secret-ref` flag blocks.
171
+ ```bash
172
+ npx archal autoloop ./prod-traces --repo . --execution-policy reproduce
173
+ ```
206
174
 
207
- ## Client-side trace ingestion
175
+ Uses the policy from Breakpoint 1. Artifacts land under `.archal/autoloop/`
176
+ (see the artifact guide below). Stop it with
177
+ `npx archal autoloop detach ./prod-traces --repo .`.
208
178
 
209
- Use `archal trace-source` when traces are not already in a hosted Postgres or
210
- Supabase table. This command normalizes source-specific payloads into Archal
211
- trace upload envelopes, writes them to a trace directory, and can upload them to
212
- hosted Autoloop when workspace auth is available.
179
+ ### Hosted database source (Postgres / Supabase)
213
180
 
214
- Common paths:
181
+ The source identity, schema mapping, cursor, and filters live in the
182
+ `.archal.json` `autoloop` block, not in flags. The starter takes only `--repo`,
183
+ `--source`, the credential (`--database-url-env` or `--database-url-secret-ref`),
184
+ `--execution-policy`, `--check`, and `--json`. A minimal config names the source:
215
185
 
216
- ```bash
217
- npx archal trace-source import ./exports --preview --json
218
- npx archal trace-source import ./exports --upload --repository owner/repo
219
-
220
- npx archal trace-source connect langfuse \
221
- --base-url https://cloud.langfuse.com \
222
- --api-key-env LANGFUSE_READ_KEY \
223
- --out .archal/traces/inbox
224
- npx archal trace-source test langfuse
225
- npx archal trace-source sync langfuse --upload --repository owner/repo
226
- npx archal trace-source watch langfuse --upload --repository owner/repo
227
-
228
- npx archal trace-source connect custom --name "prod exporter" --out .archal/traces/inbox
229
- npx archal trace-source serve "prod exporter" --port 4319
186
+ ```jsonc
187
+ // .archal.json
188
+ {
189
+ "autoloop": {
190
+ "source": { "name": "prod-agent-traces" }
191
+ }
192
+ }
230
193
  ```
231
194
 
232
- Use `archal trace-source status [source]` to inspect registry validation,
233
- cursor, and last-sync state. `watch` is for pull-style sources; push sources
234
- stay continuous through `serve`.
195
+ Check first, then register (drop `--check` to register). Registration posts the
196
+ source config to Archal and returns; hosted workers own polling after that, so
197
+ `autoloop detach` does not disable a hosted source.
235
198
 
236
- ## Trace schema mapping
199
+ ```bash
200
+ npx archal autoloop --repo . --source supabase \
201
+ --database-url-env TRACE_DATABASE_URL \
202
+ --execution-policy reproduce --check --json
203
+ ```
237
204
 
238
- Hosted sources default to `ai_traces` / `ai_spans` with `id` / `trace_id`
239
- columns and `updated_at_id` cursor mode. When the customer's tables differ, pass
240
- mapping flags to override table names, id columns, parent-span column, and
241
- cursor columns; switch to `created_at_id` cursor mode for append-only sources;
242
- and use `--source-*` filters to scope noisy sources by workspace, agent, status,
243
- trace group, or limit.
205
+ See `references/hosted-sources.md` for the read-only-role and secret-ref detail,
206
+ and `references/trace-schema-mapping.md` when the customer's tables differ from
207
+ the `ai_traces` / `ai_spans` defaults (custom columns, append-only cursor mode,
208
+ and source filters). Both are configured under `autoloop.source` in `.archal.json`.
244
209
 
245
- See `references/trace-schema-mapping.md` for the full defaults table plus the
246
- custom-schema, append-only, and filter flag blocks.
210
+ ### Client-side ingestion (traces not already in a hosted table)
247
211
 
248
- ## Local trace directory
212
+ For traces not in a hosted Postgres/Supabase table, use the dashboard OTLP
213
+ endpoint or drop normalized JSON files into an autoloop watch directory:
249
214
 
250
- Use this for a local pilot or exported trace files:
215
+ - **Dashboard OTLP** point the vendor's OpenTelemetry exporter at the OTLP
216
+ URL shown in the dashboard. Works for Langfuse, Braintrust, OTel, and custom
217
+ HTTP sources. No CLI command required.
218
+ - **File drop** — place normalized Archal trace JSON files in the watch
219
+ directory and run `archal autoloop <trace-dir>`. The loop picks them up on
220
+ the next import cycle.
251
221
 
252
- ```bash
253
- npx archal autoloop ./prod-traces --repo . --execution-policy reproduce
254
- ```
222
+ ## Policy semantics
255
223
 
256
- Artifacts are written under:
257
-
258
- ```text
259
- .archal/autoloop/
260
- autoloops.json
261
- runs.jsonl
262
- raw/
263
- grades/
264
- seeds/
265
- runs/
266
- fixes/
267
- failed/
268
- logs/
269
- ```
224
+ Two independent toggles, both per-agent and switchable from the agents tab, the
225
+ CLI, or the Archal copilot:
270
226
 
271
- Stop the local file-backed loop:
227
+ - **Autoloop toggle** - whether the loop runs at all (import -> grade ->
228
+ reproduce). Off means no traces are processed.
229
+ - **Autofix toggle** - whether the fix / PR phase runs. ON maps to
230
+ `--execution-policy fix`; OFF maps to `--execution-policy reproduce`.
272
231
 
273
- ```bash
274
- npx archal detach ./prod-traces --repo .
275
- ```
232
+ `--execution-policy` stops the loop at a phase; narrower policies stop earlier:
233
+
234
+ | Policy | Stops after | Autofix |
235
+ |--------|-------------|---------|
236
+ | `observe` | import | off |
237
+ | `grade` | grading | off |
238
+ | `seed` | seeding | off |
239
+ | `reproduce` | reproduction | off |
240
+ | `fix` | PR or blocked fix status | on |
276
241
 
277
- Do not describe `archal detach` as a hosted source disable command.
278
-
279
- ## CLI-first operation
280
-
281
- Prefer CLI and artifact evidence for handoffs unless the user explicitly asks
282
- for a workspace page.
283
-
284
- - Local file-backed loops: `archal autoloop <trace-dir> --repo ...` starts the
285
- watcher, `archal detach <trace-dir> --repo ...` stops it, `archal
286
- autoloop-status --repo ...` summarizes trace jobs, and `archal
287
- autoloop-reprocess --repo ... <trace-id>` retries terminal jobs after a
288
- blocker is fixed.
289
- - Hosted database sources: `archal autoloop --source postgres|supabase ...`
290
- registers the source and returns. Local `archal detach` does not disable a
291
- hosted source because hosted workers own polling after registration.
292
- - Safe resume means re-running the same `archal autoloop` registration or
293
- reprocessing a terminal local trace only after the missing evidence,
294
- credential, mapping, harness, or GitHub blocker is corrected.
295
-
296
- Report exact artifact paths and statuses. Do not make dashboard pages the only
297
- place a user can understand what happened.
298
-
299
- ## How to diagnose failures
300
-
301
- Classify failures precisely:
302
-
303
- - Trace import failure: database/source auth, mapping, cursor, filters, bad
304
- trace shape.
305
- - Trace ingestion failure: `trace-source` adapter mismatch, rejected hosted
306
- upload, missing workspace auth, bad idempotency key, or receiver auth failure.
307
- - Grade failure: judge could not determine expected outcome, missing evaluator
308
- contract, trace lacks task context.
309
- - Missing evidence: trace does not contain enough state to seed. Add spans,
310
- state snapshots, or repo-owned seed templates.
311
- - Reproduction failure: scenario or seed could not replay the failure against
312
- clones. Inspect generated `scenario.md`, `seed.json`, and run manifest.
313
- - Agent behavior: the reproduced run shows the agent making the same wrong
314
- service action it made in the original trace.
315
- - Harness issue: the agent command crashes, hangs, needs UI auth, or does not
316
- reach clone-routed services.
317
- - Fix generation issue: patch does not apply, tests fail, no changes produced,
318
- or generated PR metadata is incomplete.
319
- - GitHub issue: GitHub App missing, branch protection, permission denied, PR
320
- checks unavailable.
321
-
322
- When evidence is insufficient, say so directly. Do not manufacture a seed or
323
- claim reproduction succeeded.
324
-
325
- ## Artifact reading guide
326
-
327
- Local file-backed Autoloop uses repo-local artifacts. Hosted Autoloop exposes the
328
- same phase information in the dashboard.
242
+ Policy is **pinned at import time**. Flipping a toggle affects future imports
243
+ and retries, not runs that already imported under the old policy.
244
+
245
+ ## CLI surface
246
+
247
+ Machine-readable, CLI only. Every command takes `--json` for scripting. Do not
248
+ call raw REST endpoints or dashboard URLs.
249
+
250
+ The starter flags are deliberately narrow: `--repo`, `--source`,
251
+ `--database-url-env`, `--database-url-secret-ref`, `--execution-policy`,
252
+ `--check`, and `--json`. Everything about the source itself — its name/id, schema
253
+ mapping, cursor mode and watermarks, filters, metadata, and regression scenarios export —
254
+ lives in the `.archal.json` `autoloop` block, not in flags. A retired flag now
255
+ exits `2` with a message naming the config field to set instead.
256
+
257
+ - `archal autoloop [trace-dir] --repo <repo> [--source postgres|supabase] [--execution-policy observe|grade|seed|reproduce|fix] [--check] [--json]`
258
+ starts a local file-backed loop or registers a hosted source.
259
+ - `--check --json` emits `{ ok, checks[], nextStep? }` and exits `2` when not
260
+ ready, `0` when ready. Read `checks[]` for the exact blocker.
261
+ - The starter (no `--check`) `--json` emits `{ ok, ... }` describing the
262
+ registered source or started loop.
263
+ - `archal autoloop status [run-id] [--json]` - without a run id: local ledger
264
+ status for each trace job. `--json` emits `{ ok, jobs[] }`; each row is a
265
+ trace-job summary (`traceId`, `status`, `currentPhase`, `action`,
266
+ `nextAction`, `attemptSummary`, `checkSummary`, `artifactSummary`,
267
+ `reference`, `stale`, `retryable`, `updatedAt`, plus raw ledger fields such
268
+ as `prUrl` and `error` when present). `--wait --until terminal|pr
269
+ --poll-interval <seconds> --wait-timeout <seconds>` polls for CI gates and
270
+ exits `0` when the condition holds, `1` on timeout or a terminal-failed job;
271
+ the `--json` shape is identical with or without `--wait`, and a failed wait
272
+ emits `{ ok: false, jobs[], error, kind: "wait_failed" }`.
273
+ With a hosted `<run-id>`: fetches that run's status, grade evidence, and
274
+ artifacts. This is the take-over entry point. `--json` emits
275
+ `{ ok, run, gradeEvidence, artifacts }`; `--artifact <artifactId>` prints one
276
+ artifact's payload instead. The wait-family flags and `--repo` are local-only
277
+ and cannot be combined with a run id.
278
+ - `archal autoloop reprocess [trace-id] | --all-failed` - re-queue terminal
279
+ local trace jobs after fixing the blocker. Hidden from help (repair escape
280
+ hatch), still runnable.
281
+ - `archal autoloop detach <trace-dir>` - stop a local file-backed loop. Does
282
+ not disable a hosted source.
283
+
284
+ Related commands used during take-over and debugging:
285
+
286
+ - `archal reproduce failures <grades> --json` - turn failed grades into a
287
+ seedable reproduction package. `archal reproduce verify <package-dir> --json`
288
+ re-checks seed and run evidence for an existing package.
289
+ - `archal grade trace --request <file> --json` - grade one trace.
290
+ - `archal autoloop status --json` - inspect registered sources and job state.
291
+ - `archal traces list|detail --json` - list and inspect uploaded traces.
292
+
293
+ Exit codes across this family: `0` success, `1` failure, `2` usage error or
294
+ not-ready. Failures under `--json` emit `{ ok: false, error, kind, ... }`.
295
+
296
+ ## Take-over workflow
297
+
298
+ The killer use case: autoloop graded (and, under `reproduce`, replayed) a real
299
+ production failure, and now a coding agent takes over to write and verify the
300
+ fix. Runbook:
301
+
302
+ 1. **Find the run.** `archal autoloop status --json` for local jobs, or use the
303
+ hosted run id you were handed. Note the trace id and phase.
304
+ 2. **Pull the evidence into context.** `archal autoloop status <run-id> --json`
305
+ returns `run` (grade status, failure class, reproduction status, PR/branch
306
+ if any, blocking reason), `gradeEvidence` (score, threshold, summary,
307
+ per-criterion results), and `artifacts` (ids, types, sizes).
308
+ 3. **Fetch the artifact you need.** For a specific payload (grade summary,
309
+ generated scenario, seed, run manifest), pass its id:
310
+ `archal autoloop status <run-id> --artifact <artifactId> --json`. For a
311
+ local loop, the same evidence is on disk under `.archal/autoloop/` (see the
312
+ artifact guide).
313
+ 4. **Reproduce locally.** Turn the graded failure into a reproduction package
314
+ and replay it against clones: `archal reproduce failures <grades> --json`
315
+ (point `<grades>` at the local `grades/<trace>/grade.json` or a grade
316
+ artifact directory). This confirms the failure is real before you touch code.
317
+ 5. **Write the fix** in the repo.
318
+ 6. **Verify against the same reproduction.** `archal reproduce verify <package-dir> --json`
319
+ (or re-run step 4). The fix is done when the same reproduction that failed
320
+ now passes.
321
+ 7. **Watch it land.** With Autofix ON, autoloop opens the PR; gate on it with
322
+ `archal autoloop status --wait --until pr` or watch the
323
+ PR directly. With Autofix OFF, open the PR yourself once the reproduction
324
+ passes.
325
+
326
+ ## Diagnose failures
327
+
328
+ Classify precisely; do not manufacture a seed or claim reproduction succeeded
329
+ when evidence is thin.
330
+
331
+ - **Trace import** - source auth, mapping, cursor, filters, or a bad trace shape.
332
+ - **Trace ingestion** - rejected upload, missing workspace auth, bad idempotency
333
+ key, or OTLP receiver auth failure.
334
+ - **Grade** - judge could not determine the expected outcome; missing evaluator
335
+ contract; trace lacks task context.
336
+ - **Missing evidence** - trace lacks enough state to seed. Add spans, state
337
+ snapshots, or repo-owned seed templates.
338
+ - **Reproduction** - scenario or seed could not replay the failure. Inspect the
339
+ generated `scenario.md`, `seed.json`, and run manifest.
340
+ - **Harness** - agent command crashes, hangs, needs UI auth, or never reaches
341
+ clone-routed services.
342
+ - **Fix generation** - patch does not apply, tests fail, no changes produced,
343
+ or PR metadata is incomplete.
344
+ - **GitHub** - App missing, branch protection, permission denied, or PR checks
345
+ unavailable. Re-run `archal autoloop --check --json` to confirm.
346
+
347
+ ## Artifact reading guide (local loops)
348
+
349
+ Local file-backed loops write repo-local artifacts; hosted loops expose the
350
+ same phase information through `archal autoloop status <run-id>`.
329
351
 
330
352
  | Artifact | What to inspect |
331
353
  |----------|-----------------|
332
354
  | `grades/<trace>/routing.json` | trace import route and selected phase |
333
- | `grades/<trace>/grade.json` | verdict, summary, and reproduction decision |
355
+ | `grades/<trace>/grade.json` | verdict, summary, reproduction decision |
334
356
  | `seeds/<trace>/scenario.md` | generated reproduction scenario |
335
- | `seeds/<trace>/seed.json` | generated seed request or materialized seed metadata |
336
- | `runs/<trace>/manifest.json` | reproduction status, command, attempts, evidence |
357
+ | `seeds/<trace>/seed.json` | materialized seed metadata |
358
+ | `runs/<trace>/manifest.json` | reproduction status, command, attempts |
337
359
  | `runs/<trace>/stdout.json` | machine-readable run output |
338
- | `runs/<trace>/stderr.log` | reproduction stderr |
339
360
  | `fixes/<trace>/status.json` | blocked fix status |
340
361
  | `fixes/<trace>/pr-details.md` | PR reviewer summary |
341
362
  | `fixes/<trace>/repo.patch` | patch captured when PR creation cannot complete |
342
363
 
343
364
  ## Security rules
344
365
 
345
- - Use read-only trace database credentials.
346
- - Never commit database URLs, API keys, model keys, or GitHub tokens.
347
- - Prefer `--database-url-env` locally and `--database-url-secret-ref` in hosted
348
- production setup.
366
+ - Use read-only trace database credentials (Breakpoint 3).
367
+ - Never commit or echo database URLs, API keys, model keys, or GitHub tokens.
368
+ Prefer `--database-url-env` locally and `--database-url-secret-ref` in hosted
369
+ production.
349
370
  - Do not pass production write credentials to a clone-routed reproduction.
350
371
  - Do not add model-visible copy that reveals Archal or clone routing to the
351
372
  tested agent.
@@ -354,23 +375,17 @@ same phase information in the dashboard.
354
375
 
355
376
  ## What to report back
356
377
 
357
- After setup or debugging, give the user:
358
-
359
- - command run
360
- - source provider and source id
361
- - repo full name
362
- - execution policy
363
- - CLI status command to run next
364
- - artifacts produced, if local
365
- - whether import, grade, seed, reproduce, and fix phases are ready
366
- - exact blocker if any
367
- - next command or next owner
378
+ After setup or debugging, give the user: the command run; the execution policy
379
+ and how it maps to the Autofix answer from Breakpoint 1; source provider and id;
380
+ repo full name; which phases (import, grade, seed, reproduce, fix) are ready;
381
+ the exact blocker if any; local artifact paths if applicable; and the next CLI
382
+ command or owner. Prefer CLI and artifact evidence over telling the user to open
383
+ a dashboard page.
368
384
 
369
385
  ## Docs
370
386
 
371
387
  - Autoloop production traces: https://docs.archal.ai/guides/autoloop-production-traces
372
- - Autonomous loops: https://docs.archal.ai/guides/autoloop-production-traces
373
- - CLI reference: https://docs.archal.ai/cli/autoloop
388
+ - Autoloop CLI: https://docs.archal.ai/cli/autoloop
374
389
  - Running with an agent: https://docs.archal.ai/guides/run-with-agent
375
390
  - Writing scenarios: https://docs.archal.ai/guides/writing-scenarios
376
391
  - Seeds: https://docs.archal.ai/guides/seeds