@tpsdev-ai/flair 0.58.0 → 0.59.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 (46) hide show
  1. package/README.md +3 -2
  2. package/config.yaml +3 -0
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +42 -98
  5. package/dist/commands/agent.js +160 -2
  6. package/dist/commands/doctor.js +15 -23
  7. package/dist/commands/mcp.js +53 -22
  8. package/dist/lib/daemon-liveness.js +42 -0
  9. package/dist/lib/doctor-run.js +67 -0
  10. package/dist/lib/flair-agent-role.js +116 -0
  11. package/dist/lib/launchd-management.js +3 -2
  12. package/dist/lib/mcp-enable.js +667 -72
  13. package/dist/lib/process-start-time.js +32 -0
  14. package/dist/resources/Agent.js +27 -7
  15. package/dist/resources/AgentSeed.js +9 -0
  16. package/dist/resources/Federation.js +14 -2
  17. package/dist/resources/MemoryBootstrap.js +121 -29
  18. package/dist/resources/OrgSkillAssignment.js +209 -0
  19. package/dist/resources/XAA.js +40 -11
  20. package/dist/resources/agent-status-guard.js +63 -0
  21. package/dist/resources/auth-middleware.js +2 -1
  22. package/dist/resources/federation-classify.js +22 -0
  23. package/dist/resources/flair-agent-role-boot.js +26 -0
  24. package/dist/resources/health.js +10 -2
  25. package/dist/resources/key-lock.js +31 -0
  26. package/dist/resources/mcp-oauth.js +3 -6
  27. package/dist/resources/mcp-tools.js +22 -4
  28. package/dist/resources/multi-worker-guard.js +121 -0
  29. package/dist/resources/oauth-discovery.js +1 -0
  30. package/dist/resources/oauth-wellknown.js +8 -4
  31. package/dist/resources/record-types.js +16 -0
  32. package/dist/resources/replay-store.js +56 -9
  33. package/dist/resources/skill-manifest.js +181 -0
  34. package/dist/resources/skill-provenance.js +15 -10
  35. package/dist/src/lib/flair-agent-role.js +116 -0
  36. package/docs/access-control.md +667 -0
  37. package/docs/api-reference.md +6 -2
  38. package/docs/auth.md +4 -0
  39. package/docs/deepseek-harness.md +1 -1
  40. package/docs/integrations.md +1 -1
  41. package/docs/mcp-clients.md +5 -3
  42. package/docs/releasing.md +24 -24
  43. package/package.json +4 -3
  44. package/schemas/memory.graphql +31 -0
  45. package/schemas/oauth.graphql +8 -4
  46. package/templates/launchd/start-flair-with-admin-pass.sh +89 -16
@@ -52,7 +52,7 @@ the schema section so the catalog is complete.
52
52
  | **Public** | none | Discovery, health, OAuth well-known. `GET /Presence` is public only when the instance opts in to a public roster (`PRESENCE_PUBLIC_ROSTER=true`) — by default it needs a verified reader. See [Presence for API consumers](#presence-for-api-consumers). |
53
53
  | **Ed25519 agent** | `TPS-Ed25519` header | Default agent path. Writes as self only. Reads follow the resource's read-scope (below). |
54
54
  | **Admin Basic** | Harper `HDB_ADMIN_PASSWORD` / `FLAIR_ADMIN_PASSWORD` | Whole-instance operator. Bypasses agent scoping, including `private` memory. Used by the web admin and `n8n-nodes-flair`. |
55
- | **Operator / internal** | Admin Basic, or a deliberate `internalContext()` call inside the process | Soul mutations and `AgentSeed`. Agent Ed25519 keys — including admin-agent keys — cannot author Soul. |
55
+ | **Operator / internal** | Admin Basic, or a deliberate `internalContext()` call inside the process | Soul mutations, `OrgSkillAssignment` writes and `AgentSeed`. Agent Ed25519 keys — including admin-agent keys — cannot author Soul. |
56
56
  | **Federation body-sig** | Ed25519 over the request body + timestamp/nonce; pairing uses a one-time token | `/FederationPair`, `/FederationSync`. Harper role gate is open; the handler is the auth boundary. |
57
57
  | **OAuth bearer** | Access token from Flair's AS or `@harperfast/oauth` | `/mcp` only, and only when `FLAIR_MCP_OAUTH=true` plus a public issuer. Off by default (path 404s). |
58
58
 
@@ -91,7 +91,7 @@ From `RECORD_TYPES` in `resources/record-types.ts`:
91
91
  |-------|---------|--------|
92
92
  | **open-within-org** | Own rows (any visibility) plus every other agent's non-private rows | Memory |
93
93
  | **owner-only** | Only the owning agent (plus admin / internal) | Relationship, WorkspaceState, Asset, MemoryCandidate |
94
- | **none** | Any verified agent reads every row; no visibility field | Soul, OrgEvent |
94
+ | **none** | Any verified agent reads every row; no visibility field | Soul, OrgEvent, OrgSkillAssignment |
95
95
 
96
96
  These three scopes are **not** in `RECORD_TYPES`. Each is hand-implemented on its
97
97
  own resource:
@@ -171,6 +171,8 @@ the same identity plane.
171
171
  | POST | `/MemoryReflect` | Ed25519 | REM distill → MemoryCandidate. |
172
172
  | POST | `/MemoryDedupStats` | Admin Basic | Dedup diagnostics. Fleet-wide sweep; `allowCreate` is `allowAdmin`. |
173
173
  | POST | `/SkillScan` | Ed25519 | Skill-tag scan on Memory writes. |
174
+ | GET | `/OrgSkillAssignment`, `/OrgSkillAssignment/<id>` | Ed25519 | Any verified agent. Org-scope skill assignments; see the `skills` paragraph in [docs/mcp-clients.md](mcp-clients.md). Not federated. |
175
+ | POST / PUT / PATCH / DELETE | `/OrgSkillAssignment/` (POST), `/OrgSkillAssignment/<id>` (PUT / PATCH / DELETE) | **Operator / internal** | Not Ed25519, admin-agent keys included. Each accepted write appends an `OrgSkillAssignmentHistory` row. |
174
176
 
175
177
  Skill-tagged Memory rows embed from `trigger` (the recall signal), not
176
178
  `content`. MCP tools: `skill_store`, `skill_search`, `skill_get`.
@@ -476,6 +478,8 @@ ed25519 / idp) and **Integration** (legacy platform connection).
476
478
  | **MemoryHitStat** | memory.graphql | no | Search-hit ledger (`retrievalCount`, `lastRetrieved`); overlaid onto Memory reads |
