@tpsdev-ai/flair 0.63.0 → 0.63.1

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 (63) hide show
  1. package/README.md +8 -7
  2. package/SECURITY.md +55 -33
  3. package/dist/bridges/runtime/import-runner.js +4 -0
  4. package/dist/build-info.json +3 -3
  5. package/dist/cli.js +243 -83
  6. package/dist/commands/agent.js +298 -72
  7. package/dist/commands/attention.js +2 -0
  8. package/dist/commands/bootstrap.js +2 -0
  9. package/dist/commands/bridge.js +10 -0
  10. package/dist/commands/doctor.js +87 -42
  11. package/dist/commands/export.js +141 -11
  12. package/dist/commands/import.js +36 -15
  13. package/dist/commands/init.js +373 -157
  14. package/dist/commands/keys.js +12 -8
  15. package/dist/commands/mcp.js +146 -62
  16. package/dist/commands/memory.js +5 -2
  17. package/dist/commands/migrate-harness-memory.js +9 -3
  18. package/dist/commands/principal.js +19 -14
  19. package/dist/commands/quality.js +23 -3
  20. package/dist/commands/reembed.js +468 -111
  21. package/dist/commands/search.js +2 -0
  22. package/dist/commands/service.js +25 -0
  23. package/dist/commands/status.js +130 -107
  24. package/dist/doctor-client.js +2 -23
  25. package/dist/federation/scheduler.js +148 -12
  26. package/dist/keystore.js +77 -10
  27. package/dist/lib/agent-key-file.js +509 -0
  28. package/dist/lib/agent-rotation-lock.js +249 -0
  29. package/dist/lib/atomic-write.js +2 -2
  30. package/dist/lib/auth-resolve.js +14 -14
  31. package/dist/lib/key-dir.js +203 -0
  32. package/dist/lib/launchd-management.js +7 -3
  33. package/dist/lib/local-instance-pair.js +8 -1
  34. package/dist/lib/node-alias-path.js +50 -2
  35. package/dist/lib/remote-admin-pass.js +157 -0
  36. package/dist/lib/scheduler-platform.js +13 -0
  37. package/dist/lib/service-repoint.js +13 -4
  38. package/dist/lib/skill-seed.js +35 -3
  39. package/dist/lib/terminal-text.js +32 -0
  40. package/dist/mcp-client-assertion.js +5 -4
  41. package/dist/resources/Memory.js +47 -3
  42. package/dist/resources/health.js +39 -22
  43. package/dist/resources/in-process-api.js +74 -11
  44. package/dist/resources/mcp-client-metadata-fields.js +4 -0
  45. package/dist/resources/mcp-handler.js +40 -1
  46. package/dist/resources/mcp-oauth.js +17 -1
  47. package/dist/resources/mcp-tool-scopes.js +69 -0
  48. package/dist/resources/mcp-tools.js +10 -0
  49. package/dist/resources/skill-version-write.js +16 -0
  50. package/dist/src/keystore.js +77 -10
  51. package/dist/src/lib/atomic-write.js +2 -2
  52. package/dist/src/lib/key-dir.js +203 -0
  53. package/dist/src/lib/scheduler-platform.js +13 -0
  54. package/docs/access-control.md +21 -12
  55. package/docs/api-reference.md +35 -24
  56. package/docs/auth.md +31 -22
  57. package/docs/deploying-on-fabric.md +10 -2
  58. package/docs/embedding-in-a-harper-app.md +7 -7
  59. package/docs/entity-vocabulary.md +4 -5
  60. package/docs/hosted-on-fabric.md +1 -1
  61. package/docs/secrets-and-keys.md +8 -13
  62. package/docs/upgrade.md +15 -5
  63. package/package.json +1 -1
package/README.md CHANGED
@@ -311,20 +311,21 @@ Sign `agentId:timestamp:nonce:METHOD:/path` with the agent's private key. Protoc
311
311
 
312
312
  The second front door, and the one to take if your code already runs on Harper.
313
313
 
314
- Flair *is* a Harper component. Deploy it into the instance your application already runs in and call its resources directly — `await h.post({ agentId, content })` is a **method call**, not a network call. No second service to operate, no HTTP round trip, and no key to distribute: a caller in the same process is already inside the trust boundary and names the agent it is acting as, per call.
314
+ Flair *is* a Harper component. Deploy it into the instance your application already runs in and call its facade directly — `await agent.memory.write(...)` is a **method call**, not a network call. No second service to operate, no HTTP round trip, and no key to distribute: a caller in the same process is already inside the trust boundary and names the agent it is acting as, per call.
315
315
 
