archal 0.9.19 → 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 (83) hide show
  1. package/README.md +62 -154
  2. package/agents/openclaw/.archal.json +8 -0
  3. package/agents/openclaw/Dockerfile +97 -0
  4. package/agents/openclaw/README.md +113 -0
  5. package/agents/openclaw/drive.mjs +301 -0
  6. package/agents/openclaw/extract-openclaw-response-text.mjs +49 -0
  7. package/agents/openclaw/package.json +9 -0
  8. package/agents/openclaw/scenarios/acceptance/github-escalation-and-cleanup.md +43 -0
  9. package/agents/openclaw/scenarios/acceptance/jira-linear-release-triage.md +39 -0
  10. package/agents/openclaw/scenarios/acceptance/multi-clone-customer-risk-review.md +45 -0
  11. package/agents/openclaw/scenarios/acceptance/slack-incident-handoff.md +42 -0
  12. package/agents/openclaw/scenarios/acceptance/stripe-dunning-remediation.md +40 -0
  13. package/agents/openclaw/scenarios/close-stale-issues.md +35 -0
  14. package/agents/openclaw/scenarios/github-issue-triage-read-only.md +44 -0
  15. package/agents/openclaw/workspace/AGENTS.md +23 -0
  16. package/agents/openclaw/workspace/IDENTITY.md +8 -0
  17. package/agents/openclaw/workspace/SOUL.md +14 -0
  18. package/agents/openclaw/workspace/TOOLS.md +54 -0
  19. package/clone-assets/apify/tools.json +256 -22
  20. package/clone-assets/calcom/tools.json +2062 -0
  21. package/clone-assets/clickup/tools.json +3245 -0
  22. package/clone-assets/customerio/tools.json +2350 -0
  23. package/clone-assets/datadog/tools.json +734 -0
  24. package/clone-assets/github/tools.json +307 -27
  25. package/clone-assets/gitlab/tools.json +10688 -0
  26. package/clone-assets/google-workspace/tools.json +18 -6
  27. package/clone-assets/hubspot/tools.json +1604 -0
  28. package/clone-assets/jira/fidelity.json +1 -1
  29. package/clone-assets/jira/tools.json +266 -543
  30. package/clone-assets/linear/tools.json +278 -40
  31. package/clone-assets/ownerrez/tools.json +548 -0
  32. package/clone-assets/pricelabs/tools.json +343 -0
  33. package/clone-assets/sentry/tools.json +2821 -0
  34. package/clone-assets/slack/tools.json +1 -2
  35. package/clone-assets/stripe/tools.json +299 -46
  36. package/clone-assets/supabase/tools.json +437 -0
  37. package/clone-assets/unipile/tools.json +408 -0
  38. package/clone-assets/webflow/tools.json +2185 -0
  39. package/dist/autoloop-worker-types-CHaclqtD.d.cts +160 -0
  40. package/dist/cli.cjs +127896 -84811
  41. package/dist/{vitest/chunk-L36NXAU6.js → commands/autoloop-hosted-control-plane-client.cjs} +16344 -18845
  42. package/dist/commands/autoloop-hosted-control-plane-client.d.cts +133 -0
  43. package/dist/commands/autoloop-pr-verification.cjs +4312 -0
  44. package/dist/commands/autoloop-pr-verification.d.cts +19 -0
  45. package/dist/commands/autoloop-result-parser.cjs +27058 -0
  46. package/dist/commands/autoloop-result-parser.d.cts +196 -0
  47. package/dist/commands/autoloop-worker.cjs +38488 -0
  48. package/dist/commands/autoloop-worker.d.cts +102 -0
  49. package/dist/eval-shim.mjs +216 -0
  50. package/dist/index.cjs +15 -2
  51. package/dist/index.d.cts +3 -1
  52. package/dist/layer-1-ziaLpfLr.d.cts +62 -0
  53. package/dist/metafile-cjs.json +1 -0
  54. package/dist/reporter-entry.js +3 -0
  55. package/dist/sdk/index.cjs +51630 -0
  56. package/dist/sdk/index.d.cts +626 -0
  57. package/dist/vitest/chunk-2PDHTPZC.js +4867 -0
  58. package/dist/vitest/chunk-7L4BBB6M.js +2613 -0
  59. package/dist/vitest/index.cjs +6152 -75718
  60. package/dist/vitest/index.d.ts +22 -86
  61. package/dist/vitest/index.js +45 -414
  62. package/dist/vitest/runtime/hosted-session-reaper.cjs +682 -34399
  63. package/dist/vitest/runtime/hosted-session-reaper.js +1 -1
  64. package/dist/vitest/runtime/setup-files.js +2 -2
  65. package/manifest.json +9 -0
  66. package/package.json +20 -14
  67. package/skills/archal-agent/SKILL.md +86 -0
  68. package/skills/autoloop/SKILL.md +391 -0
  69. package/skills/autoloop/references/hosted-sources.md +94 -0
  70. package/skills/autoloop/references/trace-schema-mapping.md +104 -0
  71. package/skills/eval/SKILL.md +17 -15
  72. package/skills/free-account/SKILL.md +103 -0
  73. package/skills/install-agent/SKILL.md +202 -0
  74. package/skills/onboard/SKILL.md +29 -18
  75. package/skills/scenario/SKILL.md +36 -18
  76. package/skills/seed/SKILL.md +238 -0
  77. package/skills/vitest/SKILL.md +3 -2
  78. package/dist/harness.cjs +0 -62
  79. package/dist/harness.d.cts +0 -20
  80. package/dist/seed/dynamic-generator.cjs +0 -45687
  81. package/dist/seed/dynamic-generator.d.cts +0 -106
  82. package/dist/vitest/chunk-WZ7SA4CK.js +0 -47369
  83. package/skills/attach/SKILL.md +0 -402