477
479
  | **MemoryCandidate** | memory.graphql | yes | REM draft (`claim`, `status`, `scopeTag`, visibility ruling) |
478
480
  | **Asset** | memory.graphql | yes | Blob (`contentType`, `data`) owned by `agentId`, linked by `memoryId` |
481
+ | **OrgSkillAssignment** | memory.graphql | yes | Org-scope skill assignment (`skillName`, `skillRef`, `priority`, server-stamped `writer` / `sourceClass`) |
482
+ | **OrgSkillAssignmentHistory** | memory.graphql | no | One row per accepted OrgSkillAssignment resource write (`assignmentId`, `op`, `actor`, `sourceClass`, `previousHash`) |
479
483
  | **WorkspaceState** | workspace.graphql | yes | Current work (`ref`, `provider`, `phase`, `entities`) |
480
484
  | **OrgEvent** | event.graphql | yes | Org-visible event (`authorId`, `kind`, `summary`, `entities`) |
481
485
  | **AgentReadPosition** | agent.graphql | no | Per-agent watermark (`agentId`, `stream`, `position`). HTTP via `/AgentReadPosition`, not raw-table REST. |
package/docs/auth.md CHANGED
@@ -66,6 +66,8 @@ The native `/mcp` OAuth surface (see below) doesn't need any client-side wiring
66
66
 
67
67
  Flair includes a built-in OAuth 2.1 authorization server for client integrations (e.g., Claude connecting to Flair as an MCP server).
68
68
 
69
+ The native `/mcp` endpoint is guarded by the `@harperfast/oauth` authorization server instead; who can connect through it, and how to revoke that access, is in [access-control.md](access-control.md).
70
+
69
71
  ### Dynamic Client Registration
70
72
 
71
73
  **Registration is off by default.** `POST /OAuthRegister` answers `403
@@ -232,6 +234,8 @@ For organizations using an Identity Provider (IdP), XAA lets the IdP control who
232
234
  3. Client sends the ID token to Flair's token endpoint using the `jwt-bearer` grant type
233
235
  4. Flair validates the JWT signature, checks issuer/domain, maps to a Principal, and issues a scoped access token
234
236
 
237
+ A `jti` claim, when present, must be a nonempty string, and the assertion must then carry an `exp` no more than 24 hours (plus 30 seconds of clock skew) ahead. Flair records the `jti` before it issues tokens, and refuses the assertion if it is presented to this Harper instance again.
238
+
235
239
  ```
236
240
  POST /OAuthToken
237
241
  Content-Type: application/x-www-form-urlencoded
