@inneranimalmedia/agentsam-sdk 2.4.0 → 2.5.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 (162) hide show
  1. package/README.md +7 -6
  2. package/docs/AGENTSAM_WORKBENCH.md +30 -0
  3. package/docs/AUTH_IDENTITY_CONTRACT.md +52 -0
  4. package/docs/CAPABILITIES.md +5 -3
  5. package/docs/CLI_SHELL.md +57 -80
  6. package/docs/CMS_STUDIO.md +101 -0
  7. package/docs/CONTEXT.md +170 -0
  8. package/docs/LOCAL_OLLAMA.md +58 -0
  9. package/docs/MERKLE.md +19 -19
  10. package/docs/PORTABLE_CONTEXT.md +4 -3
  11. package/docs/PROJECT_CONFIG.md +72 -0
  12. package/docs/RELEASES.md +26 -2
  13. package/docs/REPOSITORY_INTELLIGENCE.md +1 -1
  14. package/docs/REPOSITORY_KNOWLEDGE.md +114 -0
  15. package/docs/SDK_WORKER.md +86 -0
  16. package/docs/SECURITY.md +59 -22
  17. package/docs/client-cms-editor.md +15 -0
  18. package/docs/local-studio/WORKMODE_DONOR_NOTES.md +485 -0
  19. package/package.json +17 -5
  20. package/packages/identity/package.json +11 -2
  21. package/packages/identity/src/contracts/auth-config.js +98 -0
  22. package/packages/identity/src/index.js +1 -0
  23. package/packages/identity/src/oauth/README.md +2 -2
  24. package/packages/identity/src/oauth/credentials.js +11 -4
  25. package/packages/identity/src/oauth/iam-platform.js +3 -3
  26. package/packages/identity/src/providers/iam/index.js +7 -7
  27. package/packages/identity/src/providers/iam/oauth.js +6 -4
  28. package/packages/identity/src/providers/iam/profile.js +5 -5
  29. package/packages/identity/tests/auth-config.test.mjs +57 -0
  30. package/packages/identity/tests/oauth-credentials.test.mjs +13 -2
  31. package/protocol/FILEMETA_V1.md +95 -0
  32. package/protocol/INSPECT_VIEWS_V1.md +40 -0
  33. package/protocol/MERKLE_PERSISTENCE_V1.md +50 -0
  34. package/protocol/MERKLE_V1.md +3 -1
  35. package/protocol/capabilities/manifest.json +32 -3
  36. package/protocol/capabilities/repository-snapshot.schema.json +1 -0
  37. package/protocol/context/context-budget.schema.json +41 -0
  38. package/protocol/context/context-item.schema.json +20 -0
  39. package/protocol/context/resolved-context-pack.schema.json +42 -0
  40. package/protocol/context/result-policy.schema.json +17 -0
  41. package/protocol/knowledge/context-pack.schema.json +33 -0
  42. package/protocol/knowledge/retrieval-query.schema.json +68 -13
  43. package/python/README.md +15 -7
  44. package/python/agentsam_sdk/cli.py +0 -21
  45. package/python/agentsam_sdk/tui/README.md +17 -12
  46. package/python/agentsam_sdk/tui/bootstrap.py +2 -2
  47. package/python/agentsam_sdk/tui/demo.py +25 -10
  48. package/python/agentsam_sdk/tui/onboarding.py +208 -0
  49. package/python/tests/test_tui_cli.py +7 -6
  50. package/skills/README.md +21 -0
  51. package/skills/agentsam-app-fundamentals/SKILL.md +165 -0
  52. package/skills/agentsam-app-fundamentals/references/graphs-contracts-ast-merkle.md +89 -0
  53. package/skills/agentsam-app-fundamentals/references/trust-credentials-and-destinations.md +99 -0
  54. package/skills/agentsam-jr-dev/SKILL.md +232 -0
  55. package/skills/agentsam-jr-dev/references/real-application-logic.md +156 -0
  56. package/skills/agentsam-jr-dev/references/web-application-fundamentals.md +240 -0
  57. package/skills/agentsam-progression-guard/SKILL.md +197 -0
  58. package/skills/agentsam-progression-guard/references/checkpoint-chain.md +111 -0
  59. package/skills/agentsam-progression-guard/references/hooks-operational-io.md +96 -0
  60. package/skills/catalog.json +53 -0
  61. package/src/capabilities/index.js +7 -0
  62. package/src/capabilities/repository-snapshot-view.js +238 -0
  63. package/src/capabilities/repository-snapshot.js +28 -14
  64. package/src/cli.js +108 -56
  65. package/src/commands/cad.js +56 -6
  66. package/src/commands/context.js +14 -2
  67. package/src/commands/db.js +4 -7
  68. package/src/commands/deploy.js +17 -31
  69. package/src/commands/interactive.js +21 -0
  70. package/src/commands/knowledge.js +27 -4
  71. package/src/commands/merkle-persist.js +118 -0
  72. package/src/commands/merkle.js +32 -17
  73. package/src/commands/models.js +107 -0
  74. package/src/commands/ollama.js +259 -0
  75. package/src/commands/preferences.js +102 -0
  76. package/src/commands/product.js +86 -16
  77. package/src/commands/security.js +3 -3
  78. package/src/commands/shell.js +71 -27
  79. package/src/commands/skills.js +66 -0
  80. package/src/commands/start-local.js +1 -1
  81. package/src/commands/tunnel.js +5 -4
  82. package/src/context/budget.js +58 -0
  83. package/src/context/compact.js +28 -0
  84. package/src/context/index.js +5 -0
  85. package/src/context/resolve.js +84 -0
  86. package/src/context/result-policy.js +66 -0
  87. package/src/index.js +16 -0
  88. package/src/indexing/execution-boundary.js +144 -0
  89. package/src/indexing/index.js +8 -0
  90. package/src/indexing/provider.js +41 -0
  91. package/src/knowledge/config.js +2 -2
  92. package/src/knowledge/context-pack.js +12 -1
  93. package/src/knowledge/contracts.js +9 -4
  94. package/src/knowledge/engine.js +7 -3
  95. package/src/knowledge/service/server.js +1 -1
  96. package/src/lib/auth.js +10 -19
  97. package/src/lib/bridge-client.js +7 -5
  98. package/src/lib/cli-preferences.js +74 -0
  99. package/src/lib/core-client.js +8 -8
  100. package/src/lib/deploy-receipt/index.js +5 -2
  101. package/src/lib/detect-context.js +6 -5
  102. package/src/lib/identity-scaffold.js +1 -1
  103. package/src/lib/local-scaffold.js +35 -33
  104. package/src/lib/local-status.js +9 -17
  105. package/src/lib/merkle/cloudflare-persistence.js +321 -0
  106. package/src/lib/merkle/filemeta.js +43 -0
  107. package/src/lib/merkle/git-ignore.js +24 -0
  108. package/src/lib/merkle/hash.js +1 -0
  109. package/src/lib/merkle/index.js +22 -0
  110. package/src/lib/merkle/persistence.js +72 -0
  111. package/src/lib/merkle/semantic.js +359 -0
  112. package/src/lib/merkle/snapshot.js +9 -3
  113. package/src/lib/merkle/tree.js +11 -6
  114. package/src/lib/open-url.js +66 -0
  115. package/src/lib/project-config.js +227 -0
  116. package/src/lib/project-rules.js +68 -0
  117. package/src/lib/save-sdk-token.js +1 -1
  118. package/src/lib/slash-commands.js +2 -1
  119. package/src/lib/tools.js +11 -5
  120. package/src/security/index.js +1 -0
  121. package/src/security/inventory.js +4 -1
  122. package/src/security/render.js +27 -5
  123. package/src/security/scan.js +24 -9
  124. package/src/security/trust-boundary.js +24 -0
  125. package/src/skills/index.js +64 -0
  126. package/src/tools/index.js +1 -0
  127. package/src/tools/search.js +70 -0
  128. package/src/ui/ansi.js +1 -1
  129. package/src/ui/boot.js +56 -0
  130. package/src/ui/merkle/render.js +1 -0
  131. package/src/ui/runtime-activity.js +192 -0
  132. package/src/ui/theme.js +19 -18
  133. package/test/app-building-skills.test.mjs +61 -0
  134. package/test/apps-scaffold-contract.test.mjs +56 -0
  135. package/test/capabilities.test.mjs +53 -4
  136. package/test/cli-preferences.test.mjs +25 -0
  137. package/test/context.test.mjs +95 -0
  138. package/test/indexing-provider.test.mjs +29 -0
  139. package/test/jr-dev-skill.test.mjs +26 -0
  140. package/test/knowledge-context-pack.test.mjs +19 -0
  141. package/test/knowledge.test.mjs +1 -1
  142. package/test/merkle-persistence.test.mjs +91 -0
  143. package/test/merkle.test.mjs +77 -3
  144. package/test/models.test.mjs +37 -0
  145. package/test/ollama.test.mjs +94 -0
  146. package/test/open-url.test.mjs +64 -0
  147. package/test/project-config.test.mjs +81 -0
  148. package/test/project-rules.test.mjs +44 -0
  149. package/test/release-hygiene.test.mjs +34 -0
  150. package/test/repository-snapshot-view.test.mjs +112 -0
  151. package/test/runtime-activity.test.mjs +98 -0
  152. package/test/sdk-worker-contract.test.mjs +68 -0
  153. package/test/security.test.mjs +46 -0
  154. package/test/shell.test.mjs +8 -1
  155. package/test/skills.test.mjs +22 -0
  156. package/test/smoke.mjs +2 -2
  157. package/test/theme-portability.test.mjs +14 -0
  158. package/test/tools-search.test.mjs +27 -0
  159. package/examples/agentsam-tui-ansi.mjs +0 -149
  160. package/src/commands/tui.js +0 -120
  161. package/src/ui/splash-xterm.js +0 -290
  162. package/src/ui/splash.js +0 -426
