imprint-mcp 0.6.0 → 0.6.2

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 (43) hide show
  1. package/README.md +2 -0
  2. package/package.json +4 -2
  3. package/prompts/audit-agent.md +4 -2
  4. package/prompts/auth-compile-agent.md +149 -158
  5. package/prompts/build-planning.md +14 -9
  6. package/prompts/compile-agent.md +46 -23
  7. package/prompts/live-verifier-agent.md +101 -0
  8. package/prompts/playbook-compilation.md +8 -1
  9. package/prompts/tool-candidate-detection.md +9 -29
  10. package/src/cli.ts +83 -1
  11. package/src/imprint/audit.ts +219 -20
  12. package/src/imprint/auth-compile-agent.ts +215 -155
  13. package/src/imprint/auth-compile-tools.ts +300 -118
  14. package/src/imprint/auth-verifier.ts +167 -180
  15. package/src/imprint/backend-cache.ts +18 -11
  16. package/src/imprint/backend-ladder.ts +225 -177
  17. package/src/imprint/build-plan.ts +3 -8
  18. package/src/imprint/cdp-browser-fetch.ts +930 -83
  19. package/src/imprint/claude-cli-compile.ts +46 -20
  20. package/src/imprint/codex-cli-compile.ts +436 -139
  21. package/src/imprint/compile-agent-types.ts +15 -10
  22. package/src/imprint/compile-agent.ts +88 -28
  23. package/src/imprint/compile-tools.ts +228 -39
  24. package/src/imprint/compile-verification.ts +187 -0
  25. package/src/imprint/compile.ts +71 -2
  26. package/src/imprint/credential-store.ts +57 -44
  27. package/src/imprint/emit.ts +3 -1
  28. package/src/imprint/freeform-redact.ts +27 -6
  29. package/src/imprint/live-verifier.ts +1665 -0
  30. package/src/imprint/llm.ts +22 -3
  31. package/src/imprint/login.ts +107 -25
  32. package/src/imprint/mcp-compile-server.ts +447 -114
  33. package/src/imprint/mcp-live-verifier-server.ts +359 -0
  34. package/src/imprint/mcp-server.ts +116 -35
  35. package/src/imprint/probe-backends.ts +88 -7
  36. package/src/imprint/recording-request.ts +36 -0
  37. package/src/imprint/request-capture.ts +40 -17
  38. package/src/imprint/runtime.ts +490 -337
  39. package/src/imprint/teach-state.ts +36 -2
  40. package/src/imprint/teach.ts +302 -146
  41. package/src/imprint/tool-candidates.ts +8 -10
  42. package/src/imprint/tool-loader.ts +12 -4
  43. package/src/imprint/types.ts +137 -68