@@ -105,6 +105,6 @@ Field names verified against DSH `master` 2026-08-20; [their table](https://gith
105
105
 
106
106
  **Tools never appear.** DSH logs initial connection and discovery failures; by default a failed startup registers no tools rather than failing the plugin. Check `flair status` on the Flair side, and check the DSH logs for the `flair` server's connect errors. A duplicate `serverName: flair` across live instances fails the later instance at load.
107
107
 
108
- **`auth_error` on every call.** Identity/key mismatch — and remember that an exported `FLAIR_KEY_PATH` never reaches the server (caveat 1). Re-run `flair agent add <id>` (idempotent) or set `FLAIR_KEY_PATH` in `config.env`.
108
+ **`auth_error` on every call.** Read the reported cause. An exported `FLAIR_KEY_PATH` never reaches the server (caveat 1). For `unknown_agent`, no Agent row exists: run `flair agent add <id>`. For `invalid_signature`, the signature did not verify against the stored public key. Check the signing key and the signed request first. For a confirmed key mismatch, `agent add` refuses a well-formed existing row. Run `flair agent rotate-key <id>` on the Flair host; that writes the new private key on the Flair host. Copy that file to the harness host and set `FLAIR_KEY_PATH` in `config.env` to it, then restart. Other auth errors follow the cause they name.
109
109
 
110
110
  For everything else: [troubleshooting.md](troubleshooting.md).
@@ -57,7 +57,7 @@ Do not "fix" a 401 or 404 by pasting the Harper admin password into the agent's
57
57
  | Shape | What is true | What you see | What to do |
58
58
  |---|---|---|---|
59
59
  | **Record missing** | No `Agent` row for this id on **this** instance | `401 {"error":"unknown_agent"}` on every signed route | Register against the hosted URL: `flair agent add <id> --target "$FLAIR_URL" --ops-target <ops-url> --admin-pass-file <path>`. Fabric ops is not `data-port − 1` — see [quickstart-fabric.md](quickstart-fabric.md). |
60
- | **Key mismatch** | The id exists; the public key on the server is not the one in your keyfile | `401 {"error":"invalid_signature"}` | Same id, wrong key — copied from another host, rotated on one side only, or the env pointing at a different agent's file. Point the env at the key that matches **this** instance, or re-seed the hosted `Agent` row from the key on this machine: `flair agent add <id> --target "$FLAIR_URL" --ops-target <ops-url> --admin-pass-file <path>` (reuses the local keyfile). `flair agent rotate-key` is localhost-only. Restart the adapter so it reloads the key. |
60
+ | **Key mismatch** | The id exists; the public key on the server is not the one in your keyfile | `401 {"error":"invalid_signature"}` | Same id, wrong key — copied from another host, rotated on one side only, or the env pointing at a different agent's file. Point the env at the key that matches **this** instance. `flair agent add` refuses an id that already exists and does not replace the stored key. On the Flair host, `flair agent rotate-key <id>` replaces the stored public key and writes the new private key on that host (it is localhost-only). The new key file must be on the adapter host before that process can sign with it. Configure that signing process to use the local file, then restart it. |
61
61
  | **Config wrong** | Identity may be fine; you are not talking to the Flair you think | Timeouts, connection errors, or **404 from Harper's catch-all** | `FLAIR_URL` must be the origin the **signing process** can open (cloud-agent localhost is the VM, not your laptop). adk-flair also needs `FLAIR_ALLOW_REMOTE_URL=1` and a raised `FLAIR_HTTP_TIMEOUT` (defaults are localhost fail-fast). A `FLAIR_URL` with a path prefix sends every request to a route that does not exist. `/Health` can be 200 while `/Memory` is still 404 if the Flair app is not loaded yet. |
62
62
 
63
63
  Clock skew is a fourth, rarer 401: `timestamp_out_of_window`.
@@ -35,7 +35,7 @@ The snippets below are the **local** path. Flair also has a native `/mcp` endpoi
35
35
 
36
36
  Native `/mcp` is remote-only by design. The OAuth authorization server fetches client metadata over HTTPS and refuses private, loopback, and link-local hosts. `flair mcp enable` refuses localhost, loopback, RFC1918, IPv4 link-local, and `.local`. Set `FLAIR_MCP_OAUTH=true` — that is the one value that enables both Flair's `/mcp` route and the OAuth component. A loopback Flair cannot be the origin those clients dial. The stdio adapter is the local path because it speaks the instance's Ed25519 HTTP API and does not need that public origin.
37
37
 
38
- `flair init --agent <id>` attempts to wire detected local clients unless MCP wiring is disabled; bare `flair init` only initializes the instance. Turning on native `/mcp` is a separate operator step for a publicly reachable instance, documented from the API side in [api-reference.md](api-reference.md#mcp-tools).
38
+ `flair init --agent <id>` attempts to wire detected local clients unless MCP wiring is disabled; bare `flair init` only initializes the instance. Turning on native `/mcp` is a separate operator step for a publicly reachable instance, documented from the API side in [api-reference.md](api-reference.md#mcp-tools). Who can connect through native `/mcp`, and how to revoke access, is in [access-control.md](access-control.md).
39
39
 
40
40
  ---
41
41
 
@@ -322,7 +322,9 @@ The following structured-payload details describe the HTTP bootstrap response an
322
322
 
323
323
  `bootstrap` returns the canonical structured containers — `soul`, `memories`, `predicted`, `teammateFindings`, `events` — plus counts and a `tokenEstimate`. The containers are **always present** (empty `[]`/`{}` when there's nothing), so an empty container is distinguishable from an unsupported one.
324
324
 
325
- **The token ledger reconciles `tokenEstimate` from the payload alone (flair#1270).** Every token-charged content class carries a counter — `soulTokens`, `memoryTokens`, `trustTokens`, `eventsTokens` — plus a measured `scaffoldTokens` for the fixed JSON frame, and `tokenEstimate ≈ scaffoldTokens + soulTokens + memoryTokens + trustTokens + eventsTokens`. The remaining ≈ gap is the bounded per-item difference between the prose lines the memory counters measure and the heavier structured objects the containers ship. A payload whose estimate an agent can't decompose from the reported figures is a bug, not an accounting convention.
325
+ **Skill assignments are reported in `skills` and `skillDiagnostics` (flair#2141).** A `skills` entry is `{ name, skillId, scope, priority, source }` for an assigned skill that won priority resolution; a `skillDiagnostics` entry is a refused, superseded, unresolved or ambiguous assignment with its `decision` and `reason`. Both arrays are present whatever `includeSoul` and `includeContext` say, and hold the entries admitted within the remaining token budget; `skillsTruncated` and `skillDiagnosticsTruncated` count the entries that did not fit. An entry names the skill and does not carry its procedure: fetch that with `skill_get` and the `skillId`, or over REST with a signed `GET /Memory/<skillId>`, which applies the same by-id read gate as `skill_get`. A name-only assignment that wins priority resolution resolves when the agent has exactly one live skill row of its own with that name (not archived, past `validTo` or past `expiresAt`); with none it is `unresolved`, with more than one `ambiguous`. An `OrgSkillAssignment` row is also a candidate when the target's Agent record has `kind` agent and `status` active (absent counts as agent and active); humans, deactivated principals and targets with no Agent record get no org candidates. A Soul `skill-assignment` row with `metadata.optOut: true` removes the org candidates with that name for that agent before priority resolution, when this instance's id can be read and the row's `originatorInstanceId` equals it. An org `skills` entry has `scope: "org"` and its `skillId` is the row's `skillRef`; an org assignment that wins priority resolution with a `skillRef` that is not a live skill row the agent can read is `unresolved`. The `name` and `source` strings come from Soul `skill-assignment` rows, and an org entry's `name` from its `OrgSkillAssignment` row; they reach the agent without SkillScan; that is safe only because no agent key can write those rows (admin agent keys included); only operator credentials and Flair's own internal paths can, so widening who may write them changes what reaches the agent's context.
326
+
327
+ **The token ledger reconciles `tokenEstimate` from the payload alone (flair#1270).** Every token-charged content class carries a counter — `soulTokens`, `memoryTokens`, `trustTokens`, `eventsTokens`, `skillsTokens`, `skillDiagnosticsTokens` — plus a measured `scaffoldTokens` for the fixed JSON frame, and `tokenEstimate ≈ scaffoldTokens + soulTokens + memoryTokens + trustTokens + eventsTokens + skillsTokens + skillDiagnosticsTokens`. At the `/mcp` default (`includeContext: false`) the remaining ≈ gap is the bounded per-item difference between the prose lines the memory counters measure and the heavier structured objects the containers ship; with `includeContext: true` the prose `context` mirror widens it and no upper bound applies. A payload whose estimate an agent can't decompose from the reported figures is a bug, not an accounting convention.
326
328
 
327
329
  **Empty containers say why they're empty (flair#1182).** When a structured container ships empty, the payload carries a short hint naming the reason and what fills it — `eventsHint`, `teammateFindingsHint`, `predictedHint`. This is present *only* when the container is empty, so a deliberately-empty container is never confused with a silent drop (a connector never has to diff against a previous payload to tell the two apart).
328
330
 
@@ -374,7 +376,7 @@ Future MCP-capable agent CLIs (and there are more landing every month) will work
374
376
 
375
377
  **"connection_error: could not reach Flair at http://127.0.0.1:19926".** The Flair server isn't running. Run `flair status` to check; `flair start` to bring it up.
376
378
 
377
- **"auth_error: …" on every call.** The agent identity doesn't match a registered key. Re-run `flair agent add <id>` (idempotent on re-add — won't lose existing memories). Against a hosted instance the same three shapes apply (record missing / key mismatch / config wrong), and a by-id 404 is fail-closed ownership, not an existence signal — [Hosted Flair auth](integrations.md#hosted-flair-auth--your-agent-got-a-404).
379
+ **"auth_error: …" on every call.** Read the reported cause. For `unknown_agent`, no Agent row exists: run `flair agent add <id>`. For `invalid_signature`, the signature did not verify against the stored public key. Check the signing key and the signed request first. For a confirmed key mismatch, `agent add` refuses a well-formed existing row. On the Flair host, `flair agent rotate-key <id>` writes a new private key on that host. That file must be on the client host before the MCP process can sign with it. `FLAIR_KEY_PATH` only names a path on the signing host; point it at that local file when the key is not in the default location, then restart the MCP process. `flair agent remove <id>` and then add again is the other path for a well-formed row. `flair agent remove` tries to delete that agent's Memory and Soul rows. Other auth errors follow the cause they name. A by-id 404 is fail-closed ownership, not an existence signal — [Hosted Flair auth](integrations.md#hosted-flair-auth--your-agent-got-a-404).
378
380
 
379
381
  **Tool calls succeed but the agent doesn't see results in subsequent turns.** Check that the CLI is actually invoking `bootstrap` at session start — most CLIs need an explicit prompt nudge ("call the bootstrap tool now") on first use. Subsequent turns should pick up automatically once the CLI sees the schema.
380
382
 
package/docs/releasing.md CHANGED
@@ -15,13 +15,8 @@ The staging tag is an **immutable property of the staged package** (`npm help st
15
15
  re-staging the same version under a different tag requires `npm stage reject` first.
16
16
  There is no "fix the stage in place" — you reject it and re-cut the next patch.
17
17
 
18
- > `flair-bench` is version-bumped and tagged in lockstep with the other 7, and stages in
19
- > its own step in CI for [historical reasons](#flair-bench-bootstrap-one-time-done). That
20
- > step is no longer allowed to fail: every already-published package must stage
21
- > for a release to pass.
22
-
23
18
  ```
24
- merge release PR ──▶ push tag v0.11.0 ──▶ CI stages all packages (tag: staged)
19
+ merge release PR ──▶ auto-tag v0.11.0 ──▶ CI stages all packages (tag: staged)
25
20
  │
26
21
  maintainer reviews + approves (2FA)
27
22
  ▼
@@ -35,12 +30,10 @@ There is no "fix the stage in place" — you reject it and re-cut the next patch
35
30
  latest moves
36
31
  ```
37
32
 
38
- Pushing a `vX.Y.Z` tag triggers the release. This replaces the old "run
33
+ The `vX.Y.Z` tag triggers the release. This replaces the old "run
39
34
  `release.sh --publish` from a laptop logged into npm" flow. Nothing publishes without
40
35
  a human 2FA approval, and every package ships with a provenance attestation (public
41
- repo → verifiable build origin). The person who tags the release does **not** need npm
42
- credentials or `Actions: write` — only repo push access; the only privileged step is
43
- the maintainer's 2FA approval.
36
+ repo → verifiable build origin).
44
37
 
45
38
  ## Cutting a release
46
39
 
@@ -50,8 +43,10 @@ the maintainer's 2FA approval.
50
43
  ./scripts/release.sh 0.11.0
51
44
  ```
52
45
 
53
- This assembles the changelog, bumps every workspace package to the version, aligns
54
- internal deps, refreshes `bun.lock`, builds, tests, and opens a `release: v0.11.0` PR.
46
+ This assembles the changelog, bumps the lockstep release packages (listed in
47
+ `scripts/release.sh`) to the version, aligns internal deps, refreshes `bun.lock`, builds,
48
+ tests, and opens a `release: v0.11.0` PR. The Cursor workspaces (`packages/cursor-flair`
49
+ and `packages/cursor-wake-runner`) keep their own versions.
55
50
  Review and merge it (CI green + K&S approval) the same as any other PR.
56
51
 
57
52
  **Nothing about the version is bumped by hand.** The version is declared outside
@@ -84,7 +79,7 @@ fragment directory is empty (nothing to release) or when someone hand-wrote an e
84
79
  ### Phase 2 — tag the release
85
80
 
86
81
  After a release PR merges to `main`, [Release auto-tag](../.github/workflows/release-auto-tag.yml)
87
- normally creates its tag after a successful push CI run, subject to the release checks.
82
+ normally creates its tag after a successful push CI run on `main`, subject to the release checks.
88
83
  If an allowlisted advisory job fails that CI run, the immediate path is skipped and
89
84
  nightly recovery makes the tag instead. It runs at **04:23 UTC daily**, so expect up
90
85
  to **24 hours plus run time**. It uses completed CI runs regardless of their overall
@@ -92,17 +87,17 @@ conclusion and tolerates only exact names in [the advisory allowlist](../.github
92
87
  All other release conditions must pass, and it targets the version still declared
93
88
  on `main`, so a newer version supersedes a missed release.
94
89
 
95
- To tag by hand, push the version tag:
90
+ If Release auto-tag refused, resolve what it reports; do not tag by hand. If it did not
91
+ run, a repository admin tags by hand (a ruleset restricts creating `v*` tags) once the
92
+ checks it applies pass. The first command must print nothing:
96
93
 
97
94
  ```bash
95
+ git ls-remote --tags origin v0.11.0
98
96
  git checkout main && git pull
99
97
  git tag v0.11.0 && git push origin v0.11.0
100
98
  ```
101
99
 
102
- > The [`release-auto-tag`](../.github/workflows/release-auto-tag.yml) workflow
103
- > normally pushes this tag for you once a release PR merges green (see
104
- > [#1928](https://github.com/tpsdev-ai/flair/issues/1928)); the hand-push above is
105
- > the manual fallback. When the release commit's tree carries
100
+ > When the release commit's tree carries
106
101
  > `packages/adk-flair/pyproject.toml` whose `[project].version` equals the version
107
102
  > being tagged, the auto-tagger ALSO creates `adk-flair-v<version>` from the same
108
103
  > commit — so the PyPI publish run then needs only the environment gate its owner
@@ -179,11 +174,11 @@ workflow, which:
179
174
  3. Verifies every lockstep package's `package.json` is at that version.
180
175
  4. Builds every package.
181
176
  5. Runs `npm stage publish` for each lockstep package in dependency order
182
- (flair-client first), then `flair-bench` in its own step. Any lockstep package
177
+ (flair-client first). Any lockstep package
183
178
  failing to stage fails the release.
184
179
 
185
180
  It authenticates via OIDC — no secrets, and it does **not** create or move any tag (the
186
- tag you pushed is the trigger). Watch the run; when it's green, the packages are staged
181
+ tag is the trigger). Watch the run; when it's green, the packages are staged
187
182
  but **not yet live**.
188
183
 
189
184
  In parallel — and **independent of the npm staging approval** — a `github-release` job
@@ -313,6 +308,15 @@ and 0.55.1's promote had to be assembled by hand, line by line, for this reason.
313
308
  It reads `dist-tags.latest` for every lockstep package and exits non-zero
314
309
  naming any that disagree (or that differ from `<ver>`). The canary runs the same
315
310
  check BEFORE the verdict, so a pre-existing skew is visible there too.
311
+
312
+ The promote block runs this check itself, in its wait mode (`--await 120`, with
313
+ each package's previous `latest`): it reads every `latest` from the registry's
314
+ dist-tags endpoint, re-reads a package that is not yet at `<ver>` until it is or
315
+ the wait ends, and exits 3 if every such package still reads its previous
316
+ `latest` at the end. On exit 3, re-run the command the block prints before
317
+ restoring anything. A run without `--await` reads the package document, which
318
+ the public registry serves from its CDN and which can still show the previous
319
+ `latest` for a short time after a move.
316
320
  - **On FAIL**, the version stays public but unpromoted. The canary emits one
317
321
  `npm deprecate` line per package; run them, then re-cut the next patch. A
318
322
  version is never refreshed in place.
@@ -351,10 +355,6 @@ published; since flair#1683 it is a
351
355
 
352
356
  ### `flair-bench` bootstrap (one-time, done)
353
357
 
354
- **Nothing to do here.** This section is kept because the next brand-new package added to
355
- the release set will hit the same wall, and because it explains why `flair-bench` still
356
- stages in its own workflow step.
357
-
358
358
  `flair-bench` (added 2026-07-12, flair#702) was wired into the version-bump/tag flow
359
359
  (`scripts/release.sh`, `release-publish.yml`'s version-check) alongside the other 7 before
360
360
  it existed on npm at all. That is a chicken-and-egg: `npm stage publish` categorically
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpsdev-ai/flair",
3
- "version": "0.58.0",
3
+ "version": "0.59.0",
4
4
  "packageManager": "bun@1.3.10",
5
5
  "description": "Identity, memory, and soul for AI agents. Cryptographic identity (Ed25519), semantic memory with local embeddings, and persistent personality — all in a single process.",
6
6
  "type": "module",
@@ -90,11 +90,12 @@
90
90
  "mysql2": "^3.22.0",
91
91
  "mariadb": "~3.4.7",
92
92
  "qs": "^6.16.0",
93
- "fastify": "^5.12.1",
93
+ "fastify": "^5.12.5",
94
94
  "lodash": "^4.18.0",
95
95
  "ip-address": "^10.5.1",
96
96
  "joi": "^17.13.7",
97
- "moment": "^2.31.0"
97
+ "moment": "^2.31.0",
98
+ "@grpc/grpc-js": "^1.14.5"
98
99
  },
99
100
  "devDependencies": {
100
101
  "@playwright/test": "1.59.1",
@@ -383,3 +383,34 @@ type Asset @table(database: "flair") @export {
383
383
  createdAt: String! @indexed
384
384
  updatedAt: String # stamped on write; later sweep key (nullable/additive)
385
385
  }
386
+
387
+ # OrgSkillAssignment — an org-scope skill assignment (flair#2141 S1):
388
+ # `skillRef`, under `skillName` and `priority`, for the agents on this
389
+ # instance that receive org skills (resources/skill-manifest.ts). No @export:
390
+ # the REST surface is resources/OrgSkillAssignment.ts, whose writes need the
391
+ # operator or internal source and server-stamp `writer`, `sourceClass`,
392
+ # `createdAt` and `updatedAt`. Instance-local: absent from the federation table
393
+ # policy.
394
+ type OrgSkillAssignment @table(database: "flair") {
395
+ id: ID @primaryKey
396
+ skillName: String! @indexed
397
+ skillRef: String!
398
+ priority: String! # critical | high | standard | low
399
+ createdAt: String!
400
+ updatedAt: String
401
+ writer: String # the operator's principal id; null for an internal write
402
+ sourceClass: String! # operator | internal
403
+ }
404
+
405
+ # OrgSkillAssignmentHistory — one row per accepted write through
406
+ # resources/OrgSkillAssignment.ts, appended in the write's transaction.
407
+ # No @export and no resource class: there is no direct /OrgSkillAssignmentHistory route.
408
+ type OrgSkillAssignmentHistory @table(database: "flair") {
409
+ id: ID @primaryKey
410
+ assignmentId: String! @indexed
411
+ op: String! # create | update | delete
412
+ actor: String # the writer; null for an internal write
413
+ sourceClass: String! # operator | internal
414
+ previousHash: String # sha256 of the stored row before the write; null on create
415
+ at: String!
416
+ }
@@ -48,11 +48,15 @@ type IdpConfig @table(database: "flair") @export {
48
48
  updatedAt: String
49
49
  }
50
50
 
51
- # ID-JAG replay prevention — tracks used `jti` claims.
52
- type IdJagReplay @table(database: "flair") {
51
+ # ID-JAG replay prevention — one row per used `jti`, written once per instance
52
+ # under a per-key lock by resources/replay-store.ts (claimIdJagJti).
53
+ # expiration: 90000 — seconds a newly recorded row is kept. It MUST equal
54
+ # ID_JAG_REPLAY_RETENTION_S in resources/XAA.ts, which says why it outlives
55
+ # every accepted assertion whose jti was recorded;
56
+ # test/unit-isolated/xaa-jti-replay.test.ts pins both.
57
+ type IdJagReplay @table(database: "flair", expiration: 90000) {
53
58
  id: ID @primaryKey # the jti value
54
- expiresAt: String! @indexed # TTL for cleanup
55
- createdAt: String!
59
+ seenAt: Long! # ms-epoch when recorded
56
60
  }
57
61
 
58
62
  # Access + refresh tokens.
@@ -25,25 +25,98 @@ ADMIN_PASS_FILE="$1"
25
25
  NODE="$2"
26
26
  HARPER_BIN="$3"
27
27
 
28
- # flair#2040: never start a SECOND instance on a data directory that a live
29
- # process already serves. `flair init`, and a `flair start`/`doctor --fix` that
30
- # fell back to a direct start, leave the instance running outside launchd with
31
- # this plist on disk (RunAtLoad + KeepAlive). When launchd later starts the job
32
- # — at the next console login, say — Harper's own "already running" check
33
- # (hdb.pid) would refuse, but only AFTER it has loaded its config and applied
34
- # HARPER_SET_CONFIG to the data directory's config state. Refuse here, before
35
- # Harper runs at all: no config load, no hdb.pid write, no port bind, no store
36
- # open, and the admin password is never read. Exit 0 — a deliberate no-op, not a
37
- # crash. KeepAlive makes launchd retry after its throttle interval (10 s by
38
- # default); once the direct process has exited, the next attempt starts Harper
39
- # and launchd owns the instance.
40
- # Mirrors Harper's getHdbPid(): a pid that is ours, 1, or not alive is no
41
- # evidence. ROOTPATH comes from the plist's EnvironmentVariables.
28
+ # flair#2056: is "$1", the command line `ps -o command=` reports (arguments
29
+ # joined by spaces), Harper-shaped? Its first word's basename is `node` or
30
+ # `bun`, and its second word is a Harper entry path:
31
+ # `…/node_modules/harper/dist/bin/harper.js`,
32
+ # `…/node_modules/@<scope>/harper/dist/bin/harper.js` or `dist/bin/harper.js`
33
+ # (what Harper's own restart forks). A second word starting with `-`, or a
34
+ # Harper path in a later word, does not match. Because ps joins arguments with
35
+ # spaces, this does not establish which argument is the script: an argument
36
+ # containing a space can produce a matching line. Nor does it show that the
37
+ # process serves anything. The CLI's check is isHarperProcessCommandLine in
38
+ # src/lib/daemon-liveness.ts.
39
+ is_harper_command() {
40
+ HC_LINE="$1"
41
+ HC_LINE="${HC_LINE#"${HC_LINE%%[! ]*}"}"
42
+ case "$HC_LINE" in *" "*) ;; *) return 1 ;; esac
43
+ HC_EXE="${HC_LINE%% *}"
44
+ HC_REST="${HC_LINE#* }"
45
+ HC_REST="${HC_REST#"${HC_REST%%[! ]*}"}"
46
+ HC_SCRIPT="${HC_REST%% *}"
47
+ case "${HC_EXE##*/}" in node|bun) ;; *) return 1 ;; esac
48
+ case "$HC_SCRIPT" in
49
+ -*) return 1 ;;
50
+ dist/bin/harper.js) return 0 ;;
51
+ */harper/dist/bin/harper.js) ;;
52
+ *) return 1 ;;
53
+ esac
54
+ HC_DIR="${HC_SCRIPT%/harper/dist/bin/harper.js}"
55
+ case "$HC_DIR" in node_modules|*/node_modules) return 0 ;; esac
56
+ HC_SCOPE="${HC_DIR##*/}"
57
+ HC_DIR="${HC_DIR%/*}"
58
+ case "$HC_SCOPE" in @?*) ;; *) return 1 ;; esac
59
+ case "$HC_DIR" in node_modules|*/node_modules) return 0 ;; esac
60
+ return 1
61
+ }
62
+
63
+ # flair#2040 / flair#2056: do not start a second Harper on a data directory
64
+ # whose hdb.pid names a live process with a Harper-shaped command line (see
65
+ # is_harper_command above for what that does and does not establish). `kill -0`
66
+ # alone proves only that SOME process has the pid: if a direct process dies and
67
+ # leaves hdb.pid behind, another process can later get that pid, and a refusal
68
+ # on `kill -0` alone would make every KeepAlive retry exit 0 without ever
69
+ # starting Flair.
70
+ #
71
+ # So the launcher refuses only when the command line `ps -o command=` reports
72
+ # for the live pid is Harper-shaped. A flair#1454 sidecar
73
+ # (`flair-daemon.json`) is not required: an instance started by a pre-sidecar
74
+ # flair, or the instance this launcher execs (Harper writes no sidecar), has
75
+ # none. A sidecar disagrees when it names a different pid, or a startTimeMs more
76
+ # than 2000 ms from the start second `ps -o lstart=` reports (ps reports whole
77
+ # seconds, so a process started at 12.9 s is compared as 12 s). When the
78
+ # sidecar disagrees, the launcher does not refuse and continues its normal
79
+ # start.
80
+ #
81
+ # Exit 0 on the refusal: a deliberate no-op, not a crash. KeepAlive retries
82
+ # after its throttle interval; once that process has exited, a retry does not
83
+ # refuse.
42
84
  if [ -n "${ROOTPATH:-}" ] && [ -f "$ROOTPATH/hdb.pid" ]; then
43
85
  LIVE_PID="$(tr -cd '0-9' < "$ROOTPATH/hdb.pid" 2>/dev/null || true)"
44
86
  if [ -n "$LIVE_PID" ] && [ "$LIVE_PID" != "$$" ] && [ "$LIVE_PID" -gt 1 ] 2>/dev/null && kill -0 "$LIVE_PID" 2>/dev/null; then
45
- echo "start-flair-with-admin-pass: $ROOTPATH is already served by pid $LIVE_PID (not started by this launchd job); not starting a second instance. launchd retries after its throttle interval and starts Flair once that process has exited." >&2
46
- exit 0
87
+ DISAGREE=0
88
+ SIDE="$ROOTPATH/flair-daemon.json"
89
+ if [ -f "$SIDE" ]; then
90
+ SIDE_PID="$(grep -o '"pid"[[:space:]]*:[[:space:]]*[0-9][0-9]*' "$SIDE" 2>/dev/null | grep -o '[0-9][0-9]*$' || true)"
91
+ SIDE_START="$(grep -o '"startTimeMs"[[:space:]]*:[[:space:]]*[0-9][0-9]*' "$SIDE" 2>/dev/null | grep -o '[0-9][0-9]*$' || true)"
92
+ # Shell arithmetic reads a leading 0 as octal: drop leading zeros, and
93
+ # leave the sidecar unused when nothing is left or more than 15 digits are.
94
+ SIDE_START="${SIDE_START#"${SIDE_START%%[!0]*}"}"
95
+ case "$SIDE_START" in ????????????????*) SIDE_START="" ;; esac
96
+ if [ -n "$SIDE_PID" ] && [ -n "$SIDE_START" ]; then
97
+ if [ "$SIDE_PID" != "$LIVE_PID" ]; then
98
+ DISAGREE=1
99
+ else
100
+ LSTART="$(ps -o lstart= -p "$LIVE_PID" 2>/dev/null || true)"
101
+ ACT_S=""
102
+ case "$(uname -s)" in
103
+ Darwin) if [ -n "$LSTART" ]; then ACT_S="$(date -j -f "%a %b %e %T %Y" "$LSTART" +%s 2>/dev/null || true)"; fi ;;
104
+ *) if [ -n "$LSTART" ]; then ACT_S="$(date -d "$LSTART" +%s 2>/dev/null || true)"; fi ;;
105
+ esac
106
+ if [ -n "$ACT_S" ]; then
107
+ # Milliseconds against the start second in milliseconds: a start
108
+ # second of 12 s against a sidecar of 14.5 s is 2500 ms.
109
+ DIFF_MS=$((SIDE_START - ACT_S * 1000))
110
+ if [ "$DIFF_MS" -lt 0 ]; then DIFF_MS=$((0 - DIFF_MS)); fi
111
+ if [ "$DIFF_MS" -gt 2000 ]; then DISAGREE=1; fi
112
+ fi
113
+ fi
114
+ fi
115
+ fi
116
+ if [ "$DISAGREE" = "0" ] && is_harper_command "$(ps -o command= -p "$LIVE_PID" 2>/dev/null || true)"; then
117
+ echo "start-flair-with-admin-pass: $ROOTPATH/hdb.pid names pid $LIVE_PID, whose command line as ps reports it is node or bun followed by a Harper entry path; not starting a second instance. launchd retries after its throttle interval." >&2
118
+ exit 0
119
+ fi
47
120
  fi
48
121
  fi
49
122