@@ -4,7 +4,7 @@ import {
4
4
  createHostedAuthLease,
5
5
  parsePositiveInteger,
6
6
  runHostedSessionReaper
7
- } from "../chunk-WZ7SA4CK.js";
7
+ } from "../chunk-7L4BBB6M.js";
8
8
 
9
9
  // src/runtime/hosted-session-reaper.ts
10
10
  var VITEST_AUTH_LEASE_OPTIONS = {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  bootstrapArchalVitestRouting
3
- } from "../chunk-L36NXAU6.js";
4
- import "../chunk-WZ7SA4CK.js";
3
+ } from "../chunk-2PDHTPZC.js";
4
+ import "../chunk-7L4BBB6M.js";
5
5
 
6
6
  // src/runtime/setup-files.ts
7
7
  import { existsSync, rmSync } from "fs";
package/manifest.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 1,
3
+ "bundleKind": "archal-package-full",
4
+ "capabilities": [
5
+ "hosted-autoloop",
6
+ "clone-runtime",
7
+ "clone-free-autoloop"
8
+ ]
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archal",
3
- "version": "0.9.19",
3
+ "version": "0.10.0",
4
4
  "description": "Test your agents & integrations against service clones",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -13,9 +13,11 @@
13
13
  "types": "./dist/index.d.cts",
14
14
  "default": "./dist/index.cjs"
15
15
  },
