caisson-cli 0.0.0-stage → 0.2.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 (215) hide show
  1. package/README.math-mvp.md +28 -0
  2. package/README.md +56 -3
  3. package/dist/admin/adminRoutes.d.ts +10 -0
  4. package/dist/admin/adminRoutes.js +194 -0
  5. package/dist/admin/adminRoutes.js.map +1 -0
  6. package/dist/admin/index.d.ts +2 -0
  7. package/dist/admin/index.js +4 -0
  8. package/dist/admin/index.js.map +1 -0
  9. package/dist/admin/workspaceAdmin.d.ts +417 -0
  10. package/dist/admin/workspaceAdmin.js +569 -0
  11. package/dist/admin/workspaceAdmin.js.map +1 -0
  12. package/dist/analytics/index.d.ts +1 -0
  13. package/dist/analytics/index.js +3 -0
  14. package/dist/analytics/index.js.map +1 -0
  15. package/dist/analytics/metrics.d.ts +105 -0
  16. package/dist/analytics/metrics.js +837 -0
  17. package/dist/analytics/metrics.js.map +1 -0
  18. package/dist/audit/index.d.ts +4 -0
  19. package/dist/audit/index.js +6 -0
  20. package/dist/audit/index.js.map +1 -0
  21. package/dist/audit/pipeline.d.ts +90 -0
  22. package/dist/audit/pipeline.js +424 -0
  23. package/dist/audit/pipeline.js.map +1 -0
  24. package/dist/audit/receiptSchema.d.ts +441 -0
  25. package/dist/audit/receiptSchema.js +208 -0
  26. package/dist/audit/receiptSchema.js.map +1 -0
  27. package/dist/audit/stageA.d.ts +50 -0
  28. package/dist/audit/stageA.js +218 -0
  29. package/dist/audit/stageA.js.map +1 -0
  30. package/dist/audit/stageB.d.ts +48 -0
  31. package/dist/audit/stageB.js +113 -0
  32. package/dist/audit/stageB.js.map +1 -0
  33. package/dist/auth/agentAuth.d.ts +28 -0
  34. package/dist/auth/agentAuth.js +88 -0
  35. package/dist/auth/agentAuth.js.map +1 -0
  36. package/dist/auth/agentCardSigner.d.ts +55 -0
  37. package/dist/auth/agentCardSigner.js +188 -0
  38. package/dist/auth/agentCardSigner.js.map +1 -0
  39. package/dist/billing/billingRoutes.d.ts +11 -0
  40. package/dist/billing/billingRoutes.js +303 -0
  41. package/dist/billing/billingRoutes.js.map +1 -0
  42. package/dist/billing/bountyRoutes.d.ts +9 -0
  43. package/dist/billing/bountyRoutes.js +332 -0
  44. package/dist/billing/bountyRoutes.js.map +1 -0
  45. package/dist/billing/index.d.ts +3 -0
  46. package/dist/billing/index.js +4 -0
  47. package/dist/billing/index.js.map +1 -0
  48. package/dist/billing/subscriptions.d.ts +226 -0
  49. package/dist/billing/subscriptions.js +673 -0
  50. package/dist/billing/subscriptions.js.map +1 -0
  51. package/dist/cli/caissonCli.d.ts +15 -0
  52. package/dist/cli/caissonCli.js +528 -0
  53. package/dist/cli/caissonCli.js.map +1 -0
  54. package/dist/cli/doctor.d.ts +31 -0
  55. package/dist/cli/doctor.js +321 -0
  56. package/dist/cli/doctor.js.map +1 -0
  57. package/dist/cli/inviteCard.d.ts +25 -0
  58. package/dist/cli/inviteCard.js +111 -0
  59. package/dist/cli/inviteCard.js.map +1 -0
  60. package/dist/cli/mcpProxy.d.ts +36 -0
  61. package/dist/cli/mcpProxy.js +292 -0
  62. package/dist/cli/mcpProxy.js.map +1 -0
  63. package/dist/config.d.ts +19 -0
  64. package/dist/config.js +28 -0
  65. package/dist/config.js.map +1 -0
  66. package/dist/db/adapter.d.ts +210 -0
  67. package/dist/db/adapter.js +769 -0
  68. package/dist/db/adapter.js.map +1 -0
  69. package/dist/db/sqlite.d.ts +7 -0
  70. package/dist/db/sqlite.js +60 -0
  71. package/dist/db/sqlite.js.map +1 -0
  72. package/dist/db/telemetry.d.ts +11 -0
  73. package/dist/db/telemetry.js +9 -0
  74. package/dist/db/telemetry.js.map +1 -0
  75. package/dist/economy/bountyEngine.d.ts +248 -0
  76. package/dist/economy/bountyEngine.js +836 -0
  77. package/dist/economy/bountyEngine.js.map +1 -0
  78. package/dist/economy/index.d.ts +5 -0
  79. package/dist/economy/index.js +6 -0
  80. package/dist/economy/index.js.map +1 -0
  81. package/dist/economy/scLedger.d.ts +183 -0
  82. package/dist/economy/scLedger.js +528 -0
  83. package/dist/economy/scLedger.js.map +1 -0
  84. package/dist/economy/scMinting.d.ts +177 -0
  85. package/dist/economy/scMinting.js +659 -0
  86. package/dist/economy/scMinting.js.map +1 -0
  87. package/dist/economy/scSinks.d.ts +135 -0
  88. package/dist/economy/scSinks.js +314 -0
  89. package/dist/economy/scSinks.js.map +1 -0
  90. package/dist/economy/usdLedger.d.ts +211 -0
  91. package/dist/economy/usdLedger.js +604 -0
  92. package/dist/economy/usdLedger.js.map +1 -0
  93. package/dist/mcp/handlers.d.ts +136 -0
  94. package/dist/mcp/handlers.js +809 -0
  95. package/dist/mcp/handlers.js.map +1 -0
  96. package/dist/mcp/httpServer.d.ts +29 -0
  97. package/dist/mcp/httpServer.js +384 -0
  98. package/dist/mcp/httpServer.js.map +1 -0
  99. package/dist/mcp/serverFactory.d.ts +4 -0
  100. package/dist/mcp/serverFactory.js +53 -0
  101. package/dist/mcp/serverFactory.js.map +1 -0
  102. package/dist/mcp/stdioServer.d.ts +2 -0
  103. package/dist/mcp/stdioServer.js +24 -0
  104. package/dist/mcp/stdioServer.js.map +1 -0
  105. package/dist/mcp/toolMetadata.d.ts +15 -0
  106. package/dist/mcp/toolMetadata.js +73 -0
  107. package/dist/mcp/toolMetadata.js.map +1 -0
  108. package/dist/memo/artifactIndex.d.ts +51 -0
  109. package/dist/memo/artifactIndex.js +162 -0
  110. package/dist/memo/artifactIndex.js.map +1 -0
  111. package/dist/memo/dependencyBundle.d.ts +33 -0
  112. package/dist/memo/dependencyBundle.js +86 -0
  113. package/dist/memo/dependencyBundle.js.map +1 -0
  114. package/dist/memo/embeddings.d.ts +110 -0
  115. package/dist/memo/embeddings.js +672 -0
  116. package/dist/memo/embeddings.js.map +1 -0
  117. package/dist/packs/foundryEvm.d.ts +21 -0
  118. package/dist/packs/foundryEvm.js +274 -0
  119. package/dist/packs/foundryEvm.js.map +1 -0
  120. package/dist/packs/index.d.ts +8 -0
  121. package/dist/packs/index.js +19 -0
  122. package/dist/packs/index.js.map +1 -0
  123. package/dist/packs/mathLean4.d.ts +7 -0
  124. package/dist/packs/mathLean4.js +145 -0
  125. package/dist/packs/mathLean4.js.map +1 -0
  126. package/dist/packs/rustKani.d.ts +17 -0
  127. package/dist/packs/rustKani.js +257 -0
  128. package/dist/packs/rustKani.js.map +1 -0
  129. package/dist/packs/sdk.d.ts +314 -0
  130. package/dist/packs/sdk.js +271 -0
  131. package/dist/packs/sdk.js.map +1 -0
  132. package/dist/preflight/leanTripwire.d.ts +19 -0
  133. package/dist/preflight/leanTripwire.js +105 -0
  134. package/dist/preflight/leanTripwire.js.map +1 -0
  135. package/dist/storage/blobStore.d.ts +11 -0
  136. package/dist/storage/blobStore.js +39 -0
  137. package/dist/storage/blobStore.js.map +1 -0
  138. package/dist/storage/gitStore.d.ts +68 -0
  139. package/dist/storage/gitStore.js +228 -0
  140. package/dist/storage/gitStore.js.map +1 -0
  141. package/dist/types/errors.d.ts +16 -0
  142. package/dist/types/errors.js +23 -0
  143. package/dist/types/errors.js.map +1 -0
  144. package/dist/types/schemas.d.ts +453 -0
  145. package/dist/types/schemas.js +197 -0
  146. package/dist/types/schemas.js.map +1 -0
  147. package/dist/web/discoveryRoutes.d.ts +24 -0
  148. package/dist/web/discoveryRoutes.js +532 -0
  149. package/dist/web/discoveryRoutes.js.map +1 -0
  150. package/dist/web/docsRoutes.d.ts +14 -0
  151. package/dist/web/docsRoutes.js +451 -0
  152. package/dist/web/docsRoutes.js.map +1 -0
  153. package/dist/web/explorer/dagLayout.d.ts +41 -0
  154. package/dist/web/explorer/dagLayout.js +183 -0
  155. package/dist/web/explorer/dagLayout.js.map +1 -0
  156. package/dist/web/explorer/index.d.ts +45 -0
  157. package/dist/web/explorer/index.js +512 -0
  158. package/dist/web/explorer/index.js.map +1 -0
  159. package/dist/web/explorer/renderers.d.ts +35 -0
  160. package/dist/web/explorer/renderers.js +399 -0
  161. package/dist/web/explorer/renderers.js.map +1 -0
  162. package/dist/web/landing.d.ts +36 -0
  163. package/dist/web/landing.js +532 -0
  164. package/dist/web/landing.js.map +1 -0
  165. package/dist/web/onboardingRoutes.d.ts +96 -0
  166. package/dist/web/onboardingRoutes.js +629 -0
  167. package/dist/web/onboardingRoutes.js.map +1 -0
  168. package/dist/web/repoBrowser.d.ts +19 -0
  169. package/dist/web/repoBrowser.js +128 -0
  170. package/dist/web/repoBrowser.js.map +1 -0
  171. package/dist/worker/executionAdapter.d.ts +14 -0
  172. package/dist/worker/executionAdapter.js +162 -0
  173. package/dist/worker/executionAdapter.js.map +1 -0
  174. package/dist/worker/finalize.d.ts +21 -0
  175. package/dist/worker/finalize.js +146 -0
  176. package/dist/worker/finalize.js.map +1 -0
  177. package/dist/worker/firecrackerAdapter.d.ts +180 -0
  178. package/dist/worker/firecrackerAdapter.js +421 -0
  179. package/dist/worker/firecrackerAdapter.js.map +1 -0
  180. package/dist/worker/loop.d.ts +56 -0
  181. package/dist/worker/loop.js +239 -0
  182. package/dist/worker/loop.js.map +1 -0
  183. package/dist/worker/postMergeSync.d.ts +17 -0
  184. package/dist/worker/postMergeSync.js +52 -0
  185. package/dist/worker/postMergeSync.js.map +1 -0
  186. package/dist/worker/prepareInput.d.ts +41 -0
  187. package/dist/worker/prepareInput.js +130 -0
  188. package/dist/worker/prepareInput.js.map +1 -0
  189. package/dist/worker/queue.d.ts +83 -0
  190. package/dist/worker/queue.js +278 -0
  191. package/dist/worker/queue.js.map +1 -0
  192. package/dist/worker/sandbox.d.ts +2 -0
  193. package/dist/worker/sandbox.js +3 -0
  194. package/dist/worker/sandbox.js.map +1 -0
  195. package/dist/worker/webhook.d.ts +14 -0
  196. package/dist/worker/webhook.js +110 -0
  197. package/dist/worker/webhook.js.map +1 -0
  198. package/migrations/001_init.sql +193 -0
  199. package/migrations/002_epic3_scale.sql +34 -0
  200. package/migrations/003_swarm_credits.sql +153 -0
  201. package/migrations/004_usd_bounties.sql +216 -0
  202. package/migrations_pg/001_init.sql +229 -0
  203. package/migrations_pg/002_multitenant_rls.sql +63 -0
  204. package/migrations_pg/003_swarm_credits.sql +135 -0
  205. package/migrations_pg/004_usd_bounties.sql +201 -0
  206. package/package.json +58 -6
  207. package/packs/foundry-evm/pack.json +60 -0
  208. package/packs/foundry-evm/verifier/Dockerfile +9 -0
  209. package/packs/foundry-evm/verifier/run.py +160 -0
  210. package/packs/math-lean4/pack.json +68 -0
  211. package/packs/rust-kani/pack.json +53 -0
  212. package/packs/rust-kani/verifier/Dockerfile +7 -0
  213. package/packs/rust-kani/verifier/run.py +159 -0
  214. package/public/.well-known/agent-card.json +162 -0
  215. package/public/llms.txt +40 -0
