@hasna/instructions 0.5.5 → 0.6.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 (64) hide show
  1. package/README.md +64 -20
  2. package/dist/cli/fail-closed-no-env.test.d.ts +2 -0
  3. package/dist/cli/fail-closed-no-env.test.d.ts.map +1 -0
  4. package/dist/cli/index.js +1910 -561
  5. package/dist/data/config-store.d.ts +62 -33
  6. package/dist/data/config-store.d.ts.map +1 -1
  7. package/dist/db/database.d.ts.map +1 -1
  8. package/dist/generated/storage-kit/backend.d.ts +4 -4
  9. package/dist/generated/storage-kit/backend.d.ts.map +1 -1
  10. package/dist/generated/storage-kit/index.d.ts +1 -1
  11. package/dist/generated/storage-kit/index.d.ts.map +1 -1
  12. package/dist/generated/storage-kit/migrations.d.ts +21 -0
  13. package/dist/generated/storage-kit/migrations.d.ts.map +1 -1
  14. package/dist/generated/storage-kit/pool.d.ts +2 -5
  15. package/dist/generated/storage-kit/pool.d.ts.map +1 -1
  16. package/dist/index.d.ts +5 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2702 -547
  19. package/dist/lib/app-home.d.ts +9 -0
  20. package/dist/lib/app-home.d.ts.map +1 -1
  21. package/dist/lib/client-types.d.ts +130 -0
  22. package/dist/lib/client-types.d.ts.map +1 -0
  23. package/dist/lib/client-types.test.d.ts +2 -0
  24. package/dist/lib/client-types.test.d.ts.map +1 -0
  25. package/dist/lib/local-opt-in.d.ts +82 -0
  26. package/dist/lib/local-opt-in.d.ts.map +1 -0
  27. package/dist/lib/project-context.d.ts +14 -14
  28. package/dist/lib/project-context.d.ts.map +1 -1
  29. package/dist/lib/project-dashboard-standard.d.ts +1 -1
  30. package/dist/lib/project-dashboard-standard.d.ts.map +1 -1
  31. package/dist/lib/session-apply.d.ts.map +1 -1
  32. package/dist/lib/session-render-state-hermeticity.test.d.ts +2 -0
  33. package/dist/lib/session-render-state-hermeticity.test.d.ts.map +1 -0
  34. package/dist/lib/session-render-state.d.ts +57 -0
  35. package/dist/lib/session-render-state.d.ts.map +1 -0
  36. package/dist/lib/session-render-state.test.d.ts +2 -0
  37. package/dist/lib/session-render-state.test.d.ts.map +1 -0
  38. package/dist/lib/transport-resolver.d.ts +80 -0
  39. package/dist/lib/transport-resolver.d.ts.map +1 -0
  40. package/dist/lib/transport-resolver.test.d.ts +2 -0
  41. package/dist/lib/transport-resolver.test.d.ts.map +1 -0
  42. package/dist/mcp/index.d.ts.map +1 -1
  43. package/dist/mcp/index.js +1442 -192
  44. package/dist/mcp/server.d.ts.map +1 -1
  45. package/dist/sdk/index.d.ts +22 -0
  46. package/dist/sdk/index.d.ts.map +1 -0
  47. package/dist/sdk/index.js +1042 -0
  48. package/dist/sdk/resolve.d.ts +82 -0
  49. package/dist/sdk/resolve.d.ts.map +1 -0
  50. package/dist/sdk/resolve.test.d.ts +2 -0
  51. package/dist/sdk/resolve.test.d.ts.map +1 -0
  52. package/dist/sdk/sdk-bundle-self-contained.test.d.ts +2 -0
  53. package/dist/sdk/sdk-bundle-self-contained.test.d.ts.map +1 -0
  54. package/dist/sdk/v1.generated.d.ts +288 -0
  55. package/dist/sdk/v1.generated.d.ts.map +1 -0
  56. package/dist/server/cloud.d.ts.map +1 -1
  57. package/dist/server/index.d.ts.map +1 -1
  58. package/dist/server/index.js +55 -64
  59. package/dist/test-support/preload-state-home.d.ts +2 -0
  60. package/dist/test-support/preload-state-home.d.ts.map +1 -0
  61. package/package.json +12 -12
  62. package/dashboard/README.md +0 -37
  63. package/dist/lib/retired-storage-mode.d.ts +0 -8
  64. package/dist/lib/retired-storage-mode.d.ts.map +0 -1