316
316
  Adding it takes nothing away. The HTTP surface keeps serving MCP clients and remote agents exactly as before.
317
317
 
318
318
  ```javascript
319
319
  import { server } from "harper";
320
- import { agentContext, collectionResource } from "@tpsdev-ai/flair/dist/resources/in-process.js";
320
+ import { Flair } from "@tpsdev-ai/flair";
321
321
 
322
- // The RESOURCE — auth, read-scoping, visibility, embedding.
323
- // Registry keys carry no leading slash: get("Memory"), never get("/Memory").
324
- const Memory = server.resources.get("Memory").Resource;
322
+ const flair = new Flair(server);
323
+ const agent = flair.as("mybot");
325
324
 
326
- const h = await collectionResource(Memory, agentContext("mybot"));
327
- await h.post({ agentId: "mybot", content: "...", durability: "standard" });
325
+ await agent.memory.write("deploy runs at 0200 UTC", { durability: "standard" });
326
+ const hits = await agent.recall("deploy schedule", { limit: 5 }); // an array of hits
327
+ const record = await agent.memory.get(hits[0].id); // the stored row, or null
328
+ const recent = await agent.memory.search({ limit: 10 }); // an array of at most 10 rows
328
329
  ```
329
330
 
330
331
  `databases.flair.Memory` is the **table** (raw storage); the exported `Memory` class is the **resource**, where auth, read-scoping, visibility and embedding live. `new Memory(...)` is not a substitute for `collectionResource` — a create needs a collection-bound instance only Harper can produce. Both helpers refuse a missing agent id rather than defaulting it, because a resource invoked with no context resolves to Flair's trusted `internal` verdict and runs unfiltered across every agent.
package/SECURITY.md CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  Flair uses cryptographic identity (Ed25519) for agent authentication. Within
6
6
  an org, memory reads are open — agents see each other's non-private memories —
7
- while writes are isolated per agent and private memories stay strictly
8
- owner-only. The hard access boundary is the federation edge (cross-instance).
7
+ while writes are isolated per agent and private memories restrict non-admin
8
+ reads to their owner. The hard access boundary is the federation edge (cross-instance).
9
9
 
10
10
  ## Authentication
11
11
 
@@ -17,7 +17,7 @@ Every request includes an `Authorization` header:
17
17
  TPS-Ed25519 <agentId>:<timestamp>:<nonce>:<signature>
