archal 0.9.18 → 0.9.19

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.
@@ -4,7 +4,7 @@ import {
4
4
  createHostedAuthLease,
5
5
  parsePositiveInteger,
6
6
  runHostedSessionReaper
7
- } from "../chunk-CTSN67QR.js";
7
+ } from "../chunk-WZ7SA4CK.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-IVXSSEYS.js";
4
- import "../chunk-CTSN67QR.js";
3
+ } from "../chunk-L36NXAU6.js";
4
+ import "../chunk-WZ7SA4CK.js";
5
5
 
6
6
  // src/runtime/setup-files.ts
7
7
  import { existsSync, rmSync } from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archal",
3
- "version": "0.9.18",
3
+ "version": "0.9.19",
4
4
  "description": "Test your agents & integrations against service clones",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -49,13 +49,6 @@
49
49
  "clone-assets",
50
50
  "LICENSE"
51
51
  ],
52
- "scripts": {
53
- "verify:artifacts": "node scripts/assert-artifacts.mjs",
54
- "prepack": "pnpm run verify:artifacts",
55
- "prepare": "node scripts/prepare.cjs",
56
- "typecheck:raw": "node --check bin/archal.cjs && node --check scripts/assert-artifacts.mjs && node --check scripts/prepare.cjs",
57
- "typecheck": "pnpm run typecheck:raw"
58
- },
59
52
  "peerDependencies": {
60
53
  "vitest": ">=2.1.0"
61
54
  },
@@ -65,6 +58,13 @@
65
58
  }
66
59
  },
67
60
  "dependencies": {
61
+ "@aws-sdk/client-secrets-manager": "^3.1001.0",
62
+ "e2b": "^2.19.5",
68
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"
69
69
  }