16
- "./harness": {
17
- "types": "./dist/harness.d.cts",
18
- "default": "./dist/harness.cjs"
16
+ "./scenarios": {
17
+ "types": "./dist/scenarios.d.cts",
18
+ "import": "./dist/scenarios.cjs",
19
+ "require": "./dist/scenarios.cjs",
20
+ "default": "./dist/scenarios.cjs"
19
21
  },
20
22
  "./vitest": {
21
23
  "types": "./dist/vitest/index.d.ts",
@@ -45,12 +47,21 @@
45
47
  "files": [
46
48
  "bin",
47
49
  "dist",
50
+ "manifest.json",
48
51
  "skills",
49
52
  "clone-assets",
53
+ "agents",
50
54
  "LICENSE"
51
55
  ],
56
+ "scripts": {
57
+ "verify:artifacts": "node scripts/assert-artifacts.mjs",
58
+ "prepack": "node scripts/assert-artifacts.mjs",
59
+ "prepare": "node scripts/prepare.cjs",
60
+ "typecheck:raw": "node --check bin/archal.cjs && node --check scripts/assert-artifacts.mjs && node --check scripts/prepare.cjs",
61
+ "typecheck": "pnpm run typecheck:raw"
62
+ },
52
63
  "peerDependencies": {
53
- "vitest": ">=2.1.0"
64
+ "vitest": ">=2.1.0 <3"
54
65
  },
55
66
  "peerDependenciesMeta": {
56
67
  "vitest": {
@@ -58,13 +69,8 @@
58
69
  }
59
70
  },
60
71
  "dependencies": {
61
- "@aws-sdk/client-secrets-manager": "^3.1001.0",
62
- "e2b": "^2.19.5",
63
- "picomatch": "^4.0.4"
64
- },
65
- "scripts": {
66
- "verify:artifacts": "node scripts/assert-artifacts.mjs",
67
- "typecheck:raw": "node --check bin/archal.cjs && node --check scripts/assert-artifacts.mjs && node --check scripts/prepare.cjs",
68
- "typecheck": "pnpm run typecheck:raw"
72
+ "@aws-sdk/client-secrets-manager": "^3.1065.0",
73
+ "e2b": "^2.28.2",
74
+ "tsx": "^4.19.0"
69
75
  }
70
- }
76
+ }
@@ -0,0 +1,86 @@
1
+ ---
2
+ name: archal-agent
3
+ description: The front door for using Archal to test, debug, and fix an AI agent. START HERE, then route to the right sub-skill instead of guessing. Use when the user says "use Archal", "test my agent", "set up Archal", "my agent is failing", "reproduce this production failure", "grade my traces", or otherwise wants to evaluate, debug, or auto-fix an agent against service clones. Pick this whenever the request is Archal-shaped but the specific workflow is unclear.
4
+ user-invocable: true
5
+ argument-hint: "[what you want to do with your agent]"
6
+ ---
7
+
8
+ # Archal
9
+
10
+ You are the entry point for Archal. Archal is the QA layer for AI agents: it
11
+ runs an agent against stateful behavioral clones of real services (GitHub,
12
+ Slack, Stripe, Linear, Jira, Supabase, and more), scores how well it satisfies
13
+ each scenario, and turns failures into reproductions and PR fixes. Your job here
14
+ is to orient the operator and route to the sub-skill that owns their workflow.
15
+ Do not inline those flows; hand off by exact name and let the sub-skill drive.
16
+
17
+ ## Product mental model
18
+
19
+ Archal tests AI agents against service clones instead of real services, so every
20
+ run is deterministic and replayable. You describe a task and success criteria,
21
+ the agent runs against clones, and an evaluator scores satisfaction (a
22
+ probability, not pass/fail). When a real production trace shows a failure, Archal
23
+ reproduces it on clones from trace evidence and ships the fix as a GitHub PR.
24
+ Everything aims at the same thing: deterministic, replayable evals you can trust.
25
+
26
+ ## Decision guide
27
+
28
+ | I want to... | Route to |
29
+ |--------------|----------|
30
+ | Set up Archal in a repo from scratch (install, auth, detect clones) | `onboard` |
31
+ | Write or edit a scenario test file | `scenario` |
32
+ | Load explicit JSON/SQL/catalog state into a clone (deterministic, no LLM) | `seed` |
33
+ | Run scenarios or tasks and interpret satisfaction scores and failures | `eval` |
34
+ | Wire clones into an existing Vitest suite | `vitest` |
35
+ | Connect a repo's production observability so traces get captured | `install-agent` |
36
+ | Run the autoloop (ingest -> grade -> find-failed -> reproduce-on-clones) and ship the fix as a PR (autofix) over real trace sources | `autoloop` |
37
+ | Turn autofix or autoloop on/off for an agent | `autoloop`; the copilot can toggle either |
38
+
39
+ If the user is brand new and has none of this set up, start with `onboard`; it
40
+ detects clones and routes onward from there.
41
+
42
+ ## The sub-skills
43
+
44
+ Each lives in `packages/archal/skills/` and owns its own commands, contracts,
45
+ and mental model. Route by exact name:
46
+
47
+ - `onboard` — set up Archal in a repo from scratch: install the CLI, handle auth,
48
+ detect which clones the agent needs, and hand off to the right workflow.
49
+ - `scenario` — author and edit scenario test files (Setup / Prompt / Expected
50
+ Behavior / Success Criteria) that `archal run` executes against clones.
51
+ - `seed` — load explicit JSON, SQL, or catalog state into a clone deterministically,
52
+ with no LLM in the loop, so runs start from a known fixture state.
53
+ - `eval` — run scenarios or inline tasks against clones and interpret the results:
54
+ satisfaction scores, `[D]` vs `[P]` criteria, trace inspection, failure diagnosis.
55
+ - `vitest` — wire clones into an existing Vitest suite using the right composition
56
+ pattern, so the agent's own tests route through clones.
57
+ - `install-agent` — connect a repo's production observability (OTLP, Langfuse,
58
+ Braintrust, database trace tables) so real agent traces are captured for Archal.
59
+ - `autoloop` — the loop over real trace sources: ingest a trace, grade it for a
60
+ real failure, find the failed trace, and reproduce it on clones. Autofix (the
61
+ fix/PR step) is a separate toggle on top of this: when turned on, autoloop
62
+ reproduces a failure and ships the fix as a PR.
63
+
64
+ ## Autoloop and autofix toggles
65
+
66
+ Autoloop (ingest -> grade -> find-failed -> reproduce-on-clones) and autofix (the
67
+ fix/PR step) are **separate per-agent toggles**. Autofix is opt-in: it is not part
68
+ of autoloop until it is turned on. Either can be switched on or off per agent from
69
+ the agents tab, the CLI (`--execution-policy reproduce` is autoloop with autofix
70
+ off; `fix` turns autofix on), or by asking the Archal copilot in chat — the
71
+ copilot can toggle either for an agent. When the user asks to turn autofix or
72
+ autoloop on/off for an agent, handle the toggle, then route to `autoloop` for the
73
+ deeper flow.
74
+
75
+ ## Provider-switchable remediation
76
+
77
+ The Archal copilot is not locked to one model. When autofix reproduces a failure
78
+ and writes a fix, the user can drive that remediation with their own agent —
79
+ fix is written by their Claude Code, Cursor, or Codex — or let Archal's managed
80
+ agent do it. Mention this when the user asks who writes the fix or wants to use
81
+ their own coding agent, then route to `autoloop`.
82
+
83
+ ## Docs
84
+
85
+ - Quickstart: https://docs.archal.ai/quickstart
86
+ - Full docs: https://docs.archal.ai
@@ -0,0 +1,391 @@
1
+ ---
2
+ name: autoloop
3
+ description: Wire Archal Autoloop to a repo plus a real agent-trace source, then drive the import -> grade -> reproduce -> PR-fix loop. USE THIS whenever the user wants to turn production agent traces into reproducible failures and fixes: "I have prod agent traces and want to reproduce a failure", "import my Langfuse / Braintrust / OTel / Supabase traces", "connect a trace source", "grade my prod traces", "turn a failed trace into a PR", "set up / configure the autoloop", or any mention of replaying, grading, or auto-fixing real traces. Also fires when diagnosing a stuck import, grade, reproduction, or PR-fix run, or configuring trace schema mapping.
4
+ user-invocable: true
5
+ argument-hint: "[repo, trace source, or failure description]"
6
+ ---
7
+
8
+ # Archal Autoloop
9
+
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.
14
+
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.
17
+
18
+ Autoloop is also not arbitrary production trace replay. It can reproduce a
19
+ failure only when the trace, scenario contract, and seed templates contain
20
+ enough evidence to reconstruct the service state that matters. If the evidence
21
+ is thin, block and name the missing data instead of claiming reproduction.
22
+
23
+ ## Product mental model
24
+
25
+ Autoloop runs this loop:
26
+
27
+ 1. Import a trace and its child spans from a read-only source.
28
+ 2. Grade whether the trace contains a real failure.
29
+ 3. Build a reproduction scenario and clone seed from trace evidence plus
30
+ repo-owned seed templates.
31
+ 4. Run the reproduction against service clones through the customer harness.
32
+ 5. If reproduced, patch the repo and open a GitHub PR.
33
+
34
+ Steps 1-4 are **autoloop**: ingest -> grade -> find the failed trace ->
35
+ reproduce on clones. Step 5 (writing the fix and opening the PR) is **autofix**,
36
+ a separate opt-in step that is *not* part of autoloop until it is turned on.
37
+
38
+ ## Consent breakpoints (do these before you touch anything)
39
+
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.
45
+
46
+ ### Breakpoint 1 - PR-opening consent
47
+
48
+ STOP. Before anything else, state the consequence plainly and ask the user to
49
+ choose:
50
+
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?
56
+
57
+ Map the answer explicitly and never rely on the CLI default:
58
+
59
+ | User wants | Pass | Autofix |
60
+ |------------|------|---------|
61
+ | Fix PRs opened automatically | `--execution-policy fix` | ON |
62
+ | Reproduce only, no PRs | `--execution-policy reproduce` | OFF |
63
+
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.
69
+
70
+ ### Breakpoint 2 - GitHub App install (only if the user chose fix PRs)
71
+
72
+ If the user chose **reproduce only**, skip this breakpoint and note that the
73
+ fix path stays off.
74
+
75
+ If the user chose **fix PRs**, STOP and explain, then wait for confirmation:
76
+
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).
86
+
87
+ Do not proceed to a `fix` policy until the user confirms. Verify the install
88
+ with the machine check before starting the loop:
89
+
90
+ ```bash
91
+ npx archal autoloop --repo . --execution-policy fix --check --json
92
+ ```
93
+
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.
96
+
97
+ ### Breakpoint 3 - read-only database connection string
98
+
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:
102
+
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).
109
+
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.
113
+
114
+ ## Discover first
115
+
116
+ Before changing anything, inspect the repo:
117
+
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`
143
+
144
+ ```json
145
+ { "version": 1, "local": { "command": "node", "args": ["agent.mjs"] } }
146
+ ```
147
+
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.
152
+
153
+ ### `archal/scenario.md`
154
+
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.
160
+
161
+ ### Seed templates (when trace evidence is thin)
162
+
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.
166
+
167
+ ## Register the loop
168
+
169
+ ### Local trace directory (pilot / exported files)
170
+
171
+ ```bash
172
+ npx archal autoloop ./prod-traces --repo . --execution-policy reproduce
173
+ ```
174
+
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 .`.
178
+
179
+ ### Hosted database source (Postgres / Supabase)
180
+
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:
185
+
186
+ ```jsonc
187
+ // .archal.json
188
+ {
189
+ "autoloop": {
190
+ "source": { "name": "prod-agent-traces" }
191
+ }
192
+ }
193
+ ```
194
+
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.
198
+
199
+ ```bash
200
+ npx archal autoloop --repo . --source supabase \
201
+ --database-url-env TRACE_DATABASE_URL \
202
+ --execution-policy reproduce --check --json
203
+ ```
204
+
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`.
209
+
210
+ ### Client-side ingestion (traces not already in a hosted table)
211
+
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:
214
+
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.
221
+
222
+ ## Policy semantics
223
+
224
+ Two independent toggles, both per-agent and switchable from the agents tab, the
225
+ CLI, or the Archal copilot:
226
+
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`.
231
+
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 |
241
+
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>`.
351
+
352
+ | Artifact | What to inspect |
353
+ |----------|-----------------|
354
+ | `grades/<trace>/routing.json` | trace import route and selected phase |
355
+ | `grades/<trace>/grade.json` | verdict, summary, reproduction decision |
356
+ | `seeds/<trace>/scenario.md` | generated reproduction scenario |
357
+ | `seeds/<trace>/seed.json` | materialized seed metadata |
358
+ | `runs/<trace>/manifest.json` | reproduction status, command, attempts |
359
+ | `runs/<trace>/stdout.json` | machine-readable run output |
360
+ | `fixes/<trace>/status.json` | blocked fix status |
361
+ | `fixes/<trace>/pr-details.md` | PR reviewer summary |
362
+ | `fixes/<trace>/repo.patch` | patch captured when PR creation cannot complete |
363
+
364
+ ## Security rules
365
+
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.
370
+ - Do not pass production write credentials to a clone-routed reproduction.
371
+ - Do not add model-visible copy that reveals Archal or clone routing to the
372
+ tested agent.
373
+ - Do not bypass the GitHub App PR workflow with direct pushes.
374
+ - Redact raw trace payloads before sharing artifacts outside the workspace.
375
+
376
+ ## What to report back
377
+
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.
384
+
385
+ ## Docs
386
+
387
+ - Autoloop production traces: https://docs.archal.ai/guides/autoloop-production-traces
388
+ - Autoloop CLI: https://docs.archal.ai/cli/autoloop
389
+ - Running with an agent: https://docs.archal.ai/guides/run-with-agent
390
+ - Writing scenarios: https://docs.archal.ai/guides/writing-scenarios
391
+ - Seeds: https://docs.archal.ai/guides/seeds
@@ -0,0 +1,94 @@
1
+ # Hosted database source
2
+
3
+ Reference for registering a hosted Postgres or Supabase trace source. Use this
4
+ when traces live in Postgres or Supabase. Registration posts the source config to
5
+ Archal and returns; hosted workers own polling after that.
6
+
7
+ The starter takes only `--repo`, `--source`, the credential
8
+ (`--database-url-env` or `--database-url-secret-ref`), `--execution-policy`,
9
+ `--check`, and `--json`. The source identity, schema mapping, cursor, and filters
10
+ live in the `.archal.json` `autoloop` block — see `trace-schema-mapping.md`. A
11
+ minimal config names the source:
12
+
13
+ ```jsonc
14
+ // .archal.json
15
+ {
16
+ "autoloop": {
17
+ "source": { "name": "prod-agent-traces" }
18
+ }
19
+ }
20
+ ```
21
+
22
+ This is the detail behind **Breakpoint 3** in `SKILL.md`: never accept a
23
+ privileged connection string, pass the credential by env-var name (or secret
24
+ ref), and confirm the role is read-only before running any `--source` command.
25
+
26
+ ## Contents
27
+
28
+ - Read-only credential
29
+ - Check the source
30
+ - Register the source
31
+ - Secret reference (hosted production)
32
+
33
+ ## Read-only credential
34
+
35
+ First create (or ask the user to create) a read-only database role scoped to the
36
+ trace tables. For Postgres:
37
+
38
+ ```sql
39
+ CREATE ROLE archal_trace_reader LOGIN PASSWORD '<generated>';
40
+ GRANT CONNECT ON DATABASE <db> TO archal_trace_reader;
41
+ GRANT USAGE ON SCHEMA public TO archal_trace_reader;
42
+ GRANT SELECT ON ai_traces, ai_spans TO archal_trace_reader; -- trace/span tables only
43
+ ```
44
+
45
+ Then keep the URL in an env var; never inline it in a command and never echo it:
46
+
47
+ ```bash
48
+ export TRACE_DATABASE_URL='postgres://archal_trace_reader:...'
49
+ ```
50
+
51
+ ## Check the source
52
+
53
+ Run a readiness check. `--check --json` emits `{ ok, checks[], nextStep? }` and
54
+ exits `2` when not ready:
55
+
56
+ ```bash
57
+ npx archal autoloop \
58
+ --repo . \
59
+ --source supabase \
60
+ --database-url-env TRACE_DATABASE_URL \
61
+ --check --json
62
+ ```
63
+
64
+ The source name comes from `autoloop.source.name` in `.archal.json`, not a flag.
65
+
66
+ ## Register the source
67
+
68
+ Drop `--check` to register:
69
+
70
+ ```bash
71
+ npx archal autoloop \
72
+ --repo . \
73
+ --source supabase \
74
+ --database-url-env TRACE_DATABASE_URL \
75
+ --execution-policy reproduce
76
+ ```
77
+
78
+ Set `--execution-policy` to match the Autofix answer from Breakpoint 1
79
+ (`reproduce` = no PRs, `fix` = open PRs). Registration posts the source config to
80
+ Archal and returns. It does not start a local watcher and does not write local
81
+ source state.
82
+
83
+ ## Secret reference (hosted production)
84
+
85
+ Use a secret reference when the customer already has one. The ref must not
86
+ contain a plaintext credential:
87
+
88
+ ```bash
89
+ npx archal autoloop \
90
+ --repo . \
91
+ --source postgres \
92
+ --database-url-secret-ref aws-secretsmanager://customer/prod-agent-traces \
93
+ --execution-policy reproduce
94
+ ```