imprint-mcp 0.7.0 → 0.7.1

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 (55) hide show
  1. package/README.md +64 -2
  2. package/package.json +1 -1
  3. package/prompts/auth-compile-agent.md +167 -22
  4. package/prompts/compile-agent.md +45 -8
  5. package/prompts/component-recovery.md +40 -0
  6. package/prompts/master-teach-decision.md +28 -3
  7. package/prompts/master-teach-focused-planner.md +18 -5
  8. package/src/cli.ts +26 -18
  9. package/src/imprint/agent-tool.ts +15 -0
  10. package/src/imprint/agent.ts +2 -11
  11. package/src/imprint/audit.ts +35 -13
  12. package/src/imprint/auth-browser-discovery.ts +276 -0
  13. package/src/imprint/auth-compile-agent.ts +513 -224
  14. package/src/imprint/auth-compile-tools.ts +213 -25
  15. package/src/imprint/auth-discovery-evidence.ts +81 -0
  16. package/src/imprint/auth-plan.ts +28 -0
  17. package/src/imprint/auth-verifier.ts +234 -20
  18. package/src/imprint/authentication-interaction.ts +137 -0
  19. package/src/imprint/backend-ladder.ts +218 -34
  20. package/src/imprint/build-plan.ts +2 -22
  21. package/src/imprint/cdp-browser-fetch.ts +192 -53
  22. package/src/imprint/chromium.ts +93 -29
  23. package/src/imprint/claude-cli-compile.ts +2 -0
  24. package/src/imprint/codex-cli-compile.ts +99 -46
  25. package/src/imprint/compile-agent-types.ts +9 -5
  26. package/src/imprint/compile-agent.ts +33 -0
  27. package/src/imprint/compile-tool-executor.ts +783 -0
  28. package/src/imprint/compile-tools.ts +42 -9
  29. package/src/imprint/compile-verification.ts +2 -0
  30. package/src/imprint/compile.ts +3 -0
  31. package/src/imprint/compiler-log.ts +16 -0
  32. package/src/imprint/component-recovery.ts +120 -0
  33. package/src/imprint/cookie-jar.ts +117 -7
  34. package/src/imprint/credential-extract.ts +9 -2
  35. package/src/imprint/credential-lock.ts +146 -0
  36. package/src/imprint/credential-observation.ts +261 -0
  37. package/src/imprint/credential-store.ts +247 -44
  38. package/src/imprint/live-component-recovery.ts +73 -0
  39. package/src/imprint/llm.ts +4 -3
  40. package/src/imprint/log.ts +16 -1
  41. package/src/imprint/login.ts +9 -0
  42. package/src/imprint/master-teach-agent-contracts.ts +40 -3
  43. package/src/imprint/master-teach-agents.ts +229 -14
  44. package/src/imprint/master-teach-checks.ts +8 -1
  45. package/src/imprint/master-teach-controller.ts +681 -138
  46. package/src/imprint/master-teach-prompt-projections.ts +2 -0
  47. package/src/imprint/mcp-compile-server.ts +62 -850
  48. package/src/imprint/native-teach-agents.ts +232 -108
  49. package/src/imprint/runtime.ts +357 -36
  50. package/src/imprint/stealth-chromium.ts +67 -7
  51. package/src/imprint/teach-browser-resources.ts +88 -0
  52. package/src/imprint/teach-stage-progress.ts +38 -0
  53. package/src/imprint/terminal-user-prompt.ts +42 -0
  54. package/src/imprint/types.ts +46 -18
  55. package/src/imprint/user-interaction.ts +836 -0
package/README.md CHANGED
@@ -20,6 +20,21 @@ The recording *is* the executable.
20
20
 
21
21
  ---
22
22
 