70
- }
70
+ }
@@ -0,0 +1,402 @@
1
+ ---
2
+ name: attach
3
+ description: Connect Archal Attach to a repo and trace source, validate prerequisites, configure trace schema mapping, and diagnose import, grade, reproduction, and PR-fix runs.
4
+ user-invocable: true
5
+ argument-hint: "[repo, trace source, or failure description]"
6
+ ---
7
+
8
+ # Archal Attach
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.
13
+
14
+ Attach 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.
16
+
17
+ ## Product mental model
18
+
19
+ Attach does this loop:
20
+
21
+ 1. Import a trace and its child spans from a read-only source.
22
+ 2. Grade whether the trace contains a real failure.
23
+ 3. Build a reproduction scenario and clone seed from trace evidence plus
24
+ repo-owned seed templates.
25
+ 4. Run the reproduction against service clones through the customer harness.
26
+ 5. If reproduced, patch the repo and open a GitHub issue or PR.
27
+
28
+ Default policy is `fix`. Narrower policies stop earlier:
29
+
30
+ | Policy | Stops after |
31
+ |--------|-------------|
32
+ | `observe` | import |
33
+ | `grade` | grading |
34
+ | `reproduce` | reproduction |
35
+ | `fix` | PR or blocked fix status |
36
+
37
+ Do not invent or promote separate top-level judge, reproduce, fix, or
38
+ trace-replay commands. The public command is `archal attach`. Local stop
39
+ command is `archal detach` for file-backed trace directories.
40
+
41
+ ## Discover first
42
+
43
+ Before changing anything, inspect the repo:
44
+
45
+ 1. `package.json` and scripts: how is the agent run? What tests should a fix PR
46
+ pass?
47
+ 2. Existing Archal files:
48
+ - `.archal.json`
49
+ - `.archal/harness.*`
50
+ - `archal/harness.json`
51
+ - `archal/scenario.md`
52
+ - `archal/run-input.yaml`
53
+ - `archal/seeds/*.json`
54
+ - `scenarios/*.md`
55
+ 3. Service SDKs and likely clones:
56
+ - `stripe` -> `stripe`
57
+ - `@octokit/rest`, `octokit` -> `github`
58
+ - `@slack/web-api`, `@slack/bolt` -> `slack`
59
+ - `jira`, `jira-client`, `jira.js` -> `jira`
60
+ - `@linear/sdk` -> `linear`
61
+ - `@supabase/supabase-js`, `pg` -> `supabase`
62
+ - `googleapis` -> `google-workspace`
63
+ 4. GitHub remote:
64
+ ```bash
65
+ git remote get-url origin
66
+ ```
67
+ Hosted sources and `--execution-policy fix` need a GitHub remote.
68
+ 5. Trace source shape, if available:
69
+ - provider: local files, Postgres, Supabase
70
+ - trace table and span table names
71
+ - id columns
72
+ - parent span column
73
+ - timestamp/cursor columns
74
+ - status, workspace, trace group, and agent filters
75
+
76
+ Never print secrets while inspecting. If you need to show a database URL, show
77
+ only the env var name or secret reference.
78
+
79
+ ## Preconditions
80
+
81
+ You need these before a full hosted Attach setup:
82
+
83
+ - Archal CLI installed in the repo or reachable with `npx archal`
84
+ - authenticated user (`archal login`) or `ARCHAL_TOKEN=archal_ws_...`
85
+ - GitHub App installed on the target repo
86
+ - repo origin that resolves to `github.com/<owner>/<repo>`
87
+ - read-only trace source credential
88
+ - headless harness command
89
+ - `archal/scenario.md` for the trace family
90
+ - optional but strongly recommended `archal/seeds/*.json`
91
+ - model/provider keys required by the user's agent and tests
92
+
93
+ If any prerequisite is missing, make the smallest safe change and explain what
94
+ is still required. Do not continue into a fake reproduction.
95
+
96
+ ## Safe setup flow
97
+
98
+ ### 1. Install and authenticate
99
+
100
+ Prefer project-local install:
101
+
102
+ ```bash
103
+ npm install -D archal
104
+ npx archal login
105
+ npx archal usage
106
+ ```
107
+
108
+ In CI or a customer repo, use:
109
+
110
+ ```bash
111
+ export ARCHAL_TOKEN=archal_ws_...
112
+ npx archal usage
113
+ ```
114
+
115
+ Use a workspace API key for automated runs. Do not commit it.
116
+
117
+ ### 2. Add or verify `archal/harness.json`
118
+
119
+ Minimal shape:
120
+
121
+ ```json
122
+ {
123
+ "version": 1,
124
+ "local": {
125
+ "command": "node",
126
+ "args": ["agent.mjs"]
127
+ }
128
+ }
129
+ ```
130
+
131
+ The command must be headless and repeatable. It should run the real agent path,
132
+ not a hand-authored mock. During reproduction, Archal invokes this command
133
+ through `archal run`, so the agent should read the task from `AGENT_TASK` and
134
+ print its final answer to stdout. If the project already has `.archal.json` for
135
+ `archal run`, align the Attach harness with that command.
136
+
137
+ ### 3. Add or verify `archal/scenario.md`
138
+
139
+ The scenario describes the standing task and checks for this trace family.
140
+
141
+ Required sections:
142
+
143
+ ```md
144
+ # Scenario title
145
+
146
+ ## Setup
147
+ Trace-family context and the starting state Archal should reconstruct.
148
+
149
+ ## Prompt
150
+ The task the agent should complete.
151
+
152
+ ## Expected Behavior
153
+ The answer key for grading and reproduction.
154
+
155
+ ## Success Criteria
156
+ - [D] Deterministic clone-state check
157
+ - [P] Probabilistic trace/output check
158
+
159
+ ## Config
160
+ clones: stripe, slack
161
+ timeout: 120
162
+ ```
163
+
164
+ Keep model-visible instructions realistic. Do not tell the tested agent that it
165
+ is in Archal, a clone-backed environment, or a special replay.
166
+
167
+ ### 4. Add seed templates when trace evidence is thin
168
+
169
+ Recommended:
170
+
171
+ ```text
172
+ archal/seeds/
173
+ stripe-billing-support.json
174
+ jira-escalations.json
175
+ ```
176
+
177
+ Seed templates should contain stable service state for the task family. Attach
178
+ can then fill in trace-specific identifiers. This is much safer than expecting
179
+ weak traces to reconstruct full service state.
180
+
181
+ ## Hosted database source
182
+
183
+ Use this when traces live in Postgres or Supabase.
184
+
185
+ First, create or request a read-only database user. Then keep the URL in an env
186
+ var:
187
+
188
+ ```bash
189
+ export TRACE_DATABASE_URL='postgres://readonly:...'
190
+ ```
191
+
192
+ Run a check:
193
+
194
+ ```bash
195
+ npx archal attach \
196
+ --repo . \
197
+ --source supabase \
198
+ --database-url-env TRACE_DATABASE_URL \
199
+ --source-id prod-agent-traces \
200
+ --check
201
+ ```
202
+
203
+ Register:
204
+
205
+ ```bash
206
+ npx archal attach \
207
+ --repo . \
208
+ --source supabase \
209
+ --database-url-env TRACE_DATABASE_URL \
210
+ --source-id prod-agent-traces
211
+ ```
212
+
213
+ This posts the source config to Archal and returns. It does not start a local
214
+ watcher and does not write local source state.
215
+
216
+ Use a secret reference when the customer already has one:
217
+
218
+ ```bash
219
+ npx archal attach \
220
+ --repo . \
221
+ --source postgres \
222
+ --database-url-secret-ref aws-secretsmanager://customer/prod-agent-traces
223
+ ```
224
+
225
+ `--database-url-secret-ref` must not contain a plaintext credential.
226
+
227
+ ## Trace schema mapping
228
+
229
+ Defaults:
230
+
231
+ | Concept | Default |
232
+ |---------|---------|
233
+ | trace table | `ai_traces` |
234
+ | span table | `ai_spans` |
235
+ | trace id | `id` |
236
+ | span id | `id` |
237
+ | span trace id | `trace_id` |
238
+ | trace updated cursor | `updated_at` |
239
+ | span updated cursor | `updated_at` |
240
+ | cursor mode | `updated_at_id` |
241
+
242
+ For a custom schema, pass mapping flags:
243
+
244
+ ```bash
245
+ npx archal attach \
246
+ --repo . \
247
+ --source postgres \
248
+ --database-url-env TRACE_DATABASE_URL \
249
+ --trace-table public.agent_traces \
250
+ --span-table public.agent_spans \
251
+ --trace-id-column trace_id \
252
+ --span-id-column span_id \
253
+ --span-trace-id-column trace_id \
254
+ --parent-span-id-column parent_span_id \
255
+ --trace-updated-at-column updated_at \
256
+ --span-updated-at-column updated_at
257
+ ```
258
+
259
+ For append-only sources:
260
+
261
+ ```bash
262
+ npx archal attach \
263
+ --repo . \
264
+ --source supabase \
265
+ --database-url-env TRACE_DATABASE_URL \
266
+ --cursor-mode created_at_id \
267
+ --trace-created-at-column created_at \
268
+ --span-created-at-column created_at
269
+ ```
270
+
271
+ Use filters for noisy sources:
272
+
273
+ ```bash
274
+ npx archal attach \
275
+ --repo . \
276
+ --source supabase \
277
+ --database-url-env TRACE_DATABASE_URL \
278
+ --source-workspace-id workspace_123 \
279
+ --source-agent-id support-agent \
280
+ --source-status failed error \
281
+ --source-trace-group billing-support \
282
+ --source-limit 250
283
+ ```
284
+
285
+ ## Local trace directory
286
+
287
+ Use this for a local pilot or exported trace files:
288
+
289
+ ```bash
290
+ npx archal attach ./prod-traces --repo . --execution-policy reproduce
291
+ ```
292
+
293
+ Artifacts are written under:
294
+
295
+ ```text
296
+ .archal/attach/
297
+ attachments.json
298
+ runs.jsonl
299
+ raw/
300
+ grades/
301
+ seeds/
302
+ runs/
303
+ fixes/
304
+ failed/
305
+ logs/
306
+ ```
307
+
308
+ Stop the local file-backed loop:
309
+
310
+ ```bash
311
+ npx archal detach ./prod-traces --repo .
312
+ ```
313
+
314
+ Do not describe `archal detach` as a hosted source disable command.
315
+
316
+ ## Dashboard expectations
317
+
318
+ The workspace dashboard has three Attach pages:
319
+
320
+ - Imported traces: source status, imported rows, grade verdict, blocked reason.
321
+ - Reproduced failures: seed evidence, reproduction status, clone parity, run
322
+ artifacts.
323
+ - Opened issues/PRs: GitHub issue, PR, branch, checks, and fix status.
324
+
325
+ Do not route users to an old single Attach page. The user-facing pages are the
326
+ three workspace dashboard pages above.
327
+
328
+ ## How to diagnose failures
329
+
330
+ Classify failures precisely:
331
+
332
+ - Trace import failure: database/source auth, mapping, cursor, filters, bad
333
+ trace shape.
334
+ - Grade failure: judge could not determine expected outcome, missing evaluator
335
+ contract, trace lacks task context.
336
+ - Missing evidence: trace does not contain enough state to seed. Add spans,
337
+ state snapshots, or repo-owned seed templates.
338
+ - Reproduction failure: scenario or seed could not replay the failure against
339
+ clones. Inspect generated `scenario.md`, `seed.json`, and run manifest.
340
+ - Agent behavior: the reproduced run shows the agent making the same wrong
341
+ service action it made in the original trace.
342
+ - Harness issue: the agent command crashes, hangs, needs UI auth, or does not
343
+ reach clone-routed services.
344
+ - Fix generation issue: patch does not apply, tests fail, no changes produced,
345
+ or generated PR metadata is incomplete.
346
+ - GitHub issue: GitHub App missing, branch protection, permission denied, PR
347
+ checks unavailable.
348
+
349
+ When evidence is insufficient, say so directly. Do not manufacture a seed or
350
+ claim reproduction succeeded.
351
+
352
+ ## Artifact reading guide
353
+
354
+ Local file-backed Attach uses repo-local artifacts. Hosted Attach exposes the
355
+ same phase information in the dashboard.
356
+
357
+ | Artifact | What to inspect |
358
+ |----------|-----------------|
359
+ | `grades/<trace>/routing.json` | trace import route and selected phase |
360
+ | `grades/<trace>/grade.json` | verdict, summary, and reproduction decision |
361
+ | `seeds/<trace>/scenario.md` | generated reproduction scenario |
362
+ | `seeds/<trace>/seed.json` | generated seed request or materialized seed metadata |
363
+ | `runs/<trace>/manifest.json` | reproduction status, command, attempts, evidence |
364
+ | `runs/<trace>/stdout.json` | machine-readable run output |
365
+ | `runs/<trace>/stderr.log` | reproduction stderr |
366
+ | `fixes/<trace>/status.json` | blocked fix status |
367
+ | `fixes/<trace>/pr-details.md` | PR reviewer summary |
368
+ | `fixes/<trace>/repo.patch` | patch captured when PR creation cannot complete |
369
+
370
+ ## Security rules
371
+
372
+ - Use read-only trace database credentials.
373
+ - Never commit database URLs, API keys, model keys, or GitHub tokens.
374
+ - Prefer `--database-url-env` locally and `--database-url-secret-ref` in hosted
375
+ production setup.
376
+ - Do not pass production write credentials to a clone-routed reproduction.
377
+ - Do not add model-visible copy that reveals Archal or clone routing to the
378
+ tested agent.
379
+ - Do not bypass the GitHub App PR workflow with direct pushes.
380
+ - Redact raw trace payloads before sharing artifacts outside the workspace.
381
+
382
+ ## What to report back
383
+
384
+ After setup or debugging, give the user:
385
+
386
+ - command run
387
+ - source provider and source id
388
+ - repo full name
389
+ - execution policy
390
+ - dashboard pages to inspect
391
+ - artifacts produced, if local
392
+ - whether import, grade, seed, reproduce, and fix phases are ready
393
+ - exact blocker if any
394
+ - next command or next owner
395
+
396
+ ## Docs
397
+
398
+ - Attach production traces: https://docs.archal.ai/guides/attach-production-traces
399
+ - CLI reference: https://docs.archal.ai/cli/attach
400
+ - Running with an agent: https://docs.archal.ai/guides/run-with-agent
401
+ - Writing scenarios: https://docs.archal.ai/guides/writing-scenarios
402
+ - Seeds: https://docs.archal.ai/guides/seeds
@@ -122,6 +122,17 @@ Do not paste a sample config here. The right shape depends on what's already in
122
122
 