18
18
  ```
19
19
 
20
- The signature covers `agentId:timestamp:nonce:METHOD:/path` using the
20
+ The signature covers `agentId:timestamp:nonce:METHOD:/path?query` using the
21
21
  agent's Ed25519 private key. The server verifies against the agent's
22
22
  registered public key.
23
23
 
@@ -49,11 +49,14 @@ requests to it require admin Basic auth: Flair ships with
49
49
  `authorizeLocal: false`, so an unauthenticated loopback request is
50
50
  rejected (`401`) instead of being auto-elevated to super_user. The same
51
51
  API is also reachable over a Unix **domain socket**
52
- (`~/.flair/data/operations-server`, owner-write-only), which Harper
52
+ (`~/.flair/data/operations-server`), which Harper
53
53
  treats as an inherent local-admin channel — a request over the socket is
54
54
  authorized as super_user **without** credentials. This is by design (the
55
- admin-password rotation flow relies on it) and is constrained to the box
56
- owner; see Threats NOT Mitigated below.
55
+ admin-password rotation flow relies on it). CLI `init`, `start`, `restart` and
56
+ launchd repair attempt parent/socket modes `0700`/`0600` (or `0750`/`0660` with
57
+ `FLAIR_SOCKET_GROUP`, changing the socket's group); unattended macOS launchd
58
+ spawns use `Umask 077` (`0700` socket, since Darwin does not retain `0600` on
59
+ Unix sockets) without reapplying the CLI posture.
57
60
 
58
61
  ## Data Scoping
59
62
 
@@ -65,19 +68,17 @@ centralized read-scope rule), not application logic:
65
68
 
66
69
  - `GET /Memory/` — applies the owner/visibility base scope and omits retained
67
70
  closed skill payloads that fail the non-admin reader's current-authority check
68
- - `POST /MemorySearch` — same read scope: own memories plus all non-private
71
+ - `POST /SemanticSearch` — applies the owner/visibility read scope
69
72
  - `POST /Memory` — writes are attributed to the authenticated agent; an
70
73
  agent cannot write as another (write isolation)
71
74
 
72
- **Private memories are strictly owner-only** — a memory written with
73
- `visibility: private` is returned only to its author, never to another agent.
75
+ Non-admin memory reads restrict `visibility: private` to its author.
74
76
 
75
- **A write that does not name a visibility gets one anyway.** The server derives
76
- it from the memory's durability: `permanent`/`persistent` → `shared`,
77
- `standard`/`ephemeral` → `private`. Durability itself defaults to `standard`,
78
- so a write naming neither is stamped `private` and is owner-only. An explicit
79
- `visibility` on the write always overrides the rule, and the response to a
80
- create names the value the record actually landed on.
77
+ On `POST /Memory` and `PUT /Memory` creates, omitted visibility defaults by
78
+ durability: `permanent`/`persistent` → `shared`, `standard`/`ephemeral` → `private`.
79
+ Durability defaults to `standard`. Explicit visibility overrides this default;
80
+ ephemeral memories require `private`, and grant-authorized `supersedes` writes
81
+ keep the predecessor's visibility, including when visibility is omitted.
81
82
 
82
83
  ### Record Ownership on Writes
83
84
 
@@ -128,7 +129,7 @@ Within an org, non-private memories pass the base read-scope check without a
128
129
  grant; non-admin by-id and collection reads of retained closed skills
129
130
  additionally require readable current authority. This is deliberate: the goal
130
131
  is relevance (surface what's useful to the org) over secrecy. A writer keeps something private by marking it
131
- `visibility: private`, which keeps it strictly owner-only. The access boundary
132
+ `visibility: private`, which restricts non-admin reads to its author. The access boundary
132
133
  that stays hard is the **federation edge** (cross-instance / cross-org), not
133
134
  within-org reads.
134
135
 
@@ -142,9 +143,32 @@ are restricted to admin-only.
142
143
 
143
144
  ### Key Storage
144
145
 
145
- Private keys are stored at `~/.flair/keys/<agentId>.key` with `0600`
146
- permissions (owner read/write only). Legacy path `~/.tps/secrets/flair/`
147
- is supported with deprecation warnings.
146
+ Private keys at `~/.flair/keys/<agentId>.key` are created owner-only
147
+ (`0600`) from the first byte on POSIX by `flair agent add`, `flair init` (local
148
+ and remote agent provisioning), `flair principal add`, `flair import` and
149
+ `flair agent rotate-key` (which stages the replacement before it updates Flair
150
+ and renames it over the current key once Flair holds its public key). On
151
+ POSIX the keys directory is requested with mode `0700` (the umask may make it
152
+ narrower), and an owned directory with group or world bits is tightened to
153
+ `0700`; on the create and reuse paths an existing key with group or world
154
+ bits is refused with `chmod 600 <path>`, while rotation reports it. A successful
155
+ rotation replaces the file; a failed update leaves it. `flair doctor` warns
156
+ about an existing agent key file with group or world bits, and `flair status`
157
+ warns about it for a local target; both name the path, its mode and
158
+ `chmod 600 <path>`, and neither changes the file. The check covers the standard
159
+ `resolveKeyPath` locations: `$FLAIR_KEY_DIR/<agentId>.key` when that variable is
160
+ set, `~/.flair/keys/<agentId>.key`, and the legacy
161
+ `~/.tps/secrets/flair/<agentId>-priv.key`; explicit key paths (such as `--key`)
162
+ are outside this scan. A symlinked agent key is
163
+ reported as not checked. On Windows mode bits
164
+ do not establish owner-only.
165
+
166
+ `flair export --include-key` publishes its output through a `0600` temp file
167
+ renamed over the target, so an existing output file's wider mode does not apply
168
+ to the new contents. The keystore seed file is replaced the same way.
169
+ A generated passphrase is published at `0600` if its path is absent. When used
170
+ (`FLAIR_KEY_PASSPHRASE` unset), an existing generated passphrase file with group
171
+ or world bits is refused unchanged before reading, with `chmod 600 <path>`. On Windows the mode bits do not apply.
148
172
 
149
173
  ### Key Generation
150
174
 
@@ -154,8 +178,11 @@ runtime.
154
178
 
155
179
  ### Key Rotation
156
180
 
157
- `flair agent rotate-key <id>` generates a new key pair, updates the
158
- public key in Flair, and backs up the old key as `<agentId>.key.bak`.
181
+ `flair agent rotate-key <id>` generates a new key pair, stages the new private
182
+ key owner-only (`0600`) from creation on POSIX, updates the public key in
183
+ Flair, reads the row back to confirm the stored key, then renames the staged
184
+ key over the current one. The old key is backed up as a new
185
+ `<agentId>.key.bak.<UTC timestamp>`; an existing backup is left untouched.
159
186
 
160
187
  ## Threat Model
161
188
 
@@ -163,8 +190,8 @@ public key in Flair, and backs up the old key as `<agentId>.key.bak`.
163
190
 
164
191
  - **Agent impersonation:** Ed25519 signatures prevent one agent from
165
192
  acting as another without possessing the private key.
166
- - **Private-memory leakage:** memories marked `visibility: private` are
167
- strictly owner-only and never returned to another agent. Non-private
193
+ - **Private-memory leakage:** non-admin reads of `visibility: private` memories
194
+ are restricted to their author. Non-private
168
195
  memories are intentionally readable within the org (by design, not
169
196
  leakage); the cross-instance boundary is the federation edge.
170
197
  - **Write forgery:** writes are attributed to the authenticated agent —
@@ -172,8 +199,6 @@ public key in Flair, and backs up the old key as `<agentId>.key.bak`.
172
199
  - **Replay attacks:** 30-second window + nonce deduplication.
173
200
  - **Privilege escalation via SQL:** SQL and GraphQL endpoints blocked
174
201
  for non-admin agents.
175
- - **Admin token theft from filesystem:** Admin credentials are only in
176
- process environment, never on disk.
177
202
 
178
203
  ### Threats NOT Mitigated (Runtime Responsibility)
179
204
 
@@ -184,13 +209,10 @@ public key in Flair, and backs up the old key as `<agentId>.key.bak`.
184
209
  process could extract them.
185
210
  - **Network sniffing:** Flair uses HTTP by default. Use HTTPS in
186
211
  production or restrict to localhost.
187
- - **Same-OS-user ops-API socket access:** the operations-API domain
188
- socket (`operations-server`, owner-write-only) is an unauthenticated
189
- super_user channel by Harper design — any process running as the box
190
- owner can perform admin operations through it (the admin-password
191
- rotation flow uses this path). Owner-write permissions keep it
192
- unreachable by other OS users, co-tenants, and the network; isolate
193
- untrusted workloads to separate OS users.
212
+ - **Local ops-API socket access:** the operations-API domain socket
213
+ (`operations-server`) grants local admin access, restricted by the
214
+ directory and socket modes above. Isolate untrusted workloads to separate
215
+ OS users outside any configured `FLAIR_SOCKET_GROUP`.
194
216
 
195
217
  ## Recommendations
196
218
 
@@ -199,4 +221,4 @@ public key in Flair, and backs up the old key as `<agentId>.key.bak`.
199
221
  3. **Rotate keys** periodically with `flair agent rotate-key`
200
222
  4. **Back up** with `flair backup` — backup files contain memory content
201
223
  and should be treated as sensitive
202
- 5. **Monitor** with `flair status` — warns about key permission issues
224
+ 5. **Monitor** with `flair status`
@@ -17,6 +17,7 @@ import { randomUUID } from "node:crypto";
17
17
  import { BridgeRuntimeError } from "../types.js";
18
18
  import { importFromYaml } from "./execute.js";
19
19
  import { endsWithContentSelectorSuffix } from "../../lib/memory-id-policy.js";
20
+ import { requireAgentId } from "../../lib/key-dir.js";
20
21
  const VALID_DURABILITY = new Set(["ephemeral", "standard", "persistent", "permanent"]);
21
22
  /**
22
23
  * Drive a YAML descriptor's `import` block all the way through to PUTs
@@ -48,6 +49,9 @@ export async function runImport(opts) {
48
49
  hint: `record ${total} has no agentId and no --agent default was provided. Pass --agent <id> on the import command, or have the descriptor map an agentId column.`,
49
50
  });
50
51
  }
52
+ // Refuse an invalid agent id before the caller resolves a key path or reads
53
+ // a key for this record.
54
+ requireAgentId(resolvedAgent);
51
55
  const durability = (m.durability && VALID_DURABILITY.has(m.durability))
52
56
  ? m.durability
53
57
  : "standard";
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.63.0",
3
- "commit": "2684290e86191bdaf14560a45c5d1d0ec6c7d3e4",
4
- "builtAt": "2026-11-24T15:09:23.643Z",
2
+ "version": "0.63.1",
3
+ "commit": "d2469c5dec55a9fc31b1a9b8644eb086c86cd40c",
4
+ "builtAt": "2026-11-29T07:21:07.327Z",
5
5
  "builder": "tsc"
6
6
  }