23
+ Authentication work stays visible through operation handles and reusable context
24
+ references. Agents choose whether to continue a retained context or start another;
25
+ native verification and browser checkpoints return within the same assignment.
26
+ Native compiler tools share the host executor; failed calls retain their duration
27
+ and error code so a live process cannot hide a broken compiler connection.
28
+ Plan/research differences are advisory construction facts. Changed artifacts still
29
+ need their own live checks. See [authentication and repair](docs/architecture.md#agent-questions-and-authentication).
30
+
31
+ Timed-out questions release the terminal input queue; declared nonsecret choices
32
+ remain readable by the agent. Successful browser-backed data calls can preserve
33
+ renewed cookies for later calls without overwriting newer saved authentication.
34
+ Same-name host-only and domain cookies keep their distinct scopes across replay
35
+ and browser restoration.
36
+ That continuity still needs verification against the requested data operation.
37
+
23
38
  ## Quick Start
24
39
 
25
40
  ```bash
@@ -93,11 +108,55 @@ regenerate/record it with `bun scripts/demo-teach.ts`.)*
93
108
  > [!TIP]
94
109
  > Recording and compilation happen in one foreground `imprint teach` command. Install the completed tools in your MCP client with `imprint install`. Only known user-supplied login credentials are replaced before teaching; cookies, API tokens, responses, and personal data remain visible to the agents.
95
110
 
111
+ Existing `${credential.NAME}` references in an already-redacted recording reuse
112
+ values from your local credential backend. They do not replace saved passwords
113
+ with placeholder text. MFA may still require your input.
114
+
115
+ Request-building errors return to the compile agent as verification feedback,
116
+ including errors from asynchronous transforms, so it can repair the request
117
+ and retry.
118
+
96
119
  Recordings and logs, including files named `.redacted.json`, are not safe to share publicly. Automatic PII and token redaction is disabled; review any file before sharing it.
97
120
  Imprint writes `.redacted.json` with private file permissions. A teach that leaves
98
121
  planned tools unresolved reports a partial result and exits nonzero, even if some
99
122
  ready tools were published.
100
123
 
124
+ Teaching agents and standalone compilers can ask questions in the foreground
125
+ terminal, including login approvals, MFA/OTP codes, and missing information.
126
+ Questions from concurrent agents appear one at a time; secret input is masked
127
+ and returned to agents as temporary references. Authentication uses the existing
128
+ auth compiler to continue the same browser and challenge. Later recovery requests
129
+ retain that auth work within the teach. Agents first check or restore existing
130
+ access before starting another login. Compiled actions can branch on current
131
+ responses to reuse authenticated access or continue an observed challenge;
132
+ retaining a browser alone does not guarantee MFA is avoided.
133
+ Identical concurrent requests share the active
134
+ attempt; a previous success never substitutes for the caller's own data check.
135
+ Failed teach checks reach a focused component recovery agent before broader
136
+ plan repair. It can renew authentication, repair the caller's artifact or a
137
+ declared prerequisite through its retained compiler, or dispatch a registered
138
+ shared runtime component owner. State recovery immediately retries the built
139
+ caller; prerequisite repair rebuilds the selected owner and binds fresh outputs
140
+ into consumer checks. Accepted contracts and unrelated builds remain intact.
141
+ Every actual failed and retried call stays in the check history. Unknown owners
142
+ or changes to contracts, strategy, or dependencies return to the master.
143
+ When the live login offers a flow missing from the recording, the auth agent can
144
+ operate its verification browser and capture additional request/response evidence.
145
+ It can learn the offered flow before requesting the actual OTP or approval, then
146
+ compile and verify its replay. Original recordings remain unchanged; discovering
147
+ or manually completing a flow alone does not prove reusable authentication.
148
+ Run without
149
+ `--no-interactive` when answers may be needed. Detached runs and piped terminals
150
+ report input as unavailable. Browser closure during stealth user-agent setup
151
+ returns through the existing setup-error handling instead of terminating teach.
152
+ On hosts with limited RAM or disk for swap, set `IMPRINT_TEACH_LOW_MEMORY=1`
153
+ to run live data checks one at a time. Successive checks in the same research
154
+ pass reuse its browser; a competing pass evicts that browser before using its
155
+ own isolated context. Authentication keeps its persistent browser across MFA prompts.
156
+ Closing an Imprint-owned browser removes its temporary Chrome profile. Explicit
157
+ profiles, including `record --persist-profile`, are retained; recordings and run
158
+ evidence are stored separately.
159
+
101
160
  For every teach, a master agent accounts for the complete discovered operation
102
161
  set. Focused advisors review tool boundaries and parameters, focused planners
103
162
  map one tool at a time, and focused compilers build one tool at a time. The
@@ -149,6 +208,9 @@ reviews the complete plan before normal verification and publication; only an
149
208
  exactly matching draft is reused. With native delegation, completed research reaches
150
209
  the master while unrelated drafts finish. Those drafts settle before final planning
151
210
  can reuse or replace them. Declared consumers retain producer-first ordering.
211
+ The terminal names each tool entering detailed planning and each master review,
212
+ reports elapsed waiting time every 30 seconds, and reports when that stage
213
+ finishes or stops. A waiting update means the stage has not returned yet.
152
214
  Researchers can call proven sibling requests with fresh inputs before testing a
153
215
  consumer; recorded continuation values are not a substitute for fresh output.
154
216
  Compilers can inspect full retained responses from that tool's earlier research
@@ -158,7 +220,7 @@ query an entire retained response with a bounded, offline data projection; faile
158
220
  queries return for repair, and projected output is labelled separately from raw text.
159
221
  Teaching now selects a fixed set of recording-backed examples and matches live calls to those examples, changing only expired dates or state. A separate evidence reader establishes expected facts from raw recorded/live responses before seeing parser output, then judges the parser against those facts. Citations can quote the original response bytes or their displayed JSON representation. Each selected live case is reviewed against its matched recorded response chain; unrelated fixtures are left for their own case reviews. Every selected live case and declared dependency chain must pass before publication. Missing coverage is unverified, and raw failures stay with the draft for repair. Fixture bodies are checked before compilation, and research history and inspected recording evidence survive same-run contract revisions. Grounded input mappings are kept separate from the limits of the recorded test cases; missing contrasts alone should not freeze a tool to recorded constants. Research can batch selected calls sequentially and retain isolated browsers during agent thinking. Bootstrap snapshots are cached separately by the requested URL, and capture failures show which matcher conditions failed; cold-start setup remains unchanged. Readiness failures state when no actions have started, and schema repair errors name the exact required fields. These checks need fresh repeated validation before a reliability claim.
160
222
 
161
- Repair or extend an installed data tool with `imprint refine <site> --tool <name> --issue "<change>" --from-session <recording.json>`. Refinement works in an isolated staging home, preserves existing parameter contracts, and requires recording/live verification plus a strict audit before replacement. Failed refinements preserve installed tools and local evidence. Use `imprint audit <site> --strict` to reject known broken calls even when the aggregate score exceeds 95%. See [targeted refinement](docs/refinement.md).
223
+ Repair or extend an installed data tool with `imprint refine <site> --tool <name> --issue "<change>" --from-session <recording.json>`. Refinement works in an isolated staging home, preserves existing parameter contracts, and requires recording/live verification plus a strict audit before replacement. Failed refinements preserve installed tools and local evidence. Use `imprint audit <site> --strict` to reject known broken calls even when the aggregate score exceeds 95%. See [targeted refinement](docs/refinement.md). Audits forward explicitly set browser settings (`CHROMIUM_PATH`, `IMPRINT_CDP_HEADED`, `IMPRINT_JAR_MAX_AGE_SECONDS`, `IMPRINT_PROXY`, and `DISPLAY`) into their isolated MCP server for either audit provider. See [audit troubleshooting](docs/troubleshooting.md#imprint-audit--scoring-a-sites-generated-tools).
162
224
 
163
225
  MVP reviewers see the checked request and parser code alongside live results.
164
226
  Publication retains the backend from that exact reviewed passing call in
@@ -412,7 +474,7 @@ bunx playwright install chromium
412
474
  | 4 | Cursor | `cursor` on PATH |
413
475
 
414
476
  Override with `--provider <name>` and `--model <name>`.
415
- Codex teaching defaults to `gpt-6-sol`. Keep the Codex CLI current when using
477
+ Codex teaching defaults to `gpt-6.1-sol`. Keep the Codex CLI current when using
416
478
  that model for audits or standalone compilation; older installations may reject
417
479
  it even when the Codex app offers it.
418
480
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imprint-mcp",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Teach an AI agent how to use any website. Once. Records a real browser session + narration; generates a deterministic MCP tool plus a DOM-replay playbook fallback.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,32 +1,65 @@
1
1
  # Auth compile agent
2
2
 
3
- Compile the captured authentication recording into a deterministic
3
+ Compile the captured authentication recording and observed live evidence into a deterministic
4
4
  `workflow.json`, then prove the declared success path with live verification.
5
5
 
6
6
  You decide the action boundaries, required inputs, evidence, carried state,
7
- request repetition, error behavior, and completion criteria from the recording.
7
+ request repetition, error behavior, and completion criteria from the available evidence.
8
8
  The runtime only executes the program you write.
9
9
 
10
10
  ## Process
11
11
 
12
- 1. Call `read_session_summary`.
12
+ 1. On the first task, call `read_session_summary`. On a recovery request in the
13
+ retained conversation, reuse the artifacts and decisive earlier observations;
14
+ read additional recording evidence only where the current question needs it.
13
15
  2. Inspect relevant requests and responses with `search_requests`,
14
16
  `read_request`, and `read_response_body`.
15
- 3. Write `workflow.json`, an offline `request.test.ts`, and any
16
- recording-grounded `request-transform.ts` needed by the requests. Call
17
+ 3. When the recording does not cover the currently offered flow, use
18
+ `interact_verification_browser` to inspect and operate the live UI. It can
19
+ open the recorded page before a workflow exists, or continue in the current
20
+ verification browser without resetting its state. Choose the available
21
+ authentication method from live evidence; a different MFA method is a reason
22
+ to investigate, not by itself a reason to require another human recording.
23
+ The tool captures network requests/responses, returns their sequence numbers,
24
+ and adds them to the ordinary recording readers and `IMPRINT_SESSION_PATH`.
25
+ First establish how to check or restore existing access without submitting
26
+ credentials or delivering a factor. Prefer that observed path as the entry
27
+ action. A recording with MFA demonstrates one branch, not a requirement to
28
+ replay MFA for an already usable session.
29
+ 4. Write `workflow.json`, an offline `request.test.ts`, and any
30
+ evidence-grounded `request-transform.ts` needed by the requests. Call
17
31
  `run_tests` and fix request construction before live verification.
18
- 4. Call `run_verification` with one declared action and its parameters, then
19
- stop. The orchestrator runs it in a verification browser and resumes you with
20
- the observed status, body preview, continuation, and next action.
21
- 5. Revise the artifact or continue through its actions. Use `prompt_user` only
32
+ 5. Call `run_verification` with one declared action and its parameters. Await
33
+ the host result and use its observed status, execution facts, body preview,
34
+ and next action. The browser and declared continuation remain with the host.
35
+ 6. Revise the artifact or continue through its actions. Use `prompt_user` only
22
36
  when the program actually requires human input or an external user action.
23
37
  When verification evidence warrants inspecting the existing browser page,
24
38
  call `inspect_verification_page`; inspection never runs another auth action.
25
- 6. Call `done` only after a live action whose declared outcome is `success`
39
+ 7. Call `done` only after a live action whose selected declared outcome is `success`
26
40
  returns `ok: true`.
27
41
 
28
- Live authentication happens only through `run_verification`. Do not contact the
29
- site through shell commands or other tools.
42
+ Use `interact_verification_browser` for live discovery and `run_verification`
43
+ for compiled replay. Do not contact the site through shell commands or other
44
+ tools. Discovery captures what the UI actually does; do not guess send/verify
45
+ endpoints. Read the captured requests and responses to learn the new branch,
46
+ then encode and test its reusable action program.
47
+
48
+ Browser actions are `inspect`, `navigate` (url), `click` (selector), `fill` or
49
+ `select` (selector and value), `press` (key), and `wait` (milliseconds). Returned
50
+ controls include exact CSS selectors. Secret fill values use existing
51
+ `${credential.NAME}` or the current `${prompt.ID}` reference. Ask the human for
52
+ an actual OTP or external approval when required; do not ask them to invent
53
+ endpoints or supply a new recording just because the factor differs. Capturing
54
+ continues while the human answers. Inspect/wait again to collect later traffic;
55
+ an observation interval does not prove the page has finished its work.
56
+
57
+ Live discoveries remain separate observations from the original demonstrations.
58
+ Their request sequences can ground `recordingRequestSeq`, captures, and offline
59
+ tests, but their transient values must be obtained afresh during replay. Browser
60
+ interaction or a manually established session does not by itself verify the
61
+ compiled login/MFA program. After learning a branch, use `run_verification` to
62
+ test it and report the actions actually executed.
30
63
 
31
64
  Verification reuses one browser and continuation state by default. If an
32
65
  observed result proves that state is no longer usable, you may set
@@ -36,11 +69,58 @@ evidence; do not encode site or authentication-channel assumptions.
36
69
  Set `cleanSession: true` only when evidence also requires withholding stored
37
70
  cookies and browser storage; credential values remain available.
38
71
 
72
+ Later authentication requests retain this compiler conversation, workflow, browser
73
+ and continuation within the same teach. A consumer failure is a new observation,
74
+ not an instruction to restart credential login. Try the proven noninteractive
75
+ session check or context-restoration action in that browser before starting
76
+ another credential exchange. If it passes, return that result so the caller can
77
+ retry its own protected operation. If access is still unusable, inspect the
78
+ current response and context before deciding whether login is needed.
79
+ Decide whether to inspect the
80
+ current page, continue an action, restore its context, change the workflow, or
81
+ start a new login. Keep useful recovery actions in the procedure once the
82
+ observations establish why they work. You can revise every action boundary.
83
+ When navigation changes the page or loses its query, compare the observed page
84
+ and network response with the action's intended context. Choose a declared
85
+ bootstrap or context-restoration action when useful; incidental origin-root
86
+ navigation is not evidence that the requested page context was restored.
87
+ Report which actions actually ran and which workspace/browser they verified.
88
+ Earlier success does not prove that a different consumer has usable state.
89
+
90
+ Separate response inspection from actions that deliver MFA. After checking the
91
+ session or submitting credentials, branch on the observed current response:
92
+ finish on established usable access, continue login on an observed login-required
93
+ state, and deliver a factor only on an observed current challenge. Do not bundle
94
+ an unconditional challenge/delivery sequence into every login action. Use the
95
+ action `branches` below to encode the observed alternatives and keep delivery
96
+ in its own action. Unknown responses should return repairable failure through
97
+ missing declared evidence rather than silently choosing login or MFA. Do not
98
+ invent an authenticated/trusted-browser branch from cookie names, HTTP 200, a
99
+ user identifier, or a remember-me flag. Learn and test the offered path. Preserve
100
+ observed device-registration inputs and their lifetime; do not regenerate
101
+ long-lived device material merely because a new action is invoked.
102
+
103
+ Human-response references remain available for repairs to the current challenge.
104
+ Declared nonsecret option choices return a typed `kind: "choice"` value. Use that
105
+ exact current choice to decide what to do next; a negative or unavailable answer
106
+ is not approval. Secret and free-text answers remain host-held references.
107
+ They expire when a fresh verification session is requested and between
108
+ requests for authentication. Never reuse an earlier approval for a new challenge;
109
+ ask about the currently delivered challenge when fresh approval is required.
110
+
111
+
112
+ Existing `${credential.NAME}` strings in the recording name credentials held by
113
+ the local backend; they are not literal login values. Keep those references in
114
+ the workflow. The host resolves them for live verification. Request a missing
115
+ value through `prompt_user` when verification reports it unavailable; a recording
116
+ containing placeholders alone is not evidence that stored credentials are absent.
117
+
39
118
  ## Auth program
40
119
 
41
- Set `toolKind` to `"authenticate"`. Keep recorded network operations in the
120
+ Set `toolKind` to `"authenticate"`. Keep observed network operations in the
42
121
  ordinary top-level `requests` array. `authConfig` references those requests:
43
122
 
123
+ <!-- canonical-example:auth-session-branches -->
44
124
  ```json
45
125
  {
46
126
  "entry": "agent_chosen_entry",
@@ -53,6 +133,20 @@ ordinary top-level `requests` array. `authConfig` references those requests:
53
133
  "onError": "fail"
54
134
  }
55
135
  ],