123
123
  Run: `archal clone start <detected clones>` - gives live clone URLs the user's SDK clients can point at. `archal clone status` shows the active session; `archal clone stop` tears down.
124
124
 
125
+ ### Option E - Attach real trace sources
126
+
127
+ Use this when the repo already has agent traces from pre-production or
128
+ production and the user wants Archal to import, grade, reproduce, and turn
129
+ reproduced failures into GitHub issues or PRs.
130
+
131
+ **Delegate to the `attach` skill.** It owns the trace-source mapping,
132
+ `archal/harness.json`, `archal/scenario.md`, seed templates, `archal attach`
133
+ commands, dashboard expectations, and failure taxonomy. Do not inline the
134
+ Attach flow here; it changes faster than starter scenario setup.
135
+
125
136
  ## Verify
126
137
 
127
138
  Run the first scenario or task. For Options A and B, hand off to the `eval` skill to interpret the satisfaction score and diagnose failures - that skill owns the runtime mental model (`[D]` vs `[P]` criteria, trace inspection, harness execution diagnostics).
@@ -144,3 +155,4 @@ Run the first scenario or task. For Options A and B, hand off to the `eval` skil
144
155
 
145
156
  - Quickstart: https://docs.archal.ai/quickstart
146
157
  - Full docs: https://docs.archal.ai
158
+ - Attach production traces: https://docs.archal.ai/guides/attach-production-traces