package/README.md CHANGED
@@ -124,7 +124,8 @@ Surfaces:
124
124
  - `GET /openapi.json`, `GET /v1/openapi.json` → the OpenAPI 3.1 document the SDK
125
125
  is generated from.
126
126
  - `/v1/*` — versioned cloud API (configs, profiles, snapshots, stats).
127
- - `/api/*` — the local dashboard/REST surface.
127
+ - No `/api/*` — the former local REST surface is not mounted (the removed
128
+ bundled dashboard was its only consumer).
128
129
 
129
130
  ### Server data backend (postgresql)
130
131
 
@@ -144,25 +145,70 @@ contracts issue-key --app instructions --scopes 'instructions:*'
144
145
 
145
146
  Env: `HASNA_INSTRUCTIONS_DATABASE_URL` (DSN) and
146
147
  `HASNA_INSTRUCTIONS_API_SIGNING_KEY` (HMAC signing secret; `HASNA_API_SIGNING_KEY`
147
- and `API_KEY_SIGNING_SECRET` are also accepted). Client apps use
148
- `INSTRUCTIONS_API_URL` + `INSTRUCTIONS_API_KEY` never a DSN.
148
+ and `API_KEY_SIGNING_SECRET` are also accepted). Client apps never carry a DSN —
149
+ they resolve `HASNA_INSTRUCTIONS_API_KEY` (or the Keychain / credentials-file
150
+ tiers) through the one `@hasna/contracts` client resolver, and the authority
151
+ defaults to the fleet gateway `https://api.hasna.com/instructions`.
149
152
 
150
153
  ## SDK
151
154
 
152
- `@hasna/instructions-sdk` ships a zero-dependency typed client. The versioned
153
- `InstructionsV1Client` is generated from the serve OpenAPI document
154
- (`bun run generate:sdk`).
155
+ The importable module ships INSIDE `@hasna/instructions` at the `./sdk` export
156
+ (one package per app — there is no split `@hasna/instructions-sdk`). It is a
157
+ self-contained bundle (node builtins only; the `@hasna/contracts` resolver is
158
+ inlined at build time). The versioned `InstructionsV1Client` is generated from
159
+ the serve OpenAPI document (`bun run generate:sdk` → `src/sdk/v1.generated.ts`).
155
160
 
156
- ## Client transports
161
+ ```typescript
162
+ import { createInstructionsV1ClientFromEnv } from "@hasna/instructions/sdk";
163
+
164
+ const client = createInstructionsV1ClientFromEnv(); // Keychain -> disk -> HASNA_INSTRUCTIONS_API_KEY
165
+ const { configs = [] } = await client.listConfigs({ category: "rules" });
166
+ ```
157
167
 
