@tpsdev-ai/flair 0.58.0 → 0.62.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 +7 -6
- package/SECURITY.md +36 -0
- package/config.yaml +15 -1
- package/dist/bridges/builtins/mem0.js +63 -28
- 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/build-info.json +3 -3
- package/dist/cli.js +1030 -343
- package/dist/commands/agent.js +384 -45
- package/dist/commands/attention.js +4 -3
- package/dist/commands/backup.js +202 -34
- package/dist/commands/bridge.js +172 -119
- package/dist/commands/deploy.js +37 -4
- package/dist/commands/doctor.js +601 -163
- package/dist/commands/export.js +54 -19
- package/dist/commands/federation.js +141 -21
- package/dist/commands/hook.js +155 -2
- package/dist/commands/idp.js +14 -1
- package/dist/commands/import.js +7 -3
- package/dist/commands/init.js +462 -193
- package/dist/commands/integrity.js +388 -0
- package/dist/commands/keys.js +247 -58
- package/dist/commands/mcp.js +146 -53
- package/dist/commands/memory.js +171 -21
- package/dist/commands/migrate-harness-memory.js +3 -2
- package/dist/commands/orgevent.js +46 -37
- package/dist/commands/presence.js +4 -3
- package/dist/commands/principal.js +426 -48
- package/dist/commands/quality.js +10 -1
- package/dist/commands/reembed.js +141 -17
- package/dist/commands/relationship.js +2 -1
- package/dist/commands/rem.js +56 -18
- package/dist/commands/restore.js +101 -61
- package/dist/commands/search.js +6 -4
- package/dist/commands/service.js +151 -38
- package/dist/commands/soul.js +4 -3
- package/dist/commands/status.js +43 -5
- package/dist/commands/test.js +3 -2
- package/dist/commands/upgrade.js +24 -1
- package/dist/commands/workspace.js +6 -3
- package/dist/component-env.js +31 -41
- package/dist/deploy.js +77 -1
- package/dist/doctor-client.js +529 -92
- package/dist/engine-version-contract.js +1 -0
- package/dist/engine-version.js +23 -3
- package/dist/federation-verify.js +4 -3
- package/dist/hook-install.js +670 -6
- 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 +46 -0
- package/dist/lib/agent-roster.js +33 -0
- package/dist/lib/auth-resolve.js +49 -16
- package/dist/lib/capture-runtime.js +124 -0
- package/dist/lib/credential-status-rule.js +78 -0
- package/dist/lib/daemon-liveness.js +81 -8
- package/dist/lib/doctor-run.js +140 -35
- package/dist/lib/durability-copy.js +10 -0
- package/dist/lib/embedding-space-doctor.js +75 -0
- package/dist/lib/flair-agent-role.js +120 -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/launchd-management.js +27 -2
- 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 +1775 -338
- 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 +2 -0
- package/dist/lib/memory-id-policy.js +46 -0
- package/dist/lib/memory-integrity.js +309 -0
- package/dist/lib/memory-purge-response.js +20 -0
- package/dist/lib/ops-table-count.js +25 -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 +103 -7
- 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-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-seed-pending.js +24 -0
- package/dist/lib/skill-seed.js +365 -0
- package/dist/lib/stop-start-recovery.js +54 -0
- package/dist/lib/using-flair-skill.js +87 -0
- package/dist/mcp-client-assertion.js +112 -4
- package/dist/memory-id-checkpoint.js +326 -0
- package/dist/memory-node-compare.js +207 -0
- package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
- package/dist/rem/restore.js +6 -5
- package/dist/rem/runner.js +103 -44
- package/dist/resources/Agent.js +348 -8
- package/dist/resources/AgentKeyRegister.js +214 -0
- package/dist/resources/AgentKeyRegistration.js +28 -0
- package/dist/resources/AgentSeed.js +19 -4
- package/dist/resources/AutoPromoteCandidates.js +7 -1
- package/dist/resources/Credential.js +177 -2
- package/dist/resources/Federation.js +752 -132
- package/dist/resources/FederationRetry.js +140 -0
- package/dist/resources/InstructionVersion.js +220 -0
- package/dist/resources/Integration.js +300 -25
- package/dist/resources/Memory.js +2113 -604
- package/dist/resources/MemoryArchive.js +75 -42
- package/dist/resources/MemoryBootstrap.js +227 -64
- package/dist/resources/MemoryCandidate.js +21 -1
- package/dist/resources/MemoryDedupStats.js +30 -1
- package/dist/resources/MemoryFeed.js +327 -45
- package/dist/resources/MemoryGrant.js +21 -1
- package/dist/resources/MemoryMaintenance.js +129 -25
- package/dist/resources/MemoryPurge.js +232 -0
- package/dist/resources/MemoryReflect.js +7 -2
- package/dist/resources/MemoryReindex.js +24 -8
- package/dist/resources/Message.js +5 -3
- package/dist/resources/OAuth.js +186 -9
- package/dist/resources/OrgEvent.js +126 -3
- package/dist/resources/OrgSkillAssignment.js +209 -0
- package/dist/resources/Presence.js +144 -49
- package/dist/resources/PromoteMemoryCandidate.js +18 -7
- package/dist/resources/Relationship.js +23 -0
- package/dist/resources/SemanticSearch.js +63 -32
- package/dist/resources/Soul.js +189 -76
- package/dist/resources/TeamDirectory.js +35 -0
- package/dist/resources/WorkspaceState.js +21 -1
- package/dist/resources/XAA.js +212 -65
- package/dist/resources/agent-auth.js +40 -15
- package/dist/resources/agent-status-guard.js +63 -0
- package/dist/resources/auth-middleware.js +402 -162
- package/dist/resources/ed25519-auth.js +1 -1
- package/dist/resources/embedding-space-guard.js +366 -72
- package/dist/resources/engine-version-stamp-boot.js +53 -0
- package/dist/resources/federation-classify.js +94 -0
- package/dist/resources/federation-crypto.js +5 -5
- package/dist/resources/federation-retry-lib.js +135 -0
- package/dist/resources/flair-agent-role-boot.js +26 -0
- package/dist/resources/grant-visibility.js +135 -0
- package/dist/resources/harper-routing.js +83 -0
- package/dist/resources/health.js +130 -20
- package/dist/resources/host-source-citation.js +49 -0
- package/dist/resources/host-source-visibility.js +7 -6
- package/dist/resources/instance-create-lock.js +17 -0
- package/dist/resources/instance-identity.js +23 -0
- package/dist/resources/instruction-version-record.js +343 -0
- package/dist/resources/key-lock.js +31 -0
- package/dist/resources/mcp-handler.js +36 -8
- package/dist/resources/mcp-oauth-env-guard.js +36 -0
- package/dist/resources/mcp-oauth.js +26 -12
- package/dist/resources/mcp-tool-arguments.js +4 -6
- package/dist/resources/mcp-tools.js +150 -23
- package/dist/resources/memory-bootstrap-lib.js +5 -15
- package/dist/resources/memory-declared-attributes.js +3 -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 +88 -0
- package/dist/resources/memory-embedding-value.js +8 -0
- package/dist/resources/memory-host-source.js +27 -5
- package/dist/resources/memory-id-guard.js +75 -0
- package/dist/resources/memory-redaction.js +236 -0
- package/dist/resources/memory-supplied-vector.js +72 -0
- package/dist/resources/memory-write-lock.js +310 -0
- package/dist/resources/memory-write-response.js +139 -0
- package/dist/resources/migrations/data-dir.js +74 -16
- package/dist/resources/migrations/dir-safety.js +1 -1
- package/dist/resources/migrations/embedding-stamp.js +193 -79
- package/dist/resources/migrations/export.js +1 -0
- package/dist/resources/migrations/graph-heal.js +18 -25
- package/dist/resources/migrations/lock.js +7 -1
- package/dist/resources/migrations/snapshot.js +1 -0
- package/dist/resources/migrations/source-fields.js +5 -5
- package/dist/resources/migrations/synthetic-test-migration.js +14 -11
- package/dist/resources/migrations/visibility-backfill.js +29 -29
- package/dist/resources/multi-worker-guard.js +121 -0
- package/dist/resources/oauth-discovery.js +1 -0
- package/dist/resources/oauth-wellknown.js +8 -4
- package/dist/resources/object-body-guard.js +33 -0
- package/dist/resources/org-event-created-at.js +133 -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 +212 -0
- package/dist/resources/owner-scoped-writes.js +58 -0
- package/dist/resources/presence-receipt.js +236 -0
- package/dist/resources/promotion-stamp.js +47 -12
- package/dist/resources/record-owner-guard.js +74 -26
- package/dist/resources/record-types.js +17 -1
- package/dist/resources/relay-ops.js +78 -6
- package/dist/resources/replay-store.js +145 -21
- package/dist/resources/request-target.js +136 -0
- package/dist/resources/request-transaction.js +35 -0
- package/dist/resources/search-readiness.js +4 -1
- package/dist/resources/seed-ids.js +9 -0
- package/dist/resources/seed-reservation.js +117 -0
- package/dist/resources/semantic-retrieval-core.js +20 -9
- package/dist/resources/skill-manifest.js +190 -0
- package/dist/resources/skill-provenance.js +15 -10
- package/dist/resources/skill-subject.js +53 -0
- package/dist/resources/skill-version-write.js +432 -0
- package/dist/resources/skill-write-fault.js +17 -0
- package/dist/resources/skill-write-policy.js +67 -0
- package/dist/resources/skill-write.js +67 -7
- package/dist/resources/table-helpers.js +10 -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 +118 -0
- package/dist/resources/usage-recording.js +171 -63
- package/dist/resources/write-back.js +218 -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 +46 -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/flair-agent-role.js +120 -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/mcp-oauth-env-core.js +133 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/memory-id-policy.js +46 -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/systemd-agent-id.js +38 -0
- package/docs/access-control.md +768 -0
- package/docs/api-reference.md +52 -13
- package/docs/auth.md +10 -12
- package/docs/bridges.md +11 -0
- package/docs/claude-code.md +34 -4
- package/docs/deepseek-harness.md +1 -1
- package/docs/deploying-on-fabric.md +70 -0
- package/docs/deployment.md +2 -0
- package/docs/embedding-in-a-harper-app.md +1 -1
- package/docs/federation.md +33 -2
- package/docs/hosted-on-fabric.md +43 -36
- package/docs/integrations.md +6 -6
- package/docs/mcp-clients.md +10 -5
- package/docs/n8n.md +17 -11
- package/docs/notes/mcp-agent-auth-consumer.md +12 -4
- package/docs/notes/mcp-oauth-model2.md +34 -5
- package/docs/quickstart-fabric.md +2 -2
- package/docs/quickstart.md +9 -1
- package/docs/releasing.md +34 -28
- package/docs/rem.md +8 -0
- package/docs/secrets-and-keys.md +19 -2
- package/docs/standalone-local.md +1 -0
- package/docs/supply-chain-policy.md +13 -3
- package/docs/upgrade.md +32 -6
- package/package.json +12 -6
- package/schemas/agent-key-registration.graphql +22 -0
- package/schemas/agent.graphql +3 -0
- package/schemas/federation.graphql +38 -1
- package/schemas/memory.graphql +115 -5
- package/schemas/oauth.graphql +27 -4
- package/schemas/schema.graphql +2 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +89 -16
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Credential key names Flair must not add to component `.env` files.
|
|
2
|
+
//
|
|
3
|
+
// This module deliberately has NO imports. flair#2589: a plain `node` script
|
|
4
|
+
// (scripts/ci/redact-launchd-plist.mjs) imports this list to avoid drifting
|
|
5
|
+
// from the product, but the list used to live in src/component-env.ts, which
|
|
6
|
+
// imports ./lib/mcp-oauth-env-core.js — a specifier that only exists in the
|
|
7
|
+
// compiled output, not the source tree, so `node` failed with
|
|
8
|
+
// ERR_MODULE_NOT_FOUND before the script could scan anything. A module with no
|
|
9
|
+
// imports loads in the form `node` has (the source `.ts`, type-stripped) as
|
|
10
|
+
// well as in the compiled dist/. src/component-env.ts re-exports it, so its
|
|
11
|
+
// public API is unchanged.
|
|
12
|
+
export const NEVER_GENERATED_SECRET_KEYS = [
|
|
13
|
+
"HDB_ADMIN_PASSWORD",
|
|
14
|
+
"FLAIR_ADMIN_PASSWORD",
|
|
15
|
+
"FLAIR_ADMIN_PASS",
|
|
16
|
+
"FABRIC_PASSWORD",
|
|
17
|
+
"FLAIR_CLUSTER_ADMIN_PASS",
|
|
18
|
+
"CLI_TARGET_PASSWORD",
|
|
19
|
+
// The DCR initial access token (resources/dcr-gate.ts). It is a bearer
|
|
20
|
+
// credential for an unauthenticated public endpoint, so it belongs in the
|
|
21
|
+
// process environment; Flair never adds it to a deploy payload — that payload
|
|
22
|
+
// is ingested into an hdb_deployment row and replicated to every node, per the
|
|
23
|
+
// argument at the top of src/component-env.ts.
|
|
24
|
+
"FLAIR_OAUTH_DCR_TOKEN",
|
|
25
|
+
];
|
package/dist/lib/secrets-push.js
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
* endpoint that may not exist costs a silent flag-OFF boot, which is the exact
|
|
46
46
|
* failure this automation is meant to remove.
|
|
47
47
|
*/
|
|
48
|
+
import { constants, createPublicKey, publicEncrypt } from "node:crypto";
|
|
48
49
|
import { sealSecret } from "./secret-envelope.js";
|
|
49
50
|
/** `set_secret`'s delivery tier. `processEnv` is global and cannot be scoped —
|
|
50
51
|
* which is what `FLAIR_MCP_OAUTH` and the signing key PEM need, since both are
|
|
@@ -94,7 +95,16 @@ export async function probeSecretsCapability(opsUrl, authHeader, deps = {}) {
|
|
|
94
95
|
// treated exactly like unavailable — see the failure-direction note above.
|
|
95
96
|
return { available: false, reason: "the target answered the probe without a usable public key — using the staged-file flow" };
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
+
try {
|
|
99
|
+
const key = createPublicKey(pem);
|
|
100
|
+
if (key.asymmetricKeyType !== "rsa")
|
|
101
|
+
throw new Error("not an RSA key");
|
|
102
|
+
publicEncrypt({ key, padding: constants.RSA_PKCS1_OAEP_PADDING, oaepHash: "sha256" }, Buffer.alloc(32));
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return { available: false, reason: "the target answered the probe with an invalid or unusable RSA public key — using the staged-file flow" };
|
|
106
|
+
}
|
|
107
|
+
return { available: true, reason: "target provided a usable RSA public key; attempting push over the ops API", publicKeyPem: pem };
|
|
98
108
|
}
|
|
99
109
|
/** Pull the PEM out of whatever shape the operation returns, without guessing
|
|
100
110
|
* at a value that is not obviously a key. */
|
|
@@ -115,31 +125,49 @@ export async function pushSecrets(opsUrl, authHeader, vars, publicKeyPem, deps =
|
|
|
115
125
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
116
126
|
const results = [];
|
|
117
127
|
for (const [name, value] of Object.entries(vars)) {
|
|
128
|
+
let envelope;
|
|
129
|
+
try {
|
|
130
|
+
envelope = (deps.sealImpl ?? sealSecret)(value, publicKeyPem);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
results.push({ name, ok: false, kind: "local-failure", detail: "local encryption failure: nothing was sent, nothing stored by this attempt" });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
// Without a confirmed response, the push outcome is unknown: it may have stored.
|
|
137
|
+
let r;
|
|
118
138
|
try {
|
|
119
|
-
|
|
120
|
-
const err = String(r.json?.error ?? "").slice(0, 140);
|
|
121
|
-
if (!r.ok) {
|
|
122
|
-
results.push({ name, ok: false, detail: `HTTP ${r.status}${err ? `: ${err}` : ""}` });
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
// Read back one pushed row to verify processEnv actually materialised.
|
|
126
|
-
// A 200 from set_secret is not proof — core silently ignores unknown
|
|
127
|
-
// params, so the row can be accepted and still land inert.
|
|
128
|
-
const verify = await opsCall(opsUrl, authHeader, { operation: "search_by_value", database: "system", table: "hdb_secret", search_attribute: "name", search_value: name, get_attributes: ["name", "processEnv"] }, fetchImpl);
|
|
129
|
-
if (!verify.ok) {
|
|
130
|
-
results.push({ name, ok: false, detail: `push returned 200 but verify failed HTTP ${verify.status}` });
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const row = Array.isArray(verify.json) ? verify.json[0] : verify.json?.[0];
|
|
134
|
-
if (!row || row.processEnv !== true) {
|
|
135
|
-
results.push({ name, ok: false, detail: `push returned 200 but read-back shows processEnv is ${row?.processEnv ?? "missing"}, not true — secret is inert` });
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
results.push({ name, ok: true });
|
|
139
|
+
r = await opsCall(opsUrl, authHeader, { operation: "set_secret", name, envelope, processEnv: true }, fetchImpl);
|
|
139
140
|
}
|
|
140
141
|
catch (err) {
|
|
141
|
-
results.push({ name, ok: false, detail: String(err?.message ?? err).slice(0, 140) });
|
|
142
|
+
results.push({ name, ok: false, kind: "push-unconfirmed", detail: `push outcome could not be confirmed (it may have been stored): ${String(err?.message ?? err).slice(0, 140)}` });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const err = String(r.json?.error ?? "").slice(0, 140);
|
|
146
|
+
if (!r.ok) {
|
|
147
|
+
results.push({ name, ok: false, kind: "push", detail: `HTTP ${r.status}${err ? `: ${err}` : ""}` });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
// A successful set_secret response does not confirm storage with processEnv=true.
|
|
151
|
+
// Read-back failures belong to the confirm stage.
|
|
152
|
+
let verify;
|
|
153
|
+
try {
|
|
154
|
+
verify = await opsCall(opsUrl, authHeader, { operation: "search_by_value", database: "system", table: "hdb_secret", search_attribute: "name", search_value: name, get_attributes: ["name", "processEnv"] }, fetchImpl);
|
|
155
|
+
}
|
|
156
|
+
catch (verifyErr) {
|
|
157
|
+
// A thrown read-back leaves storage with processEnv=true unconfirmed.
|
|
158
|
+
results.push({ name, ok: false, kind: "confirm", detail: `push returned HTTP ${r.status} but the read-back threw (${String(verifyErr?.message ?? verifyErr).slice(0, 120)}) — whether the row carries processEnv=true could not be confirmed` });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (!verify.ok) {
|
|
162
|
+
results.push({ name, ok: false, kind: "confirm", detail: `push returned HTTP ${r.status} but verify failed HTTP ${verify.status}` });
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const row = Array.isArray(verify.json) ? verify.json[0] : verify.json?.[0];
|
|
166
|
+
if (!row || row.processEnv !== true) {
|
|
167
|
+
results.push({ name, ok: false, kind: "confirm", detail: `push returned HTTP ${r.status} but read-back shows processEnv is ${row?.processEnv ?? "missing"}, not true — storage with processEnv=true could not be confirmed` });
|
|
168
|
+
continue;
|
|
142
169
|
}
|
|
170
|
+
results.push({ name, ok: true });
|
|
143
171
|
}
|
|
144
172
|
return { allOk: results.every((x) => x.ok), results };
|
|
145
173
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { existsSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
export function skillSeedPendingPath(dataDir) {
|
|
4
|
+
return join(dataDir, "using-flair-seed-pending");
|
|
5
|
+
}
|
|
6
|
+
export function markSkillSeedPending(dataDir) {
|
|
7
|
+
writeFileSync(skillSeedPendingPath(dataDir), "pending\n", { mode: 0o600 });
|
|
8
|
+
}
|
|
9
|
+
export function clearSkillSeedPending(dataDir) {
|
|
10
|
+
const path = skillSeedPendingPath(dataDir);
|
|
11
|
+
if (existsSync(path))
|
|
12
|
+
unlinkSync(path);
|
|
13
|
+
}
|
|
14
|
+
/** Return null when there is no pending seed; retain the marker on any failure. */
|
|
15
|
+
export async function reconcilePendingSkillSeed(dataDir, seed) {
|
|
16
|
+
const path = skillSeedPendingPath(dataDir);
|
|
17
|
+
if (!existsSync(path))
|
|
18
|
+
return null;
|
|
19
|
+
const outcome = await seed();
|
|
20
|
+
if (outcome.kind === "refused")
|
|
21
|
+
return outcome;
|
|
22
|
+
clearSkillSeedPending(dataDir);
|
|
23
|
+
return outcome;
|
|
24
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill-seed.ts — the `using-flair` seed: the decision, and its install-time
|
|
3
|
+
* write (flair#2141 S2).
|
|
4
|
+
*
|
|
5
|
+
* A normal `flair init` ensures both rows. Re-initializing an already-installed
|
|
6
|
+
* default local instance with `flair init --skip-start` defers them to a later
|
|
7
|
+
* `flair start` that has the admin credential (FLAIR_ADMIN_PASS or the
|
|
8
|
+
* admin-pass file; without one that start warns and leaves the seed pending).
|
|
9
|
+
* Re-runs may find both rows already
|
|
10
|
+
* current. Writes use
|
|
11
|
+
* a verified Basic administrator over authenticated Basic REST requests
|
|
12
|
+
* (`PUT /Memory/<id>`, `PUT /OrgSkillAssignment/<id>`) — so the rows carry
|
|
13
|
+
* the operator's id. Resource write paths check the operator source (Basic
|
|
14
|
+
* administrator or deliberate internal call) for the fixed ids. The Memory
|
|
15
|
+
* reservation has documented bookkeeping writes (resources/seed-reservation.ts).
|
|
16
|
+
*
|
|
17
|
+
* Before it writes anything, the seed refuses:
|
|
18
|
+
* - a read that FAILS (never read as "absent");
|
|
19
|
+
* - an Agent record whose id is the operator's: a row owned by that id could
|
|
20
|
+
* have been written by the agent, so its owner is ambiguous;
|
|
21
|
+
* - an existing skill row not owned by the operator;
|
|
22
|
+
* - an existing skill row whose content is not text, or that is not a live
|
|
23
|
+
* org skill: no `skill` tag, durability not `persistent`, visibility not
|
|
24
|
+
* `shared`, archived, closed (`validTo`) or expired (`expiresAt`), or
|
|
25
|
+
* another id;
|
|
26
|
+
* - an existing assignment with another id, `skillRef`, `skillName` or
|
|
27
|
+
* priority.
|
|
28
|
+
*
|
|
29
|
+
* Otherwise the rule for the row is small and pure, so it is unit-tested
|
|
30
|
+
* without a server:
|
|
31
|
+
*
|
|
32
|
+
* - no stored row → write the current text;
|
|
33
|
+
* - stored text = the current text → unchanged;
|
|
34
|
+
* - stored text's hash is listed → replace (the text matches a listed
|
|
35
|
+
* shipped version);
|
|
36
|
+
* - otherwise → keep, and report it.
|
|
37
|
+
*
|
|
38
|
+
* Both ids are fixed, so a re-run reads by primary key and updates the same
|
|
39
|
+
* rows instead of adding rows. After each write the seed reads the row back
|
|
40
|
+
* and applies the same checks; it reports success only when both rows pass.
|
|
41
|
+
*
|
|
42
|
+
* The IO seam is a tiny REST client, so the fail-closed contract is testable
|
|
43
|
+
* without a server and the real path is the one `flair init` runs.
|
|
44
|
+
*/
|
|
45
|
+
import { USING_FLAIR_SKILL_CONTENT, USING_FLAIR_SKILL_NAME, USING_FLAIR_SKILL_TRIGGER, USING_FLAIR_SHIPPED_HASHES, usingFlairSkillHash, } from "./using-flair-skill.js";
|
|
46
|
+
/**
|
|
47
|
+
* The skill Memory row's id, and the org assignment's `skillRef`. Must equal
|
|
48
|
+
* `SEED_SKILL_ROW_ID` in resources/seed-ids.ts (a unit test pins it).
|
|
49
|
+
*/
|
|
50
|
+
export const SEED_SKILL_ID = "skill:using-flair";
|
|
51
|
+
/** The org assignment's id. Fixed, so a re-run lands on the same row. */
|
|
52
|
+
export const SEED_ASSIGNMENT_ID = "org-skill:using-flair";
|
|
53
|
+
/** The org-scope assignment's priority. */
|
|
54
|
+
export const SEED_ASSIGNMENT_PRIORITY = "standard";
|
|
55
|
+
/**
|
|
56
|
+
* The bound on the seed's reads and on its assignment write, so a stalled
|
|
57
|
+
* instance cannot hang init.
|
|
58
|
+
*/
|
|
59
|
+
export const SEED_REQUEST_TIMEOUT_MS = 15_000;
|
|
60
|
+
/**
|
|
61
|
+
* The bound on the skill row's write. The instance embeds a skill row as it
|
|
62
|
+
* writes it (`Memory.put` awaits `getEmbedding`), and the first embed awaits
|
|
63
|
+
* the embedding model's readiness: the model may need to download (~80 MB) or
|
|
64
|
+
* load in the background, and Harper can report healthy before that ends. So
|
|
65
|
+
* this one write can outlast the 15 s bound on a healthy instance.
|
|
66
|
+
* The 180 s limit bounds the wait; it does not guarantee a download completes.
|
|
67
|
+
* It stays under the 300 s default headers timeout of Node's fetch, so this
|
|
68
|
+
* bound and its message fire first.
|
|
69
|
+
*/
|
|
70
|
+
export const SEED_SKILL_WRITE_TIMEOUT_MS = 180_000;
|
|
71
|
+
/** How long the skill row's write runs before init says what it is waiting on. */
|
|
72
|
+
export const SEED_SKILL_WRITE_NOTICE_MS = 5_000;
|
|
73
|
+
/** The shipped `using-flair` skill as this build defines it. */
|
|
74
|
+
export function currentSeed() {
|
|
75
|
+
return {
|
|
76
|
+
name: USING_FLAIR_SKILL_NAME,
|
|
77
|
+
content: USING_FLAIR_SKILL_CONTENT,
|
|
78
|
+
trigger: USING_FLAIR_SKILL_TRIGGER,
|
|
79
|
+
hashes: USING_FLAIR_SHIPPED_HASHES,
|
|
80
|
+
priority: SEED_ASSIGNMENT_PRIORITY,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The decision for one seeding pass. `stored` is the row's `content`, or null
|
|
85
|
+
* when the row does not exist.
|
|
86
|
+
*/
|
|
87
|
+
export function decideSkillSeed(stored, currentContent, shippedHashes, currentHash = usingFlairSkillHash(currentContent)) {
|
|
88
|
+
if (stored === null)
|
|
89
|
+
return "create";
|
|
90
|
+
const hash = usingFlairSkillHash(stored);
|
|
91
|
+
if (hash === currentHash)
|
|
92
|
+
return "unchanged";
|
|
93
|
+
if (shippedHashes.includes(hash))
|
|
94
|
+
return "replace";
|
|
95
|
+
return "keep";
|
|
96
|
+
}
|
|
97
|
+
function isPast(value, now) {
|
|
98
|
+
return typeof value === "string" && value.length > 0 && Date.parse(value) < now;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* What keeps a stored skill row from being the live org `using-flair` skill
|
|
102
|
+
* that bootstrap's manifest resolves (resources/skill-manifest.ts,
|
|
103
|
+
* resolvableSkillRows), or [] when nothing does. Ownership and content are
|
|
104
|
+
* checked separately.
|
|
105
|
+
*/
|
|
106
|
+
export function seedRowProblems(row, now = Date.now()) {
|
|
107
|
+
const problems = [];
|
|
108
|
+
if (row.id !== SEED_SKILL_ID)
|
|
109
|
+
problems.push(`its id is ${JSON.stringify(row.id ?? null)}`);
|
|
110
|
+
if (!Array.isArray(row.tags) || !row.tags.includes("skill"))
|
|
111
|
+
problems.push('it has no "skill" tag');
|
|
112
|
+
if (row.durability !== "persistent")
|
|
113
|
+
problems.push(`its durability is ${JSON.stringify(row.durability ?? null)}, not "persistent"`);
|
|
114
|
+
if (row.visibility !== "shared")
|
|
115
|
+
problems.push(`its visibility is ${JSON.stringify(row.visibility ?? null)}, not "shared"`);
|
|
116
|
+
if (row.archived === true)
|
|
117
|
+
problems.push("it is archived");
|
|
118
|
+
if (isPast(row.validTo, now))
|
|
119
|
+
problems.push("it is closed (validTo is past)");
|
|
120
|
+
if (isPast(row.expiresAt, now))
|
|
121
|
+
problems.push("it has expired (expiresAt is past)");
|
|
122
|
+
return problems;
|
|
123
|
+
}
|
|
124
|
+
/** What makes a stored org assignment differ from the seed's, or [] when nothing does. */
|
|
125
|
+
export function seedAssignmentProblems(row, current) {
|
|
126
|
+
const problems = [];
|
|
127
|
+
if (row.id !== SEED_ASSIGNMENT_ID)
|
|
128
|
+
problems.push(`its id is ${JSON.stringify(row.id ?? null)}`);
|
|
129
|
+
if (row.skillRef !== SEED_SKILL_ID)
|
|
130
|
+
problems.push(`it names ${JSON.stringify(row.skillRef ?? null)} instead of "${SEED_SKILL_ID}"`);
|
|
131
|
+
if (row.skillName !== current.name)
|
|
132
|
+
problems.push(`its skillName is ${JSON.stringify(row.skillName ?? null)}, not "${current.name}"`);
|
|
133
|
+
if (row.priority !== current.priority)
|
|
134
|
+
problems.push(`its priority is ${JSON.stringify(row.priority ?? null)}, not "${current.priority}"`);
|
|
135
|
+
return problems;
|
|
136
|
+
}
|
|
137
|
+
function refused(error, message) {
|
|
138
|
+
return { kind: "refused", error, message };
|
|
139
|
+
}
|
|
140
|
+
const NOTHING_WRITTEN = "the seed wrote neither seed row";
|
|
141
|
+
const ROW_PATH = `/Memory/${encodeURIComponent(SEED_SKILL_ID)}`;
|
|
142
|
+
const ASSIGNMENT_PATH = `/OrgSkillAssignment/${encodeURIComponent(SEED_ASSIGNMENT_ID)}`;
|
|
143
|
+
const ROW_REMEDY = `Inspect it (GET ${ROW_PATH}), delete it with the operator's Basic credentials (DELETE ${ROW_PATH}), ` +
|
|
144
|
+
"then re-run 'flair init'";
|
|
145
|
+
const ASSIGNMENT_REMEDY = `Inspect it (GET ${ASSIGNMENT_PATH}), correct or delete it with the operator's Basic credentials, ` +
|
|
146
|
+
"then re-run 'flair init'";
|
|
147
|
+
/** Apply the seed rule over `io`. Preflight reads and checks pass before either write. */
|
|
148
|
+
export async function runSkillSeed(io, current) {
|
|
149
|
+
const rowRead = await io.readRow();
|
|
150
|
+
if (!rowRead.ok) {
|
|
151
|
+
return refused("skill_seed_row_unreadable", `the "${SEED_SKILL_ID}" Memory row could not be read (${rowRead.detail ?? "no detail"}); ${NOTHING_WRITTEN}. ` +
|
|
152
|
+
"Check the instance and re-run 'flair init'");
|
|
153
|
+
}
|
|
154
|
+
const agentRead = await io.readOperatorAgent();
|
|
155
|
+
if (!agentRead.ok) {
|
|
156
|
+
return refused("skill_seed_operator_unreadable", `the Agent record for the operator id "${io.operator}" could not be read (${agentRead.detail ?? "no detail"}); ` +
|
|
157
|
+
`${NOTHING_WRITTEN}. Check the instance and re-run 'flair init'`);
|
|
158
|
+
}
|
|
159
|
+
// Checked before any write, with or without a stored row: a row init wrote
|
|
160
|
+
// now would be refused by the next run for the same reason.
|
|
161
|
+
if (agentRead.row) {
|
|
162
|
+
return refused("skill_seed_operator_ambiguous", `an Agent record has the operator's id "${io.operator}", so a skill row owned by "${io.operator}" cannot be ` +
|
|
163
|
+
`told apart from one that agent wrote; ${NOTHING_WRITTEN}. Rename or remove that agent, then re-run 'flair init'`);
|
|
164
|
+
}
|
|
165
|
+
const stored = rowRead.row ?? null;
|
|
166
|
+
if (stored) {
|
|
167
|
+
if (stored.agentId !== io.operator) {
|
|
168
|
+
return refused("skill_seed_row_foreign_owner", `the "${SEED_SKILL_ID}" Memory row is owned by ${JSON.stringify(stored.agentId ?? null)}, not the operator ` +
|
|
169
|
+
`"${io.operator}"; ${NOTHING_WRITTEN}. ${ROW_REMEDY}`);
|
|
170
|
+
}
|
|
171
|
+
if (typeof stored.content !== "string") {
|
|
172
|
+
return refused("skill_seed_row_malformed", `the "${SEED_SKILL_ID}" Memory row exists but its content is not text; ${NOTHING_WRITTEN}. ${ROW_REMEDY}`);
|
|
173
|
+
}
|
|
174
|
+
const problems = seedRowProblems(stored);
|
|
175
|
+
if (problems.length > 0) {
|
|
176
|
+
return refused("skill_seed_row_incomplete", `the "${SEED_SKILL_ID}" Memory row is not a live org skill: ${problems.join("; ")}; ${NOTHING_WRITTEN}. ${ROW_REMEDY}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const storedContent = typeof stored?.content === "string" ? stored.content : null;
|
|
180
|
+
const assignRead = await io.readAssignment();
|
|
181
|
+
if (!assignRead.ok) {
|
|
182
|
+
return refused("skill_seed_assignment_unreadable", `the "${SEED_ASSIGNMENT_ID}" org assignment could not be read (${assignRead.detail ?? "no detail"}); ` +
|
|
183
|
+
`${NOTHING_WRITTEN}. Check the instance and re-run 'flair init'`);
|
|
184
|
+
}
|
|
185
|
+
if (assignRead.row) {
|
|
186
|
+
const problems = seedAssignmentProblems(assignRead.row, current);
|
|
187
|
+
if (problems.length > 0) {
|
|
188
|
+
return refused("skill_seed_assignment_mismatch", `the "${SEED_ASSIGNMENT_ID}" org assignment ${problems.join("; ")}; ${NOTHING_WRITTEN}. ${ASSIGNMENT_REMEDY}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const action = decideSkillSeed(storedContent, current.content, current.hashes);
|
|
192
|
+
if (action === "create" || action === "replace") {
|
|
193
|
+
const write = await io.putRow();
|
|
194
|
+
if (!write.ok) {
|
|
195
|
+
return refused("skill_seed_write_failed", `writing the "${SEED_SKILL_ID}" skill row failed (${write.detail ?? "no detail"}); the org assignment was not ` +
|
|
196
|
+
"written. Re-run 'flair init'");
|
|
197
|
+
}
|
|
198
|
+
const after = await io.readRow();
|
|
199
|
+
if (!after.ok) {
|
|
200
|
+
return refused("skill_seed_verify_failed", `the "${SEED_SKILL_ID}" skill row could not be read back after the write (${after.detail ?? "no detail"}); ` +
|
|
201
|
+
"the org assignment was not written. Check the instance and re-run 'flair init'");
|
|
202
|
+
}
|
|
203
|
+
const row = after.row ?? null;
|
|
204
|
+
const problems = row ? seedRowProblems(row) : ["it is absent"];
|
|
205
|
+
if (row && row.agentId !== io.operator)
|
|
206
|
+
problems.push(`it is owned by ${JSON.stringify(row.agentId ?? null)}`);
|
|
207
|
+
if (row && row.content !== current.content)
|
|
208
|
+
problems.push("it does not hold the current text");
|
|
209
|
+
if (problems.length > 0) {
|
|
210
|
+
return refused("skill_seed_verify_failed", `the "${SEED_SKILL_ID}" skill row read back after the write is not the operator's live org skill: ` +
|
|
211
|
+
`${problems.join("; ")}; the org assignment was not written. Check the Memory table and re-run 'flair init'`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
let assignmentId = String(assignRead.row?.id ?? "");
|
|
215
|
+
if (!assignRead.row) {
|
|
216
|
+
const write = await io.putAssignment();
|
|
217
|
+
if (!write.ok) {
|
|
218
|
+
return refused("skill_seed_write_failed", `writing the "${SEED_ASSIGNMENT_ID}" org assignment failed (${write.detail ?? "no detail"}); re-run 'flair init'`);
|
|
219
|
+
}
|
|
220
|
+
const after = await io.readAssignment();
|
|
221
|
+
if (!after.ok) {
|
|
222
|
+
return refused("skill_seed_verify_failed", `the "${SEED_ASSIGNMENT_ID}" org assignment could not be read back after the write (${after.detail ?? "no detail"}); ` +
|
|
223
|
+
`check the instance and re-run 'flair init'`);
|
|
224
|
+
}
|
|
225
|
+
const problems = after.row ? seedAssignmentProblems(after.row, current) : ["it is absent"];
|
|
226
|
+
if (problems.length > 0) {
|
|
227
|
+
return refused("skill_seed_verify_failed", `the "${SEED_ASSIGNMENT_ID}" org assignment read back after the write ${problems.join("; ")}; ` +
|
|
228
|
+
`check the OrgSkillAssignment table and re-run 'flair init'`);
|
|
229
|
+
}
|
|
230
|
+
assignmentId = String(after.row?.id ?? "");
|
|
231
|
+
}
|
|
232
|
+
const message = action === "create"
|
|
233
|
+
? `seeded the using-flair skill (${SEED_SKILL_ID}) and its org assignment`
|
|
234
|
+
: action === "replace"
|
|
235
|
+
? `replaced the using-flair skill with the current shipped text (${SEED_SKILL_ID})`
|
|
236
|
+
: action === "unchanged"
|
|
237
|
+
? `using-flair is already current (${SEED_SKILL_ID})`
|
|
238
|
+
: `the using-flair text matches no listed shipped version; kept it unchanged (${SEED_SKILL_ID})`;
|
|
239
|
+
return { kind: "ok", action, skillId: SEED_SKILL_ID, assignmentId, message };
|
|
240
|
+
}
|
|
241
|
+
function detailOf(err) {
|
|
242
|
+
return err instanceof Error ? err.message : String(err);
|
|
243
|
+
}
|
|
244
|
+
/** `AbortSignal.timeout` rejects a fetch with a DOMException named "TimeoutError". */
|
|
245
|
+
function isTimeout(err) {
|
|
246
|
+
return typeof err === "object" && err !== null && err.name === "TimeoutError";
|
|
247
|
+
}
|
|
248
|
+
function seconds(ms) {
|
|
249
|
+
return `${Math.round(ms / 100) / 10} s`;
|
|
250
|
+
}
|
|
251
|
+
function authHeader(user, pass) {
|
|
252
|
+
return `Basic ${Buffer.from(`${user}:${pass}`).toString("base64")}`;
|
|
253
|
+
}
|
|
254
|
+
function seedSkillBody(operatorId, current) {
|
|
255
|
+
return {
|
|
256
|
+
id: SEED_SKILL_ID,
|
|
257
|
+
// The operator that runs the seed owns the row, so a non-owner agent is
|
|
258
|
+
// refused on the row's write paths and the row carries real attribution.
|
|
259
|
+
agentId: operatorId,
|
|
260
|
+
content: current.content,
|
|
261
|
+
trigger: current.trigger,
|
|
262
|
+
tags: ["skill"],
|
|
263
|
+
durability: "persistent",
|
|
264
|
+
visibility: "shared",
|
|
265
|
+
metadata: JSON.stringify({ name: current.name }),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** The real IO: REST reads and writes against one instance, as the operator. */
|
|
269
|
+
export function skillSeedRestIo(opts, current = currentSeed()) {
|
|
270
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
271
|
+
const base = opts.baseUrl.replace(/\/$/, "");
|
|
272
|
+
const auth = authHeader(opts.user, opts.pass);
|
|
273
|
+
const requestMs = opts.requestTimeoutMs ?? SEED_REQUEST_TIMEOUT_MS;
|
|
274
|
+
const skillWriteMs = opts.skillWriteTimeoutMs ?? SEED_SKILL_WRITE_TIMEOUT_MS;
|
|
275
|
+
const skillNoticeMs = opts.skillWriteNoticeMs ?? SEED_SKILL_WRITE_NOTICE_MS;
|
|
276
|
+
const readById = async (table, id) => {
|
|
277
|
+
let res;
|
|
278
|
+
try {
|
|
279
|
+
res = await fetchImpl(`${base}/${table}/${encodeURIComponent(id)}`, {
|
|
280
|
+
headers: { Authorization: auth },
|
|
281
|
+
signal: AbortSignal.timeout(requestMs),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
return { ok: false, detail: `the request failed: ${detailOf(err)}` };
|
|
286
|
+
}
|
|
287
|
+
if (res.status === 404)
|
|
288
|
+
return { ok: true, row: null };
|
|
289
|
+
if (!res.ok)
|
|
290
|
+
return { ok: false, detail: `HTTP ${res.status}` };
|
|
291
|
+
const text = await res.text().catch(() => "");
|
|
292
|
+
try {
|
|
293
|
+
const parsed = JSON.parse(text);
|
|
294
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
295
|
+
return { ok: false, detail: "the response was not one record" };
|
|
296
|
+
}
|
|
297
|
+
return { ok: true, row: parsed };
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
return { ok: false, detail: "the response was not JSON" };
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const putById = async (table, id, body, timeoutMs, onTimeout = (ms) => `no answer within ${seconds(ms)}`) => {
|
|
304
|
+
let res;
|
|
305
|
+
try {
|
|
306
|
+
res = await fetchImpl(`${base}/${table}/${encodeURIComponent(id)}`, {
|
|
307
|
+
method: "PUT",
|
|
308
|
+
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
309
|
+
body: JSON.stringify(body),
|
|
310
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
catch (err) {
|
|
314
|
+
if (isTimeout(err))
|
|
315
|
+
return { ok: false, detail: onTimeout(timeoutMs) };
|
|
316
|
+
return { ok: false, detail: `the request failed: ${detailOf(err)}` };
|
|
317
|
+
}
|
|
318
|
+
if (!res.ok) {
|
|
319
|
+
const text = await res.text().catch(() => "");
|
|
320
|
+
return { ok: false, detail: `HTTP ${res.status}${text ? `: ${text.slice(0, 200)}` : ""}` };
|
|
321
|
+
}
|
|
322
|
+
return { ok: true };
|
|
323
|
+
};
|
|
324
|
+
// The skill row's write waits on the instance's embedding model (see
|
|
325
|
+
// SEED_SKILL_WRITE_TIMEOUT_MS), so it gets its own bound and says what it is
|
|
326
|
+
// waiting on. A client-side timeout does not cancel the write on the
|
|
327
|
+
// instance, which may still land it. The id is fixed, so a re-run updates
|
|
328
|
+
// that row rather than adding one; a re-run started while the first write is
|
|
329
|
+
// still pending can send a second PUT to the same id.
|
|
330
|
+
const putRow = async () => {
|
|
331
|
+
const notice = setTimeout(() => {
|
|
332
|
+
opts.notify?.(`using-flair skill: still writing "${SEED_SKILL_ID}" — the instance embeds a skill row as it writes it, ` +
|
|
333
|
+
`and it may need to download (~80 MB) or load the embedding model first; waiting up to ${seconds(skillWriteMs)}`);
|
|
334
|
+
}, skillNoticeMs);
|
|
335
|
+
notice.unref?.();
|
|
336
|
+
try {
|
|
337
|
+
return await putById("Memory", SEED_SKILL_ID, seedSkillBody(opts.user, current), skillWriteMs, (ms) => `no answer within ${seconds(ms)} — the instance embeds a skill row as it writes it, so this write also ` +
|
|
338
|
+
`waits for its embedding model, which may need to download or load; 'flair doctor' reports embeddings. The write may ` +
|
|
339
|
+
`still land; the id is fixed, so a re-run updates that row rather than adding one`);
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
clearTimeout(notice);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
return {
|
|
346
|
+
operator: opts.user,
|
|
347
|
+
readRow: () => readById("Memory", SEED_SKILL_ID),
|
|
348
|
+
readAssignment: () => readById("OrgSkillAssignment", SEED_ASSIGNMENT_ID),
|
|
349
|
+
readOperatorAgent: () => readById("Agent", opts.user),
|
|
350
|
+
putRow,
|
|
351
|
+
putAssignment: () => putById("OrgSkillAssignment", SEED_ASSIGNMENT_ID, {
|
|
352
|
+
skillName: current.name,
|
|
353
|
+
skillRef: SEED_SKILL_ID,
|
|
354
|
+
priority: current.priority,
|
|
355
|
+
}, requestMs),
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Seed `using-flair` on the instance at `baseUrl`, as the operator. Used by
|
|
360
|
+
* `flair init` and a pending `flair start`; reports the action or a refusal
|
|
361
|
+
* with a remedy.
|
|
362
|
+
*/
|
|
363
|
+
export function seedUsingFlairSkill(opts) {
|
|
364
|
+
return runSkillSeed(skillSeedRestIo(opts), currentSeed());
|
|
365
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { connect } from "node:net";
|
|
2
|
+
import { healthIndicatesListener } from "./daemon-liveness.js";
|
|
3
|
+
export function classifyPortProbe(errCode, connected) {
|
|
4
|
+
if (connected)
|
|
5
|
+
return "listening";
|
|
6
|
+
if (errCode === "ECONNREFUSED")
|
|
7
|
+
return "free";
|
|
8
|
+
return "unknown";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Open a TCP connection to `host:port` and report whether anything accepts it.
|
|
12
|
+
* Bounded; the timer is the whole budget, so a silently-dropping socket cannot
|
|
13
|
+
* hang the caller.
|
|
14
|
+
*/
|
|
15
|
+
export async function probePortListening(port, timeoutMs = 3_000, host = "127.0.0.1") {
|
|
16
|
+
return await new Promise((resolve) => {
|
|
17
|
+
const socket = connect({ port, host });
|
|
18
|
+
let settled = false;
|
|
19
|
+
let timer;
|
|
20
|
+
const finish = (result) => {
|
|
21
|
+
if (settled)
|
|
22
|
+
return;
|
|
23
|
+
settled = true;
|
|
24
|
+
if (timer)
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
socket.removeAllListeners();
|
|
27
|
+
socket.destroy();
|
|
28
|
+
resolve(result);
|
|
29
|
+
};
|
|
30
|
+
timer = setTimeout(() => finish("unknown"), timeoutMs);
|
|
31
|
+
socket.once("connect", () => finish("listening"));
|
|
32
|
+
socket.once("error", (err) => finish(classifyPortProbe(err?.code, false)));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export function decideStartOnUnknown(opts) {
|
|
36
|
+
const { evidence, detail, port, probe } = opts;
|
|
37
|
+
const pid = evidence.pidfile.kind === "present" ? evidence.pidfile.pid : evidence.lastKnownPid;
|
|
38
|
+
const ownerExited = evidence.dataDirUnsafe === null && evidence.pidfile.kind !== "unreadable"
|
|
39
|
+
&& pid !== undefined && evidence.pidLiveness?.kind === "gone"
|
|
40
|
+
&& evidence.sidecar?.kind !== "unreadable"
|
|
41
|
+
&& (evidence.sidecar?.kind !== "present" || evidence.sidecarLiveness?.kind === "gone")
|
|
42
|
+
&& !healthIndicatesListener(evidence.health);
|
|
43
|
+
if (ownerExited && probe === "free") {
|
|
44
|
+
return { proceed: true, lines: [`⚠️ ${detail}`, ` Recorded owner has exited; connection to port ${port} was refused — starting.`] };
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
proceed: false,
|
|
48
|
+
lines: [
|
|
49
|
+
`⚠️ ${detail}`,
|
|
50
|
+
` Refusing to start — could not determine whether Flair is running.`,
|
|
51
|
+
` Inspect the instance with 'flair doctor'.`,
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* using-flair-skill.ts — the shipped `using-flair` skill text (flair#2141 S2).
|
|
3
|
+
*
|
|
4
|
+
* Normal `flair init` ensures this skill's Memory row and org assignment.
|
|
5
|
+
* Re-initializing an already-installed default local instance
|
|
6
|
+
* with `flair init --skip-start` defers that to a later `flair start`
|
|
7
|
+
* with the admin credential.
|
|
8
|
+
* Re-runs preserve edited text. An eligible agent's bootstrap may list it when
|
|
9
|
+
* the assignment wins same-name conflict resolution and fits the budget.
|
|
10
|
+
*
|
|
11
|
+
* ONE reviewed text, reconciled from the flair best-practices guidance and the
|
|
12
|
+
* cursor-flair skills (remember, bootstrap, coordinate, soul). It covers when to
|
|
13
|
+
* write and at what durability, provenance, recall habits, what not to store,
|
|
14
|
+
* identity, and where the Agent and Presence records describe the office.
|
|
15
|
+
*
|
|
16
|
+
* The text is code: it is reviewed like any other file, it carries a content
|
|
17
|
+
* hash, and the shipped-hash list below is the record of every version this
|
|
18
|
+
* repo has ever shipped. `src/lib/skill-seed.ts` (the decision and the write)
|
|
19
|
+
* reads them.
|
|
20
|
+
*
|
|
21
|
+
* Pure constants + one hash function, no Harper import, so the seed decision is
|
|
22
|
+
* unit-testable without a server.
|
|
23
|
+
*/
|
|
24
|
+
import { createHash } from "node:crypto";
|
|
25
|
+
/** The skill's Memory `metadata.name` and the org assignment's `skillName`. */
|
|
26
|
+
export const USING_FLAIR_SKILL_NAME = "using-flair";
|
|
27
|
+
/** The recall trigger — the "when to use" text a skill row embeds from. */
|
|
28
|
+
export const USING_FLAIR_SKILL_TRIGGER = "Use when you are about to store a durable decision, lesson, preference or fact, " +
|
|
29
|
+
"recall prior context at session start or after a gap, or look up who is in the office.";
|
|
30
|
+
/** The procedure, separating current Flair behaviour from recommended practice. */
|
|
31
|
+
export const USING_FLAIR_SKILL_CONTENT = [
|
|
32
|
+
"# Using Flair",
|
|
33
|
+
"",
|
|
34
|
+
"## Current Flair behavior",
|
|
35
|
+
"",
|
|
36
|
+
"### Durability and visibility",
|
|
37
|
+
"- Memory supports `permanent`, `persistent`, `standard` (the default), and `ephemeral` durability. Ephemeral memory expires on a timer (24 hours by default), not at the end of a session.",
|
|
38
|
+
"- permanent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it); it never decays; bootstrap considers the bootstrapping agent's own permanent memories before recent rows, subject to scope, expiry/closure and the token budget.",
|
|
39
|
+
"- persistent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it).",
|
|
40
|
+
"- standard — routine maintenance archives it once its validTo passes or, as a session note, after 30 days.",
|
|
41
|
+
"- ephemeral — routine maintenance reaps it once its TTL (24h by default) passes.",
|
|
42
|
+
"- No tier adds a flush, fsync, backup or replica acknowledgement: an explicit delete (owner or admin) or a store failure can end any of them.",
|
|
43
|
+
"- `permanent` and `persistent` default to `shared`; `standard` and `ephemeral` default to `private`.",
|
|
44
|
+
"",
|
|
45
|
+
"### Provenance",
|
|
46
|
+
"- `Memory.post` and `Memory.put` refuse a non-admin write whose `agentId` names another principal; admins bypass this mismatch check.",
|
|
47
|
+
"",
|
|
48
|
+
"### Identity and office records",
|
|
49
|
+
"- Your identity and standing instructions live in Soul. A bootstrap carries them when it is asked for soul (`includeSoul`) and when they fit its token budget.",
|
|
50
|
+
"- `Agent` holds registered agent records with `kind`, `role`, and `status` fields. A Basic administrator need not have an Agent row, and an Agent record is not a promise that the principal is reachable.",
|
|
51
|
+
"- Where a record exists, `Presence` uses `lastHeartbeatAt` to decide its `presenceStatus`. `activity` describes work; it is not a liveness verdict. A Presence record is not a guaranteed address.",
|
|
52
|
+
"",
|
|
53
|
+
"## Recommended practice",
|
|
54
|
+
"",
|
|
55
|
+
"### Writing and recall",
|
|
56
|
+
"- Store a decision, lesson, preference, or fact that should outlive this session as one concise `content` string.",
|
|
57
|
+
"- Use `permanent` for identity and long-lived facts, `persistent` for decisions and lessons, `standard` for ordinary working memory, and `ephemeral` for private scratch.",
|
|
58
|
+
"- Set `visibility: \"shared\"` explicitly to share an ordinary working fact with teammates.",
|
|
59
|
+
"- Write as yourself.",
|
|
60
|
+
"- Confirm a write with the returned id and a short preview.",
|
|
61
|
+
"- At session start, on resume, or after a long gap, load your bootstrap before answering from memory.",
|
|
62
|
+
"- On a task switch, search memory from two or three angles before acting.",
|
|
63
|
+
"- When a search surfaces a row you just wrote or a near-duplicate, update that row instead of adding another.",
|
|
64
|
+
"",
|
|
65
|
+
"### What not to store",
|
|
66
|
+
"- Never store secrets: API keys, passwords, tokens, or key-file contents.",
|
|
67
|
+
"- Never store another person's private data.",
|
|
68
|
+
"",
|
|
69
|
+
"### Identity",
|
|
70
|
+
"- Set identity and standing instructions deliberately in Soul rather than leaving them to memory.",
|
|
71
|
+
].join("\n");
|
|
72
|
+
/** sha256 of a skill row's `content` — the value the shipped-hash list holds. */
|
|
73
|
+
export function usingFlairSkillHash(content) {
|
|
74
|
+
return createHash("sha256").update(content, "utf8").digest("hex");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The hashes of every `using-flair` text this repository has shipped. A stored
|
|
78
|
+
* row whose content hash is in this list holds text that matches a listed
|
|
79
|
+
* shipped version, so the installer may replace it; any other text is left
|
|
80
|
+
* alone. (A hash does not identify who wrote the text.) Append a new hash here
|
|
81
|
+
* whenever the text above changes.
|
|
82
|
+
*/
|
|
83
|
+
export const USING_FLAIR_SHIPPED_HASHES = Object.freeze([
|
|
84
|
+
usingFlairSkillHash(USING_FLAIR_SKILL_CONTENT),
|
|
85
|
+
]);
|
|
86
|
+
/** The current shipped content's hash. */
|
|
87
|
+
export const USING_FLAIR_CURRENT_HASH = usingFlairSkillHash(USING_FLAIR_SKILL_CONTENT);
|