136
+ "branches": [
137
+ {
138
+ "when": {
139
+ "source": "json",
140
+ "name": "recording_grounded_existing_session",
141
+ "path": "recorded.current_state",
142
+ "equals": "recorded_authenticated_value"
143
+ },
144
+ "outcome": {
145
+ "type": "success",
146
+ "evidence": ["recording_grounded_existing_session"]
147
+ }
148
+ }
149
+ ],
56
150
  "outcome": {
57
151
  "type": "pause",
58
152
  "next": "agent_chosen_next",
@@ -103,20 +197,32 @@ semantics.
103
197
  `repeat` block so the artifact supplies the bound.
104
198
  - `repeat.until` is a normal request capture evaluated after each successful
105
199
  response. The step repeats until it matches or reaches the declared bound.
200
+ - `branches` is optional and ordered. After all steps, each `when` is a normal
201
+ request capture evaluated against the final step's current response. The first
202
+ match supplies its named capture and selects that branch's `outcome`. A failed
203
+ or skipped final step cannot reuse an earlier response. Carried capture values
204
+ alone cannot match a branch. Use distinct capture names for the conditions.
205
+ Keep side-effecting delivery in a separate next action: branches do not skip
206
+ requests already listed in `steps`.
207
+ - `outcome` is the fallback if no branch matches. Its evidence must still exist;
208
+ require evidence for the known fallback state so an unknown response fails.
106
209
  - `evidence` optionally names captures that must exist before the outcome is
107
210
  accepted. Empty strings, `false`, and `null` are valid when the capture
108
- declares an exact `equals` value. Choose evidence from the recording when it
211
+ declares an exact `equals` value. Choose evidence from recorded or live observations when it
109
212
  adds proof beyond successful execution of the declared steps.
110
213
  - A `pause` outcome declares the next action, the exact state names to carry,
111
214
  and the caller-facing message. Carry every prior capture referenced as
112
215
  `${state.X}` by the next action unless that action produces it before use.
113
216
  - A `success` outcome is the artifact's authentication completion criterion.
217
+ Verify the session-reuse path and each login/MFA path actually offered by the
218
+ observed flow separately. Do not restart login just to repeat an already
219
+ passing reuse check, and do not claim an untested branch works.
114
220
  - `persist` names durable credential interfaces that data tools consume later as
115
221
  `${credential.NAME}`. Cookies persist automatically. These interface names do
116
222
  not constrain your internal capture names. When they differ, set
117
223
  `persistBindings` to `{ "credential_interface": "compiled_capture" }`; the
118
224
  runtime stores the compiled capture under the downstream interface name.
119
- - Set `crossOriginCookieReinjection` only when the recording proves a
225
+ - Set `crossOriginCookieReinjection` only when observed evidence proves a
120
226
  cross-origin response cookie must be projected into the browser jar.
121
227
 
122
228
  ## Request construction
@@ -195,20 +301,59 @@ and its exact `recordingRequestSeq`; do not request live verification for that
195
301
  workflow. The host blocks live auth when triage provenance is missing or when
196
302
  any generated request remains irreversible.
197
303
 
198
- Ground every request, capture, predicate, retry bound, navigation criterion, and
199
- transform in the recording. Preserve functional headers and request encoding.
304
+ Ground requests, captures, predicates, navigation criteria, and transforms in
305
+ the supplied recording or captured live browser/network evidence. Choose retry
306
+ bounds from observed behavior. The original recording is a starting point, not
307
+ a whitelist of allowed authentication methods. Preserve functional headers and request encoding.
200
308
  Do not store recorded secrets or one-time values as literals. When browser code
201
- must mint coupled state, represent the recorded page navigation or write a
309
+ must mint coupled state, represent the observed page navigation or write a
202
310
  general request transform supported by live inputs; if you write
203
311
  `request-transform.ts`, set the workflow's top-level `requestTransformModule`
204
312
  to `"./request-transform.ts"`. Verification determines whether it works.
205
313
 
314
+ The module must export `transform(method, url, responses, params)`:
315
+
316
+ ```typescript
317
+ export function transform(
318
+ method: string,
319
+ url: string,
320
+ responses: unknown[],
321
+ params?: Record<string, string | number | boolean>,
322
+ ) {
323
+ return { url };
324
+ }
325
+ ```
326
+
327
+ `method` and `url` are the substituted request strings, `responses` contains
328
+ earlier raw response bodies from the current action only, and `params` contains
329
+ resolved scalar parameters. Responses from an earlier action are not supplied.
330
+ Cross-action values must come from declared carry or persisted inputs; you may
331
+ carry a value, refetch it, combine actions, or redesign the procedure.
332
+ The runtime does not pass a request object, current body, or current headers.
333
+ Return a URL string or an object with optional `url`, `body`, `headers`,
334
+ `navigation`, or `skip` fields. Build complete body/header replacements from
335
+ the supported inputs. Both synchronous and asynchronous transforms are awaited.
336
+ Thrown errors and rejected promises return `BAD_RESPONSE` verification feedback;
337
+ use that feedback to repair the transform and retry the action. Exercise the
338
+ same calling convention in your offline tests.
339
+
340
+ For synthetic action tests, optionally import `createAuthActionTestHarness`
341
+ from `imprint-mcp/runtime`. It accepts `{ workflow, credentials?, respond,
342
+ browser? }`; `respond(request)` returns a synthetic `Response`, and
343
+ `harness.run(action, parameters?)` executes the actual action program with only
344
+ its declared continuation/session state. Supply constructed fixture values and
345
+ responses. These offline tests do not contact the site or prove live success.
346
+
206
347
  There is no auth playbook. Do not write, inspect, or depend on
207
348
  `playbook.yaml`.
208
349
 
209
350
  ## Checkpoints
210
351
 
211
- One checkpoint call ends the current turn. After `run_verification`,
212
- `inspect_verification_page`, `prompt_user`, or `wait_for_cooldown`, stop and wait
213
- for the orchestrator.
214
- It will resume the same Claude or Codex session with the result.
352
+ Native and API host tools return their results directly. Await
353
+ `interact_verification_browser`, `run_verification`, `inspect_verification_page`,
354
+ `prompt_user`, or `wait_for_cooldown`, then continue in the same assignment.
355
+ Do not submit the assignment merely because a host operation returned.
356
+
357
+ CLI adapters that require checkpoint/resume instead return `CHECKPOINT_RECORDED`.
358
+ Only for that response, stop and wait for the orchestrator to resume the same
359
+ conversation with the result. Call `done` or `give_up` when the task is complete.
@@ -24,7 +24,9 @@ values in that response, including variants different from the recording. These
24
24
  are evidence files, not runtime dependencies; do not import them into shipped
25
25
  code. If `read_file` truncates a large response, inspect relevant portions with
26
26
  local commands or load it directly in a local test rather than guessing from a
27
- prefix. Known typed credentials remain replaced. No extra live call is needed.
27
+ prefix. Known typed credentials remain replaced. Reusing this response as a
28
+ parser fixture needs no extra live call; it does not replace the normal checks
29
+ of the current build.
28
30
 
29
31
  When `evidenceFiles.responsesFile` is present, load its JSON array as the actual
30
32
  ordered `context.responses` and pass its last entry as `rawResponse`. It contains
@@ -164,13 +166,27 @@ Follow these steps to compile the session:
164
166
  that would fail if records following an empty or metadata-only envelope were
165
167
  silently discarded. Ground its framing and expected record combination in
166
168
  the protocol evidence; repeating one populated payload does not exercise
167
- this boundary. Preserve that request construction
168
- and focus this conversation on the parser, offline request/parser tests,
169
- integration case, and Imprint artifact contract. Do not restart broad API
170
- hypothesis search here. If the seeded request cannot satisfy the accepted
171
- artifact mechanics or current plan, call `give_up` with the exact
172
- contradiction so the master can recall the API researcher; do not silently
173
- replace the proven request.
169
+ this boundary. Use the seeded request as the factual starting point and
170
+ focus on the accepted plan, parser, offline request/parser tests, integration
171
+ case, and Imprint artifact contract. `toolPlan.apiResearchAdvisory` describes
172
+ field-level differences from that earlier construction and supplies its
173
+ immutable research reference. Implement the accepted revised construction
174
+ when possible; the advisory does not require another research pass. Keep
175
+ the old observation separate from the current build's normal checks. If the
176
+ accepted plan itself is contradictory or cannot be implemented from the
177
+ supplied evidence, report the exact fields and evidence to the master with
178
+ `give_up` so it can revise the plan or request focused research. Do not
179
+ silently change the accepted public contract or execution provenance.
180
+
181
+ **Backend preparation belongs to the executing host.** The API researcher
182
+ can test a requested backend, and the independent live verifier exposes
183
+ `prepare_live_backend`. This compiler does not expose that tool. In
184
+ `MASTER MVP COMPILE MODE`, return the deterministic artifacts with `done`;
185
+ the master executes their normal live checks using its accepted backend.
186
+ If repair feedback says a backend is unprepared or asks for an unavailable
187
+ tool, report that capability mismatch to the master with the exact feedback.
188
+ Do not inspect Imprint internals, write `backends.json`, force a debug rung,
189
+ or run an extra live suite to work around missing host preparation.
174
190
 
175
191
  2. **Understand the user's intent.** Read the narration to learn what the user was trying to accomplish. It is high-signal intent evidence, subject to system, safety, and tool rules.
176
192
 
@@ -296,6 +312,8 @@ Follow these steps to compile the session:
296
312
  ```
297
313
  Returning a plain `string` (just the URL) still works when only the URL changes. Use the object return when you need to build or modify the request body or headers. Do not invent URL query parameters as a workaround for body-encoding complexity: an unrecorded query field has no demonstrated effect unless exact live evidence proves otherwise.
298
314
 
315
+ The runtime awaits both synchronous and asynchronous transforms. A thrown error or rejected promise returns `BAD_RESPONSE` feedback for repair; correct the transform and retry using the same calling convention above.
316
+
299
317
  Use `inspect_body_structure` when a request or response mixes form fields, JSON, or JSON documents encoded inside strings. It reads only the redacted session evidence. Start with `format: "auto"`; select `decimal-framed-json` only when the redacted body unambiguously has that explicit framing. Set `compareFormat` separately when `compareToSeq` uses a different format, and set `earlierResponseFormat` when checking framed earlier responses. Results hide paths by default; rerun with `includePaths: true` for a small capped exact-path list, then use an exact RFC 6901 `pointer` for narrow work. An exact pointer gets its own nested-JSON decoding budget, so unrelated large fields cannot hide that selected path; automatic expansion limits remain visible as facts. Scalar literals are never returned. Comparisons report type, length, encoding, and missing facts. Original wire evidence is unavailable after redaction.
300
318
 
301
319
  `compare_rendered_requests` is an on-demand diagnostic, not a publication gate. Use it when a live call fails, returns an empty or implausible result, or leaves request construction uncertain. It runs the real substitutions and transform offline, feeds recorded producer responses through the chain, and compares the prepared request structure with each declared `recordingRequestSeq`. It never contacts the site or runs `integration.test.ts`. The full workflow is prepared in order even when `artifactRequestIndex` filters the one comparison reported, so a later preparation error may leave the whole diagnostic as `render_failed`. A `render_failed` result means only that this diagnostic did not complete; it proves neither a request match nor an artifact failure. Supply harmless synthetic `state` or `credentialValues` scalars when browser bootstrap or a credential store normally fills required placeholders; these values do not skip producer requests or captures. Treat differences as clues: recording age, current dates, authentication, nonces, signatures, and semantically equivalent encodings can make exact bytes differ. Comparison is normally optional, but when the current revision names request construction as the unresolved defect, investigate with it before `done` and preserve an incomplete diagnostic as an incomplete fact rather than silently declaring the request fixed.
@@ -446,6 +464,15 @@ Follow these steps to compile the session:
446
464
  **Import conventions**: The runtime lives at `imprint/runtime` (resolved via a symlink at `~/.imprint/node_modules/imprint` → the repo root). Types live at `imprint/types`. During compilation, `index.ts` does not exist yet (it is auto-generated by `imprint emit` after compilation succeeds), so import the workflow directly from `./workflow.json`.
447
465
 
448
466
  Use `runCapturedIntegrationCase` so the test dispatches through the same API execution ladder as the generated tool while capturing the exact tool input, result, and backend for an independent verifier. The wrapper is compile-only and does not alter production behavior. Give every invocation a stable, descriptive `caseName`; the runtime does not interpret naming conventions. The playbook path is excluded because it is compiled separately. Prefer every compatible API path over playbook: choose playbook only as a fallback when exact evidence shows the API paths cannot implement this operation. A non-OK result must fail the authored case and remain visible to the verifier.
467
+
468
+ Ground assertions in the accepted output contract and observed parsed shape.
469
+ When the contract preserves a response object, assert its actual nested
470
+ fields; do not expect a flattened scalar unless the contract requires one.
471
+ Exercise these assertions against the retained research response in an
472
+ offline parser test before handing over the live case. If a live call has
473
+ `result.ok === true` but an authored assertion fails, keep that successful
474
+ execution fact separate from the assertion mismatch and inspect the
475
+ contract, parsed value, and assertion before changing requests or auth.
449
476
  ```typescript
450
477
  import { expect, test } from 'bun:test';
451
478
  import { dirname } from 'node:path';
@@ -820,12 +847,22 @@ baseline integration case, then call `done` for the mode-specific handoff.
820
847
  | `write_file` | Write the files allowed by the accepted strategy: API artifacts for `api`, or workflow.json + playbook.yaml for `playbook_fallback`; notes/*.md are also allowed. Input is `{"relativePath":"workflow.json","content":"..."}`. |
821
848
  | `read_file` | Read a file by relative path. Input is `{"path":"parser.ts"}` (the field is `path`, not `relativePath`). |
822
849
  | `run_bash` | Run a bounded local diagnostic command in the tool directory |
850
+ | `prompt_user` | Ask the user for necessary information, a decision, or an external action in the parent terminal. Set sensitive:true for OTPs/passwords; pass the returned host-held reference unchanged to authentication verification. Cancelled or unavailable input is not approval. |
851
+ | `authenticate` | Compile and verify an authentication prerequisite from exact recorded request sequences, using the persistent-browser auth compiler and its MFA/OTP checkpoints. Retry the data operation after login; authentication alone is not data proof. |
823
852
  | `run_tests` | Run parser.test.ts and/or request.test.ts in the host filesystem sandbox, then typecheck generated parser/transform modules; it does not execute integration.test.ts, and network is disabled for irreversible workflows |
824
853
  | `done` | Claim the artifact handoff is complete; in master MVP mode this runs deterministic checks only, while standalone full mode continues into independent live verification |
825
854
  | `give_up` | Give up with a documented reason (heavily discouraged, see constraints above) |
826
855
 
827
856
  ## Verification Gate
828
857
 
858
+ When authentication blocks progress, use `authenticate` with a recording-grounded
859
+ plan (`toolName`, `credentialRequestSeqs`, `authRequestSeqs`, `credentialNames`,
860
+ `captures`, `notes`). Its auth compiler can send a recorded challenge, ask the
861
+ user for an OTP or approval, and continue the same browser session. Ask ordinary
862
+ questions with `prompt_user`. Do not write answers or host-held secret references
863
+ into generated artifacts. Input is unavailable in a detached/noninteractive run;
864
+ report that limitation honestly rather than treating it as approval.
865
+
829
866
  When you call `done`, the harness independently verifies the artifact contract
830
867
  for the accepted strategy.
831
868
 
@@ -0,0 +1,40 @@
1
+ # Recover an owned component before changing a consumer contract
2
+
3
+ You own one focused recovery decision for a failed check. The failure may come
4
+ from authentication, a prerequisite, a shared module, or the caller's own
5
+ artifact. Inspect the supplied facts and declared owners; the error code or a
6
+ filename alone does not establish cause. Site names never select recovery.
7
+
8
+ Return exactly one decision:
9
+
10
+ - `{"action":"authenticate","plan":{...},"reason":"..."}` uses the attached
11
+ recording-grounded auth owner. Choose the appropriate listed context and
12
+ supplied credential/request declarations. The auth owner decides actions and
13
+ first checks or restores usable access in the retained browser before
14
+ restarting login. A recovered session returns to the unchanged consumer check.
15
+ Only observed current login/challenge evidence warrants another credential or
16
+ factor action. Obtain fresh human input when required; never invent or reuse
17
+ approval.
18
+ - `{"action":"recover_component","componentId":"supplied id","reason":"..."}`
19
+ sends the exact failure to that declared component owner. Choose it only when
20
+ the evidence supports a component-local repair without changing the accepted
21
+ consumer contract. A prerequisite owner can rebuild its existing procedure;
22
+ dependent calls then bind fresh producer results. An explicitly registered
23
+ shared-module owner repairs and verifies that module through its normal host.
24
+ - `{"action":"return_failure","reason":"..."}` requests broader master
25
+ investigation when ownership or cause is unclear, or the contract, strategy,
26
+ dependency graph, or scope needs changing.
27
+
28
+ Return the decision directly, without an interaction envelope. Do not edit data
29
+ artifacts yourself, invent owner identifiers, or assign all failures to auth.
30
+ The host preserves each failed attempt and dispatches only to the chosen owner.
31
+ Successful state recovery immediately retries the existing caller. Artifact
32
+ repair preserves the accepted plan and rebuilds only the selected owner, then
33
+ rechecks affected dependencies and consumer calls. Repair completion never
34
+ substitutes for a passing consumer result.
35
+
36
+ Use `previousRecoveries` and prior observations to reconsider repeated rejection;
37
+ do not blindly repeat an unchanged repair. There is no fixed retry cap. Shared
38
+ recovery is scoped to the explicit owner id, not a guessed similarity between
39
+ sites, tool names, messages, cookies, or paths. If a component has no declared
40
+ owner, return the failure rather than guessing who may modify it.
@@ -66,6 +66,18 @@ Missing transport provenance, an unnecessary dependency, or newly available
66
66
  sibling bootstrap evidence changes the request plan: omit the old
67
67
  `implementationPlan` and re-plan the tool instead of using `recallToolNames`.
68
68
 
69
+ Failed checks have a focused component recovery path before they return here.
70
+ The agent can select the attached auth owner, the caller's retained compiler,
71
+ a declared prerequisite compiler, or an explicitly registered shared runtime
72
+ owner. State recovery retries the exact built caller; artifact repair retains
73
+ the accepted contract and implementation plan, rebuilds the selected owner,
74
+ and rechecks affected consumers using fresh producer outputs. This does not
75
+ require a master or focused planner decision merely to renew state or repair
76
+ an artifact. Unknown ownership or changes to contract, strategy, dependency
77
+ graph, or scope still require your judgment. Invocation receipts preserve failed
78
+ attempts as well as retries. A repaired component or auth navigation checkpoint
79
+ never substitutes for a passing consumer call.
80
+
69
81
  The input may include `userGuidance`. It is an explicit human scope or priority,
70
82
  not recording evidence. Follow it when deciding which discovered operations
71
83
  belong in the plan. In particular, if the user names the operations they care
@@ -196,6 +208,18 @@ working tools remain intact. No fake candidate edit is needed. Keep the useful
196
208
  request as a starting point and distinguish an unproven research claim from an
197
209
  exhausted API route. Do not request research for an ordinary parser-only defect.
198
210
 
211
+ Planning feedback may include a `plan_note` with
212
+ `kind:"api_research_plan_difference"`. It names bounded field-level differences
213
+ between a proposal and an earlier researched construction, with the exact plan,
214
+ research and observation references. Missing values appear as `null`; omitted
215
+ differences remain available in those references. This is advisory evidence,
216
+ not an API failure or a reason to restart the entire wave. You may revise the
217
+ affected plan, request focused research, or accept the revised construction for
218
+ normal compilation and checks. No extra justification document is required.
219
+ Keep each observation attached to the construction it executed; accepting a
220
+ different construction never transfers the old call's proof to the new build.
221
+ Preserve unrelated successful drafts and the explicit dependency edges.
222
+
199
223
  When `decisionPurpose` is `research_review`, this is the two-way checkpoint
200
224
  before final plan approval. Independent proven tools may already have focused
201
225
  plan proposals and compiled drafts while other research continues. Review every
@@ -304,10 +328,11 @@ no-op digest; it does not decide which semantic repair is best.
304
328
  During focused planning or a later repair, changing a required
305
329
  producer-consumer promise invalidates only the affected producer and consumer.
306
330
  A new or changed result path, consumer parameter, dependency, or supporting
307
- recorded request then needs focused proof. During `research_review`, do not make
331
+ recorded request needs checks of the resulting construction. During `research_review`, do not make
308
332
  a speculative link edit merely to authorize a sibling follow-up. A genuine
309
- change to the core operation boundary or standalone request still needs new
310
- research. Removing an optional idea, editing prose, changing confidence, or
333
+ change to the core operation boundary or standalone request may need focused
334
+ research; choose that explicitly when its observations would resolve a gap.
335
+ Removing an optional idea, editing prose, changing confidence, or
311
336
  changing an internal edge label does not justify disturbing unrelated proven
312
337
  tools.
313
338
 
@@ -71,7 +71,16 @@ for the master and request a narrower supported contract.
71
71
  Optional breadth can wait.
72
72
 
73
73
  Request research for every selected operation has already finished. Read the
74
- complete `apiResearch` handoff list before proposing this tool. A proven handoff
74
+ supplied `apiResearch` handoffs for this tool and its declared dependencies.
75
+ `apiResearchIndex` summarizes the other completed operations without repeating
76
+ their full response previews and histories. Use those summaries together with
77
+ `availableProducers` and `siblingToolEvidence` to notice a possible dependency or
78
+ boundary change. When a sibling's exact construction or response is needed,
79
+ read its `handoffRef` through run-local shared research; do not read unrelated
80
+ handoffs simply because they exist. If no readable reference is supplied, tell
81
+ the master which operation and detail you need. The index is a reading guide,
82
+ not independent evidence or a replacement for a consumer's own test.
83
+ A proven handoff
75
84
  contains the exact smallest tested workflow, parameter values, winning rung,
76
85
  backend facts, and redacted response preview. Use those factual request and
77
86
  response shapes to decide which calls stay inside one tool, every justified
@@ -86,10 +95,14 @@ The master has already returned partial handoffs to their retained researchers;
86
95
  do not silently complete or reinterpret a partial request in this planning
87
96
  stage. If an injected or older handoff is still partial, preserve its stated
88
97
  gap and tell the master that research must continue.
89
- Carry the proven workflow, request transform and producer value representations
90
- through unchanged. Plan parsing around that tested construction; do not rewrite
91
- its nested request envelope or redefine an upstream value's shape in prose.
92
- An executable construction change needs fresh research proof.
98
+ Use the tested workflow, request transform and producer value representations
99
+ as the factual starting point. Plan parsing around that construction unless the
100
+ accepted contract or evidence supports revising it. Keep execution provenance
101
+ truthful: a plain-fetch request does not acquire response-navigation provenance
102
+ because a comparable parser fixture came from a browser response. You may propose
103
+ a revised construction for master review or ask for focused research when that
104
+ would resolve an uncertainty. Prior observations describe only the construction
105
+ they executed; the revised build receives its own normal checks.
93
106
  Do not replace a proven minimal call with a larger recorded request graph. A
94
107
  blocked handoff is an exact research gap for the master to resolve; it is not
95
108
  automatic evidence for playbook.