158
- Every CLI command, MCP tool, and SDK method routes through a single `ConfigStore`
159
- abstraction with two transports:
168
+ `createInstructionsV1ClientFromEnv` resolves the credential through the same
169
+ `@hasna/contracts` chain as the CLI and the MCP server — fresh on every
170
+ request, so a rotated key heals a long-lived client without rebuilding it.
171
+ `resolveInstructionsSdkTransport(options)` reports WHICH tier supplied the
172
+ credential (never the value). An explicit `baseUrl` requires an explicit
173
+ `apiKey` (hasna/apps#1794): the SDK never attaches the machine's fleet key to
174
+ an authority the caller chose itself. No credential anywhere throws; there is
175
+ no local mode and no unauthenticated client on this surface.
176
+
177
+ ## Client transports
160
178
 
161
- - **local** on-box SQLite (`LocalConfigStore`), fully first-class. Used when no
162
- API env vars are set.
163
- - **api** HTTP `/v1` + bearer key (`CloudConfigStore`).
164
- Activated by setting **both** `HASNA_INSTRUCTIONS_API_URL` and
165
- `HASNA_INSTRUCTIONS_API_KEY`.
179
+ Every CLI command, MCP tool, and SDK method resolves its credential and service
180
+ authority through the ONE client resolver in `@hasna/contracts`
181
+ (`hasna/apps#1720`)the package owns no second chain. The tiers, fresh per
182
+ call:
183
+
184
+ | Tier | Credential | Authority |
185
+ |---|---|---|
186
+ | 1 — argument | `--api-key` / `--profile` | explicit `baseUrl` (SDK only) |
187
+ | 2 — env pointer | `HASNA_INSTRUCTIONS_API_KEY_OVERRIDE`, `HASNA_PROFILE`, `HASNA_INSTRUCTIONS_API_KEY_REF` | — |
188
+ | 3 — macOS Keychain | `hasna.credentials.instructions.api-key` (account `HASNA_STATION` → `hostname -s` → `$USER`) | `hasna.credentials.instructions.api-url` |
189
+ | 4 — disk | `~/.hasna/instructions/config/credentials` (owner-only 0400/0600; `HASNA_HOME` / `HASNA_CONFIG_HOME` move the root) | same file's `HASNA_INSTRUCTIONS_API_URL` |
190
+ | 5 — env | `HASNA_INSTRUCTIONS_API_KEY` | `HASNA_INSTRUCTIONS_API_URL` |
191
+
192
+ With a credential resolved and nothing configuring the authority, the default is
193
+ the fleet gateway `https://api.hasna.com/instructions`. The unprefixed
194
+ `INSTRUCTIONS_API_URL` / `INSTRUCTIONS_API_KEY` names are accepted for one
195
+ release as silent aliases one rung below the canonical `HASNA_INSTRUCTIONS_*`
196
+ names.
197
+
198
+ The two transports behind `ConfigStore`:
199
+
200
+ - **api** — HTTP `/v1` through the shared authenticated transport
201
+ (`CloudConfigStore`). Runs fail loud with no credential: non-zero exit naming
202
+ the tiers consulted, no SQLite fallback, no local-fallback event.
203
+ - **local** — on-box SQLite (`LocalConfigStore`), **opt-in only**:
204
+ `HASNA_INSTRUCTIONS_LOCAL=1`, honoured only when the environment configures
205
+ no authority and no credential. Every local run says `local mode` once on
206
+ stderr.
207
+
208
+ Retired locations (`~/.hasna/fleet-env`, `~/.hasna/cloud`, `~/.config/hasna`,
209
+ `$XDG_CONFIG_HOME`, a `~/.instructions/config.json` key store) are inputs
210
+ nowhere, and no `*_MODE` / `*_STORAGE_MODE` switch selects anything — the
211
+ transport is decided by what resolves, never by a mode word.
166
212
 
167
213
  Clients never hold a database DSN. The raw Postgres connection is a server-only
168
214
  concern (`instructions-serve`), selected by `HASNA_INSTRUCTIONS_DATABASE_URL`.
@@ -344,12 +390,9 @@ These profiles resolve machine variables like `{{WORKSPACE_ROOT}}`,
344
390
  `{{BUN_BIN_DIR}}`, `{{BUN_PATH}}`, and `{{PATH_PREFIX}}`, so synced configs can be
345
391
  portable across Linux and macOS arm64 machines.
346
392
 
347
- They also include project dashboard variables used by agent-managed project
393
+ They also include the project channel variable used by agent-managed project
348
394
  workflows:
349
395
 
350
- - `{{PROJECT_DASHBOARD_DIR}}` -> `.hasna/project`
351
- - `{{PROJECT_DASHBOARD_RENDER_MANIFEST}}` -> `.hasna/project/dashboard/render.json`
352
- - `{{PROJECT_DASHBOARD_SNAPSHOTS_DIR}}` -> `.hasna/project/dashboard/snapshots`
353
396
  - `{{PROJECT_CHANNEL_PREFIX}}` -> `""` (no prefix; the channel is the normalized project slug)
354
397
 
355
398
  Existing profiles can be migrated in place without deleting or recreating them:
@@ -361,8 +404,9 @@ instructions profile update linux-arm64 \
361
404
  ```
362
405
 
363
406
  `instructions init` and `bun run seed` seed the
364
- `agent-managed-project-dashboard-standard` reference. It documents the standard
365
- `.hasna/project` layout, `projects dashboard *` commands, provider panel
407
+ `agent-managed-project-dashboard-standard` reference. It documents the canonical
408
+ per-workspace store layout (`~/.hasna/projects/workspaces/<workspace_id>/` the
409
+ only project-layout convention), `projects dashboard *` commands, provider panel
366
410
  commands, normalized project-slug channel naming, durable todos/goal workflow,
367
411
  and the rule that dashboards must show ids/statuses/evidence refs instead of raw
368
412
  private documents or secrets.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fail-closed-no-env.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fail-closed-no-env.test.d.ts","sourceRoot":"","sources":["../../src/cli/fail-closed-no-env.test.ts"],"names":[],"mappings":""}