@@ -50,22 +50,16 @@ export interface CompileAgentProgress extends AgentProgress {
50
50
  /** 1-based verification cycle. Cycle 1 is the initial agent run. Subsequent cycles
51
51
  * happen when the agent claims done() but external verification fails. */
52
52
  verificationCycle: number;
53
- /** Hard cap on verification cycles (typically 5). */
54
- maxVerificationCycles: number;
53
+ /** Verification cap for bounded data-tool compiles; auth is deadline-bounded. */
54
+ maxVerificationCycles?: number;
55
55
  // ── Auth segments only (all optional; data-compile + codex paths leave unset) ──
56
56
  /** 1-based current segment index in the resumable auth loop. */
57
57
  segment?: number;
58
- /** Total segment budget (MAX_AUTH_SEGMENTS). */
59
- maxSegments?: number;
60
- /** Live `initiate` attempts spent so far (AuthVerifier.attemptsUsed). */
61
- attempt?: number;
62
- /** Attempt cap (AuthVerifier.maxInitiateAttempts). */
63
- maxAttempts?: number;
64
58
  /** The most recent live verification result, so the orchestrator's progress
65
59
  * line can surface a failure (e.g. a 403) the instant it happens instead of
66
60
  * only feeding it to the agent. Grounded purely in AuthPhaseResult fields. */
67
61
  lastVerification?: {
68
- phase: string;
62
+ action: string;
69
63
  ok: boolean;
70
64
  status?: number;
71
65
  error?: string;
@@ -82,7 +76,18 @@ export interface CompileAgentProgress extends AgentProgress {
82
76
  * the cooldown — then resumes the agent (`claude --resume`) with the result as a
83
77
  * follow-up user message. Site/channel-agnostic. */
84
78
  export type AuthCheckpoint =
85
- | { kind: 'run_verification'; phase: 'initiate' | 'submit_otp' | 'complete'; otp_code?: string }
79
+ | {
80
+ kind: 'run_verification';
81
+ action: string;
82
+ parameters?: Record<string, string | number | boolean>;
83
+ freshSession?: boolean;
84
+ cleanSession?: boolean;
85
+ }
86
+ | {
87
+ kind: 'inspect_verification_page';
88
+ maxChars?: number;
89
+ includeCookies?: boolean;
90
+ }
86
91
  | { kind: 'prompt_user'; message: string; options?: string[] }
87
92
  | { kind: 'wait_for_cooldown'; minutes: number; reason?: string };
88
93
 
@@ -28,6 +28,11 @@ import {
28
28
  externalVerification,
29
29
  } from './compile-tools.ts';
30
30
  import { type Replacement, extractCredentials } from './credential-extract.ts';
31
+ import {
32
+ mergeSemanticParamVerification,
33
+ runLiveSemanticVerification,
34
+ semanticVerificationFailures,
35
+ } from './live-verifier.ts';
31
36
  import {
32
37
  type LLMOptions,
33
38
  type ProviderName,
@@ -39,6 +44,7 @@ import {
39
44
  import { loadJsonFile } from './load-json.ts';
40
45
  import { createLog } from './log.ts';
41
46
  import { localSiteDir } from './paths.ts';
47
+ import { rebindExistingBackendsCacheToWorkflow } from './probe-backends.ts';
42
48
  import { detectPageMintedHeaders, redactSession } from './redact.ts';
43
49
  import type { ClassifiedValue } from './session-diff.ts';
44
50
  import type { SharedCompileContext, ToolCandidate } from './tool-candidates.ts';
@@ -51,6 +57,19 @@ const log = createLog('compile-agent');
51
57
  const REPO_ROOT = pathJoin(import.meta.dir, '..', '..');
52
58
  const PROMPTS_DIR = pathJoin(REPO_ROOT, 'prompts');
53
59
 
60
+ let claudeCliCompiler = compileViaClaudeCli;
61
+ let codexCliCompiler = compileViaCodexCli;
62
+
63
+ export function __setCompileAgentCliCompilersForTest(
64
+ compilers: {
65
+ claude?: typeof compileViaClaudeCli;
66
+ codex?: typeof compileViaCodexCli;
67
+ } | null,
68
+ ): void {
69
+ claudeCliCompiler = compilers?.claude ?? compileViaClaudeCli;
70
+ codexCliCompiler = compilers?.codex ?? compileViaCodexCli;
71
+ }
72
+
54
73
  /** Re-exported for callers (cli, teach) that need to display the selected
55
74
  * model before kicking off the agent loop. */
56
75
  export function resolveCompileAgentModel(provider: ProviderName): string {
@@ -101,6 +120,19 @@ interface CompileAgentOptions {
101
120
  * response parsing, shared-module imports). Injected into the agent's initial
102
121
  * message so the compile follows it. Generic — not tied to any site. */
103
122
  toolPlan?: string;
123
+ /** Revise an existing generated artifact, using durable verification feedback
124
+ * as the starting point instead of rebuilding it from raw capture. */
125
+ revisionMode?: boolean;
126
+ }
127
+
128
+ function formatRevisionMode(enabled: boolean | undefined): string {
129
+ return enabled
130
+ ? [
131
+ 'REVISION MODE: this is a bounded resume of an existing generated tool, not a from-scratch compile.',
132
+ 'Use read_session_summary.revisionContext, then read the listed current artifacts and durable verification feedback before inspecting raw response bodies.',
133
+ 'Preserve proven behavior and make the smallest evidence-backed repair or contract reduction.',
134
+ ].join(' ')
135
+ : '';
104
136
  }
105
137
 
106
138
  export async function compileAgent(opts: CompileAgentOptions): Promise<CompileAgentResult> {
@@ -203,6 +235,7 @@ export async function compileAgent(opts: CompileAgentOptions): Promise<CompileAg
203
235
  teachCredentials: opts.teachCredentials,
204
236
  buildPlanPath: opts.buildPlanPath,
205
237
  sharedModules: opts.sharedModules,
238
+ revisionMode: opts.revisionMode,
206
239
  }),
207
240
  doneTool(),
208
241
  giveUpTool(),
@@ -216,11 +249,12 @@ Tool directory: ${absoluteToolDir}
216
249
  You will write artifacts into the tool directory.
217
250
  ${formatCandidateContext(opts.candidate, opts.sharedContext, assignedSharedModules)}
218
251
  ${formatToolPlan(opts.toolPlan)}
252
+ ${formatRevisionMode(opts.revisionMode)}
219
253
 
220
254
  Begin by calling read_session_summary to orient yourself, then proceed per the system prompt.`;
221
255
 
222
256
  // 7. Compute deadline
223
- const deadlineMs = Date.now() + (opts.maxDurationMs ?? 20 * 60 * 1000);
257
+ let deadlineMs = Date.now() + (opts.maxDurationMs ?? 20 * 60 * 1000);
224
258
 
225
259
  // 8. Instantiate provider (or use injected one for testing).
226
260
  // CLI providers take a different path: they don't implement Anthropic
@@ -232,7 +266,7 @@ Begin by calling read_session_summary to orient yourself, then proceed per the s
232
266
  } else {
233
267
  const resolvedProvider = resolveProvider(opts.llmConfig);
234
268
  if (resolvedProvider.name === 'claude-cli') {
235
- return await compileViaClaudeCli({
269
+ return await claudeCliCompiler({
236
270
  session,
237
271
  absoluteToolDir,
238
272
  sessionPath: opts.sessionPath,
@@ -247,10 +281,12 @@ Begin by calling read_session_summary to orient yourself, then proceed per the s
247
281
  buildPlanPath: opts.buildPlanPath,
248
282
  sharedModules: opts.sharedModules,
249
283
  toolPlan: opts.toolPlan,
284
+ revisionMode: opts.revisionMode,
285
+ model: opts.llmConfig?.model,
250
286
  });
251
287
  }
252
288
  if (resolvedProvider.name === 'codex-cli') {
253
- return await compileViaCodexCli({
289
+ return await codexCliCompiler({
254
290
  session,
255
291
  absoluteToolDir,
256
292
  sessionPath: opts.sessionPath,
@@ -264,6 +300,8 @@ Begin by calling read_session_summary to orient yourself, then proceed per the s
264
300
  buildPlanPath: opts.buildPlanPath,
265
301
  sharedModules: opts.sharedModules,
266
302
  toolPlan: opts.toolPlan,
303
+ revisionMode: opts.revisionMode,
304
+ model: opts.llmConfig?.model,
267
305
  });
268
306
  }
269
307
  if (!isToolUseProvider(resolvedProvider)) {
@@ -336,11 +374,9 @@ Begin by calling read_session_summary to orient yourself, then proceed per the s
336
374
  }
337
375
 
338
376
  // Perform external verification
339
- const { failures, warnings, paramVerification, liveVerification } = await externalVerification(
340
- absoluteToolDir,
341
- session,
342
- sessionPathAbs,
343
- {
377
+ const deterministicVerificationStartedAt = Date.now();
378
+ const { failures, warnings, paramVerification, integrationEvidence } =
379
+ await externalVerification(absoluteToolDir, session, sessionPathAbs, {
344
380
  expectedToolName: opts.candidate?.toolName,
345
381
  likelyParams: opts.candidate?.likelyParams,
346
382
  candidateRequestSeqs: opts.candidate?.requestSeqs,
@@ -355,35 +391,58 @@ Begin by calling read_session_summary to orient yourself, then proceed per the s
355
391
  requiredInputs,
356
392
  credentialValues: opts.teachCredentials?.values,
357
393
  credentialNames: opts.sharedContext?.credentialNames,
358
- },
359
- );
394
+ deferLiveIntegrationToSemanticAgent: true,
395
+ });
396
+ deadlineMs += Date.now() - deterministicVerificationStartedAt;
360
397
 
361
398
  if (warnings.length > 0) {
362
399
  log(`verification warnings (non-blocking):\n${warnings.join('\n')}`);
363
400
  }
364
401
 
365
402
  if (failures.length === 0) {
366
- // Success (possibly with warnings). Persist per-parameter verified flags
367
- // and the live-verification stamp into workflow.json so downstream
368
- // (audit, teach summary) can see which tools shipped without a passing
369
- // live call.
370
- applyLiveVerification(absoluteToolDir, liveVerification);
371
- const paramWarnings = applyParamVerification(absoluteToolDir, paramVerification);
372
- const allWarnings = [...warnings, ...paramWarnings];
373
- if (paramWarnings.length > 0) {
374
- log(`parameter verification:\n${paramWarnings.join('\n')}`);
375
- }
376
- message = result.doneSummary ?? 'Task completed';
377
- if (allWarnings.length > 0) {
378
- message += `\n\nWarnings:\n${allWarnings.join('\n')}`;
403
+ const semanticVerificationStartedAt = Date.now();
404
+ const semantic = await runLiveSemanticVerification({
405
+ provider: provider.name,
406
+ toolDir: absoluteToolDir,
407
+ evidence: integrationEvidence,
408
+ // Live semantic verification is a distinct phase. Do not inherit a
409
+ // nearly exhausted compile-agent deadline.
410
+ });
411
+ deadlineMs += Date.now() - semanticVerificationStartedAt;
412
+ failures.push(...semanticVerificationFailures(semantic.report));
413
+ if (semantic.report.status === 'approved_with_gaps') {
414
+ warnings.push(
415
+ `independent semantic verification approved with gaps: ${semantic.report.gaps.join('; ')}`,
416
+ );
379
417
  }
380
- if (!opts.keepTest) {
381
- for (const f of ['parser.test.ts', 'integration.test.ts']) {
382
- const testPath = pathJoin(absoluteToolDir, f);
383
- if (existsSync(testPath)) unlinkSync(testPath);
418
+ if (failures.length === 0) {
419
+ // Success (possibly with explicit semantic gaps). Persist per-parameter
420
+ // flags and mint liveVerified=true only after independent approval.
421
+ applyLiveVerification(absoluteToolDir, undefined);
422
+ const paramWarnings = applyParamVerification(
423
+ absoluteToolDir,
424
+ mergeSemanticParamVerification(paramVerification, semantic.report),
425
+ );
426
+ // liveVerified/parameter annotations change the hash-strict cache key,
427
+ // but not transport capabilities. Rebind the backend already exercised
428
+ // by the verifier instead of triggering another probe.
429
+ rebindExistingBackendsCacheToWorkflow(absoluteToolDir);
430
+ const allWarnings = [...warnings, ...paramWarnings];
431
+ if (paramWarnings.length > 0) {
432
+ log(`parameter verification:\n${paramWarnings.join('\n')}`);
384
433
  }
434
+ message = result.doneSummary ?? 'Task completed';
435
+ if (allWarnings.length > 0) {
436
+ message += `\n\nWarnings:\n${allWarnings.join('\n')}`;
437
+ }
438
+ if (!opts.keepTest) {
439
+ for (const f of ['parser.test.ts', 'integration.test.ts']) {
440
+ const testPath = pathJoin(absoluteToolDir, f);
441
+ if (existsSync(testPath)) unlinkSync(testPath);
442
+ }
443
+ }
444
+ break;
385
445
  }
386
- break;
387
446
  }
388
447
 
389
448
  // Verification failed — re-enter the loop with a continuation message
@@ -399,6 +458,7 @@ Begin by calling read_session_summary to orient yourself, then proceed per the s
399
458
  ${failures.map((f) => `- ${f}`).join('\n')}
400
459
 
401
460
  Resume your work. Read the files you wrote (workflow.json, parser.ts, parser.test.ts), fix the issues, re-run tests, and call done again when fixed.`;
461
+ currentInitialMessage += `\n\nUse the verifier's semantic evidence, not a requirement for 100% of the original candidate inputs. If the core intent works but a secondary parameter cannot be supported from the recording and live evidence without guessing, remove that parameter and add workflow.limitations with omittedParameters and a specific reason. Do not use a limitation to hide a broken core tool, and do not keep a known broken or ignored public input.`;
402
462
  }
403
463
 
404
464
  // 10. Final flush of the complete conversation log