@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,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The embedding provider's write refusal, shared by the writers that retry it.
|
|
3
|
+
*
|
|
4
|
+
* The server answers `503` with error code `memory_provider_timeout` when the
|
|
5
|
+
* provider did not answer within its bound. The write-lock contract states
|
|
6
|
+
* such a refusal wrote nothing, so replaying the write with the same id
|
|
7
|
+
* cannot double-write the row.
|
|
8
|
+
*/
|
|
9
|
+
import { ApiHttpError, apiErrorRawBody } from "./auth-resolve.js";
|
|
10
|
+
/** Base wait before a retry of a memory write refused with `503 memory_provider_timeout`. */
|
|
11
|
+
export const MEMORY_PROVIDER_RETRY_DELAY_MS = 1_000;
|
|
12
|
+
/**
|
|
13
|
+
* The server's `error` code on an `ApiHttpError`, parsed from the response body
|
|
14
|
+
* that error carries (`apiErrorRawBody`; the message is never read). Returns
|
|
15
|
+
* undefined for a non-HTTP error, an error that carries no body, or a body
|
|
16
|
+
* without a string `error` field.
|
|
17
|
+
*/
|
|
18
|
+
export function apiErrorCode(err) {
|
|
19
|
+
const text = apiErrorRawBody(err);
|
|
20
|
+
if (text === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
const body = JSON.parse(text);
|
|
24
|
+
return body && typeof body === "object" && typeof body.error === "string" ? body.error : undefined;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** A memory write refused with exactly 503 and `memory_provider_timeout`. */
|
|
31
|
+
export function isProviderTimeoutRefusal(err) {
|
|
32
|
+
return err instanceof ApiHttpError && err.status === 503 && apiErrorCode(err) === "memory_provider_timeout";
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ids a POST /MemoryPurge response lists as removed. Throws when the
|
|
3
|
+
* response is not `{ removed, removedIds }` with `removed` equal to the list's
|
|
4
|
+
* length, or when the list leaves out a requested id.
|
|
5
|
+
*/
|
|
6
|
+
export function confirmedPurgeIds(response, requested) {
|
|
7
|
+
const body = response;
|
|
8
|
+
const removedIds = body?.removedIds;
|
|
9
|
+
if (!Array.isArray(removedIds) ||
|
|
10
|
+
!removedIds.every((id) => typeof id === "string") ||
|
|
11
|
+
body?.removed !== removedIds.length) {
|
|
12
|
+
throw new Error(`POST /MemoryPurge returned a response that does not list the removed rows: ${String(JSON.stringify(response)).slice(0, 200)}`);
|
|
13
|
+
}
|
|
14
|
+
const removed = new Set(removedIds);
|
|
15
|
+
const unconfirmed = requested.filter((id) => !removed.has(id));
|
|
16
|
+
if (unconfirmed.length > 0) {
|
|
17
|
+
throw new Error(`POST /MemoryPurge did not list ${unconfirmed.length} requested row(s) as removed: ${unconfirmed.slice(0, 5).join(", ")}`);
|
|
18
|
+
}
|
|
19
|
+
return removedIds;
|
|
20
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mqtt-config.ts — the MQTT-off configuration flair runs Harper with, in the
|
|
3
|
+
* two shapes Harper accepts it, and the reading of an instance's `mqtt`
|
|
4
|
+
* configuration section.
|
|
5
|
+
*
|
|
6
|
+
* Flair does not use MQTT. Harper's mqtt component (server/mqtt.ts
|
|
7
|
+
* `handleApplication`) binds a TCP listener on `mqtt.network.port` (1883) and
|
|
8
|
+
* a TLS listener on `mqtt.network.securePort` (8883) whenever EITHER is truthy
|
|
9
|
+
* (`if (port || securePort)`), plus a WebSocket upgrade path on the HTTP port
|
|
10
|
+
* when `mqtt.webSocket` is true. Nulling only `network.port` leaves
|
|
11
|
+
* `network.securePort` at its 8883 default, so the TLS listener still binds.
|
|
12
|
+
* Fully disabling MQTT requires nulling BOTH ports and turning off the
|
|
13
|
+
* WebSocket path.
|
|
14
|
+
*
|
|
15
|
+
* Where it is applied:
|
|
16
|
+
* - flair's local spawns: the HARPER_SET_CONFIG builders (src/cli.ts,
|
|
17
|
+
* src/commands/init.ts) carry MQTT_DISABLED_CONFIG, and the direct-spawn
|
|
18
|
+
* environment and launchd plist re-assert it with MQTT_* variables;
|
|
19
|
+
* - a component deployment (`flair deploy`, `flair upgrade --target`):
|
|
20
|
+
* src/mqtt-off-deploy.ts sends MQTT_DISABLED_SET_CONFIGURATION to the
|
|
21
|
+
* target's operations API before the deploy, requests the shared worker
|
|
22
|
+
* threads' restart when the application is isolated, and after the
|
|
23
|
+
* deploy's restart reads the saved configuration back, which must be a
|
|
24
|
+
* recognizable root configuration (rootConfigurationProblem) showing
|
|
25
|
+
* those values (mqttOffConfirmed). It does not probe the listeners. A
|
|
26
|
+
* component's own config.yaml cannot set it: `mqtt` is a section of the
|
|
27
|
+
* instance's root configuration, not of an application's.
|
|
28
|
+
* `flair doctor` reports an instance whose saved configuration starts an MQTT
|
|
29
|
+
* listener (src/lib/mqtt-listener-doctor.ts); it reads the configuration, not
|
|
30
|
+
* the running listeners.
|
|
31
|
+
*
|
|
32
|
+
* Note: config-root.schema.json still documents a flat `mqtt.port` /
|
|
33
|
+
* `mqtt.securePort`, but the runtime reads the nested `mqtt.network.*` form
|
|
34
|
+
* (see static/defaultConfig.yaml) — the flat keys are stale.
|
|
35
|
+
*/
|
|
36
|
+
import { harperPortValue } from "./harper-port-value.js";
|
|
37
|
+
/** Harper's `mqtt` configuration section with every MQTT listener off. */
|
|
38
|
+
export const MQTT_DISABLED_CONFIG = {
|
|
39
|
+
network: { port: null, securePort: null },
|
|
40
|
+
webSocket: false,
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* MQTT_DISABLED_CONFIG as the operations API's `set_configuration`
|
|
44
|
+
* parameters: Harper's flattened config names, each set on its own, so the
|
|
45
|
+
* rest of the instance's `mqtt` section (requireAuthentication, mtls) is left
|
|
46
|
+
* as it is.
|
|
47
|
+
*/
|
|
48
|
+
export const MQTT_DISABLED_SET_CONFIGURATION = Object.freeze({
|
|
49
|
+
mqtt_network_port: MQTT_DISABLED_CONFIG.network.port,
|
|
50
|
+
mqtt_network_securePort: MQTT_DISABLED_CONFIG.network.securePort,
|
|
51
|
+
mqtt_webSocket: MQTT_DISABLED_CONFIG.webSocket,
|
|
52
|
+
});
|
|
53
|
+
function isObject(value) {
|
|
54
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Why `config` is not taken for an instance's root configuration (the
|
|
58
|
+
* operations API's `get_configuration` answer), or null when it is: it must be
|
|
59
|
+
* an object with an object `http`, an object `operationsApi` and a non-empty
|
|
60
|
+
* string `rootPath`, which every root configuration Harper returns carries.
|
|
61
|
+
* It checks only those three fields: an answer missing any of them (`{}`, an
|
|
62
|
+
* error object) is refused, and nothing is concluded from it; any object that
|
|
63
|
+
* carries all three is accepted, whatever else it lacks.
|
|
64
|
+
*/
|
|
65
|
+
export function rootConfigurationProblem(config) {
|
|
66
|
+
if (!isObject(config))
|
|
67
|
+
return "the answer is not an object";
|
|
68
|
+
const missing = [
|
|
69
|
+
isObject(config.http) ? null : "http",
|
|
70
|
+
isObject(config.operationsApi) ? null : "operationsApi",
|
|
71
|
+
typeof config.rootPath === "string" && config.rootPath !== "" ? null : "rootPath",
|
|
72
|
+
].filter((m) => m !== null);
|
|
73
|
+
return missing.length ? `it has no ${missing.join(", ")}` : null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The MQTT listeners Harper starts for an instance whose root configuration
|
|
77
|
+
* holds `config` (the operations API's `get_configuration` answer), in
|
|
78
|
+
* Harper's own terms: none when the configuration has no `mqtt` section
|
|
79
|
+
* (Harper does not load the component), a WebSocket path when
|
|
80
|
+
* `mqtt.webSocket` is truthy, a TCP listener when `mqtt.network.port` is
|
|
81
|
+
* truthy and a TLS listener when `mqtt.network.securePort` is. Returns a
|
|
82
|
+
* description of each, empty when MQTT is off.
|
|
83
|
+
*/
|
|
84
|
+
export function mqttListenersOn(config) {
|
|
85
|
+
const mqtt = isObject(config) ? config.mqtt : undefined;
|
|
86
|
+
if (!isObject(mqtt))
|
|
87
|
+
return [];
|
|
88
|
+
const listeners = [];
|
|
89
|
+
if (mqtt.webSocket)
|
|
90
|
+
listeners.push("MQTT over WebSocket on the HTTP port (mqtt.webSocket)");
|
|
91
|
+
const network = isObject(mqtt.network) ? mqtt.network : {};
|
|
92
|
+
// A port is printed only as the integer it parses to; any other value is not.
|
|
93
|
+
const portText = (value) => {
|
|
94
|
+
const port = harperPortValue(value);
|
|
95
|
+
return port === null ? "" : ` ${port}`;
|
|
96
|
+
};
|
|
97
|
+
if (network.port)
|
|
98
|
+
listeners.push(`MQTT on TCP port${portText(network.port)} (mqtt.network.port)`);
|
|
99
|
+
if (network.securePort)
|
|
100
|
+
listeners.push(`MQTT on TLS port${portText(network.securePort)} (mqtt.network.securePort)`);
|
|
101
|
+
return listeners;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Why `config` (a `get_configuration` answer read after the MQTT-off
|
|
105
|
+
* configuration was set) does not show those values, or null when it does:
|
|
106
|
+
* an `mqtt` section whose `network.port` and `network.securePort` are null and
|
|
107
|
+
* whose `webSocket` is false. Unlike mqttListenersOn, an empty or malformed
|
|
108
|
+
* answer is not taken for "off". The reason names fixed field names and
|
|
109
|
+
* categories only ("mqtt.webSocket is not false"), never a value the answer
|
|
110
|
+
* carries.
|
|
111
|
+
*/
|
|
112
|
+
export function mqttOffConfirmed(config) {
|
|
113
|
+
if (!isObject(config))
|
|
114
|
+
return "the answer is not a configuration object";
|
|
115
|
+
const mqtt = config.mqtt;
|
|
116
|
+
if (!isObject(mqtt))
|
|
117
|
+
return "the answer has no mqtt section";
|
|
118
|
+
const problems = [];
|
|
119
|
+
if (mqtt.webSocket !== false)
|
|
120
|
+
problems.push(mqtt.webSocket === undefined ? "mqtt.webSocket is missing" : "mqtt.webSocket is not false");
|
|
121
|
+
const network = mqtt.network;
|
|
122
|
+
if (!isObject(network)) {
|
|
123
|
+
problems.push("mqtt.network is missing");
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
if (network.port !== null)
|
|
127
|
+
problems.push(network.port === undefined ? "mqtt.network.port is missing" : "mqtt.network.port is not null");
|
|
128
|
+
if (network.securePort !== null)
|
|
129
|
+
problems.push(network.securePort === undefined ? "mqtt.network.securePort is missing" : "mqtt.network.securePort is not null");
|
|
130
|
+
}
|
|
131
|
+
return problems.length ? problems.join(", ") : null;
|
|
132
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mqtt-listener-doctor.ts — the `flair doctor` check that reports when the
|
|
3
|
+
* saved configuration of the instance it inspects starts an MQTT listener.
|
|
4
|
+
*
|
|
5
|
+
* Flair runs Harper with MQTT off (src/lib/mqtt-config.ts): its local spawns
|
|
6
|
+
* assert it, and `flair deploy` / `flair upgrade --target` set it on a
|
|
7
|
+
* component deployment and request the restart that applies it. This check reads the
|
|
8
|
+
* instance's root configuration through the operations API
|
|
9
|
+
* (`get_configuration`) and names each MQTT listener that configuration starts
|
|
10
|
+
* — the TCP and TLS listeners and the WebSocket path — with the operation that
|
|
11
|
+
* sets them off in the configuration, as Flair sets them by default. It never
|
|
12
|
+
* changes the configuration.
|
|
13
|
+
*
|
|
14
|
+
* It reads the CONFIGURATION, not the running listeners: Harper applies a
|
|
15
|
+
* changed `mqtt` section when the HTTP worker threads restart, so worker
|
|
16
|
+
* threads that have not restarted since it changed may still serve their
|
|
17
|
+
* previous listener configuration. The section says so on every path, including the NOT RUN
|
|
18
|
+
* ones doctor prints itself (src/commands/doctor.ts), and names how to
|
|
19
|
+
* confirm on a node: connect an MQTT client to its MQTT ports or WebSocket
|
|
20
|
+
* path. Flair does not probe the listeners.
|
|
21
|
+
*
|
|
22
|
+
* The read answers "not run" when it fails or when the answer is not a
|
|
23
|
+
* recognizable root configuration (rootConfigurationProblem: an answer without
|
|
24
|
+
* an object `http`, an object `operationsApi` and a non-empty string
|
|
25
|
+
* `rootPath`, such as `{}`, a lone `mqtt` section or an error object; an object
|
|
26
|
+
* carrying all three is accepted, whatever else it lacks), so a doctor that
|
|
27
|
+
* cannot establish the configuration reports the check as NOT RUN and counts
|
|
28
|
+
* it, rather than passing it.
|
|
29
|
+
*/
|
|
30
|
+
import { MQTT_DISABLED_SET_CONFIGURATION, mqttListenersOn, rootConfigurationProblem } from "./mqtt-config.js";
|
|
31
|
+
/** The doctor line when the instance's configuration starts no MQTT listener. */
|
|
32
|
+
export const MQTT_LISTENERS_OFF_LINE = "No MQTT listener is configured on this instance (mqtt.network.port, mqtt.network.securePort and mqtt.webSocket are off).";
|
|
33
|
+
/** What every MQTT line adds: the check reads the saved configuration, not the running listeners, and how to confirm on a node. */
|
|
34
|
+
export const MQTT_CONFIGURATION_NOTE = "This reads the saved configuration, not the running listeners: worker threads that have not restarted since it changed may still serve their previous listener configuration. " +
|
|
35
|
+
"To confirm on a node, connect an MQTT client to its MQTT ports or WebSocket path.";
|
|
36
|
+
/** The set_configuration call that sets every MQTT listener off in the configuration, as an operator would send it. */
|
|
37
|
+
export function mqttOffOperation() {
|
|
38
|
+
return JSON.stringify({ operation: "set_configuration", ...MQTT_DISABLED_SET_CONFIGURATION });
|
|
39
|
+
}
|
|
40
|
+
/** The doctor finding for an instance configuration: null when no MQTT listener is on. */
|
|
41
|
+
export function describeMqttListenerFinding(config) {
|
|
42
|
+
const listeners = mqttListenersOn(config);
|
|
43
|
+
if (listeners.length === 0)
|
|
44
|
+
return null;
|
|
45
|
+
return {
|
|
46
|
+
message: `This instance's configuration starts ${listeners.length === 1 ? "an MQTT listener" : `${listeners.length} MQTT listeners`}: ${listeners.join("; ")}. Flair sets MQTT off in Harper's configuration by default.`,
|
|
47
|
+
fixHint: `send ${mqttOffOperation()} to the operations API: it sets every MQTT listener off in the configuration, as Flair does by default ` +
|
|
48
|
+
"(flair's local spawns on every start; flair deploy and flair upgrade --target for a component deployment). The listeners stop when Harper's worker threads restart, so restart them.",
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read the instance's root configuration through the operations API. A
|
|
53
|
+
* redirect is not followed: any 3xx answer is NOT RUN (named by its status;
|
|
54
|
+
* the location it names is not printed and receives nothing), so the check
|
|
55
|
+
* reads only the endpoint it was given.
|
|
56
|
+
*/
|
|
57
|
+
export async function readInstanceConfiguration(args) {
|
|
58
|
+
const fetchImpl = args.fetchImpl ?? fetch;
|
|
59
|
+
let res;
|
|
60
|
+
try {
|
|
61
|
+
res = await fetchImpl(args.opsUrl, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: { "Content-Type": "application/json", Authorization: args.authHeader },
|
|
64
|
+
body: JSON.stringify({ operation: "get_configuration" }),
|
|
65
|
+
signal: AbortSignal.timeout(args.timeoutMs ?? 5000),
|
|
66
|
+
redirect: "manual",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return { kind: "not-run", reason: "the configuration read failed" };
|
|
71
|
+
}
|
|
72
|
+
if (res.status >= 300 && res.status < 400) {
|
|
73
|
+
return { kind: "not-run", reason: `the configuration read was answered with a redirect (HTTP ${res.status}), which is not followed` };
|
|
74
|
+
}
|
|
75
|
+
if (!res.ok)
|
|
76
|
+
return { kind: "not-run", reason: `the configuration read was answered HTTP ${res.status}` };
|
|
77
|
+
let data;
|
|
78
|
+
try {
|
|
79
|
+
data = await res.json();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return { kind: "not-run", reason: "the configuration answer is not JSON" };
|
|
83
|
+
}
|
|
84
|
+
const problem = rootConfigurationProblem(data);
|
|
85
|
+
if (problem)
|
|
86
|
+
return { kind: "not-run", reason: `the answer is not a recognizable root configuration (${problem})` };
|
|
87
|
+
return { kind: "ok", config: data };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The doctor's "MQTT listeners (configuration)" section for a configuration
|
|
91
|
+
* read: `ok` with the all-off line, `issue` with the listeners on and the fix,
|
|
92
|
+
* or `not-run` with why the configuration could not be established; each with
|
|
93
|
+
* MQTT_CONFIGURATION_NOTE (the configuration, not the running listeners).
|
|
94
|
+
* Doctor counts every status but `ok` as an issue.
|
|
95
|
+
*/
|
|
96
|
+
export function mqttListenerSection(read) {
|
|
97
|
+
if (read.kind === "not-run") {
|
|
98
|
+
return { status: "not-run", line: `MQTT listeners: NOT RUN — ${read.reason}, so the MQTT listener configuration check did not run.`, note: MQTT_CONFIGURATION_NOTE };
|
|
99
|
+
}
|
|
100
|
+
const finding = describeMqttListenerFinding(read.config);
|
|
101
|
+
if (!finding)
|
|
102
|
+
return { status: "ok", line: MQTT_LISTENERS_OFF_LINE, note: MQTT_CONFIGURATION_NOTE };
|
|
103
|
+
return { status: "issue", line: finding.message, note: MQTT_CONFIGURATION_NOTE, fix: finding.fixHint };
|
|
104
|
+
}
|
|
@@ -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,25 @@
|
|
|
1
|
+
export async function readExactTableCount(opsPost, table) {
|
|
2
|
+
const parsed = await opsPost({ operation: "describe_table", database: "flair", table, exact_count: true }, `${table} row count`);
|
|
3
|
+
const n = parsed?.record_count;
|
|
4
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
5
|
+
throw new Error(`${table} row count via the operations API: response carried no record_count`);
|
|
6
|
+
}
|
|
7
|
+
return n;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The exact count of the rows a bounded table read matches — those with
|
|
11
|
+
* `attribute` at or after `since` — through the operations API (`describe_table`
|
|
12
|
+
* counts a whole table, not a range). The bounded deletion-history read is
|
|
13
|
+
* bracketed against this the way a whole-table read is bracketed against
|
|
14
|
+
* `readExactTableCount`: a result the count does not match is a read error, never
|
|
15
|
+
* a history that would read as an unexplained loss.
|
|
16
|
+
*/
|
|
17
|
+
export async function readExactCountSince(opsPost, table, attribute, since) {
|
|
18
|
+
const parsed = await opsPost({ operation: "sql", sql: `SELECT COUNT(*) AS n FROM flair.${table} WHERE ${attribute} >= '${since}'` }, `${table} bounded row count`);
|
|
19
|
+
const row = Array.isArray(parsed) ? parsed[0] : Array.isArray(parsed?.results) ? parsed.results[0] : undefined;
|
|
20
|
+
const n = row?.n;
|
|
21
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
22
|
+
throw new Error(`${table} bounded row count via the operations API: response carried no n`);
|
|
23
|
+
}
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ops-url.ts — derive a remote instance's operations API URL from its Flair
|
|
3
|
+
* base URL, the way every remote flair command does (resolveEffectiveOpsUrl in
|
|
4
|
+
* src/cli.ts, which also honours --ops-target / FLAIR_OPS_TARGET). Shared by
|
|
5
|
+
* src/cli.ts and the deploy channel (src/deploy.ts).
|
|
6
|
+
*/
|
|
7
|
+
/** The default operations API port for a self-hosted instance on plain HTTP with no explicit port. */
|
|
8
|
+
export const DEFAULT_OPS_PORT = 19925;
|
|
9
|
+
/** The operations API port of a Harper Fabric cluster. */
|
|
10
|
+
export const FABRIC_OPS_PORT = 9925;
|
|
11
|
+
/** Derive the ops API URL from a Flair base URL.
|
|
12
|
+
* https with effective port 443 (no explicit port, or explicit :443): returns
|
|
13
|
+
* <host>:9925 (FABRIC_OPS_PORT) — the Fabric managed case where port-1/:442
|
|
14
|
+
* is a dead-end.
|
|
15
|
+
* All other cases unchanged:
|
|
16
|
+
* https with non-443 explicit port → port-1 (self-hosted TLS: 19926→19925, 8443→8442)
|
|
17
|
+
* http with explicit port → port-1 (19926→19925)
|
|
18
|
+
* http with no port → DEFAULT_OPS_PORT (19925)
|
|
19
|
+
* Bare hosts are normalised to https:// (effective-443 → Fabric path).
|
|
20
|
+
* Throws on unparseable URLs or out-of-range ports.
|
|
21
|
+
*/
|
|
22
|
+
export function resolveOpsUrlFromTarget(targetUrl) {
|
|
23
|
+
// Normalise bare hosts: add https:// prefix so URL parser can handle them.
|
|
24
|
+
const normalised = targetUrl.includes("://") ? targetUrl : `https://${targetUrl}`;
|
|
25
|
+
const url = new URL(normalised);
|
|
26
|
+
// https target with effective port 443 (no explicit port, or explicit :443):
|
|
27
|
+
// this is the Fabric managed case — the ops API is on the well-known Fabric
|
|
28
|
+
// ops port, never REST-adjacent. The port-1 / :442 logic is a dead-end here.
|
|
29
|
+
if (url.protocol === "https:" && (url.port === "" || url.port === "443")) {
|
|
30
|
+
url.port = String(FABRIC_OPS_PORT);
|
|
31
|
+
return url.toString().replace(/\/$/, "");
|
|
32
|
+
}
|
|
33
|
+
// All other cases: unchanged port-1 convention.
|
|
34
|
+
// https with non-443 explicit port → port-1 (self-hosted TLS: 19926→19925, 8443→8442)
|
|
35
|
+
// http with explicit port → port-1 (19926→19925)
|
|
36
|
+
// http with no port → DEFAULT_OPS_PORT (19925)
|
|
37
|
+
const port = parseInt(url.port, 10);
|
|
38
|
+
if (!isNaN(port) && port > 0 && port <= 65535) {
|
|
39
|
+
const opsPort = port - 1;
|
|
40
|
+
if (opsPort < 1)
|
|
41
|
+
throw new Error(`Derived ops port ${opsPort} is out of range; target port must be > 1`);
|
|
42
|
+
url.port = String(opsPort);
|
|
43
|
+
return url.toString().replace(/\/$/, "");
|
|
44
|
+
}
|
|
45
|
+
// No valid explicit port — reject port 0 or out-of-range
|
|
46
|
+
if (url.port !== "" && url.port !== undefined) {
|
|
47
|
+
throw new Error(`Invalid target port: ${url.port} (must be 1-65535)`);
|
|
48
|
+
}
|
|
49
|
+
// No explicit port on http — use the default ops port.
|
|
50
|
+
url.port = String(DEFAULT_OPS_PORT);
|
|
51
|
+
return url.toString().replace(/\/$/, "");
|
|
52
|
+
}
|
package/dist/lib/owned-pins.js
CHANGED
|
@@ -17,7 +17,7 @@ import { existsSync, lstatSync, readFileSync, statSync } from "node:fs";
|
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
18
|
import { withHome } from "./home.js";
|
|
19
19
|
import { ALL_CLIENTS, clientConfigPath, codexWiringPin, repinCodexPin, repinJsonMcpPin, } from "../install/clients.js";
|
|
20
|
-
import { checkSessionStartHook, isFlairHookCommand, SESSION_START_HOOK_INVOCATION_RE, readClientMcpBlock, } from "../doctor-client.js";
|
|
20
|
+
import { checkSessionStartHook, fixSessionStartHook, hookHarnessFromSettingsPath, isFlairHookCommand, SESSION_START_HOOK_INVOCATION_RE, readClientMcpBlock, sessionStartHookHint, } from "../doctor-client.js";
|
|
21
21
|
import { decodeWiringSpec, decodeWiringSpecs, isComparableWiringPin, wiringPinString, } from "./wiring-spec.js";
|
|
22
22
|
import { isUnsafeAdapterPin } from "./stale-client-pin.js";
|
|
23
23
|
import { hookInstallHint, parseInstallerHookForm, hookSettingsPath, repinSessionStartHook, SUPPORTED_HARNESSES, } from "../hook-install.js";
|
|
@@ -68,15 +68,46 @@ function readFileText(path) {
|
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
const SESSION_START_HOOK_INVOCATIONS_RE = new RegExp(SESSION_START_HOOK_INVOCATION_RE.source, "g");
|
|
72
|
+
/** Read the pin named by a captured installer span or matching command text.
|
|
73
|
+
* Hold multiple `npx -y -p <spec>` spans or a pin without a matching span. */
|
|
74
|
+
function hookInvocationSpec(command) {
|
|
75
|
+
const invocations = (command.match(/\bnpx -y -p (?=\S)/g) ?? []).length;
|
|
76
|
+
if (invocations > 1)
|
|
77
|
+
return { spec: null, invocations, held: true };
|
|
78
|
+
const form = parseInstallerHookForm(command);
|
|
79
|
+
if (form)
|
|
80
|
+
return { spec: form.pkgSpec, invocations, held: false };
|
|
81
|
+
const matches = command.match(SESSION_START_HOOK_INVOCATIONS_RE) ?? [];
|
|
82
|
+
if (invocations === 1 && matches.length === 1) {
|
|
83
|
+
return { spec: matches[0].slice("npx -y -p ".length, -" flair-session-start".length), invocations, held: false };
|
|
84
|
+
}
|
|
85
|
+
const pinned = decodeWiringSpecs(command, FLAIR_MCP_PACKAGE).some((s) => wiringPinString(s) !== null);
|
|
86
|
+
return { spec: null, invocations, held: pinned };
|
|
87
|
+
}
|
|
71
88
|
export function readOwnedPin(target, homeDir) {
|
|
72
89
|
if (target.kind === "session-start-hook") {
|
|
73
90
|
const hook = checkSessionStartHook(homeDir, target.path);
|
|
74
|
-
|
|
91
|
+
// flair#2291: more than one marker match is held, the writer's own rule
|
|
92
|
+
// (repinSessionStartHook holds on it too).
|
|
93
|
+
const duplicates = hook.present && (hook.matches ?? 1) > 1;
|
|
94
|
+
const present = duplicates || !!(hook.present && hook.command && isFlairHookCommand(hook.command));
|
|
95
|
+
if (!present)
|
|
96
|
+
return { target, present, entryExists: present, pin: null };
|
|
97
|
+
const span = duplicates ? null : hookInvocationSpec(hook.command);
|
|
98
|
+
const held = duplicates
|
|
99
|
+
? `${hook.matches} Flair SessionStart hooks match in ${target.displayPath} — pin not read, not re-pinned; remove all but one`
|
|
100
|
+
: span.held
|
|
101
|
+
? span.invocations === 1
|
|
102
|
+
? `No \`npx -y -p\` span invokes Flair in ${target.displayPath} — pin not read, not re-pinned; use \`npx -y -p ${FLAIR_MCP_PACKAGE} flair-session-start\``
|
|
103
|
+
: `${span.invocations} \`npx -y -p\` spans in ${target.displayPath} — pin not read, not re-pinned; edit the hook to one`
|
|
104
|
+
: undefined;
|
|
75
105
|
return {
|
|
76
106
|
target,
|
|
77
107
|
present,
|
|
78
108
|
entryExists: present,
|
|
79
|
-
pin:
|
|
109
|
+
pin: held || !span || span.spec === null ? null : wiringPinString(decodeWiringSpec(span.spec, FLAIR_MCP_PACKAGE)),
|
|
110
|
+
...(held ? { held } : {}),
|
|
80
111
|
};
|
|
81
112
|
}
|
|
82
113
|
const block = readClientMcpBlock(target.id, homeDir);
|
|
@@ -227,10 +258,41 @@ export function pinDirection(pin, target) {
|
|
|
227
258
|
* surface with its own rendering.
|
|
228
259
|
*/
|
|
229
260
|
export function sessionStartHookPinFindings(homeDir, expectedVersion = flairCliVersion()) {
|
|
230
|
-
|
|
261
|
+
const stale = staleSessionStartHookPins(homeDir, expectedVersion).map((reading) => ({
|
|
231
262
|
reading,
|
|
232
263
|
direction: pinDirection(reading.pin, expectedVersion),
|
|
233
264
|
}));
|
|
265
|
+
// flair#2291: a HELD hook (no pin read) is a finding too, direction "unknown".
|
|
266
|
+
const held = listOwnedPinTargets(homeDir)
|
|
267
|
+
.filter((t) => t.kind === "session-start-hook")
|
|
268
|
+
.map((t) => readOwnedPin(t, homeDir))
|
|
269
|
+
.filter((r) => r.held)
|
|
270
|
+
.map((reading) => ({ reading, direction: "unknown" }));
|
|
271
|
+
return [...stale, ...held];
|
|
272
|
+
}
|
|
273
|
+
export function applyOrRepinSessionStartHook(homeDir, agentId, skip, settingsPath) {
|
|
274
|
+
const existing = checkSessionStartHook(homeDir, settingsPath);
|
|
275
|
+
if (existing.present) {
|
|
276
|
+
const harness = hookHarnessFromSettingsPath(existing.path);
|
|
277
|
+
const finding = sessionStartHookPinFindings(homeDir).find((f) => f.reading.target.id === harness);
|
|
278
|
+
if (!finding) {
|
|
279
|
+
return { applied: false, ok: true, message: `SessionStart hook already wired in ${existing.path}` };
|
|
280
|
+
}
|
|
281
|
+
if (finding.reading.held) {
|
|
282
|
+
return { applied: false, ok: false, message: finding.reading.held };
|
|
283
|
+
}
|
|
284
|
+
if (skip) {
|
|
285
|
+
return { applied: false, ok: false, message: `SessionStart hook in ${existing.path} not re-pinned (--skip-hook)` };
|
|
286
|
+
}
|
|
287
|
+
const repin = repinSessionStartHookGuarded(homeDir, harness);
|
|
288
|
+
return { applied: repin.action === "update", ok: repin.ok, message: repin.message };
|
|
289
|
+
}
|
|
290
|
+
const hint = sessionStartHookHint(agentId, existing.path);
|
|
291
|
+
if (skip) {
|
|
292
|
+
return { applied: false, ok: false, message: "SessionStart hook skipped (--skip-hook)", hint };
|
|
293
|
+
}
|
|
294
|
+
const fix = fixSessionStartHook(homeDir, agentId, settingsPath ?? existing.path);
|
|
295
|
+
return { applied: fix.ok, ok: fix.ok, message: fix.message, hint: fix.ok ? undefined : hint };
|
|
234
296
|
}
|
|
235
297
|
/**
|
|
236
298
|
* Stale MCP-client pins, each annotated with its direction — the client-side
|
|
@@ -284,12 +346,7 @@ export function repinSessionStartHookGuarded(homeDir, harness, target) {
|
|
|
284
346
|
const wouldWrite = flairCliVersion();
|
|
285
347
|
const command = checkSessionStartHook(homeDir, resolved.path).command;
|
|
286
348
|
const form = command ? parseInstallerHookForm(command) : null;
|
|
287
|
-
|
|
288
|
-
// the status-only match may recover an unreadable pin for a HOLD; it cannot
|
|
289
|
-
// authorize a write. The writer still validates the full command in-lock.
|
|
290
|
-
const invocation = form ? undefined : command?.match(SESSION_START_HOOK_INVOCATION_RE)?.[0];
|
|
291
|
-
const spec = form?.pkgSpec
|
|
292
|
-
?? invocation?.slice("npx -y -p ".length, -" flair-session-start".length);
|
|
349
|
+
const spec = command ? hookInvocationSpec(command).spec : null;
|
|
293
350
|
const existing = spec ? wiringPinString(decodeWiringSpec(spec, FLAIR_MCP_PACKAGE)) : null;
|
|
294
351
|
// A comparable pin in a non-installer command is a shape refusal, not an
|
|
295
352
|
// unknown pin. Let the writer retain its "not one of the installer forms"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Documented Peer.status CLI vocabulary. */
|
|
2
|
+
export const PEER_STATUS = {
|
|
3
|
+
PAIRED: "paired",
|
|
4
|
+
CONNECTED: "connected",
|
|
5
|
+
DISCONNECTED: "disconnected",
|
|
6
|
+
REVOKED: "revoked",
|
|
7
|
+
};
|
|
8
|
+
/** Values listed in the Peer.status schema comment. */
|
|
9
|
+
export const PEER_STATUS_VALUES = [
|
|
10
|
+
PEER_STATUS.PAIRED,
|
|
11
|
+
PEER_STATUS.CONNECTED,
|
|
12
|
+
PEER_STATUS.DISCONNECTED,
|
|
13
|
+
PEER_STATUS.REVOKED,
|
|
14
|
+
];
|
|
15
|
+
export const PEER_MEMBERSHIP_STATUSES = [
|
|
16
|
+
PEER_STATUS.PAIRED,
|
|
17
|
+
PEER_STATUS.CONNECTED,
|
|
18
|
+
PEER_STATUS.DISCONNECTED,
|
|
19
|
+
];
|
|
20
|
+
/** Classify the documented CLI vocabulary. */
|
|
21
|
+
export function isPeerStatus(value) {
|
|
22
|
+
return typeof value === "string" && PEER_STATUS_VALUES.includes(value);
|
|
23
|
+
}
|
|
24
|
+
/** Classify the documented membership statuses. */
|
|
25
|
+
export function isPeerMemberStatus(value) {
|
|
26
|
+
return typeof value === "string" && PEER_MEMBERSHIP_STATUSES.includes(value);
|
|
27
|
+
}
|
|
@@ -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
|
+
}
|