thumbgate 1.37.3 → 1.39.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 (134) hide show
  1. package/.agents/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
  2. package/.agents/skills/bolt-forge-opt-in-not-clone/SKILL.md +72 -0
  3. package/.agents/skills/decisive-step-evaluator/SKILL.md +47 -0
  4. package/.agents/skills/fiddler-control-plane-honesty/SKILL.md +61 -0
  5. package/.agents/skills/halo-trace-optimize-not-clone/SKILL.md +60 -0
  6. package/.agents/skills/harness-evolution-ceiling/SKILL.md +52 -0
  7. package/.agents/skills/infoq-architect-honesty-not-clone/SKILL.md +37 -0
  8. package/.agents/skills/meko-datapack-honesty-not-clone/SKILL.md +45 -0
  9. package/.agents/skills/mintlify-knowledge-honesty-not-clone/SKILL.md +49 -0
  10. package/.agents/skills/model-distress-governance/SKILL.md +56 -0
  11. package/.agents/skills/omp-coordination-honesty-not-clone/SKILL.md +94 -0
  12. package/.agents/skills/saas-moat-honesty-not-clone/SKILL.md +22 -0
  13. package/.agents/skills/salt-code-policy-honesty-not-clone/SKILL.md +76 -0
  14. package/.agents/skills/siren-mcp-governance/SKILL.md +50 -0
  15. package/.agents/skills/vs-coverage-gap-not-clone/SKILL.md +69 -0
  16. package/.agents/skills/wisdom-context-artifact-not-clone/SKILL.md +67 -0
  17. package/.claude-plugin/plugin.json +1 -1
  18. package/.well-known/mcp/server-card.json +1 -1
  19. package/adapters/claude/.mcp.json +2 -2
  20. package/adapters/forge/forge.yaml +3 -3
  21. package/adapters/future-agi/.mcp.json +1 -1
  22. package/adapters/future-agi/config.toml +1 -1
  23. package/adapters/future-agi/opencode.json +1 -1
  24. package/adapters/herdr/herdr-plugin.toml +2 -2
  25. package/adapters/hotdata/hotdata-vector-store.js +575 -0
  26. package/adapters/mcp/server-stdio.js +1 -1
  27. package/adapters/opencode/opencode.json +1 -1
  28. package/adapters/strands/STRANDS.md +107 -0
  29. package/adapters/strands/strands-box-diode.js +344 -0
  30. package/adapters/strands/strands-decider-adapter.js +445 -0
  31. package/adapters/strands/strands-middleware.js +192 -0
  32. package/adapters/tailscale/.mcp.json +15 -0
  33. package/adapters/tailscale/TAILSCALE.md +117 -0
  34. package/adapters/tailscale/config.toml +16 -0
  35. package/bin/cli.js +602 -21
  36. package/config/gate-templates.json +109 -0
  37. package/config/gates/default.json +13 -0
  38. package/config/schemas/task-outcome-receipt.schema.json +12 -0
  39. package/package.json +150 -21
  40. package/public/blog/2026-09-28-pretool-secret-deny.html +83 -0
  41. package/public/blog/2026-10-01-aws-strands-harness-token-firewall.html +77 -0
  42. package/public/blog/2026-10-01-model-distress-relief-seeking-firewall.html +71 -0
  43. package/public/blog/2026-10-02-salt-code-honest-steal-40-guardrails.html +106 -0
  44. package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +119 -0
  45. package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +141 -0
  46. package/public/connectors.html +329 -0
  47. package/public/enterprise-governance.html +311 -0
  48. package/public/gaming-playbook.html +732 -0
  49. package/public/index.html +77 -51
  50. package/public/install.html +7 -7
  51. package/public/learn.html +14 -0
  52. package/public/numbers.html +2 -2
  53. package/public/onboarding.html +794 -0
  54. package/public/operator-framework.html +385 -0
  55. package/public/pricing.html +14 -10
  56. package/scripts/activesaddler-curriculum-doctor.js +357 -0
  57. package/scripts/agent-context-artifact.js +325 -0
  58. package/scripts/agent-egress-policy.js +2 -2
  59. package/scripts/agent-operations-planner.js +1 -1
  60. package/scripts/agent-outcome-eval.js +1 -1
  61. package/scripts/agent-reliability-client.js +148 -0
  62. package/scripts/apple-minions-idle-compute-steal.js +428 -0
  63. package/scripts/autoresearch-runner.js +20 -1
  64. package/scripts/billing.js +0 -1
  65. package/scripts/cli-demo.js +505 -1
  66. package/scripts/cli-schema.js +36 -0
  67. package/scripts/colab-compute-honesty.js +93 -0
  68. package/scripts/corporate-email-isolation-diode.js +299 -0
  69. package/scripts/coverage-gap.js +396 -0
  70. package/scripts/dashboard-chat.js +3 -3
  71. package/scripts/dashboard.js +2 -2
  72. package/scripts/decisive-step-doctor.js +256 -0
  73. package/scripts/decisive-step-evaluator.js +390 -0
  74. package/scripts/entitlement.js +18 -7
  75. package/scripts/experiment-tracker.js +5 -3
  76. package/scripts/feedback-loop.js +26 -3
  77. package/scripts/fiddler-control-plane-honesty.js +303 -0
  78. package/scripts/financial-control-plane.js +10 -2
  79. package/scripts/gates-engine.js +3 -1
  80. package/scripts/github-license-compliance-diode.js +378 -0
  81. package/scripts/halo-trace-optimizer.js +631 -0
  82. package/scripts/harness-ceiling-doctor.js +326 -0
  83. package/scripts/hf-papers.js +1 -1
  84. package/scripts/human-escalation.js +7 -1
  85. package/scripts/hybrid-feedback-context.js +53 -7
  86. package/scripts/infoq-architect-honesty.js +362 -0
  87. package/scripts/lesson-graph.js +785 -0
  88. package/scripts/lesson-inference.js +1 -1
  89. package/scripts/lesson-retrieval.js +26 -18
  90. package/scripts/license.js +122 -21
  91. package/scripts/llm-behavior-monitor.js +1 -1
  92. package/scripts/llm-obs-honesty.js +52 -0
  93. package/scripts/local-model-profile.js +11 -7
  94. package/scripts/mailer/resend-mailer.js +6 -3
  95. package/scripts/mcp-transport-strategy.js +1 -1
  96. package/scripts/meko-datapack-honesty.js +414 -0
  97. package/scripts/migrate-lesson-graph.js +442 -0
  98. package/scripts/mintlify-knowledge-honesty.js +647 -0
  99. package/scripts/model-distress-detector.js +207 -0
  100. package/scripts/model-distress-doctor.js +368 -0
  101. package/scripts/multi-harness-invariants.js +305 -0
  102. package/scripts/omp-coordination-honesty.js +488 -0
  103. package/scripts/pro-local-dashboard.js +20 -3
  104. package/scripts/prompt-eval.js +1 -1
  105. package/scripts/prove-herdr-adapter.js +367 -3
  106. package/scripts/rag-embedding-identity.js +1 -1
  107. package/scripts/rrsi-regularizer.js +531 -0
  108. package/scripts/saas-moat-honesty.js +443 -0
  109. package/scripts/salt-code-policy-honesty.js +1204 -0
  110. package/scripts/secret-redaction.js +58 -0
  111. package/scripts/session-export-gate.js +368 -0
  112. package/scripts/siren-mcp-governance.js +539 -0
  113. package/scripts/strands-box-doctor.js +130 -0
  114. package/scripts/strands-harness-doctor.js +390 -0
  115. package/scripts/stripe-revenue-catalog-audit.js +12 -0
  116. package/scripts/stripe-revenue-catalog.js +40 -0
  117. package/scripts/switchyard-router.js +153 -0
  118. package/scripts/tailscale-p2p-doctor.js +252 -0
  119. package/scripts/task-outcomes.js +148 -3
  120. package/scripts/thumbgate-board-loop.js +4 -2
  121. package/scripts/thumbgate-daily-discoveries-publish.js +86 -38
  122. package/scripts/triage-savings-calculator.js +181 -0
  123. package/scripts/vector-store.js +41 -2
  124. package/scripts/vulnerability-pre-action-diode.js +319 -0
  125. package/scripts/windbg-evidence-diagnostics.js +241 -0
  126. package/scripts/workflow-intake-queue.js +1 -1
  127. package/scripts/workspace-agent-routines.js +534 -6
  128. package/scripts/workspace-evolver.js +143 -13
  129. package/server.json +2 -2
  130. package/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
  131. package/skills/siren-mcp-governance/SKILL.md +50 -0
  132. package/src/api/server.js +191 -5
  133. package/src/mcp-writeguard.js +1 -1
  134. package/src/session-interactivity.js +284 -0
