@tpsdev-ai/flair 0.59.0 → 0.63.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.
- package/README.md +10 -10
- package/SECURITY.md +49 -5
- package/config.yaml +23 -12
- package/dist/bridges/builtins/mem0.js +63 -28
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/runtime/import-runner.js +12 -0
- package/dist/bridges/runtime/load-plugin.js +42 -13
- package/dist/bridges/runtime/yaml-loader.js +4 -2
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1054 -367
- package/dist/commands/agent.js +233 -90
- package/dist/commands/attention.js +4 -3
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +211 -39
- package/dist/commands/bootstrap.js +3 -1
- package/dist/commands/bridge.js +172 -119
- package/dist/commands/deploy.js +71 -8
- package/dist/commands/doctor.js +711 -146
- package/dist/commands/export.js +57 -23
- package/dist/commands/federation.js +787 -82
- package/dist/commands/grant.js +5 -6
- package/dist/commands/help.js +25 -0
- package/dist/commands/hook.js +155 -2
- package/dist/commands/idp.js +27 -19
- package/dist/commands/import.js +136 -20
- package/dist/commands/init.js +469 -200
- package/dist/commands/integrity.js +387 -0
- package/dist/commands/keys.js +247 -58
- package/dist/commands/mcp.js +108 -52
- package/dist/commands/memory.js +203 -35
- package/dist/commands/migrate-harness-memory.js +3 -2
- package/dist/commands/orgevent.js +51 -47
- package/dist/commands/presence.js +4 -3
- package/dist/commands/principal.js +428 -62
- package/dist/commands/quality.js +13 -1
- package/dist/commands/reembed.js +141 -17
- package/dist/commands/relationship.js +2 -1
- package/dist/commands/rem.js +537 -80
- package/dist/commands/restore.js +413 -65
- package/dist/commands/search.js +6 -4
- package/dist/commands/service.js +235 -40
- package/dist/commands/soul.js +4 -9
- package/dist/commands/status.js +94 -38
- package/dist/commands/test.js +7 -3
- package/dist/commands/upgrade.js +77 -23
- package/dist/commands/workspace.js +13 -11
- package/dist/component-env.js +31 -41
- package/dist/deploy.js +136 -4
- package/dist/doctor-client.js +534 -92
- package/dist/engine-version-contract.js +1 -0
- package/dist/engine-version.js +23 -3
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation-verify.js +273 -180
- package/dist/hook-install.js +670 -6
- package/dist/install/clients.js +171 -35
- package/dist/keystore.js +72 -0
- package/dist/lib/action-recall-runtime.js +328 -0
- package/dist/lib/agent-home-fields.js +132 -0
- package/dist/lib/agent-home.js +427 -0
- package/dist/lib/agent-id-rule.js +88 -0
- package/dist/lib/agent-roster.js +33 -0
- package/dist/lib/atomic-write.js +1 -1
- package/dist/lib/auth-resolve.js +1069 -60
- package/dist/lib/backup-approval-store.js +612 -0
- package/dist/lib/backup-artifact.js +343 -0
- package/dist/lib/capture-runtime.js +124 -0
- package/dist/lib/config-critical-section.js +212 -25
- package/dist/lib/connect-phase.js +33 -0
- package/dist/lib/credential-status-rule.js +78 -0
- package/dist/lib/daemon-liveness.js +43 -11
- package/dist/lib/doctor-run.js +75 -37
- package/dist/lib/durability-copy.js +10 -0
- package/dist/lib/embedding-space-doctor.js +75 -0
- package/dist/lib/federation-pair-access.js +4 -0
- package/dist/lib/federation-retry-queue.js +283 -0
- package/dist/lib/federation-retry-row.js +101 -0
- package/dist/lib/flair-agent-role.js +4 -0
- package/dist/lib/hub-url.js +12 -0
- package/dist/lib/init-admin-pass.js +88 -12
- package/dist/lib/init-listener-environ.js +1 -2
- package/dist/lib/init-occupied-listener.js +15 -111
- package/dist/lib/init-spawn-attribution.js +73 -0
- package/dist/lib/init-tcp-probe.js +33 -0
- package/dist/lib/instance-identity-row.js +20 -0
- package/dist/lib/instruction-event-contract.js +17 -0
- package/dist/lib/instruction-event-doctor.js +102 -0
- package/dist/lib/launchd-management.js +38 -3
- package/dist/lib/listener-table.js +268 -0
- package/dist/lib/local-delete-instance.js +27 -0
- package/dist/lib/local-instance-pair.js +256 -0
- package/dist/lib/mcp-enable.js +1182 -341
- package/dist/lib/mcp-oauth-env-core.js +133 -0
- package/dist/lib/mcp-oauth-env.js +125 -0
- package/dist/lib/mcp-spec.js +17 -1
- package/dist/lib/memory-attributes.js +4 -0
- package/dist/lib/memory-id-policy.js +46 -0
- package/dist/lib/memory-integrity.js +309 -0
- package/dist/lib/memory-provider-timeout.js +33 -0
- package/dist/lib/memory-purge-response.js +20 -0
- package/dist/lib/mqtt-config.js +132 -0
- package/dist/lib/mqtt-listener-doctor.js +104 -0
- package/dist/lib/open-live-row.js +20 -0
- package/dist/lib/ops-table-count.js +25 -0
- package/dist/lib/ops-url.js +52 -0
- package/dist/lib/owned-pins.js +67 -10
- package/dist/lib/peer-status.js +27 -0
- package/dist/lib/principal-status.js +29 -0
- package/dist/lib/process-start-time.js +76 -12
- package/dist/lib/promotion-content-hash.js +20 -0
- package/dist/lib/proto-safe-record.js +42 -0
- package/dist/lib/record-id-path.js +25 -0
- package/dist/lib/reembed-server-support.js +66 -0
- package/dist/lib/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +104 -0
- package/dist/lib/scheduler-platform.js +10 -6
- package/dist/lib/secret-keys.js +25 -0
- package/dist/lib/secrets-push.js +50 -22
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed-pending.js +24 -0
- package/dist/lib/skill-seed.js +448 -0
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/stop-start-recovery.js +54 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/lib/using-flair-skill.js +87 -0
- package/dist/mcp-client-assertion.js +114 -14
- package/dist/memory-id-checkpoint.js +347 -0
- package/dist/memory-node-compare.js +207 -0
- package/dist/mqtt-off-deploy.js +550 -0
- package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
- package/dist/rem/promote-policy.js +3 -3
- package/dist/rem/restore.js +303 -26
- package/dist/rem/runner.js +317 -96
- package/dist/rem/scheduler.js +21 -4
- package/dist/resources/A2AAdapter.js +131 -178
- package/dist/resources/AdminMemory.js +2 -0
- package/dist/resources/AdminMemoryCandidates.js +116 -0
- package/dist/resources/Agent.js +463 -33
- package/dist/resources/AgentCard.js +4 -0
- package/dist/resources/AgentKeyRegister.js +248 -0
- package/dist/resources/AgentKeyRegistration.js +28 -0
- package/dist/resources/AgentReadPosition.js +7 -0
- package/dist/resources/AgentSeed.js +238 -107
- package/dist/resources/AutoPromoteCandidates.js +413 -78
- package/dist/resources/Credential.js +183 -10
- package/dist/resources/Federation.js +915 -145
- package/dist/resources/FederationRetry.js +140 -0
- package/dist/resources/InstructionVersion.js +220 -0
- package/dist/resources/Integration.js +300 -25
- package/dist/resources/MCPClientMetadata.js +6 -3
- package/dist/resources/Memory.js +3300 -758
- package/dist/resources/MemoryArchive.js +171 -53
- package/dist/resources/MemoryBootstrap.js +122 -61
- package/dist/resources/MemoryCandidate.js +37 -3
- package/dist/resources/MemoryConsolidate.js +2 -2
- package/dist/resources/MemoryDedupStats.js +30 -1
- package/dist/resources/MemoryFeed.js +545 -50
- package/dist/resources/MemoryGrant.js +21 -1
- package/dist/resources/MemoryMaintenance.js +368 -46
- package/dist/resources/MemoryPurge.js +348 -0
- package/dist/resources/MemoryReflect.js +71 -12
- package/dist/resources/MemoryReindex.js +111 -17
- package/dist/resources/Message.js +16 -5
- package/dist/resources/OAuth.js +342 -48
- package/dist/resources/OAuthClient.js +1 -1
- package/dist/resources/OrgEvent.js +405 -19
- package/dist/resources/OrgEventCatchup.js +7 -0
- package/dist/resources/OrgEventMaintenance.js +48 -10
- package/dist/resources/PairingToken.js +1 -1
- package/dist/resources/Presence.js +166 -51
- package/dist/resources/PromoteMemoryCandidate.js +24 -7
- package/dist/resources/RecordUsage.js +2 -4
- package/dist/resources/Relationship.js +23 -0
- package/dist/resources/SemanticSearch.js +63 -32
- package/dist/resources/Soul.js +191 -76
- package/dist/resources/SoulFeed.js +2 -1
- package/dist/resources/TeamDirectory.js +35 -0
- package/dist/resources/WorkspaceLatest.js +4 -0
- package/dist/resources/WorkspaceState.js +21 -1
- package/dist/resources/XAA.js +207 -63
- package/dist/resources/a2a-stream.js +313 -0
- package/dist/resources/a2a-url.js +4 -5
- package/dist/resources/agent-admin.js +10 -1
- package/dist/resources/agent-auth.js +138 -83
- package/dist/resources/agent-read-position-lib.js +4 -1
- package/dist/resources/agent-status-guard.js +9 -7
- package/dist/resources/auth-middleware.js +534 -171
- package/dist/resources/authority-field-guard.js +9 -11
- package/dist/resources/auto-promote-lib.js +8 -5
- package/dist/resources/basic-auth-header.js +21 -0
- package/dist/resources/bm25-index-service.js +4 -5
- package/dist/resources/dedup-cluster.js +6 -1
- package/dist/resources/ed25519-auth.js +1 -1
- package/dist/resources/embedding-space-guard.js +366 -72
- package/dist/resources/embeddings-provider.js +25 -0
- package/dist/resources/engine-version-stamp-boot.js +53 -0
- package/dist/resources/federation-classify.js +161 -0
- package/dist/resources/federation-crypto.js +5 -5
- package/dist/resources/federation-retry-lib.js +60 -0
- package/dist/resources/grant-visibility.js +135 -0
- package/dist/resources/harper-routing.js +83 -0
- package/dist/resources/health.js +163 -22
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- package/dist/resources/host-source-citation.js +49 -0
- package/dist/resources/host-source-visibility.js +7 -6
- package/dist/resources/in-process.js +24 -22
- package/dist/resources/instance-create-lock.js +17 -0
- package/dist/resources/instance-identity.js +23 -0
- package/dist/resources/instruction-version-record.js +587 -0
- package/dist/resources/internal-authority.js +13 -0
- package/dist/resources/key-lock.js +3 -3
- package/dist/resources/mcp-handler.js +141 -19
- package/dist/resources/mcp-oauth-env-guard.js +36 -0
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +450 -56
- package/dist/resources/mcp-tool-arguments.js +4 -6
- package/dist/resources/mcp-tools.js +187 -40
- package/dist/resources/memory-bootstrap-lib.js +5 -15
- package/dist/resources/memory-declared-attributes.js +4 -1
- package/dist/resources/memory-deletion-history.js +55 -0
- package/dist/resources/memory-durability.js +54 -0
- package/dist/resources/memory-embed-hash.js +144 -0
- package/dist/resources/memory-embedding-value.js +8 -0
- package/dist/resources/memory-host-source.js +32 -7
- package/dist/resources/memory-id-guard.js +75 -0
- package/dist/resources/memory-redaction.js +236 -0
- package/dist/resources/memory-reflect-lib.js +1 -1
- package/dist/resources/memory-supplied-vector.js +72 -0
- package/dist/resources/memory-write-lock.js +489 -0
- package/dist/resources/memory-write-response.js +139 -0
- package/dist/resources/memory-write-transaction.js +243 -0
- package/dist/resources/migration-boot.js +17 -12
- package/dist/resources/migrations/boot-progress.js +25 -0
- package/dist/resources/migrations/data-dir.js +90 -19
- package/dist/resources/migrations/dir-safety.js +61 -3
- package/dist/resources/migrations/embedding-stamp.js +462 -82
- package/dist/resources/migrations/export.js +1 -0
- package/dist/resources/migrations/graph-heal.js +27 -27
- package/dist/resources/migrations/ledger.js +5 -2
- package/dist/resources/migrations/lock.js +870 -77
- package/dist/resources/migrations/progress.js +71 -10
- package/dist/resources/migrations/runner.js +212 -18
- package/dist/resources/migrations/snapshot.js +1 -0
- package/dist/resources/migrations/source-fields.js +5 -5
- package/dist/resources/migrations/state.js +36 -1
- package/dist/resources/migrations/status.js +2 -13
- package/dist/resources/migrations/synthetic-test-migration.js +81 -12
- package/dist/resources/migrations/types.js +26 -1
- package/dist/resources/migrations/visibility-backfill.js +113 -72
- package/dist/resources/oauth-discovery.js +0 -5
- package/dist/resources/object-body-guard.js +40 -0
- package/dist/resources/org-event-created-at.js +133 -0
- package/dist/resources/org-event-reserved.js +92 -0
- package/dist/resources/org-event-write-fault.js +19 -0
- package/dist/resources/originator-instance.js +39 -7
- package/dist/resources/owner-delete-recheck.js +78 -0
- package/dist/resources/owner-field-guard.js +39 -5
- package/dist/resources/owner-scoped-write-policy.js +256 -0
- package/dist/resources/owner-scoped-writes.js +89 -0
- package/dist/resources/path-id-rewrite.js +76 -0
- package/dist/resources/presence-internal.js +5 -5
- package/dist/resources/presence-receipt.js +236 -0
- package/dist/resources/promotion-binding.js +43 -0
- package/dist/resources/promotion-stamp.js +143 -17
- package/dist/resources/protocol-context.js +189 -0
- package/dist/resources/record-owner-guard.js +74 -26
- package/dist/resources/record-type-kit.js +2 -4
- package/dist/resources/record-types.js +1 -1
- package/dist/resources/relay-ops.js +78 -6
- package/dist/resources/replay-store.js +96 -19
- package/dist/resources/request-target.js +163 -0
- package/dist/resources/request-transaction.js +46 -1
- package/dist/resources/search-readiness.js +4 -1
- package/dist/resources/seed-ids.js +9 -0
- package/dist/resources/seed-reservation.js +116 -0
- package/dist/resources/semantic-retrieval-core.js +27 -15
- package/dist/resources/server-row-validation.js +71 -0
- package/dist/resources/skill-manifest.js +24 -14
- package/dist/resources/skill-subject.js +53 -0
- package/dist/resources/skill-version-write.js +789 -0
- package/dist/resources/skill-write-fault.js +20 -0
- package/dist/resources/skill-write-policy.js +68 -0
- package/dist/resources/skill-write.js +67 -7
- package/dist/resources/soul-write-policy.js +26 -7
- package/dist/resources/table-helpers.js +10 -7
- package/dist/resources/table-subscription-policy.js +518 -85
- package/dist/resources/table-subscriptions.js +20 -7
- package/dist/resources/team-directory.js +248 -0
- package/dist/resources/tool-descriptors/index.js +69 -8
- package/dist/resources/txn-pause-point.js +235 -0
- package/dist/resources/usage-recording.js +186 -70
- package/dist/resources/write-back.js +383 -0
- package/dist/resources/write-journal-context.js +5 -0
- package/dist/resources/write-journal.js +289 -0
- package/dist/src/engine-version-contract.js +1 -0
- package/dist/src/keystore.js +72 -0
- package/dist/src/lib/agent-home-fields.js +132 -0
- package/dist/src/lib/agent-id-rule.js +88 -0
- package/dist/src/lib/agent-key-register.js +80 -0
- package/dist/src/lib/atomic-write.js +256 -0
- package/dist/src/lib/credential-status-rule.js +78 -0
- package/dist/src/lib/expired-by-agent.js +37 -0
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/flair-agent-role.js +4 -0
- package/dist/src/lib/idp-mapping-rule.js +81 -0
- package/dist/src/lib/instance-identity-row.js +20 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/mcp-oauth-env-core.js +133 -0
- package/dist/src/lib/memory-attributes.js +4 -0
- package/dist/src/lib/memory-id-policy.js +46 -0
- package/dist/src/lib/open-live-row.js +20 -0
- package/dist/src/lib/principal-status.js +29 -0
- package/dist/src/lib/proto-safe-record.js +42 -0
- package/dist/src/lib/reembed-server-support.js +66 -0
- package/dist/src/lib/scheduler-platform.js +10 -6
- package/dist/src/lib/soul-scope-fields.js +26 -0
- package/dist/src/lib/systemd-agent-id.js +38 -0
- package/dist/src/rem/promote-policy.js +3 -3
- package/dist/src/rem/scheduler.js +21 -4
- package/docs/access-control.md +164 -54
- package/docs/api-reference.md +165 -32
- package/docs/auth.md +46 -30
- package/docs/bridges.md +11 -0
- package/docs/claude-code.md +37 -7
- package/docs/deploying-on-fabric.md +178 -0
- package/docs/deployment.md +19 -0
- package/docs/embedding-in-a-harper-app.md +17 -15
- package/docs/entity-vocabulary.md +3 -6
- package/docs/federation.md +61 -3
- package/docs/hosted-on-fabric.md +43 -36
- package/docs/integrations.md +14 -14
- package/docs/mcp-clients.md +12 -7
- package/docs/n8n.md +17 -11
- package/docs/notes/mcp-agent-auth-consumer.md +16 -13
- package/docs/notes/mcp-oauth-model2.md +40 -11
- package/docs/openclaw.md +1 -1
- package/docs/quickstart-fabric.md +4 -4
- package/docs/quickstart.md +12 -4
- package/docs/releasing.md +25 -19
- package/docs/rem.md +32 -3
- package/docs/secrets-and-keys.md +21 -4
- package/docs/standalone-local.md +30 -2
- package/docs/supply-chain-policy.md +34 -16
- package/docs/the-team.md +2 -2
- package/docs/upgrade.md +46 -6
- package/package.json +24 -12
- package/schemas/agent-key-registration.graphql +22 -0
- package/schemas/agent.graphql +6 -3
- package/schemas/federation.graphql +41 -1
- package/schemas/memory.graphql +91 -7
- package/schemas/oauth.graphql +19 -0
- package/schemas/schema.graphql +2 -0
- package/templates/bin/flair-rem-nightly.sh.tmpl +7 -1
- package/templates/launchd/start-flair-with-admin-pass.sh +188 -10
- package/dist/resources/soul-adk-guard.js +0 -68
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* credential-status-rule.ts — the Credential-usability rule shared by the MCP
|
|
3
|
+
* credential resolver, the principal linker and the XAA jwt-bearer grant, from
|
|
4
|
+
* both the CLI (src/) and the server (resources/).
|
|
5
|
+
*
|
|
6
|
+
* A `Credential(kind:"idp")` is the mapping that turns an IdP subject into a
|
|
7
|
+
* flair principal. `resolveAgentFromSub` (resources/mcp-handler.ts) resolves a
|
|
8
|
+
* token subject through it at request time, `provisionIdpIdentityMapping`
|
|
9
|
+
* (src/lib/mcp-enable.ts) is the operator-facing layer that writes and
|
|
10
|
+
* maintains it (the MCP and XAA JIT provisioners also create one when their
|
|
11
|
+
* lookup finds none), and the XAA jwt-bearer grant (resources/XAA.ts,
|
|
12
|
+
* `resolveOrCreatePrincipalLocked`) resolves an ID-JAG subject through it.
|
|
13
|
+
* Before this module the resolver and the linker accepted every status except
|
|
14
|
+
* `"revoked"`, so a principal-bearing row with a missing, empty or unknown
|
|
15
|
+
* status was served as a live mapping; on the resolver's path a revoked row was
|
|
16
|
+
* also skipped, so it could re-create a principal when JIT provisioning was
|
|
17
|
+
* enabled. XAA already accepted only `"active"` (flair#2501). All three sites
|
|
18
|
+
* now use this module's shared rule for row usability.
|
|
19
|
+
*
|
|
20
|
+
* The rule is an ALLOWLIST: a credential is usable only when its `status` is
|
|
21
|
+
* exactly `"active"`. Missing, empty, `"revoked"` and any other value are not
|
|
22
|
+
* usable. All three sites apply `credentialMapsPrincipal`: the row must also
|
|
23
|
+
* name a principal, a non-empty string `principalId`. The schema requires
|
|
24
|
+
* `principalId` and Harper refuses a write that omits it, but it stores an
|
|
25
|
+
* empty string, and no site relies on the schema to exclude a row without one.
|
|
26
|
+
*
|
|
27
|
+
* Deliberately dependency-free (it imports nothing): the resource/CLI boundary
|
|
28
|
+
* guard (test/unit/resource-src-purity-1775.test.ts) requires every src/ module
|
|
29
|
+
* a resources/ file imports to emit no module loads, and src/ must never import
|
|
30
|
+
* harper.
|
|
31
|
+
*/
|
|
32
|
+
/** The only `status` value a Credential is usable with. */
|
|
33
|
+
export const CREDENTIAL_STATUS_ACTIVE = "active";
|
|
34
|
+
/**
|
|
35
|
+
* Is `cred` a credential this rule accepts as usable? Exactly
|
|
36
|
+
* `status === "active"`. A null/undefined credential, a missing status, an
|
|
37
|
+
* empty string, `"revoked"` and any other value are all not usable.
|
|
38
|
+
*/
|
|
39
|
+
export function isUsableCredential(cred) {
|
|
40
|
+
return cred?.status === CREDENTIAL_STATUS_ACTIVE;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The principal `cred` names: its `principalId` when that is a non-empty
|
|
44
|
+
* string, otherwise null. The resolver, the linker and XAA all decide "names
|
|
45
|
+
* no principal" with this one test.
|
|
46
|
+
*/
|
|
47
|
+
export function credentialPrincipalId(cred) {
|
|
48
|
+
const principalId = cred?.principalId;
|
|
49
|
+
return typeof principalId === "string" && principalId !== "" ? principalId : null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Does `cred` map a principal? It must be usable (`status === "active"`) and
|
|
53
|
+
* name a principal. Anything else maps nothing.
|
|
54
|
+
*/
|
|
55
|
+
export function credentialMapsPrincipal(cred) {
|
|
56
|
+
return isUsableCredential(cred) && credentialPrincipalId(cred) !== null;
|
|
57
|
+
}
|
|
58
|
+
/** How a refusal names the status it found: the stored value, or that none was there. */
|
|
59
|
+
function credentialStatusPhrase(status) {
|
|
60
|
+
return status === undefined || status === null ? "no status" : `status ${JSON.stringify(status)}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The named refusal for a Credential that maps no principal: it names the
|
|
64
|
+
* actor (the named credential — pass the surrounding subject too when the
|
|
65
|
+
* caller has one), the state (the stored status, or that there is none, and,
|
|
66
|
+
* when applicable, that it names no principal) and the remedy (an operator
|
|
67
|
+
* re-links the subject, which writes an active mapping that names its
|
|
68
|
+
* principal). The resolver builds its JSON-RPC refusal from this, so that
|
|
69
|
+
* wording has one home.
|
|
70
|
+
*/
|
|
71
|
+
export function credentialRefusal(actor, cred) {
|
|
72
|
+
const state = credentialPrincipalId(cred) === null
|
|
73
|
+
? `${credentialStatusPhrase(cred?.status)} and names no principal`
|
|
74
|
+
: credentialStatusPhrase(cred?.status);
|
|
75
|
+
return (`forbidden: ${actor} has ${state}; a Credential is usable only when its status is "active" and it names a ` +
|
|
76
|
+
"principal, so it was not used and nothing was written. An operator must re-link the credential " +
|
|
77
|
+
"(`flair mcp enable`, or `flair principal link`) to write an active mapping.");
|
|
78
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Named agents in the warning before the remainder is folded into a count. */
|
|
2
|
+
export const EXPIRED_BY_AGENT_NAMED_MAX = 5;
|
|
3
|
+
export function summarizeExpiredByAgent(counts, driver, max = EXPIRED_BY_AGENT_NAMED_MAX) {
|
|
4
|
+
const positive = [...counts].filter(([, n]) => n > 0);
|
|
5
|
+
const entries = positive.filter(([id]) => id !== "");
|
|
6
|
+
entries.sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
7
|
+
const keep = Math.max(0, max);
|
|
8
|
+
const named = entries.slice(0, keep);
|
|
9
|
+
const rest = entries.slice(keep);
|
|
10
|
+
const installedFor = (agentId) => driver.installed !== true ? driver.installed : driver.agentKnown ? agentId === driver.agent : null;
|
|
11
|
+
return {
|
|
12
|
+
agents: named.map(([agentId, count]) => ({ agentId, count, nightlyDriverInstalled: installedFor(agentId) })),
|
|
13
|
+
agentCount: entries.length,
|
|
14
|
+
total: positive.reduce((sum, [, n]) => sum + n, 0),
|
|
15
|
+
remainderCount: rest.reduce((sum, [, n]) => sum + n, 0),
|
|
16
|
+
unownedCount: positive.filter(([id]) => id === "").reduce((sum, [, n]) => sum + n, 0),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function expiredByAgentWarningLines(b) {
|
|
20
|
+
if (b.total === 0)
|
|
21
|
+
return "";
|
|
22
|
+
const lines = [" grouped by agent:\n"];
|
|
23
|
+
for (const a of b.agents) {
|
|
24
|
+
const state = a.nightlyDriverInstalled === true
|
|
25
|
+
? "installed nightly scheduler names this agent"
|
|
26
|
+
: a.nightlyDriverInstalled === false
|
|
27
|
+
? "NO matching installed nightly scheduler"
|
|
28
|
+
: "nightly driver state unknown";
|
|
29
|
+
lines.push(` ${a.agentId}: ${a.count} — ${state}\n`);
|
|
30
|
+
}
|
|
31
|
+
const remaining = b.agentCount - b.agents.length;
|
|
32
|
+
if (remaining > 0)
|
|
33
|
+
lines.push(` and ${remaining} more agent(s) (${b.remainderCount} expired rows)\n`);
|
|
34
|
+
if (b.unownedCount > 0)
|
|
35
|
+
lines.push(` ${b.unownedCount} expired row(s) with no agent id\n`);
|
|
36
|
+
return lines.join("");
|
|
37
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* federation-retry-row.ts — a federation retry row's key, outcome vocabulary
|
|
3
|
+
* and sender-convention check, in one module.
|
|
4
|
+
*
|
|
5
|
+
* Pure, DB-free and dependency-free: a resource imports it directly
|
|
6
|
+
* (resources/federation-retry-lib.ts re-exports it), and a src module that a
|
|
7
|
+
* resource imports must load no other module (test/unit/resource-src-purity-
|
|
8
|
+
* 1775.test.ts). The CLI build (src/) and the Harper resources share this one
|
|
9
|
+
* copy. The receiver's admin/read resources and the generic-Memory sender both
|
|
10
|
+
* classify rows with retryRowProblem: the retry selector excludes a malformed
|
|
11
|
+
* row, while an eligible cursor-selected source is still sent and its
|
|
12
|
+
* malformed retry row is left as stored. The reason vocabulary differs: the
|
|
13
|
+
* caller passes the predicate
|
|
14
|
+
* its own path uses (`isSkipReason` plus local reasons for a Harper resource;
|
|
15
|
+
* the sender's stricter pending-row list).
|
|
16
|
+
*/
|
|
17
|
+
// ─── Key ───
|
|
18
|
+
/**
|
|
19
|
+
* Encode the (peerId, table, recordId) tuple as the row's primary key.
|
|
20
|
+
*
|
|
21
|
+
* A JSON array join, never a bare concatenation: a naive `${peerId}${table}
|
|
22
|
+
* ${recordId}` collides (peer `a` + table `bc` is peer `ab` + table `c`), and
|
|
23
|
+
* peer and record ids are arbitrary strings off the wire, including legacy
|
|
24
|
+
* `.content`-suffixed ids. JSON quotes and escapes each component, so distinct
|
|
25
|
+
* tuples encode to distinct strings and the components round-trip exactly.
|
|
26
|
+
*
|
|
27
|
+
* Every component must be a non-empty string; a missing component is a caller
|
|
28
|
+
* bug, not a row to write, so this THROWS rather than mint a malformed key.
|
|
29
|
+
*/
|
|
30
|
+
export function retryEntryKey(peerId, table, recordId) {
|
|
31
|
+
for (const [name, value] of [
|
|
32
|
+
["peerId", peerId],
|
|
33
|
+
["table", table],
|
|
34
|
+
["recordId", recordId],
|
|
35
|
+
]) {
|
|
36
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
37
|
+
throw new Error(`federation retry: ${name} must be a non-empty string`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return JSON.stringify([peerId, table, recordId]);
|
|
41
|
+
}
|
|
42
|
+
/** Decode {@link retryEntryKey}'s output, or null when `id` is not a retry key. */
|
|
43
|
+
export function parseRetryEntryKey(id) {
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(id);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(parsed) || parsed.length !== 3)
|
|
52
|
+
return null;
|
|
53
|
+
const [peerId, table, recordId] = parsed;
|
|
54
|
+
if (typeof peerId !== "string" || typeof table !== "string" || typeof recordId !== "string")
|
|
55
|
+
return null;
|
|
56
|
+
if (peerId.length === 0 || table.length === 0 || recordId.length === 0)
|
|
57
|
+
return null;
|
|
58
|
+
return { peerId, table, recordId };
|
|
59
|
+
}
|
|
60
|
+
export const RETRY_RESOLUTIONS = new Set([
|
|
61
|
+
"merged",
|
|
62
|
+
"refused_terminal",
|
|
63
|
+
"source_deleted",
|
|
64
|
+
"source_ineligible",
|
|
65
|
+
"peer_unavailable",
|
|
66
|
+
"retry_exhausted",
|
|
67
|
+
]);
|
|
68
|
+
export const RETRY_BOUNDS = new Set(["attempts", "age", "both"]);
|
|
69
|
+
export function isRetryResolution(value) {
|
|
70
|
+
return typeof value === "string" && RETRY_RESOLUTIONS.has(value);
|
|
71
|
+
}
|
|
72
|
+
export function isRetryBound(value) {
|
|
73
|
+
return typeof value === "string" && RETRY_BOUNDS.has(value);
|
|
74
|
+
}
|
|
75
|
+
export function retryRowProblem(row, isKnownReason) {
|
|
76
|
+
let expectedId = null;
|
|
77
|
+
try {
|
|
78
|
+
expectedId = retryEntryKey(row.peerId, row.table, row.recordId);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
expectedId = null;
|
|
82
|
+
}
|
|
83
|
+
if (expectedId === null || row.id !== expectedId)
|
|
84
|
+
return "id_mismatch";
|
|
85
|
+
if (row.state !== "pending" && row.state !== "terminal")
|
|
86
|
+
return "unknown_state";
|
|
87
|
+
if (row.lastReason != null && !isKnownReason(row.lastReason))
|
|
88
|
+
return "unknown_reason";
|
|
89
|
+
if (row.state === "pending") {
|
|
90
|
+
if (row.resolution != null || row.bound != null)
|
|
91
|
+
return "outcome_mismatch";
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
if (!isRetryResolution(row.resolution))
|
|
95
|
+
return "outcome_mismatch";
|
|
96
|
+
const exhausted = row.resolution === "retry_exhausted";
|
|
97
|
+
if (exhausted ? !isRetryBound(row.bound) : row.bound != null)
|
|
98
|
+
return "outcome_mismatch";
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
@@ -79,6 +79,10 @@ export const FLAIR_AGENT_PERMISSION = {
|
|
|
79
79
|
// no write grant. The history table has no direct REST route.
|
|
80
80
|
OrgSkillAssignment: grant(true, false, false, false),
|
|
81
81
|
OrgSkillAssignmentHistory: grant(false, false, false, false),
|
|
82
|
+
// flair#2139 S1: instruction-version history. Read only — the resource
|
|
83
|
+
// itself denies every mutation verb to every principal, and the only
|
|
84
|
+
// application writer is the in-process append helper. See resources/InstructionVersion.ts.
|
|
85
|
+
InstructionVersion: grant(true, false, false, false),
|
|
82
86
|
// Federation / OAuth / IdP / internal — system + admin only; agents get none.
|
|
83
87
|
Peer: grant(false, false, false, false),
|
|
84
88
|
PairingToken: grant(false, false, false, false),
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* idp-mapping-rule.ts — which writes to an IdP identity mapping the Credential
|
|
3
|
+
* resource (resources/Credential.ts) reserves for an administrator or the
|
|
4
|
+
* server.
|
|
5
|
+
*
|
|
6
|
+
* An IdP identity mapping is a `Credential` row of kind "idp". The /mcp OAuth
|
|
7
|
+
* resolver (resources/mcp-handler.ts) resolves a token's subject to the
|
|
8
|
+
* principal named by the active idp row whose `idpSubject` is that subject,
|
|
9
|
+
* and the XAA jwt-bearer grant (resources/XAA.ts) resolves to the principal
|
|
10
|
+
* named by the active idp row whose `idpSubject` and `idpProvider` match the
|
|
11
|
+
* assertion and its IdP configuration ("active" is exactly the status
|
|
12
|
+
* src/lib/credential-status-rule.ts accepts). An administrator and trusted
|
|
13
|
+
* server code write those rows: the /mcp and XAA JIT provisioners in-process,
|
|
14
|
+
* and `flair mcp enable` / `flair principal link` through the operations API.
|
|
15
|
+
*
|
|
16
|
+
* Through the Credential resource, a caller that is neither an administrator
|
|
17
|
+
* nor trusted server code:
|
|
18
|
+
* - cannot create a kind:"idp" row;
|
|
19
|
+
* - cannot change a row's kind to or from "idp";
|
|
20
|
+
* - cannot change an idp row's principalId, idpProvider or idpSubject;
|
|
21
|
+
* - cannot change an idp row's status to anything but "revoked", so cannot
|
|
22
|
+
* reactivate one;
|
|
23
|
+
* - may relabel its own idp row, revoke it, and delete it (DELETE is the
|
|
24
|
+
* owner check's, not this rule's).
|
|
25
|
+
*
|
|
26
|
+
* Dependency-free (imports nothing): resources/ imports it, and the
|
|
27
|
+
* resource/CLI boundary guard (test/unit/resource-src-purity-1775.test.ts)
|
|
28
|
+
* requires such a module to emit no module loads.
|
|
29
|
+
*/
|
|
30
|
+
/** The Credential kind that is an IdP identity mapping. */
|
|
31
|
+
export const IDP_KIND = "idp";
|
|
32
|
+
/** The named refusal for a write this rule does not allow the caller. */
|
|
33
|
+
export const IDP_MAPPING_ADMIN_ONLY = "idp_mapping_admin_only";
|
|
34
|
+
/** The refusal's message. It names the rule and carries nothing from the request. */
|
|
35
|
+
export const IDP_MAPPING_REFUSAL_MESSAGE = 'forbidden: only an administrator or the server creates an IdP identity mapping (a Credential of kind "idp"), ' +
|
|
36
|
+
"changes its kind or identity fields, or reactivates it; a principal may relabel, revoke or delete its own";
|
|
37
|
+
/**
|
|
38
|
+
* The fields of an idp row, besides `kind` and `status`, that the two
|
|
39
|
+
* resolvers use to decide which principal a subject resolves to: the subject
|
|
40
|
+
* they match on (and, for XAA, the provider), and the principal the row names.
|
|
41
|
+
*/
|
|
42
|
+
export const IDP_MAPPING_IDENTITY_FIELDS = Object.freeze(["principalId", "idpProvider", "idpSubject"]);
|
|
43
|
+
/** The one status a non-admin may set on its own idp row. */
|
|
44
|
+
export const IDP_SELF_SERVICE_STATUS = "revoked";
|
|
45
|
+
/**
|
|
46
|
+
* Does `kind` name an idp row? Also true for a multi-valued kind that includes
|
|
47
|
+
* "idp", since an indexed attribute is matched per value.
|
|
48
|
+
*/
|
|
49
|
+
export function namesIdpKind(kind) {
|
|
50
|
+
return kind === IDP_KIND || (Array.isArray(kind) && kind.includes(IDP_KIND));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Is the field exactly as it was? A null and an absent value differ here, so
|
|
54
|
+
* a write that sets an absent field to null, or removes a null one, changes
|
|
55
|
+
* it. (An array kind is compared by reference: an array the write supplies
|
|
56
|
+
* differs from the stored one even when it holds the same items.)
|
|
57
|
+
*/
|
|
58
|
+
function sameValue(a, b) {
|
|
59
|
+
return a === b;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Would a write that turns `stored` into `next` create an IdP identity
|
|
63
|
+
* mapping, or change one in a way this rule reserves for administrators and
|
|
64
|
+
* the server? `stored` is the row before the write (null or undefined when
|
|
65
|
+
* the write creates it); `next` is the row as the write would store it. Pure.
|
|
66
|
+
*/
|
|
67
|
+
export function isIdpMappingChange(stored, next) {
|
|
68
|
+
// Neither side is a mapping: not this rule's business.
|
|
69
|
+
if (!namesIdpKind(stored?.kind) && !namesIdpKind(next?.kind))
|
|
70
|
+
return false;
|
|
71
|
+
// No stored row: the write creates a mapping.
|
|
72
|
+
if (!stored || !next)
|
|
73
|
+
return true;
|
|
74
|
+
// The kind (to or from "idp") and the identity fields are fixed.
|
|
75
|
+
for (const field of ["kind", ...IDP_MAPPING_IDENTITY_FIELDS]) {
|
|
76
|
+
if (!sameValue(stored[field], next[field]))
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
// The status may stay as it is or become "revoked".
|
|
80
|
+
return !sameValue(stored.status, next.status) && next.status !== IDP_SELF_SERVICE_STATUS;
|
|
81
|
+
}
|
|
@@ -503,6 +503,26 @@ export async function probeInstanceIdentity(endpoint) {
|
|
|
503
503
|
const roleNames = await readRoleNames(endpoint);
|
|
504
504
|
return { rows, roleNames };
|
|
505
505
|
}
|
|
506
|
+
export async function probeInstanceIds(endpoint) {
|
|
507
|
+
try {
|
|
508
|
+
const rows = await readInstanceRows(endpoint);
|
|
509
|
+
const ids = rows.map((r) => r.id);
|
|
510
|
+
try {
|
|
511
|
+
const parsed = await opsPost(endpoint, { operation: "sql", sql: "SELECT id FROM flair.Agent" }, "Agent read");
|
|
512
|
+
const agents = Array.isArray(parsed) ? parsed : Array.isArray(parsed?.results) ? parsed.results : null;
|
|
513
|
+
if (agents === null || agents.some((row) => typeof row?.id !== "string" || !row.id.trim())) {
|
|
514
|
+
throw new Error("Agent read returned no usable row list");
|
|
515
|
+
}
|
|
516
|
+
return { state: "read", ids, agentIds: agents.map((row) => row.id) };
|
|
517
|
+
}
|
|
518
|
+
catch (err) {
|
|
519
|
+
return { state: "read", ids, agentIds: null, agentReadReason: err instanceof Error ? err.message : String(err) };
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
catch (err) {
|
|
523
|
+
return { state: "unreadable", reason: err instanceof Error ? err.message : String(err) };
|
|
524
|
+
}
|
|
525
|
+
}
|
|
506
526
|
/**
|
|
507
527
|
* What a prune prints when it is about to delete rows (flair#1883 round 3).
|
|
508
528
|
*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* instruction-event-contract.ts — the shared reserved-event predicate
|
|
3
|
+
* (flair#2139 slice 3a). Kept in `src/lib` so both the OrgEvent resource and
|
|
4
|
+
* the `flair doctor` check import one definition without crossing the CLI
|
|
5
|
+
* build's rootDir.
|
|
6
|
+
*/
|
|
7
|
+
export const RESERVED_EVENT_KINDS = Object.freeze(["soul.changed", "skill.changed"]);
|
|
8
|
+
export const RESERVED_EVENT_ID_PREFIX = "instruction-change:";
|
|
9
|
+
/** Whether a record carries a reserved kind or id prefix. Non-records are not reserved. */
|
|
10
|
+
export function isReservedEventRecord(record) {
|
|
11
|
+
if (record == null || typeof record !== "object" || Array.isArray(record))
|
|
12
|
+
return false;
|
|
13
|
+
const { kind, id } = record;
|
|
14
|
+
if (typeof kind === "string" && RESERVED_EVENT_KINDS.includes(kind))
|
|
15
|
+
return true;
|
|
16
|
+
return typeof id === "string" && id.startsWith(RESERVED_EVENT_ID_PREFIX);
|
|
17
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/** The provider whose block the shipped `config.yaml` declares. */
|
|
2
|
+
export const SHIPPED_IDP_PROVIDER = "github";
|
|
3
|
+
/** Suffixes of the three per-provider variables, matching `buildSecretsBundle`
|
|
4
|
+
* (src/lib/mcp-enable.ts) and the shipped `config.yaml`. */
|
|
5
|
+
export const IDP_CLIENT_ID_SUFFIX = "_CLIENT_ID";
|
|
6
|
+
export const IDP_CLIENT_SECRET_SUFFIX = "_CLIENT_SECRET";
|
|
7
|
+
export const IDP_REDIRECT_URI_SUFFIX = "_REDIRECT_URI";
|
|
8
|
+
/** `OAUTH_<PROVIDER>` — the prefix every IdP variable shares. */
|
|
9
|
+
export function idpEnvPrefix(provider = SHIPPED_IDP_PROVIDER) {
|
|
10
|
+
return `OAUTH_${provider.toUpperCase()}`;
|
|
11
|
+
}
|
|
12
|
+
/** The three variable NAMES for a provider. */
|
|
13
|
+
export function idpEnvNames(provider = SHIPPED_IDP_PROVIDER) {
|
|
14
|
+
const prefix = idpEnvPrefix(provider);
|
|
15
|
+
return {
|
|
16
|
+
clientId: `${prefix}${IDP_CLIENT_ID_SUFFIX}`,
|
|
17
|
+
clientSecret: `${prefix}${IDP_CLIENT_SECRET_SUFFIX}`,
|
|
18
|
+
redirectUri: `${prefix}${IDP_REDIRECT_URI_SUFFIX}`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const PLACEHOLDER_RE = /^\$\{[^}]*\}$/;
|
|
22
|
+
/** Provider configuration checks treat blanks and whole-token `${VAR}` placeholders as missing. */
|
|
23
|
+
export function isUnresolvedEnvValue(value) {
|
|
24
|
+
if (value == null)
|
|
25
|
+
return true;
|
|
26
|
+
const trimmed = value.trim();
|
|
27
|
+
return trimmed === "" || PLACEHOLDER_RE.test(trimmed);
|
|
28
|
+
}
|
|
29
|
+
/** The strict read of `FLAIR_MCP_OAUTH` flair's own `/mcp` route uses
|
|
30
|
+
* (`resources/mcp-oauth-flag.ts`): 1/true/yes/on, case-insensitive. */
|
|
31
|
+
export function mcpOAuthEnabledIn(env) {
|
|
32
|
+
const raw = (env.FLAIR_MCP_OAUTH ?? "").trim().toLowerCase();
|
|
33
|
+
return raw === "1" || raw === "true" || raw === "yes" || raw === "on";
|
|
34
|
+
}
|
|
35
|
+
export function issuerFromEnv(env) {
|
|
36
|
+
const raw = env.FLAIR_MCP_ISSUER;
|
|
37
|
+
return isUnresolvedEnvValue(raw) ? null : raw.trim();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The locally inferred `FLAIR_MCP_OAUTH` for an instance, decided the way Harper's
|
|
41
|
+
* shipped `loadEnv` settings decide it: the component `.env` beside `config.yaml`
|
|
42
|
+
* (flair#1152 makes the on/off choice live there, not in the packed file),
|
|
43
|
+
* overlaid with the process environment, which wins.
|
|
44
|
+
*
|
|
45
|
+
* `envText` is the `.env` content or null when there is none; `overlay` is the
|
|
46
|
+
* environment to prefer (the operator's `process.env` for `flair doctor`). This
|
|
47
|
+
* decides only report severity. With no readable file, the overlay decides.
|
|
48
|
+
*/
|
|
49
|
+
export function mcpOAuthEnabledFromComponentEnv(envText, overlay = {}) {
|
|
50
|
+
const env = { ...parseMcpComponentEnv(envText ?? "") };
|
|
51
|
+
for (const [key, value] of Object.entries(overlay))
|
|
52
|
+
if (value !== undefined)
|
|
53
|
+
env[key] = value;
|
|
54
|
+
return mcpOAuthEnabledIn(env);
|
|
55
|
+
}
|
|
56
|
+
export function validateRedirectIssuer(issuer) {
|
|
57
|
+
if (isUnresolvedEnvValue(issuer))
|
|
58
|
+
return { redirect: null, reason: "missing-issuer" };
|
|
59
|
+
let url;
|
|
60
|
+
try {
|
|
61
|
+
url = new URL(issuer);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return { redirect: null, reason: "invalid-origin" };
|
|
65
|
+
}
|
|
66
|
+
if (url.username || url.password || /^[a-z]+:\/\/[^/?#]*@/i.test(issuer.trim()))
|
|
67
|
+
return { redirect: null, reason: "origin-has-userinfo" };
|
|
68
|
+
if (issuer.includes("\\"))
|
|
69
|
+
return { redirect: null, reason: "origin-has-path" };
|
|
70
|
+
if (url.search)
|
|
71
|
+
return { redirect: null, reason: "origin-has-query" };
|
|
72
|
+
if (url.hash)
|
|
73
|
+
return { redirect: null, reason: "origin-has-fragment" };
|
|
74
|
+
const suffix = /^[a-z]+:\/\/[^/?#]+(.*)$/i.exec(issuer.trim())?.[1];
|
|
75
|
+
if (suffix !== "" && suffix !== "/")
|
|
76
|
+
return { redirect: null, reason: "origin-has-path" };
|
|
77
|
+
const loopback = url.hostname === "localhost" || url.hostname === "[::1]" || /^127\.\d+\.\d+\.\d+$/.test(url.hostname);
|
|
78
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
|
|
79
|
+
return { redirect: null, reason: "origin-requires-https" };
|
|
80
|
+
}
|
|
81
|
+
return { redirect: `${url.origin}/oauth` };
|
|
82
|
+
}
|
|
83
|
+
export function redirectUriForIssuer(issuer) {
|
|
84
|
+
return validateRedirectIssuer(issuer).redirect;
|
|
85
|
+
}
|
|
86
|
+
export function readMcpProviderReadiness(env, provider = SHIPPED_IDP_PROVIDER) {
|
|
87
|
+
const names = idpEnvNames(provider);
|
|
88
|
+
return {
|
|
89
|
+
credentialsPresent: !isUnresolvedEnvValue(env[names.clientId]) && !isUnresolvedEnvValue(env[names.clientSecret]),
|
|
90
|
+
redirectPresent: !isUnresolvedEnvValue(env[names.redirectUri]),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export function guardMcpOAuthEnv(env, provider = SHIPPED_IDP_PROVIDER) {
|
|
94
|
+
const names = idpEnvNames(provider);
|
|
95
|
+
if (!isUnresolvedEnvValue(env[names.redirectUri]))
|
|
96
|
+
return { degraded: false, neutralizedVars: [] };
|
|
97
|
+
const credVars = [names.clientId, names.clientSecret];
|
|
98
|
+
const credentialsPresent = credVars.every((k) => !isUnresolvedEnvValue(env[k]));
|
|
99
|
+
if (!credentialsPresent)
|
|
100
|
+
return { degraded: false, neutralizedVars: [] };
|
|
101
|
+
for (const k of credVars)
|
|
102
|
+
delete env[k];
|
|
103
|
+
return {
|
|
104
|
+
degraded: true,
|
|
105
|
+
reason: `${names.redirectUri} is not set, so the ${provider} OAuth provider cannot be configured`,
|
|
106
|
+
neutralizedVars: credVars,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function describeMcpRedirectFinding(readiness) {
|
|
110
|
+
if (!readiness)
|
|
111
|
+
return { isIssue: false, message: "MCP OAuth redirect: cannot verify target configuration" };
|
|
112
|
+
if (!readiness.credentialsPresent || readiness.redirectPresent)
|
|
113
|
+
return null;
|
|
114
|
+
const names = idpEnvNames();
|
|
115
|
+
return {
|
|
116
|
+
isIssue: true,
|
|
117
|
+
message: `${names.redirectUri} is missing from the target's github OAuth configuration`,
|
|
118
|
+
fixHint: `set ${names.redirectUri} in the instance environment, or re-run: flair mcp enable; then restart`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export function parseMcpComponentEnv(text) {
|
|
122
|
+
const assignments = /^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?$/gm;
|
|
123
|
+
const values = {};
|
|
124
|
+
for (const match of text.replace(/\r\n?/g, "\n").matchAll(assignments)) {
|
|
125
|
+
let value = (match[2] ?? "").trim();
|
|
126
|
+
const quote = value[0];
|
|
127
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
|
|
128
|
+
if (quote === '"')
|
|
129
|
+
value = value.replace(/\\n/g, "\n").replace(/\\r/g, "\r");
|
|
130
|
+
values[match[1]] = value;
|
|
131
|
+
}
|
|
132
|
+
return values;
|
|
133
|
+
}
|
|
@@ -14,6 +14,7 @@ export const DECLARED_MEMORY_ATTRIBUTES = Object.freeze([
|
|
|
14
14
|
"visibility",
|
|
15
15
|
"embedding",
|
|
16
16
|
"embeddingModel",
|
|
17
|
+
"embeddedContentHash",
|
|
17
18
|
"tags",
|
|
18
19
|
"durability",
|
|
19
20
|
"source",
|
|
@@ -25,9 +26,11 @@ export const DECLARED_MEMORY_ATTRIBUTES = Object.freeze([
|
|
|
25
26
|
"retrievalCount",
|
|
26
27
|
"lastRetrieved",
|
|
27
28
|
"usageCount",
|
|
29
|
+
"writeBackWriteId",
|
|
28
30
|
"promotionStatus",
|
|
29
31
|
"promotedAt",
|
|
30
32
|
"promotedBy",
|
|
33
|
+
"promotionContentHash",
|
|
31
34
|
"archived",
|
|
32
35
|
"archivedAt",
|
|
33
36
|
"archivedBy",
|
|
@@ -45,6 +48,7 @@ export const DECLARED_MEMORY_ATTRIBUTES = Object.freeze([
|
|
|
45
48
|
"originatorInstanceId",
|
|
46
49
|
"metadata",
|
|
47
50
|
"entities",
|
|
51
|
+
"skillSubjectId",
|
|
48
52
|
]);
|
|
49
53
|
/** Pre-existing UNDECLARED attributes the codebase deliberately stores on a
|
|
50
54
|
* Memory row and must keep (the guard's job is the POINTER, not these).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory-id-policy.ts — the Memory record-id rule for the `.content` selector
|
|
3
|
+
* (flair#2199). PURE: string/decoding logic only. Deliberately imports nothing
|
|
4
|
+
* (resources importing this compiled helper require it to be load-free).
|
|
5
|
+
*/
|
|
6
|
+
export const MEMORY_CONTENT_SELECTOR_SUFFIX = ".content";
|
|
7
|
+
/**
|
|
8
|
+
* True when `id` is a Memory record id ending in the `.content` property
|
|
9
|
+
* suffix. Only a string can carry the suffix; a non-string id (Harper allows
|
|
10
|
+
* numeric ids) returns false.
|
|
11
|
+
*/
|
|
12
|
+
export function endsWithContentSelectorSuffix(id) {
|
|
13
|
+
return typeof id === "string" && id.endsWith(MEMORY_CONTENT_SELECTOR_SUFFIX);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* True when an id segment (the raw, still-percent-encoded last path segment of
|
|
17
|
+
* a Memory request) contains an encoded `/`, in any case (`%2F` / `%2f`).
|
|
18
|
+
*/
|
|
19
|
+
export function idSegmentHasEncodedSlash(segment) {
|
|
20
|
+
// Match an encoded slash in the segment as sent, and in its DECODED form — so
|
|
21
|
+
// a `%2f`/`%2F` in any case, and a slash encoded one level deeper
|
|
22
|
+
// (`%252F`, whose decoded form still carries `%2f`), both count. Deciding on
|
|
23
|
+
// the decoded segment is the same decode-then-scan the property-suffix rule
|
|
24
|
+
// uses, so the two agree on how a segment is read.
|
|
25
|
+
return /%2f/i.test(segment) || /%2f/i.test(decodeMemoryIdSegment(segment));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decode one path segment the way Harper decodes a request path before its
|
|
29
|
+
* property parse (`RequestTarget` decodes the path). Returns the raw segment
|
|
30
|
+
* when it is not valid percent-encoding, so a caller here never throws on it.
|
|
31
|
+
* Such a Memory request whose last segment ends in `.content` is refused by
|
|
32
|
+
* the auth middleware with the named 400 (`memory_id_content_suffix`) before
|
|
33
|
+
* any auth branch; another malformed segment is left to Harper's own path
|
|
34
|
+
* handling.
|
|
35
|
+
*
|
|
36
|
+
* Shared so the resource-layer guard and the auth middleware decode a URL-bound
|
|
37
|
+
* id the SAME way (flair#2199 follow-up).
|
|
38
|
+
*/
|
|
39
|
+
export function decodeMemoryIdSegment(raw) {
|
|
40
|
+
try {
|
|
41
|
+
return decodeURIComponent(raw);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return raw;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* open-live-row.ts — the skill writer's "open live" Memory-row predicate
|
|
3
|
+
* (flair#2662), shared so `flair doctor` asks the same question the writer
|
|
4
|
+
* answers. It checks the row's fields and the current time (for `expiresAt`). Deliberately imports nothing (resources
|
|
5
|
+
* importing this compiled helper require it to be load-free).
|
|
6
|
+
*
|
|
7
|
+
* A row is open-live when it is not archived, is not expired (`expiresAt`
|
|
8
|
+
* absent, or a string later than now), and carries no `validTo`.
|
|
9
|
+
*/
|
|
10
|
+
export function isOpenLiveRow(row) {
|
|
11
|
+
if (!row || typeof row !== "object")
|
|
12
|
+
return false;
|
|
13
|
+
if (row.archived === true)
|
|
14
|
+
return false;
|
|
15
|
+
if (row.expiresAt != null && (typeof row.expiresAt !== "string" || !(Date.parse(row.expiresAt) > Date.now())))
|
|
16
|
+
return false;
|
|
17
|
+
if (typeof row.validTo === "string" && row.validTo.length > 0)
|
|
18
|
+
return false;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* principal-status.ts — the ONE "is this principal deactivated?" predicate
|
|
3
|
+
* (flair#2378).
|
|
4
|
+
*
|
|
5
|
+
* `Agent.status` is a principal's lifecycle state. The auth path decides it
|
|
6
|
+
* here: a principal is deactivated when `status` is present and is not exactly
|
|
7
|
+
* "active". An ABSENT (undefined) `status` means active.
|
|
8
|
+
*
|
|
9
|
+
* The human-readable `flair principal show` and `principal list` outputs call
|
|
10
|
+
* this function and read the principal as stored — `show` over REST, `list` from an
|
|
11
|
+
* unprojected row — so an absent `status` (active) stays distinct from an
|
|
12
|
+
* explicit `null`, which the gate treats as deactivated.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately dependency-free (no `harper`, no resource) so both the CLI
|
|
15
|
+
* (`src/`) and the server (`resources/`) import it: `src/` must not import
|
|
16
|
+
* `resources/`, because those imports do not survive npm packaging.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* True iff this principal is deactivated: its `status` is present and is not
|
|
20
|
+
* exactly the string "active". A null/undefined principal, or one whose
|
|
21
|
+
* `status` is undefined, is not deactivated.
|
|
22
|
+
*/
|
|
23
|
+
export function isPrincipalDeactivated(agent) {
|
|
24
|
+
if (agent == null)
|
|
25
|
+
return false;
|
|
26
|
+
if (agent.status === undefined)
|
|
27
|
+
return false;
|
|
28
|
+
return agent.status !== "active";
|
|
29
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* proto-safe-record.ts — shared helper for these converted sites, copying own
|
|
3
|
+
* keys into a null-prototype record, entry by entry (flair#2235).
|
|
4
|
+
*
|
|
5
|
+
* Why this exists. A copy built with `Object.assign(target, source)` or an
|
|
6
|
+
* explicit `target[key] = value` loop goes through [[Set]]. For the key
|
|
7
|
+
* `__proto__` on a plain object that runs the inherited `Object.prototype`
|
|
8
|
+
* accessor instead of creating a key, so an own `__proto__` key is either
|
|
9
|
+
* turned into the copy's prototype (object value) or dropped (primitive
|
|
10
|
+
* value). A comparison or checkpoint that reads the copy then silently
|
|
11
|
+
* ignores a value the source carried (flair#2225, #2233).
|
|
12
|
+
*
|
|
13
|
+
* The copy here is built on `Object.create(null)` and each entry is defined as
|
|
14
|
+
* an OWN property with `Object.defineProperty`, so every own enumerable string
|
|
15
|
+
* key it copies survives, `__proto__` included, and the copy can never inherit
|
|
16
|
+
* a prototype it did not ask for.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Build a null-prototype record from `source`, own key by own key. Each key is
|
|
20
|
+
* defined as an own enumerable property, so `__proto__` is a data key and never
|
|
21
|
+
* the record's prototype. With `validate`, the first refused value throws a
|
|
22
|
+
* `TypeError` naming the key, with no record returned.
|
|
23
|
+
*/
|
|
24
|
+
export function protoSafeRecord(source, options = {}) {
|
|
25
|
+
const src = source;
|
|
26
|
+
const keys = options.keys ?? Object.keys(src);
|
|
27
|
+
const out = Object.create(null);
|
|
28
|
+
for (const key of keys) {
|
|
29
|
+
const raw = src[key];
|
|
30
|
+
const refused = options.validate?.(raw, key);
|
|
31
|
+
if (refused !== undefined) {
|
|
32
|
+
throw new TypeError(`protoSafeRecord: refused value for "${key}": ${refused}`);
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(out, key, {
|
|
35
|
+
value: options.map ? options.map(raw, key) : raw,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|