@@ -0,0 +1,156 @@
1
+ # Real Application Logic — Build/Inspection Gate
2
+
3
+ Use this checklist when AgentSam builds, inspects, or revises an application,
4
+ website with behavior, service, microservice, CLI, or cross-layer feature.
5
+
6
+ The purpose is to distinguish a real implementation from a convincing-looking
7
+ surface.
8
+
9
+ ## 1. State the behavior
10
+
11
+ Write one sentence describing what a user/system can now actually do.
12
+
13
+ Bad:
14
+
15
+ > Add an agent dashboard.
16
+
17
+ Better:
18
+
19
+ > A signed-in user can start an agent run, watch its live task state, cancel it,
20
+ > and reopen its persisted result later.
21
+
22
+ That sentence exposes the required mechanics.
23
+
24
+ ## 2. Find the current architecture
25
+
26
+ Prove where these concerns live today:
27
+
28
+ - entrypoint,
29
+ - UI/client,
30
+ - API/action boundary,
31
+ - business/domain logic,
32
+ - persistence,
33
+ - identity/auth,
34
+ - background work,
35
+ - external providers,
36
+ - tests,
37
+ - deployment/runtime.
38
+
39
+ Do not create a second architecture because the first one took effort to find.
40
+
41
+ ## 3. Identify authority
42
+
43
+ For every important state value, ask:
44
+
45
+ > Who is allowed to declare this true?
46
+
47
+ Examples:
48
+
49
+ - `isMenuOpen` -> frontend UI state,
50
+ - `currentUserId` -> verified backend identity,
51
+ - `paymentSucceeded` -> payment provider/backend webhook,
52
+ - `agentRun.status` -> agent runtime/store,
53
+ - `deployment.version` -> deployment system,
54
+ - `file root hash` -> Merkle computation/evidence store.
55
+
56
+ Many broken applications are authority bugs disguised as UI bugs.
57
+
58
+ ## 4. Trace the complete flow
59
+
60
+ For mutations:
61
+
62
+ ```text
63
+ intent
64
+ -> input
65
+ -> validation
66
+ -> authorization
67
+ -> business rule
68
+ -> mutation/provider operation
69
+ -> persistence/event
70
+ -> response
71
+ -> visible state
72
+ ```
73
+
74
+ For reads:
75
+
76
+ ```text
77
+ question/view
78
+ -> query/request
79
+ -> authorization/scope
80
+ -> authoritative source
81
+ -> bounded result
82
+ -> transformation
83
+ -> presentation
84
+ ```
85
+
86
+ Mark every missing edge before coding.
87
+
88
+ ## 5. Handle non-happy paths
89
+
90
+ At minimum consider:
91
+
92
+ - invalid input,
93
+ - unauthenticated/unauthorized request,
94
+ - missing resource,
95
+ - provider/network failure,
96
+ - timeout/cancellation,
97
+ - duplicate/retried request,
98
+ - partial failure,
99
+ - stale client state,
100
+ - empty/loading state.
101
+
102
+ Do not add elaborate machinery for impossible cases, but do not pretend the
103
+ happy path is the whole application either.
104
+
105
+ ## 6. Verify reality
106
+
107
+ Prefer the strongest available proof:
108
+
109
+ 1. real end-to-end path,
110
+ 2. integration test against real local dependency,
111
+ 3. contract/API test,
112
+ 4. unit test,
113
+ 5. static/type/lint check.
114
+
115
+ A screenshot proves appearance. It does not prove persistence, authorization,
116
+ API correctness, side effects, cancellation, or recovery.
117
+
118
+ ## 7. Inspect/revision questions
119
+
120
+ When auditing an existing project, ask:
121
+
122
+ - Is there more than one source of truth for the same state?
123
+ - Does frontend code hold secrets or claim authority it should not have?
124
+ - Does the backend trust client-supplied identity/ownership fields?
125
+ - Are runtime entrypoints overloaded with business logic?
126
+ - Are shared packages actually portable, or importing host-specific internals?
127
+ - Are API contracts explicit and validated?
128
+ - Are writes idempotent where retries can occur?
129
+ - Are errors observable and actionable?
130
+ - Are generated/demo/reference files being mistaken for runtime authority?
131
+ - Does the deployment path match the development path closely enough to trust?
132
+ - Can an agent retrieve the exact evidence it needs without flooding context?
133
+
134
+ ## 8. Junior explanation after implementation
135
+
136
+ When reporting back, explain in this order:
137
+
138
+ ```text
139
+ What changed
140
+ user-visible behavior
141
+
142
+ How it works
143
+ 3-7 step real flow
144
+
145
+ Where it lives
146
+ exact important files/modules
147
+
148
+ Why the boundaries are there
149
+ authority/security/state reasons
150
+
151
+ How we proved it
152
+ tests/commands/real runtime evidence
153
+ ```
154
+
155
+ Keep implementation detail proportional to the user's curiosity, but never hide
156
+ an unimplemented layer behind simplified language.
@@ -0,0 +1,240 @@
1
+ # Web/Application Fundamentals — Jr Dev Reference
2
+
3
+ Use this reference when teaching web application architecture. Adapt it to the
4
+ actual repository instead of assuming every project uses these exact directory
5
+ names.
6
+
7
+ ## HTTP
8
+
9
+ HTTP is a request/response protocol: one program sends a structured request to
10
+ another program, and the receiving program sends a structured response back.
11
+
12
+ A simplified exchange:
13
+
14
+ ```text
15
+ browser/client server/backend
16
+ | |
17
+ | GET /api/models |
18
+ |------------------------------------->|
19
+ | | find/compute result
20
+ | 200 OK |
21
+ | { "models": [...] } |
22
+ |<-------------------------------------|
23
+ ```
24
+
25
+ An HTTP request commonly contains:
26
+
27
+ - method (`GET`, `POST`, `PATCH`, `DELETE`, ...),
28
+ - URL/path,
29
+ - headers,
30
+ - optional body.
31
+
32
+ A response commonly contains:
33
+
34
+ - status (`200`, `201`, `400`, `401`, `403`, `404`, `500`, ...),
35
+ - headers,
36
+ - optional body.
37
+
38
+ The method is a convention about intent, not magic business logic:
39
+
40
+ - `GET` usually reads,
41
+ - `POST` usually creates or starts an action,
42
+ - `PUT` usually replaces,
43
+ - `PATCH` usually changes part,
44
+ - `DELETE` usually removes.
45
+
46
+ The backend still decides what is valid and authorized.
47
+
48
+ ## API
49
+
50
+ An API is an interface another program can use. An HTTP API defines routes and
51
+ message shapes such as:
52
+
53
+ ```text
54
+ POST /api/runs
55
+ GET /api/runs/:id
56
+ POST /api/runs/:id/cancel
57
+ ```
58
+
59
+ The route is the door. The business logic behind the door is the important part.
60
+
61
+ ## Frontend
62
+
63
+ The frontend/client is the code responsible for what the user directly
64
+ interacts with in their browser/app process.
65
+
66
+ Typical responsibilities:
67
+
68
+ - rendering UI,
69
+ - handling clicks/typing/navigation,
70
+ - temporary UI state,
71
+ - requesting trusted operations from the backend,
72
+ - presenting loading/success/error states.
73
+
74
+ A frontend should not be trusted with server secrets merely because JavaScript
75
+ can technically contain them. Browser code is delivered to the user's machine
76
+ and can be inspected or modified by that user.
77
+
78
+ ## Backend
79
+
80
+ The backend/server is the trusted application runtime for operations that need a
81
+ controlled authority.
82
+
83
+ Typical responsibilities:
84
+
85
+ - request validation,
86
+ - authorization,
87
+ - secrets/provider credentials,
88
+ - database writes,
89
+ - trusted model/provider calls,
90
+ - filesystem/Git/cloud operations,
91
+ - durable business rules,
92
+ - rate limits and policy.
93
+
94
+ A backend may run in a traditional server, serverless function, Worker, container,
95
+ VM, local process, or another runtime. "Backend" describes responsibility more
96
+ than hosting technology.
97
+
98
+ ## Shared/contracts
99
+
100
+ Frontend and backend often need the same definition of an object or event.
101
+ Shared code should usually contain contracts that are safe on both sides:
102
+
103
+ ```ts
104
+ interface CreateRunRequest {
105
+ goal: string;
106
+ mode: "ask" | "plan" | "agent" | "debug" | "multitask";
107
+ }
108
+
109
+ interface CreateRunResponse {
110
+ id: string;
111
+ status: "queued" | "running";
112
+ }
113
+ ```
114
+
115
+ Shared code is usually a bad home for server secrets, database connections, or
116
+ privileged runtime objects.
117
+
118
+ ## Server/worker entrypoints
119
+
120
+ A runtime entrypoint is the first code the host invokes. A Worker might expose:
121
+
122
+ ```js
123
+ export default {
124
+ fetch(request, env, ctx) {
125
+ return handleRequest(request, env, ctx);
126
+ }
127
+ };
128
+ ```
129
+
130
+ A maintainable architecture often keeps that adapter thin:
131
+
132
+ ```text
133
+ runtime/worker entrypoint
134
+ -> application router
135
+ -> use case/business logic
136
+ -> database/provider adapters
137
+ ```
138
+
139
+ The entrypoint connects the host runtime to the application. It does not need to
140
+ contain the entire application.
141
+
142
+ ## Database and persistence
143
+
144
+ State has to live somewhere. Ask how long it must survive and who must share it.
145
+
146
+ Examples:
147
+
148
+ ```text
149
+ React component state survives a render/session as designed
150
+ localStorage stays in one browser/profile
151
+ SQLite durable local process/application state
152
+ Postgres/D1 shared durable application state
153
+ object storage files/blobs/large artifacts
154
+ Git source-control history
155
+ Merkle snapshots evidence of filesystem state
156
+ ```
157
+
158
+ Do not add a database if browser-local state satisfies the actual requirement.
159
+ Do not use browser-local state for data that must be authoritative across users
160
+ or machines.
161
+
162
+ ## Authentication vs authorization
163
+
164
+ Authentication asks:
165
+
166
+ > Who are you?
167
+
168
+ Authorization asks:
169
+
170
+ > Are you allowed to do this?
171
+
172
+ A verified user ID on the backend is evidence for authentication. A policy or
173
+ ownership check deciding whether that user can edit a project is authorization.
174
+
175
+ Never trust a browser-supplied `user_id` merely because it is present in JSON.
176
+
177
+ ## WebSocket
178
+
179
+ HTTP is naturally request/response. A WebSocket keeps a two-way connection open,
180
+ which is useful for terminals, streaming events, multiplayer state, and other
181
+ interactive flows.
182
+
183
+ ```text
184
+ client <==========================> server
185
+ commands / output / events
186
+ ```
187
+
188
+ Use it when the interaction actually benefits from a persistent two-way channel;
189
+ do not reach for it when a normal HTTP request is simpler.
190
+
191
+ ## Service and microservice
192
+
193
+ A service is a capability that runs behind an interface.
194
+
195
+ A microservice is typically a relatively small service that can be deployed and
196
+ operated independently. A folder called `services/` does not automatically make
197
+ something a microservice.
198
+
199
+ Before calling something a microservice, look for evidence such as:
200
+
201
+ - independent runtime/process,
202
+ - explicit network or message interface,
203
+ - separate deployment lifecycle,
204
+ - clear ownership boundary.
205
+
206
+ ## Package vs app vs service
207
+
208
+ A useful distinction:
209
+
210
+ ```text
211
+ package/library
212
+ reusable code imported by other code
213
+
214
+ app/product
215
+ complete user-facing or operator-facing composition
216
+
217
+ service
218
+ independently running capability accessed through an interface
219
+ ```
220
+
221
+ A monorepo can contain all three.
222
+
223
+ ## End-to-end example
224
+
225
+ Suppose the user clicks "Start agent":
226
+
227
+ ```text
228
+ 1. frontend button receives click
229
+ 2. frontend validates obvious input
230
+ 3. frontend POSTs /api/runs
231
+ 4. backend authenticates/authorizes request
232
+ 5. backend validates CreateRunRequest
233
+ 6. backend creates the authoritative run
234
+ 7. backend starts/schedules model/tool work
235
+ 8. backend returns run ID/status
236
+ 9. frontend subscribes/polls for updates
237
+ 10. UI renders running/completed/error state
238
+ ```
239
+
240
+ The feature is not complete merely because step 1 and a spinner exist.
@@ -0,0 +1,197 @@
1
+ ---
2
+ name: agentsam-progression-guard
3
+ description: >
4
+ Turn application growth into explicit no-regression checkpoints across local work,
5
+ Git/PR CI, predeploy, deploy, postdeploy, and runtime operation. Use when adding a
6
+ feature/service/package, designing hooks or CI/CD, preparing a release, deciding what
7
+ should block a merge/deploy, implementing canary/rollback/feature-flag mechanics, or
8
+ proving a change is safer than the last promoted baseline. Triggers on "no regress",
9
+ "progression guard", "ship guard", "CI", "deploy hook", "pre-commit", "predeploy",
10
+ "postdeploy", "rollback", "canary", "feature flag", "release gate", and "promotion".
11
+ metadata:
12
+ short-description: "Evidence gates and hook contracts that let a growing app progress without silently regressing"
13
+ aliases:
14
+ - progression-guard
15
+ - no-regress
16
+ - ship-guard
17
+ - release-guard
18
+ user-invocable: true
19
+ ---
20
+
21
+ # AgentSam Progression Guard
22
+
23
+ The system should not depend on a developer remembering every rule in a million-line
24
+ codebase. Put important invariants at lifecycle checkpoints and make promotion depend
25
+ on evidence.
26
+
27
+ ## Core law
28
+
29
+ **A state may be promoted only after the checks appropriate to that boundary pass. A
30
+ failed candidate must not advance the last-known-good baseline.**
31
+
32
+ This is the same principle whether the boundary is a commit, merge, deployment,
33
+ feature rollout, schema migration, or service version.
34
+
35
+ ## Checkpoint chain
36
+
37
+ ```text
38
+ intent/design
39
+ -> local edit loop
40
+ -> commit/push gate
41
+ -> clean CI / PR gate
42
+ -> predeploy evidence capture
43
+ -> deploy
44
+ -> postdeploy smoke + contract checks
45
+ -> promote baseline
46
+ -> runtime observe / canary / rollback
47
+ ```
48
+
49
+ Do not run the heaviest possible suite at every keystroke. Use the dependency graph to
50
+ make early gates fast and affected-only, then require broader proof at merge/release.
51
+
52
+ Read `references/checkpoint-chain.md` for the detailed gate matrix.
53
+
54
+ ## Hooks are operational I/O contracts
55
+
56
+ A hook is not "some script that happens to run." Every hook should have a small
57
+ contract:
58
+
59
+ ```text
60
+ Hook
61
+ event:
62
+ scope/affected graph:
63
+ immutable input refs:
64
+ allowed reads:
65
+ allowed writes/side effects:
66
+ credential scope:
67
+ command/handler:
68
+ timeout/retry:
69
+ output receipt:
70
+ failure policy: warn | block | rollback | quarantine
71
+ ```
72
+
73
+ Prefer idempotent hooks when practical. Never give a hook broader credentials than the
74
+ work it performs. Never let its output leak secret values. Never mark a deploy
75
+ successful because the provider command returned zero if the required postdeploy
76
+ checks have not run.
77
+
78
+ Read `references/hooks-operational-io.md` for hook design and failure semantics.
79
+
80
+ ## AgentSam's existing proof chain
81
+
82
+ Use the SDK mechanics as one coherent gate system rather than unrelated commands:
83
+
84
+ ```bash
85
+ # Architecture/index/trust evidence
86
+ agentsam inspect --json
87
+ agentsam security scan --path .
88
+
89
+ # Capture exact predeploy state and delta from the last promoted baseline
90
+ agentsam deploy-receipt capture . --project <project> --json
91
+
92
+ # Run the real provider deploy here
93
+ # e.g. npm run deploy / wrangler deploy / project-specific release command
94
+
95
+ # Only after required postdeploy checks succeed
96
+ agentsam deploy-receipt success . --deployment-id <id> --worker-version <id> --json
97
+
98
+ # If deploy or postdeploy verification fails
99
+ agentsam deploy-receipt failure . --deployment-id <id> --json
100
+ ```
101
+
102
+ A successful finalize advances the local promoted Merkle baseline. A failure preserves
103
+ the previous trusted baseline. Keep provider deployment identity and AgentSam evidence
104
+ identity together in the receipt when available.
105
+
106
+ ## What each layer should catch
107
+
108
+ - **AST/index gate:** structural contradictions, dependency edges, execution-domain mistakes, contract ownership drift.
109
+ - **Merkle gate:** exact before/after source identity and change scope.
110
+ - **Security gate:** dependency advisories plus client/server trust-boundary contradictions.
111
+ - **Type/schema gate:** compile-time and runtime contract drift.
112
+ - **Test gate:** behavior regressions at unit/integration/end-to-end boundaries.
113
+ - **Firewall/WAF/rate-limit gate:** hostile or abusive ingress patterns before application logic.
114
+ - **Auth/authorization gate:** verified identity, scope, ownership, and privileged action rules inside the application.
115
+ - **Deploy/postdeploy gate:** provider accepted the artifact *and* critical live behavior still works.
116
+ - **Runtime gate:** error/latency/saturation/security signals after promotion.
117
+
118
+ None of these replaces the others.
119
+
120
+ ## Package/service progression rule
121
+
122
+ When a package/service changes:
123
+
124
+ ```text
125
+ changed node
126
+ -> compute affected downstream nodes
127
+ -> run local affected checks
128
+ -> run clean CI for required contract/build/security coverage
129
+ -> deploy only the changed deployable units plus required dependents
130
+ -> smoke their public contracts
131
+ -> promote their evidence baseline
132
+ ```
133
+
134
+ For a cross-service contract change, producers and consumers are one change set even
135
+ if they live in separate packages/repositories. Use versioned schemas/contracts and
136
+ consumer tests to make the coupling explicit.
137
+
138
+ ## Deployment safety ladder
139
+
140
+ Not every app needs every rung on day one. Add protection as risk grows:
141
+
142
+ ```text
143
+ single deploy + smoke test
144
+ -> automatic rollback on failed smoke
145
+ -> feature flag separating deploy from release
146
+ -> canary / small traffic cohort
147
+ -> metrics comparison window
148
+ -> gradual promotion
149
+ ```
150
+
151
+ The point is not ceremony. The point is reducing blast radius and making the system
152
+ prove health before widening exposure.
153
+
154
+ ## Regression rules
155
+
156
+ 1. Never advance a trusted baseline after a failed deploy or failed postdeploy check.
157
+ 2. Never let local success substitute for clean-environment CI on merge/release.
158
+ 3. Never make all hooks blocking; classify fast/blocking versus informational/async deliberately.
159
+ 4. Never make a pre-commit hook so expensive developers bypass it; move broad work to CI.
160
+ 5. Never let branch protection depend on checks that are not deterministic/reproducible enough to trust.
161
+ 6. Never deploy a breaking contract without proving affected consumers or a compatibility strategy.
162
+ 7. Never use a WAF rule as a substitute for application authorization.
163
+ 8. Never auto-rollback a database/schema change unless the data migration itself is designed and proven reversible; prefer forward-fix/expand-contract strategies where rollback would lose data.
164
+ 9. Never make feature flags permanent invisible architecture. Give them an owner and cleanup condition.
165
+ 10. Never call observability "monitoring later." Define the success/failure signal before promotion.
166
+
167
+ ## Completion receipt
168
+
169
+ When acting as the release/build agent, finish with a compact receipt:
170
+
171
+ ```text
172
+ Candidate
173
+ git/revision:
174
+ merkle root:
175
+ semantic metadata root:
176
+ affected packages/services:
177
+
178
+ Gates
179
+ type/build:
180
+ tests:
181
+ contracts:
182
+ security:
183
+ deploy:
184
+ postdeploy:
185
+
186
+ Promotion
187
+ provider deployment/version:
188
+ baseline advanced: yes/no
189
+ feature flag/canary state:
190
+ rollback/failure action:
191
+
192
+ Open risks
193
+ ...
194
+ ```
195
+
196
+ A human should be able to understand why this state was promoted without reading the
197
+ entire CI log.
@@ -0,0 +1,111 @@
1
+ # Checkpoint Chain
2
+
3
+ ## Gate 0 — intent/design
4
+
5
+ Before code, name the behavior, authority owner, boundary contracts, state owner, and
6
+ credentialed destinations. For sensitive paths, name abuse/failure cases too.
7
+
8
+ Evidence: short design/plan, relevant schema/type, destination card.
9
+
10
+ ## Gate 1 — local edit loop
11
+
12
+ Goal: feedback in seconds.
13
+
14
+ Prefer changed/affected scope:
15
+
16
+ - syntax/lint;
17
+ - TypeScript/type checking for affected packages;
18
+ - narrow unit tests;
19
+ - AST/index contradiction checks when boundaries changed;
20
+ - secret scan for newly touched material.
21
+
22
+ Do not run a 20-minute suite on every save.
23
+
24
+ ## Gate 2 — commit/push
25
+
26
+ Goal: stop obvious bad states before remote review.
27
+
28
+ Typical blocking checks:
29
+
30
+ - formatting/lint/type sanity;
31
+ - fast affected tests;
32
+ - secret scanning;
33
+ - generated-contract consistency if committed artifacts are expected.
34
+
35
+ A pre-commit/push hook is local convenience and early protection. CI remains the
36
+ shared authority because local hooks can be skipped or differ by machine.
37
+
38
+ ## Gate 3 — PR / clean CI
39
+
40
+ Goal: prove the candidate from a clean environment.
41
+
42
+ Typical required checks:
43
+
44
+ - clean dependency install;
45
+ - full/required build;
46
+ - broader unit/integration tests;
47
+ - contract/schema compatibility;
48
+ - `agentsam security scan`;
49
+ - deterministic repository/AST/Merkle evidence;
50
+ - deployment dry run where supported.
51
+
52
+ Use branch protection to make required checks real gates instead of reminders.
53
+
54
+ ## Gate 4 — predeploy
55
+
56
+ Goal: tie the exact candidate to a reproducible evidence identity.
57
+
58
+ Capture the Merkle/semantic snapshot and compare with the last promoted baseline.
59
+ Confirm:
60
+
61
+ - source tree/revision intended for deploy;
62
+ - no unexplained trust-boundary contradictions;
63
+ - required release checks green;
64
+ - credentialed destinations/config are present without logging their secret values;
65
+ - migration/deploy plan is understood.
66
+
67
+ Use `agentsam deploy-receipt capture` immediately before the provider release command
68
+ when practical.
69
+
70
+ ## Gate 5 — deploy
71
+
72
+ Goal: perform the real side effect with the smallest necessary authority.
73
+
74
+ Record provider deployment/version identity. Deployment success means the provider
75
+ accepted the candidate; it does not yet prove user-visible health.
76
+
77
+ ## Gate 6 — postdeploy
78
+
79
+ Goal: exercise critical live I/O.
80
+
81
+ Examples:
82
+
83
+ - health endpoint;
84
+ - authentication callback/session creation;
85
+ - one critical read/write path against non-destructive test data;
86
+ - public asset/route availability;
87
+ - service binding/RPC call;
88
+ - external provider integration where a safe smoke path exists;
89
+ - error/latency signals for the new version.
90
+
91
+ Failure should block promotion and trigger the defined rollback/quarantine response.
92
+
93
+ ## Gate 7 — promote
94
+
95
+ Only now advance the last-known-good evidence baseline. In AgentSam that means
96
+ finalizing the deploy receipt as success. Failed deploy or failed smoke must finalize
97
+ as failure and leave the trusted baseline untouched.
98
+
99
+ ## Gate 8 — runtime
100
+
101
+ Continue observing after promotion. For higher-risk changes, use a canary cohort,
102
+ feature flag, or gradual rollout so health can be compared before full exposure.
103
+
104
+ Runtime signals should have owners and actions, not just dashboards:
105
+
106
+ ```text
107
+ signal -> threshold/window -> action -> receipt/incident
108
+ ```
109
+
110
+ Examples: error-rate spike -> disable feature flag; auth failures -> halt rollout;
111
+ latency regression -> keep canary at current cohort and investigate.