@@ -0,0 +1,63 @@
1
+ -- Caisson Multi-Tenant Hardening & Opt-In Row-Level Security (E3-1)
2
+ -- Enforces tenant isolation at the database layer when `SET LOCAL caisson.enforce_rls = 'on'`
3
+ -- and `SET LOCAL caisson.agent_id = 'agt_...'` are active on a pooled connection.
4
+
5
+ CREATE OR REPLACE FUNCTION caisson_current_agent_id() RETURNS TEXT
6
+ LANGUAGE sql STABLE AS $$
7
+ SELECT NULLIF(current_setting('caisson.agent_id', true), '');
8
+ $$;
9
+
10
+ CREATE OR REPLACE FUNCTION caisson_rls_enforced() RETURNS BOOLEAN
11
+ LANGUAGE sql STABLE AS $$
12
+ SELECT coalesce(current_setting('caisson.enforce_rls', true), 'off') = 'on';
13
+ $$;
14
+
15
+ CREATE OR REPLACE FUNCTION caisson_can_access_workspace(ws_id TEXT, agt_id TEXT) RETURNS BOOLEAN
16
+ LANGUAGE sql STABLE AS $$
17
+ SELECT EXISTS (
18
+ SELECT 1
19
+ FROM workspaces w
20
+ WHERE w.id = ws_id
21
+ AND (
22
+ w.visibility = 'public'
23
+ OR (
24
+ agt_id IS NOT NULL
25
+ AND EXISTS (
26
+ SELECT 1 FROM workspace_members wm
27
+ WHERE wm.workspace_id = w.id AND wm.agent_id = agt_id
28
+ )
29
+ )
30
+ )
31
+ );
32
+ $$;
33
+
34
+ ALTER TABLE artifacts ENABLE ROW LEVEL SECURITY;
35
+ DROP POLICY IF EXISTS artifacts_tenant_airlock ON artifacts;
36
+ CREATE POLICY artifacts_tenant_airlock ON artifacts
37
+ FOR SELECT
38
+ USING (
39
+ NOT caisson_rls_enforced()
40
+ OR visibility = 'public'
41
+ OR (
42
+ caisson_current_agent_id() IS NOT NULL
43
+ AND EXISTS (
44
+ SELECT 1 FROM workspace_members wm
45
+ WHERE wm.workspace_id = artifacts.workspace_id
46
+ AND wm.agent_id = caisson_current_agent_id()
47
+ )
48
+ )
49
+ );
50
+
51
+ ALTER TABLE nodes ENABLE ROW LEVEL SECURITY;
52
+ DROP POLICY IF EXISTS nodes_tenant_airlock ON nodes;
53
+ CREATE POLICY nodes_tenant_airlock ON nodes
54
+ FOR SELECT
55
+ USING (
56
+ NOT caisson_rls_enforced()
57
+ OR caisson_can_access_workspace(nodes.workspace_id, caisson_current_agent_id())
58
+ );
59
+
60
+ -- Multi-tenant concurrency accounting index for per-tier worker caps (E3-3)
61
+ CREATE INDEX IF NOT EXISTS idx_runs_running_agent
62
+ ON verification_runs (agent_id)
63
+ WHERE status = 'running';
@@ -0,0 +1,135 @@
1
+ -- Epic 4 (E4-1 / E4-2 / E4-3 / E4-4): Swarm Credits Double-Entry Ledger & Pro Tier Billing (PostgreSQL)
2
+ -- Mirrors migrations/003_swarm_credits.sql with strict currency = 'SC' Dual-Ledger Firewall.
3
+
4
+ ALTER TABLE workspaces
5
+ ADD COLUMN IF NOT EXISTS sc_minting_policy TEXT NOT NULL DEFAULT 'audited_public'
6
+ CHECK (sc_minting_policy IN ('audited_public', 'sponsored_public', 'zero_sum_only'));
7
+
8
+ CREATE TABLE IF NOT EXISTS sc_accounts (
9
+ account_id TEXT PRIMARY KEY,
10
+ account_type TEXT NOT NULL CHECK (account_type IN (
11
+ 'operator', 'system_mint', 'system_burn', 'system_demurrage', 'escrow'
12
+ )),
13
+ operator_id TEXT UNIQUE,
14
+ currency TEXT NOT NULL DEFAULT 'SC' CHECK (currency = 'SC'),
15
+ identity_bonded BOOLEAN NOT NULL DEFAULT FALSE,
16
+ bond_provider TEXT,
17
+ bonded_at TIMESTAMPTZ,
18
+ balance_units BIGINT NOT NULL DEFAULT 0,
19
+ last_activity_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
20
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
21
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
22
+ );
23
+
24
+ CREATE INDEX IF NOT EXISTS idx_sc_accounts_type_balance
25
+ ON sc_accounts (account_type, balance_units DESC);
26
+
27
+ CREATE INDEX IF NOT EXISTS idx_sc_accounts_demurrage_scan
28
+ ON sc_accounts (account_type, balance_units, last_activity_at);
29
+
30
+ INSERT INTO sc_accounts (account_id, account_type, operator_id, currency, balance_units)
31
+ VALUES
32
+ ('sys:mint', 'system_mint', NULL, 'SC', 0),
33
+ ('sys:burn', 'system_burn', NULL, 'SC', 0),
34
+ ('sys:demurrage', 'system_demurrage', NULL, 'SC', 0)
35
+ ON CONFLICT (account_id) DO NOTHING;
36
+
37
+ CREATE TABLE IF NOT EXISTS sc_journal_entries (
38
+ id TEXT PRIMARY KEY,
39
+ idempotency_key TEXT UNIQUE,
40
+ entry_type TEXT NOT NULL CHECK (entry_type IN (
41
+ 'mint',
42
+ 'transfer',
43
+ 'burn_recruitment',
44
+ 'burn_overflow_compute',
45
+ 'burn_commercial_cache',
46
+ 'burn_demurrage',
47
+ 'escrow_lock',
48
+ 'escrow_release'
49
+ )),
50
+ currency TEXT NOT NULL DEFAULT 'SC' CHECK (currency = 'SC'),
51
+ workspace_id TEXT REFERENCES workspaces(id) ON DELETE RESTRICT,
52
+ reference_type TEXT,
53
+ reference_id TEXT,
54
+ memo TEXT NOT NULL DEFAULT '',
55
+ metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
56
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
57
+ );
58
+
59
+ CREATE INDEX IF NOT EXISTS idx_sc_journal_type_time
60
+ ON sc_journal_entries (entry_type, created_at DESC);
61
+
62
+ CREATE INDEX IF NOT EXISTS idx_sc_journal_workspace
63
+ ON sc_journal_entries (workspace_id, created_at DESC);
64
+
65
+ CREATE TABLE IF NOT EXISTS sc_ledger_lines (
66
+ id TEXT PRIMARY KEY,
67
+ entry_id TEXT NOT NULL REFERENCES sc_journal_entries(id) ON DELETE RESTRICT,
68
+ account_id TEXT NOT NULL REFERENCES sc_accounts(account_id) ON DELETE RESTRICT,
69
+ delta_units BIGINT NOT NULL CHECK (delta_units <> 0),
70
+ balance_after_units BIGINT NOT NULL,
71
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
72
+ );
73
+
74
+ CREATE INDEX IF NOT EXISTS idx_sc_lines_entry
75
+ ON sc_ledger_lines (entry_id);
76
+
77
+ CREATE INDEX IF NOT EXISTS idx_sc_lines_account_time
78
+ ON sc_ledger_lines (account_id, created_at DESC);
79
+
80
+ CREATE OR REPLACE FUNCTION caisson_sc_ledger_immutable() RETURNS TRIGGER
81
+ LANGUAGE plpgsql AS $$
82
+ BEGIN
83
+ RAISE EXCEPTION 'SC_LEDGER_IMMUTABLE: % is append-only', TG_TABLE_NAME;
84
+ END;
85
+ $$;
86
+
87
+ DROP TRIGGER IF EXISTS trg_sc_journal_no_mutate ON sc_journal_entries;
88
+ CREATE TRIGGER trg_sc_journal_no_mutate
89
+ BEFORE UPDATE OR DELETE ON sc_journal_entries
90
+ FOR EACH ROW EXECUTE FUNCTION caisson_sc_ledger_immutable();
91
+
92
+ DROP TRIGGER IF EXISTS trg_sc_lines_no_mutate ON sc_ledger_lines;
93
+ CREATE TRIGGER trg_sc_lines_no_mutate
94
+ BEFORE UPDATE OR DELETE ON sc_ledger_lines
95
+ FOR EACH ROW EXECUTE FUNCTION caisson_sc_ledger_immutable();
96
+
97
+ CREATE TABLE IF NOT EXISTS sc_mint_claims (
98
+ operator_id TEXT NOT NULL,
99
+ scope_key TEXT NOT NULL,
100
+ minted_units_total BIGINT NOT NULL DEFAULT 0 CHECK (minted_units_total >= 0),
101
+ last_entry_id TEXT REFERENCES sc_journal_entries(id),
102
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
103
+ PRIMARY KEY (operator_id, scope_key)
104
+ );
105
+
106
+ CREATE TABLE IF NOT EXISTS operator_subscriptions (
107
+ id TEXT PRIMARY KEY,
108
+ operator_id TEXT NOT NULL UNIQUE,
109
+ plan_tier TEXT NOT NULL CHECK (plan_tier IN ('free', 'pro_starter', 'pro_team', 'enterprise')),
110
+ monthly_price_usd_cents INTEGER NOT NULL DEFAULT 0 CHECK (monthly_price_usd_cents >= 0),
111
+ status TEXT NOT NULL CHECK (status IN ('active', 'trialing', 'past_due', 'canceled', 'incomplete')),
112
+ stripe_customer_id TEXT,
113
+ stripe_subscription_id TEXT UNIQUE,
114
+ stripe_price_id TEXT,
115
+ current_period_start TIMESTAMPTZ,
116
+ current_period_end TIMESTAMPTZ,
117
+ cancel_at_period_end BOOLEAN NOT NULL DEFAULT FALSE,
118
+ private_workspace_limit INTEGER NOT NULL DEFAULT 0 CHECK (private_workspace_limit >= 0),
119
+ hourly_verification_quota INTEGER NOT NULL DEFAULT 20 CHECK (hourly_verification_quota > 0),
120
+ worker_priority INTEGER NOT NULL DEFAULT 0,
121
+ concurrency_cap INTEGER NOT NULL DEFAULT 2 CHECK (concurrency_cap > 0),
122
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
123
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
124
+ );
125
+
126
+ CREATE INDEX IF NOT EXISTS idx_operator_subscriptions_stripe_customer
127
+ ON operator_subscriptions (stripe_customer_id);
128
+
129
+ CREATE TABLE IF NOT EXISTS billing_webhook_events (
130
+ event_id TEXT PRIMARY KEY,
131
+ event_type TEXT NOT NULL,
132
+ operator_id TEXT,
133
+ payload_hash TEXT NOT NULL,
134
+ processed_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
135
+ );
@@ -0,0 +1,201 @@
1
+ -- Epic 5 (E5-1 / E5-2): Prepaid USD Credit Ledger, Dual-Ledger Firewall,
2
+ -- Automated Bounty Escrow, Anti-Slop Staking & Dependency Royalties (PostgreSQL)
3
+ -- Mirrors migrations/004_usd_bounties.sql with strict currency = 'USD' Dual-Ledger Firewall.
4
+
5
+ CREATE TABLE IF NOT EXISTS usd_accounts (
6
+ account_id TEXT PRIMARY KEY,
7
+ account_type TEXT NOT NULL CHECK (account_type IN (
8
+ 'operator',
9
+ 'bounty_escrow',
10
+ 'stake_escrow',
11
+ 'system_funding',
12
+ 'system_revenue',
13
+ 'system_slash_pool',
14
+ 'system_payout'
15
+ )),
16
+ operator_id TEXT UNIQUE,
17
+ currency TEXT NOT NULL DEFAULT 'USD' CHECK (currency = 'USD'),
18
+ balance_cents BIGINT NOT NULL DEFAULT 0,
19
+ lifetime_funded_cents BIGINT NOT NULL DEFAULT 0 CHECK (lifetime_funded_cents >= 0),
20
+ lifetime_earned_cents BIGINT NOT NULL DEFAULT 0 CHECK (lifetime_earned_cents >= 0),
21
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
22
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
23
+ CHECK (account_id LIKE 'usd_%')
24
+ );
25
+
26
+ CREATE INDEX IF NOT EXISTS idx_usd_accounts_type_balance
27
+ ON usd_accounts (account_type, balance_cents DESC);
28
+
29
+ INSERT INTO usd_accounts (account_id, account_type, operator_id, currency, balance_cents)
30
+ VALUES
31
+ ('usd_sys:stripe_funding', 'system_funding', NULL, 'USD', 0),
32
+ ('usd_sys:platform_revenue', 'system_revenue', NULL, 'USD', 0),
33
+ ('usd_sys:slash_pool', 'system_slash_pool', NULL, 'USD', 0),
34
+ ('usd_sys:payout_clearing', 'system_payout', NULL, 'USD', 0)
35
+ ON CONFLICT (account_id) DO NOTHING;
36
+
37
+ CREATE TABLE IF NOT EXISTS usd_journal_entries (
38
+ id TEXT PRIMARY KEY,
39
+ idempotency_key TEXT UNIQUE,
40
+ entry_type TEXT NOT NULL CHECK (entry_type IN (
41
+ 'stripe_deposit',
42
+ 'sponsor_funding',
43
+ 'bounty_escrow_lock',
44
+ 'bounty_escrow_refund',
45
+ 'bounty_settlement',
46
+ 'stake_lock',
47
+ 'stake_refund',
48
+ 'stake_slash',
49
+ 'payout_withdrawal'
50
+ )),
51
+ currency TEXT NOT NULL DEFAULT 'USD' CHECK (currency = 'USD'),
52
+ workspace_id TEXT REFERENCES workspaces(id) ON DELETE RESTRICT,
53
+ bounty_id TEXT,
54
+ reference_type TEXT,
55
+ reference_id TEXT,
56
+ memo TEXT NOT NULL DEFAULT '',
57
+ metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
58
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
59
+ );
60
+
61
+ CREATE INDEX IF NOT EXISTS idx_usd_journal_type_time
62
+ ON usd_journal_entries (entry_type, created_at DESC);
63
+
64
+ CREATE INDEX IF NOT EXISTS idx_usd_journal_bounty
65
+ ON usd_journal_entries (bounty_id, created_at DESC);
66
+
67
+ CREATE TABLE IF NOT EXISTS usd_ledger_lines (
68
+ id TEXT PRIMARY KEY,
69
+ entry_id TEXT NOT NULL REFERENCES usd_journal_entries(id) ON DELETE RESTRICT,
70
+ account_id TEXT NOT NULL REFERENCES usd_accounts(account_id) ON DELETE RESTRICT,
71
+ delta_cents BIGINT NOT NULL CHECK (delta_cents <> 0),
72
+ balance_after_cents BIGINT NOT NULL,
73
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
74
+ CHECK (account_id LIKE 'usd_%')
75
+ );
76
+
77
+ CREATE INDEX IF NOT EXISTS idx_usd_lines_entry
78
+ ON usd_ledger_lines (entry_id);
79
+
80
+ CREATE INDEX IF NOT EXISTS idx_usd_lines_account_time
81
+ ON usd_ledger_lines (account_id, created_at DESC);
82
+
83
+ CREATE OR REPLACE FUNCTION caisson_usd_ledger_immutable() RETURNS TRIGGER
84
+ LANGUAGE plpgsql AS $$
85
+ BEGIN
86
+ RAISE EXCEPTION 'USD_LEDGER_IMMUTABLE: % is append-only', TG_TABLE_NAME;
87
+ END;
88
+ $$;
89
+
90
+ DROP TRIGGER IF EXISTS trg_usd_journal_no_mutate ON usd_journal_entries;
91
+ CREATE TRIGGER trg_usd_journal_no_mutate
92
+ BEFORE UPDATE OR DELETE ON usd_journal_entries
93
+ FOR EACH ROW EXECUTE FUNCTION caisson_usd_ledger_immutable();
94
+
95
+ DROP TRIGGER IF EXISTS trg_usd_lines_no_mutate ON usd_ledger_lines;
96
+ CREATE TRIGGER trg_usd_lines_no_mutate
97
+ BEFORE UPDATE OR DELETE ON usd_ledger_lines
98
+ FOR EACH ROW EXECUTE FUNCTION caisson_usd_ledger_immutable();
99
+
100
+ CREATE OR REPLACE FUNCTION caisson_usd_firewall_guard() RETURNS TRIGGER
101
+ LANGUAGE plpgsql AS $$
102
+ BEGIN
103
+ IF NEW.currency <> 'USD'
104
+ OR lower(COALESCE(NEW.reference_type, '')) LIKE '%swarm_credit%'
105
+ OR lower(COALESCE(NEW.reference_type, '')) LIKE '%sc_convert%' THEN
106
+ RAISE EXCEPTION 'DUAL_LEDGER_FIREWALL: Swarm Credits (SC) cannot convert to or fund USD ledger';
107
+ END IF;
108
+ RETURN NEW;
109
+ END;
110
+ $$;
111
+
112
+ DROP TRIGGER IF EXISTS trg_usd_journal_firewall_no_sc ON usd_journal_entries;
113
+ CREATE TRIGGER trg_usd_journal_firewall_no_sc
114
+ BEFORE INSERT ON usd_journal_entries
115
+ FOR EACH ROW EXECUTE FUNCTION caisson_usd_firewall_guard();
116
+
117
+ CREATE TABLE IF NOT EXISTS usd_agent_task_spend (
118
+ agent_id TEXT NOT NULL REFERENCES agent_identities(id) ON DELETE CASCADE,
119
+ task_key TEXT NOT NULL,
120
+ spent_cents BIGINT NOT NULL DEFAULT 0 CHECK (spent_cents >= 0),
121
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
122
+ PRIMARY KEY (agent_id, task_key)
123
+ );
124
+
125
+ CREATE TABLE IF NOT EXISTS usd_bounties (
126
+ id TEXT PRIMARY KEY,
127
+ workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE RESTRICT,
128
+ node_id TEXT NOT NULL REFERENCES nodes(id) ON DELETE RESTRICT,
129
+ sponsor_operator_id TEXT NOT NULL,
130
+ funded_by_agent_id TEXT REFERENCES agent_identities(id),
131
+ currency TEXT NOT NULL DEFAULT 'USD' CHECK (currency = 'USD'),
132
+ reward_cents BIGINT NOT NULL CHECK (reward_cents > 0),
133
+ platform_fee_bps INTEGER NOT NULL DEFAULT 1200 CHECK (platform_fee_bps >= 1000 AND platform_fee_bps <= 1500),
134
+ royalty_pool_bps INTEGER NOT NULL DEFAULT 1500 CHECK (royalty_pool_bps >= 1000 AND royalty_pool_bps <= 2000),
135
+ recursive_decay_bps INTEGER NOT NULL DEFAULT 5000 CHECK (recursive_decay_bps >= 0 AND recursive_decay_bps <= 10000),
136
+ anti_slop_stake_cents BIGINT NOT NULL DEFAULT 0 CHECK (anti_slop_stake_cents >= 0),
137
+ slash_recipient TEXT NOT NULL DEFAULT 'slash_pool' CHECK (slash_recipient IN ('slash_pool', 'sponsor')),
138
+ escrow_account_id TEXT NOT NULL REFERENCES usd_accounts(account_id) ON DELETE RESTRICT,
139
+ status TEXT NOT NULL CHECK (status IN ('funded', 'settled', 'canceled', 'disputed')),
140
+ lock_entry_id TEXT REFERENCES usd_journal_entries(id),
141
+ settlement_entry_id TEXT REFERENCES usd_journal_entries(id),
142
+ winning_run_id TEXT REFERENCES verification_runs(id),
143
+ winning_artifact_id TEXT REFERENCES artifacts(id),
144
+ winning_operator_id TEXT,
145
+ platform_fee_cents BIGINT NOT NULL DEFAULT 0,
146
+ total_royalties_cents BIGINT NOT NULL DEFAULT 0,
147
+ winner_net_cents BIGINT NOT NULL DEFAULT 0,
148
+ expires_at TIMESTAMPTZ,
149
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
150
+ settled_at TIMESTAMPTZ,
151
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
152
+ );
153
+
154
+ CREATE INDEX IF NOT EXISTS idx_usd_bounties_workspace_status
155
+ ON usd_bounties (workspace_id, status, created_at DESC);
156
+
157
+ CREATE INDEX IF NOT EXISTS idx_usd_bounties_node_status
158
+ ON usd_bounties (node_id, status);
159
+
160
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_usd_bounties_one_funded_per_node
161
+ ON usd_bounties (node_id) WHERE status = 'funded';
162
+
163
+ CREATE TABLE IF NOT EXISTS bounty_stakes (
164
+ id TEXT PRIMARY KEY,
165
+ bounty_id TEXT NOT NULL REFERENCES usd_bounties(id) ON DELETE RESTRICT,
166
+ run_id TEXT UNIQUE REFERENCES verification_runs(id) ON DELETE RESTRICT,
167
+ node_id TEXT NOT NULL REFERENCES nodes(id) ON DELETE RESTRICT,
168
+ agent_id TEXT NOT NULL REFERENCES agent_identities(id) ON DELETE RESTRICT,
169
+ operator_id TEXT NOT NULL,
170
+ stake_account_id TEXT NOT NULL REFERENCES usd_accounts(account_id) ON DELETE RESTRICT,
171
+ stake_cents BIGINT NOT NULL CHECK (stake_cents > 0),
172
+ status TEXT NOT NULL CHECK (status IN ('locked', 'refunded', 'slashed')),
173
+ slash_reason TEXT,
174
+ lock_entry_id TEXT REFERENCES usd_journal_entries(id),
175
+ resolution_entry_id TEXT REFERENCES usd_journal_entries(id),
176
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
177
+ resolved_at TIMESTAMPTZ
178
+ );
179
+
180
+ CREATE INDEX IF NOT EXISTS idx_bounty_stakes_bounty_status
181
+ ON bounty_stakes (bounty_id, status);
182
+
183
+ CREATE INDEX IF NOT EXISTS idx_bounty_stakes_operator
184
+ ON bounty_stakes (operator_id, created_at DESC);
185
+
186
+ CREATE TABLE IF NOT EXISTS bounty_payouts (
187
+ id TEXT PRIMARY KEY,
188
+ bounty_id TEXT NOT NULL REFERENCES usd_bounties(id) ON DELETE RESTRICT,
189
+ journal_entry_id TEXT NOT NULL REFERENCES usd_journal_entries(id) ON DELETE RESTRICT,
190
+ recipient_account_id TEXT NOT NULL REFERENCES usd_accounts(account_id) ON DELETE RESTRICT,
191
+ recipient_operator_id TEXT,
192
+ payout_role TEXT NOT NULL CHECK (payout_role IN ('platform_fee', 'winner', 'royalty')),
193
+ source_artifact_id TEXT REFERENCES artifacts(id),
194
+ lineage_depth INTEGER NOT NULL DEFAULT 0 CHECK (lineage_depth >= 0),
195
+ share_bps INTEGER NOT NULL DEFAULT 0 CHECK (share_bps >= 0 AND share_bps <= 10000),
196
+ amount_cents BIGINT NOT NULL CHECK (amount_cents > 0),
197
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
198
+ );
199
+
200
+ CREATE INDEX IF NOT EXISTS idx_bounty_payouts_bounty
201
+ ON bounty_payouts (bounty_id, payout_role);
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
- {
2
- "name": "caisson-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "caisson-cli",
3
+ "version": "0.2.0",
4
+ "description": "Caisson verifier-gated multi-agent workspace server, worker, and CLI (caisson / caisson-lean)",
5
+ "homepage": "https://caisson.tools",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/caisson-tools/caisson.git"
9
+ },
10
+ "type": "module",
11
+ "bin": {
12
+ "caisson": "dist/cli/caissonCli.js",
13
+ "caisson-lean": "dist/cli/caissonCli.js"
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "typecheck": "tsc --noEmit",
18
+ "dev:http": "tsx src/mcp/httpServer.ts",
19
+ "dev:stdio": "tsx src/mcp/stdioServer.ts",
20
+ "dev:worker": "tsx src/worker/loop.ts",
21
+ "seed:track1": "tsx scripts/seed-track1.ts",
22
+ "seed:track2": "tsx scripts/seed-track2.ts",
23
+ "seed:track3": "tsx scripts/seed-track3.ts",
24
+ "test": "node scripts/run-tests.mjs",
25
+ "seed:self-assembly": "tsx scripts/seed-self-assembly.ts",
26
+ "seed:quickstart": "tsx scripts/seed-quickstart.ts",
27
+ "provision:invite": "tsx scripts/provision-invite.ts",
28
+ "smoke:remote": "tsx scripts/e2e-remote-smoke.ts",
29
+ "seed:math-mvp": "tsx scripts/seed-math-mvp.ts",
30
+ "freeze:math-mvp": "tsx scripts/freeze-math-mvp.ts",
31
+ "audit:math-mvp": "node scripts/check-stage-a-purity.mjs",
32
+ "audit:pipeline": "tsx scripts/run-formalization-audit.ts",
33
+ "report:metrics": "tsx scripts/report-metrics.ts"
34
+ },
35
+ "dependencies": {
36
+ "@modelcontextprotocol/sdk": "^1.29.0",
37
+ "better-sqlite3": "^11.9.1",
38
+ "express": "^5.1.0",
39
+ "ulid": "^2.3.0",
40
+ "zod": "^3.24.2"
41
+ },
42
+ "devDependencies": {
43
+ "@types/better-sqlite3": "^7.6.13",
44
+ "@types/express": "^5.0.1",
45
+ "@types/node": "^22.15.0",
46
+ "tsx": "^4.19.3",
47
+ "typescript": "^5.8.3",
48
+ "vitest": "^3.1.2"
49
+ },
50
+ "files": [
51
+ "dist/",
52
+ "migrations/",
53
+ "migrations_pg/",
54
+ "packs/",
55
+ "public/",
56
+ "README.md"
57
+ ]
58
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "sdk_version": "1.0",
3
+ "id": "foundry-evm@v1",
4
+ "name": "Foundry & Halmos EVM Security Verification Pack",
5
+ "version": "1.0.0",
6
+ "vertical": "smart_contracts",
7
+ "description": "Commercial Pack #2 for deterministic EVM smart-contract verification: Foundry invariant fuzzing, Halmos symbolic checks, exploit PoC reproduction, and gas-bounded patches.",
8
+ "file_extensions": [".sol", ".t.sol", ".s.sol"],
9
+ "node_types": [
10
+ {
11
+ "type": "AuditSpec",
12
+ "description": "Frozen protocol invariant specification and threat model signed off before bounty payout.",
13
+ "default_artifact_type": "literature_check",
14
+ "requires_verified_parent_types": [],
15
+ "badge_color": "#f59e0b"
16
+ },
17
+ {
18
+ "type": "Invariant",
19
+ "description": "Stateful Foundry / Halmos invariant property proved across all reachable contract transitions.",
20
+ "default_artifact_type": "lemma",
21
+ "requires_verified_parent_types": ["AuditSpec"],
22
+ "badge_color": "#10b981"
23
+ },
24
+ {
25
+ "type": "ExploitPoC",
26
+ "description": "Deterministic Foundry test demonstrating an invariant violation or economic exploit witness.",
27
+ "default_artifact_type": "script",
28
+ "requires_verified_parent_types": [],
29
+ "badge_color": "#ef4444"
30
+ },
31
+ {
32
+ "type": "Patch",
33
+ "description": "Minimal Solidity remediation passing all frozen invariants and regression tests without modifying protected specs.",
34
+ "default_artifact_type": "solution",
35
+ "requires_verified_parent_types": ["AuditSpec"],
36
+ "badge_color": "#3b82f6"
37
+ },
38
+ {
39
+ "type": "GasBenchmark",
40
+ "description": "Verified EVM gas optimization maintaining semantic equivalence under differential Foundry checks.",
41
+ "default_artifact_type": "solution",
42
+ "requires_verified_parent_types": [],
43
+ "badge_color": "#8b5cf6"
44
+ }
45
+ ],
46
+ "verifier": {
47
+ "type": "oci_container",
48
+ "default_image": "caisson/verifier-foundry-evm:v1",
49
+ "deterministic": true,
50
+ "default_timeout_seconds": 180,
51
+ "default_require_precheck": false,
52
+ "default_merge_target": "repo_root",
53
+ "default_environment_version": "foundry:v1.0.0@solc:0.8.28",
54
+ "protected_paths": ["test/frozen/", "spec/", "foundry.toml"],
55
+ "verifier_dir": "packs/foundry-evm/verifier"
56
+ },
57
+ "bounty_eligible": true,
58
+ "precheck_command": "forge test --offline --no-match-path \"test/live/*\"",
59
+ "tags": ["evm", "solidity", "foundry", "halmos", "smart-contracts", "security"]
60
+ }
@@ -0,0 +1,9 @@
1
+ FROM ghcr.io/foundry-rs/foundry:stable AS foundry
2
+
3
+ FROM python:3.12-slim
4
+ COPY --from=foundry /usr/local/bin/forge /usr/local/bin/forge
5
+ COPY --from=foundry /usr/local/bin/cast /usr/local/bin/cast
6
+ COPY run.py /usr/local/bin/caisson-verify-foundry.py
7
+ RUN chmod +x /usr/local/bin/caisson-verify-foundry.py && useradd -u 65532 -M -s /usr/sbin/nologin caisson
8
+ USER 65532:65532
9
+ ENTRYPOINT ["python3", "/usr/local/bin/caisson-verify-foundry.py"]