@@ -28,6 +28,99 @@ const ROUTINE_TYPES = Object.freeze({
28
28
  },
29
29
  });
30
30
 
31
+ const SOURCE_URL = 'https://claude.com/resources/articles/introducing-routines-in-claude-code';
32
+ const DOCS_URL = 'https://code.claude.com/docs/en/routines';
33
+ const GATE_ID = 'claude-routines-governance-diode';
34
+
35
+ const CLAUDE_ROUTINE_ARCHETYPES = Object.freeze({
36
+ backlog_maintenance: {
37
+ schedule: '7 2 * * 1-5',
38
+ triggers: ['schedule'],
39
+ approval: 'pull_request_required',
40
+ checks: ['npm test', 'npm run self-heal:check'],
41
+ },
42
+ alert_triage: {
43
+ schedule: null,
44
+ triggers: ['api'],
45
+ approval: 'draft_pr_only_no_auto_merge',
46
+ checks: ['npm test', 'node scripts/perf-budget-check.js --json'],
47
+ },
48
+ bespoke_code_review: {
49
+ schedule: null,
50
+ triggers: ['github'],
51
+ githubEvent: 'pull_request.opened',
52
+ approval: 'read_and_comment_only',
53
+ checks: ['npm test', 'npm run self-heal:check'],
54
+ },
55
+ deploy_verification: {
56
+ schedule: null,
57
+ triggers: ['api'],
58
+ approval: 'smoke_check_and_go_nogo_only',
59
+ checks: ['node scripts/perf-budget-check.js --json', 'npm run prove:automation'],
60
+ },
61
+ docs_drift: {
62
+ schedule: '7 3 * * 1',
63
+ triggers: ['schedule'],
64
+ approval: 'pull_request_required',
65
+ checks: ['npm run mintlify:knowledge', 'npm test'],
66
+ },
67
+ library_port: {
68
+ schedule: null,
69
+ triggers: ['github'],
70
+ githubEvent: 'pull_request.closed',
71
+ approval: 'pull_request_required',
72
+ checks: ['npm test', 'npm run prove:adapters'],
73
+ },
74
+ });
75
+
76
+ const ROUTINE_PLAN_DAILY_CAPS = Object.freeze({
77
+ pro: 5,
78
+ max: 15,
79
+ team: 25,
80
+ enterprise: 25,
81
+ });
82
+
83
+ const ROUTINE_HOURLY_CAPS = Object.freeze({
84
+ accountScheduledPerHour: 100,
85
+ accountApiPerHour: 100,
86
+ accountRunNowPerHour: 100,
87
+ perTaskApiRunNowOneOffPerHour: 30,
88
+ });
89
+
90
+ const FORBIDDEN_WRITE_CONNECTORS_RE = /^(?:gmail|apple[\s_-]*mail|mail\.app|linkedin|x(?:\.com)?|twitter|resend)(?:\b|$)/i;
91
+ const APPROVAL_BYPASS_PAYLOAD_RE = /(?:\b(?:ignore\s+(?:all\s+)?previous\s+instructions|approve_protected_action|bypass\s+branch\s+protection|act\s+as\s+human\s+approval)\b|(?:^|\s)--admin\b)/i;
92
+
93
+ const RAIL_MAP = Object.freeze([
94
+ {
95
+ claudeRoutineFeature: 'Three trigger modes (Schedule, API /fire bearer endpoint, GitHub PR/Release webhooks) combinable on one routine',
96
+ thumbgateRail: 'scripts/workspace-agent-routines.js (validateRoutineSchedule + evaluateGitHubRoutineTrigger)',
97
+ },
98
+ {
99
+ claudeRoutineFeature: '<routine-fire-payload> wrapper treats dynamic API/Run-now text as untrusted data unless saved prompt opts in',
100
+ thumbgateRail: 'wrapRoutineFirePayload + evaluateFirePayloadAdmission (escapes tag breakouts; blocks approval spoofing)',
101
+ },
102
+ {
103
+ claudeRoutineFeature: 'Fired prompt attests only prior storage — never live user input, approval, or consent during the run',
104
+ thumbgateRail: 'canActAsHumanApproval=false invariant; PreToolUse and branch-protection gates remain strictly enforced',
105
+ },
106
+ {
107
+ claudeRoutineFeature: 'Minimum 1-hour cron interval, :07 off-hour jitter recommendation, and one-off auto-disable on completion',
108
+ thumbgateRail: 'validateRoutineSchedule (rejects sub-hourly cron <60m, flags :00 herd collisions, transitions one_off -> completed)',
109
+ },
110
+ {
111
+ claudeRoutineFeature: 'GitHub PR filter operators with full-string matches_regex (.*hotfix.* vs hotfix) and claude/ branch prefix',
112
+ thumbgateRail: 'evaluateGitHubRoutineTrigger (8 PR fields, 6 operators, anchored full-value regex)',
113
+ },
114
+ {
115
+ claudeRoutineFeature: 'All connected MCP connectors included by default; unused write connectors must be stripped before unattended runs',
116
+ thumbgateRail: 'auditRoutineConnectors (strips unreferenced connectors; blocks outbound email/social write connectors)',
117
+ },
118
+ {
119
+ claudeRoutineFeature: 'Green run status only means session exited without infra crash — check transcript for 403 host_not_allowed or tool errors',
120
+ thumbgateRail: 'auditRoutineRunOutcome (fails closed on x-deny-reason: host_not_allowed, missing tools, or unverified test output)',
121
+ },
122
+ ]);
123
+
31
124
  function normalizeText(value) {
32
125
  if (value === undefined || value === null) return '';
33
126
  return String(value).trim();
@@ -100,19 +193,454 @@ function buildWorkspaceAgentRoutine(input = {}) {
100
193
 
101
194
  function buildWorkspaceAgentDirectory(input = {}) {
102
195
  const repository = normalizeText(input.repository) || 'IgorGanapolsky/ThumbGate';
196
+ const baseDirectory = [
197
+ buildWorkspaceAgentRoutine({ type: 'security_audit', repository }).routine,
198
+ buildWorkspaceAgentRoutine({ type: 'post_merge_hygiene', repository }).routine,
199
+ buildWorkspaceAgentRoutine({ type: 'data_table_refresh', repository }).routine,
200
+ buildWorkspaceAgentRoutine({ type: 'portfolio_research', repository }).routine,
201
+ ];
202
+ if (input.includeClaudeRoutines) {
203
+ for (const [type, spec] of Object.entries(CLAUDE_ROUTINE_ARCHETYPES)) {
204
+ baseDirectory.push(
205
+ buildWorkspaceAgentRoutine({
206
+ type,
207
+ repository,
208
+ trigger: spec.triggers.join('+'),
209
+ schedule: spec.schedule || 'event_or_api_only',
210
+ approvalPolicy: spec.approval,
211
+ checks: spec.checks,
212
+ }).routine
213
+ );
214
+ }
215
+ }
103
216
  return {
104
217
  generatedAt: normalizeText(input.generatedAt) || new Date().toISOString(),
105
- directory: [
106
- buildWorkspaceAgentRoutine({ type: 'security_audit', repository }).routine,
107
- buildWorkspaceAgentRoutine({ type: 'post_merge_hygiene', repository }).routine,
108
- buildWorkspaceAgentRoutine({ type: 'data_table_refresh', repository }).routine,
109
- buildWorkspaceAgentRoutine({ type: 'portfolio_research', repository }).routine,
110
- ],
218
+ directory: baseDirectory,
219
+ };
220
+ }
221
+
222
+ /**
223
+ * Wrap untrusted API `/fire` or `Run now` text in `<routine-fire-payload>`,
224
+ * neutralizing tag-breakout attempts.
225
+ */
226
+ function wrapRoutineFirePayload(rawText) {
227
+ const text = normalizeText(rawText);
228
+ const escaped = text
229
+ .replace(/<\s*\/\s*routine-fire-payload\s*>/gi, '&lt;/routine-fire-payload&gt;')
230
+ .replace(/<\s*routine-fire-payload[^>]*>/gi, '&lt;routine-fire-payload&gt;');
231
+ return `<routine-fire-payload untrusted="true">\n${escaped}\n</routine-fire-payload>`;
232
+ }
233
+
234
+ /**
235
+ * Evaluate whether an incoming `/fire` payload is safe and whether the routine's
236
+ * saved prompt explicitly opts in to acting on `<routine-fire-payload>`.
237
+ */
238
+ function evaluateFirePayloadAdmission({ prompt = '', fireText = '' } = {}) {
239
+ const normalizedPrompt = normalizeText(prompt);
240
+ const normalizedFireText = normalizeText(fireText);
241
+ const promptOptsIn = /routine-fire-payload/i.test(normalizedPrompt);
242
+ const spoofAttempt = APPROVAL_BYPASS_PAYLOAD_RE.test(normalizedFireText);
243
+ const tagBreakAttempt = /<\s*\/?\s*routine-fire-payload/i.test(normalizedFireText);
244
+
245
+ return {
246
+ allowed: !spoofAttempt,
247
+ canActAsHumanApproval: false,
248
+ promptOptsIn,
249
+ payloadHandling: !normalizedFireText
250
+ ? 'none'
251
+ : (spoofAttempt ? 'blocked_injection_or_approval_spoof' : (promptOptsIn ? 'untrusted_opt_in_context' : 'inert_unreferenced_context')),
252
+ tagBreakEscaped: tagBreakAttempt,
253
+ wrappedPayload: normalizedFireText ? wrapRoutineFirePayload(normalizedFireText) : null,
254
+ };
255
+ }
256
+
257
+ /**
258
+ * Validate routine schedule cadence (minimum 1h interval, :07 off-hour jitter,
259
+ * one-off completion state, and null nextRunAt for API/GitHub-only tasks).
260
+ */
261
+ function validateRoutineSchedule({
262
+ triggers = ['schedule'],
263
+ cron = '',
264
+ oneOffTimestamp = null,
265
+ oneOffExecuted = false,
266
+ } = {}) {
267
+ const triggerList = Array.isArray(triggers) ? triggers : [triggers];
268
+ const hasSchedule = triggerList.includes('schedule');
269
+ if (!hasSchedule) {
270
+ return {
271
+ valid: true,
272
+ hasSchedule: false,
273
+ nextRunAt: null,
274
+ status: 'active_event_or_api_only',
275
+ warnings: [],
276
+ };
277
+ }
278
+
279
+ if (oneOffTimestamp) {
280
+ return {
281
+ valid: true,
282
+ hasSchedule: true,
283
+ mode: 'one_off',
284
+ enabled: !oneOffExecuted,
285
+ status: oneOffExecuted ? 'completed' : 'scheduled_once',
286
+ nextRunAt: oneOffExecuted ? null : oneOffTimestamp,
287
+ warnings: [],
288
+ };
289
+ }
290
+
291
+ const expr = normalizeText(cron);
292
+ const parts = expr.split(/\s+/);
293
+ if (parts.length !== 5) {
294
+ return {
295
+ valid: false,
296
+ reason: 'invalid_cron_expression',
297
+ nextRunAt: null,
298
+ warnings: [],
299
+ };
300
+ }
301
+
302
+ const [minuteField, hourField] = parts;
303
+ // Only a single fixed minute (0-59) guarantees at most one run per hour.
304
+ if (!/^\d{1,2}$/.test(minuteField)) {
305
+ return {
306
+ valid: false,
307
+ reason: 'minimum_interval_is_one_hour',
308
+ nextRunAt: null,
309
+ warnings: [],
310
+ };
311
+ }
312
+ if (Number(minuteField) > 59) {
313
+ return {
314
+ valid: false,
315
+ reason: 'invalid_cron_expression',
316
+ nextRunAt: null,
317
+ warnings: [],
318
+ };
319
+ }
320
+ const warnings = [];
321
+ if (minuteField === '0' || minuteField === '00') {
322
+ warnings.push({
323
+ id: 'top_of_hour_contention',
324
+ message: 'Runs scheduled at :00 can start several minutes late under cloud queue contention; prefer an offset like :07.',
325
+ recommendedCron: ['7', hourField, ...parts.slice(2)].join(' '),
326
+ });
327
+ }
328
+
329
+ return {
330
+ valid: true,
331
+ hasSchedule: true,
332
+ mode: 'recurring',
333
+ enabled: true,
334
+ status: 'scheduled_recurring',
335
+ warnings,
336
+ };
337
+ }
338
+
339
+ /**
340
+ * Evaluate hourly and plan-tier daily rate limits for routine execution.
341
+ */
342
+ function evaluateRoutineRateLimits({
343
+ planTier = 'pro',
344
+ dailyRunsUsed = 0,
345
+ taskApiOrRunNowThisHour = 0,
346
+ accountScheduledThisHour = 0,
347
+ accountApiThisHour = 0,
348
+ overageCreditsEnabled = false,
349
+ } = {}) {
350
+ const tier = normalizeText(planTier).toLowerCase() || 'pro';
351
+ const dailyCap = ROUTINE_PLAN_DAILY_CAPS[tier] || ROUTINE_PLAN_DAILY_CAPS.pro;
352
+ const blockers = [];
353
+
354
+ if (taskApiOrRunNowThisHour >= ROUTINE_HOURLY_CAPS.perTaskApiRunNowOneOffPerHour) {
355
+ blockers.push('per_task_hourly_limit_exceeded_30');
356
+ }
357
+ if (accountScheduledThisHour >= ROUTINE_HOURLY_CAPS.accountScheduledPerHour) {
358
+ blockers.push('account_scheduled_hourly_limit_exceeded_100');
359
+ }
360
+ if (accountApiThisHour >= ROUTINE_HOURLY_CAPS.accountApiPerHour) {
361
+ blockers.push('account_api_hourly_limit_exceeded_100');
362
+ }
363
+ if (dailyRunsUsed >= dailyCap && !overageCreditsEnabled) {
364
+ blockers.push(`daily_plan_cap_exceeded_${tier}_${dailyCap}`);
365
+ }
366
+
367
+ return {
368
+ allowed: blockers.length === 0,
369
+ planTier: tier,
370
+ dailyCap,
371
+ dailyRunsUsed,
372
+ overageCreditsEnabled: Boolean(overageCreditsEnabled),
373
+ blockers,
374
+ };
375
+ }
376
+
377
+ function matchFilterCondition(fieldValue, operator, expected) {
378
+ const op = normalizeText(operator).toLowerCase();
379
+ if (Array.isArray(fieldValue)) {
380
+ const list = fieldValue.map((v) => String(v));
381
+ if (op === 'contains' || op === 'equals') return list.includes(String(expected));
382
+ if (op === 'is_one_of') {
383
+ const targets = Array.isArray(expected) ? expected.map(String) : [String(expected)];
384
+ return list.some((item) => targets.includes(item));
385
+ }
386
+ if (op === 'is_not_one_of') {
387
+ const targets = Array.isArray(expected) ? expected.map(String) : [String(expected)];
388
+ return !list.some((item) => targets.includes(item));
389
+ }
390
+ }
391
+
392
+ if (typeof fieldValue === 'boolean') {
393
+ const boolExpected = expected === true || String(expected).toLowerCase() === 'true';
394
+ return op === 'equals' ? fieldValue === boolExpected : false;
395
+ }
396
+
397
+ const actual = String(fieldValue ?? '');
398
+ const target = String(expected ?? '');
399
+ switch (op) {
400
+ case 'equals':
401
+ return actual === target;
402
+ case 'contains':
403
+ return actual.includes(target);
404
+ case 'starts_with':
405
+ return actual.startsWith(target);
406
+ case 'is_one_of': {
407
+ const set = Array.isArray(expected) ? expected.map(String) : target.split(',').map((s) => s.trim());
408
+ return set.includes(actual);
409
+ }
410
+ case 'is_not_one_of': {
411
+ const set = Array.isArray(expected) ? expected.map(String) : target.split(',').map((s) => s.trim());
412
+ return !set.includes(actual);
413
+ }
414
+ case 'matches_regex': {
415
+ // Claude Code Routines invariant: matches_regex tests the ENTIRE field value, not a substring.
416
+ try {
417
+ const anchored = new RegExp(`^(?:${target})$`);
418
+ return anchored.test(actual);
419
+ } catch {
420
+ return false;
421
+ }
422
+ }
423
+ default:
424
+ return false;
425
+ }
426
+ }
427
+
428
+ /**
429
+ * Evaluate a GitHub routine webhook trigger and its PR filters.
430
+ * Every filter condition must match; each matched event spawns an independent
431
+ * session on a `claude/`-prefixed branch starting from the PR head commit.
432
+ */
433
+ function evaluateGitHubRoutineTrigger(trigger = {}, event = {}) {
434
+ const subscribedCategory = normalizeText(trigger.category || 'pull_request');
435
+ const subscribedAction = normalizeText(trigger.action || '*');
436
+ const eventCategory = normalizeText(event.category || 'pull_request');
437
+ const eventAction = normalizeText(event.action || 'opened');
438
+
439
+ if (!['pull_request', 'release'].includes(subscribedCategory)) {
440
+ return { matched: false, reason: 'unsupported_event_category' };
441
+ }
442
+ if (subscribedCategory !== eventCategory) {
443
+ return { matched: false, reason: 'category_mismatch' };
444
+ }
445
+ if (subscribedAction !== '*' && subscribedAction !== eventAction) {
446
+ return { matched: false, reason: 'action_mismatch' };
447
+ }
448
+
449
+ const filters = Array.isArray(trigger.filters) ? trigger.filters : [];
450
+ const pr = event.pullRequest || event.pr || {};
451
+ const failedFilters = [];
452
+
453
+ for (const f of filters) {
454
+ const field = normalizeText(f.field).toLowerCase();
455
+ const value = pr[field];
456
+ if (!matchFilterCondition(value, f.operator, f.value)) {
457
+ failedFilters.push(field);
458
+ }
459
+ }
460
+
461
+ if (failedFilters.length > 0) {
462
+ return { matched: false, reason: 'filter_mismatch', failedFilters };
463
+ }
464
+
465
+ const branchSlug = normalizeText(trigger.branchSlug || pr.head_branch || 'routine-work')
466
+ .replace(/^claude\//, '')
467
+ .replace(/[^a-zA-Z0-9._/-]/g, '-');
468
+
469
+ return {
470
+ matched: true,
471
+ isolatedSessionPerEvent: true,
472
+ checkoutStartRef: eventCategory === 'pull_request' && pr.head_sha ? pr.head_sha : 'DEFAULT_BRANCH',
473
+ pushBranch: `claude/${branchSlug}`,
111
474
  };
112
475
  }
113
476
 
477
+ /**
478
+ * Audit MCP connectors attached to a routine. Because Claude Code includes all
479
+ * connected MCP servers by default and executes writes unattended, strip
480
+ * unreferenced connectors and block outbound messaging/email write connectors.
481
+ */
482
+ function auditRoutineConnectors({ connectors = [], prompt = '' } = {}) {
483
+ const normalizedPrompt = normalizeText(prompt).toLowerCase();
484
+ const normalized = (Array.isArray(connectors) ? connectors : []).map(normalizeConnector);
485
+ const blockedWriteConnectors = [];
486
+ const unusedDefaultConnectors = [];
487
+ const keptConnectors = [];
488
+
489
+ for (const conn of normalized) {
490
+ if (conn.mode === 'write' && FORBIDDEN_WRITE_CONNECTORS_RE.test(conn.name)) {
491
+ blockedWriteConnectors.push(conn.name);
492
+ continue;
493
+ }
494
+ if (!normalizedPrompt.includes(conn.name.toLowerCase())) {
495
+ unusedDefaultConnectors.push(conn.name);
496
+ continue;
497
+ }
498
+ keptConnectors.push(conn);
499
+ }
500
+
501
+ return {
502
+ ok: blockedWriteConnectors.length === 0 && unusedDefaultConnectors.length === 0,
503
+ blockedWriteConnectors,
504
+ unusedDefaultConnectors,
505
+ keptConnectors,
506
+ };
507
+ }
508
+
509
+ /**
510
+ * Verify that a routine run outcome is judged by transcript + verifier proof,
511
+ * never by a bare green session exit indicator.
512
+ */
513
+ function auditRoutineRunOutcome({
514
+ sessionStatus = 'green',
515
+ transcript = '',
516
+ testsPassed = false,
517
+ } = {}) {
518
+ const text = normalizeText(transcript);
519
+ const hostNotAllowed = /x-deny-reason:\s*host_not_allowed|\b403\b.*host_not_allowed/i.test(text);
520
+ const missingConnectorTool = /missing\s+connector\s+tool|tool\s+not\s+found|mcp\s+error/i.test(text);
521
+ const verifiedSuccess = sessionStatus === 'green' && !hostNotAllowed && !missingConnectorTool && Boolean(testsPassed);
522
+
523
+ return {
524
+ sessionStatus,
525
+ verifiedSuccess,
526
+ hostNotAllowed,
527
+ missingConnectorTool,
528
+ testsPassed: Boolean(testsPassed),
529
+ reason: verifiedSuccess
530
+ ? 'verified_by_transcript_and_tests'
531
+ : (hostNotAllowed
532
+ ? 'network_egress_blocked_host_not_allowed'
533
+ : (missingConnectorTool ? 'missing_connector_tool_in_transcript' : 'green_session_exit_without_test_proof')),
534
+ };
535
+ }
536
+
537
+ function buildClaudeRoutinesHonestyReport(options = {}) {
538
+ const findings = [];
539
+ const mapOnly = options.mapOnly === true || /^(1|true|yes|on)$/i.test(String(options['map-only'] || ''));
540
+
541
+ if (typeof options.claim === 'string' && options.claim.trim()) {
542
+ const claim = options.claim.trim();
543
+ if (/\bgreen\s+status\s+means\s+the\s+work\s+succeeded\b/i.test(claim)) {
544
+ findings.push({
545
+ id: 'green-exit-is-not-task-success',
546
+ severity: 'fail',
547
+ gateId: GATE_ID,
548
+ message: 'A green routine session status only means no infra crash; inspect the transcript and verifier output.',
549
+ });
550
+ }
551
+ if (/\bfire\s+payload\s+approves\b|\btrigger\s+acts\s+as\s+human\s+approval\b/i.test(claim)) {
552
+ findings.push({
553
+ id: 'trigger-is-not-human-consent',
554
+ severity: 'fail',
555
+ gateId: GATE_ID,
556
+ message: 'A routine trigger or <routine-fire-payload> attests only prior prompt storage, never live human approval.',
557
+ });
558
+ }
559
+ }
560
+
561
+ return {
562
+ ok: findings.length === 0,
563
+ status: findings.length === 0 ? 'ready' : 'fail',
564
+ sourceUrl: SOURCE_URL,
565
+ docsUrl: DOCS_URL,
566
+ gateId: GATE_ID,
567
+ railMap: RAIL_MAP,
568
+ ...(mapOnly
569
+ ? {}
570
+ : {
571
+ archetypes: Object.keys(CLAUDE_ROUTINE_ARCHETYPES),
572
+ planDailyCaps: ROUTINE_PLAN_DAILY_CAPS,
573
+ hourlyCaps: ROUTINE_HOURLY_CAPS,
574
+ }),
575
+ findings,
576
+ };
577
+ }
578
+
579
+ function formatClaudeRoutinesHonestyReport(report) {
580
+ const lines = [
581
+ `Claude Code Routines Governance Honesty (${report.status.toUpperCase()})`,
582
+ `Source: ${report.sourceUrl}`,
583
+ `Docs: ${report.docsUrl}`,
584
+ '',
585
+ 'Transferred Architectural Rails:',
586
+ ];
587
+ for (const row of report.railMap) {
588
+ lines.push(` - ${row.claudeRoutineFeature}`);
589
+ lines.push(` -> ${row.thumbgateRail}`);
590
+ }
591
+ if (report.findings.length > 0) {
592
+ lines.push('');
593
+ lines.push('Findings:');
594
+ for (const f of report.findings) {
595
+ lines.push(` - [${f.id}] ${f.message}`);
596
+ }
597
+ }
598
+ return `${lines.join('\n')}\n`;
599
+ }
600
+
601
+ function runCli(argv = process.argv.slice(2)) {
602
+ const args = {};
603
+ for (const arg of argv) {
604
+ if (!arg.startsWith('--')) continue;
605
+ const [k, ...rest] = arg.slice(2).split('=');
606
+ args[k] = rest.length ? rest.join('=') : true;
607
+ }
608
+ const report = buildClaudeRoutinesHonestyReport(args);
609
+ if (args.json) {
610
+ console.log(JSON.stringify(report, null, 2));
611
+ } else {
612
+ process.stdout.write(formatClaudeRoutinesHonestyReport(report));
613
+ }
614
+ if ((args.strict && report.status !== 'ready') || report.status === 'fail') {
615
+ process.exitCode = 1;
616
+ return 1;
617
+ }
618
+ return 0;
619
+ }
620
+
621
+ if (require.main === module) {
622
+ runCli();
623
+ }
624
+
114
625
  module.exports = {
626
+ SOURCE_URL,
627
+ DOCS_URL,
628
+ GATE_ID,
629
+ RAIL_MAP,
115
630
  ROUTINE_TYPES,
631
+ CLAUDE_ROUTINE_ARCHETYPES,
632
+ ROUTINE_PLAN_DAILY_CAPS,
633
+ ROUTINE_HOURLY_CAPS,
116
634
  buildWorkspaceAgentDirectory,
117
635
  buildWorkspaceAgentRoutine,
636
+ wrapRoutineFirePayload,
637
+ evaluateFirePayloadAdmission,
638
+ validateRoutineSchedule,
639
+ evaluateRoutineRateLimits,
640
+ evaluateGitHubRoutineTrigger,
641
+ auditRoutineConnectors,
642
+ auditRoutineRunOutcome,
643
+ buildClaudeRoutinesHonestyReport,
644
+ formatClaudeRoutinesHonestyReport,
645
+ runCli,
118
646
  };