@tpsdev-ai/flair 0.62.0 → 0.63.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -13
- package/SECURITY.md +73 -43
- package/config.yaml +11 -11
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/runtime/import-runner.js +4 -0
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +309 -205
- package/dist/commands/agent.js +325 -137
- package/dist/commands/attention.js +2 -0
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +37 -33
- package/dist/commands/bootstrap.js +5 -1
- package/dist/commands/bridge.js +10 -0
- package/dist/commands/deploy.js +37 -7
- package/dist/commands/doctor.js +206 -42
- package/dist/commands/export.js +144 -15
- package/dist/commands/federation.js +653 -68
- package/dist/commands/grant.js +5 -6
- package/dist/commands/help.js +25 -0
- package/dist/commands/idp.js +14 -19
- package/dist/commands/import.js +167 -34
- package/dist/commands/init.js +380 -164
- package/dist/commands/integrity.js +5 -6
- package/dist/commands/keys.js +12 -8
- package/dist/commands/mcp.js +157 -79
- package/dist/commands/memory.js +38 -17
- package/dist/commands/migrate-harness-memory.js +9 -3
- package/dist/commands/orgevent.js +5 -10
- package/dist/commands/principal.js +32 -39
- package/dist/commands/quality.js +26 -3
- package/dist/commands/reembed.js +468 -111
- package/dist/commands/rem.js +484 -65
- package/dist/commands/restore.js +352 -44
- package/dist/commands/search.js +2 -0
- package/dist/commands/service.js +109 -2
- package/dist/commands/soul.js +0 -6
- package/dist/commands/status.js +165 -124
- package/dist/commands/test.js +4 -1
- package/dist/commands/upgrade.js +53 -22
- package/dist/commands/workspace.js +7 -8
- package/dist/deploy.js +59 -3
- package/dist/doctor-client.js +9 -25
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation/scheduler.js +148 -12
- package/dist/federation-verify.js +269 -177
- package/dist/install/clients.js +171 -35
- package/dist/keystore.js +77 -10
- package/dist/lib/agent-id-rule.js +44 -2
- package/dist/lib/agent-key-file.js +509 -0
- package/dist/lib/agent-rotation-lock.js +249 -0
- package/dist/lib/atomic-write.js +3 -3
- package/dist/lib/auth-resolve.js +1040 -64
- package/dist/lib/backup-approval-store.js +612 -0
- package/dist/lib/backup-artifact.js +343 -0
- package/dist/lib/config-critical-section.js +212 -25
- package/dist/lib/connect-phase.js +33 -0
- package/dist/lib/daemon-liveness.js +2 -1
- 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/instruction-event-contract.js +17 -0
- package/dist/lib/instruction-event-doctor.js +102 -0
- package/dist/lib/key-dir.js +203 -0
- package/dist/lib/launchd-management.js +21 -6
- package/dist/lib/local-instance-pair.js +8 -1
- package/dist/lib/mcp-enable.js +14 -15
- package/dist/lib/memory-attributes.js +2 -0
- package/dist/lib/memory-provider-timeout.js +33 -0
- package/dist/lib/mqtt-config.js +132 -0
- package/dist/lib/mqtt-listener-doctor.js +104 -0
- package/dist/lib/node-alias-path.js +50 -2
- package/dist/lib/open-live-row.js +20 -0
- package/dist/lib/ops-url.js +52 -0
- package/dist/lib/promotion-content-hash.js +20 -0
- package/dist/lib/remote-admin-pass.js +157 -0
- package/dist/lib/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +1 -1
- package/dist/lib/scheduler-platform.js +13 -0
- package/dist/lib/service-repoint.js +13 -4
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed.js +125 -10
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/terminal-text.js +32 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/mcp-client-assertion.js +7 -14
- package/dist/memory-id-checkpoint.js +28 -7
- package/dist/mqtt-off-deploy.js +550 -0
- package/dist/rem/promote-policy.js +3 -3
- package/dist/rem/restore.js +302 -26
- package/dist/rem/runner.js +220 -58
- 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 +155 -45
- package/dist/resources/AgentCard.js +4 -0
- package/dist/resources/AgentKeyRegister.js +56 -22
- package/dist/resources/AgentReadPosition.js +7 -0
- package/dist/resources/AgentSeed.js +232 -107
- package/dist/resources/AutoPromoteCandidates.js +413 -84
- package/dist/resources/Credential.js +6 -8
- package/dist/resources/Federation.js +219 -57
- package/dist/resources/FederationRetry.js +4 -4
- package/dist/resources/InstructionVersion.js +1 -1
- package/dist/resources/MCPClientMetadata.js +6 -3
- package/dist/resources/Memory.js +1348 -271
- package/dist/resources/MemoryArchive.js +149 -64
- package/dist/resources/MemoryBootstrap.js +12 -22
- package/dist/resources/MemoryCandidate.js +16 -2
- package/dist/resources/MemoryConsolidate.js +2 -2
- package/dist/resources/MemoryFeed.js +360 -147
- package/dist/resources/MemoryMaintenance.js +290 -72
- package/dist/resources/MemoryPurge.js +138 -22
- package/dist/resources/MemoryReflect.js +68 -14
- package/dist/resources/MemoryReindex.js +91 -13
- package/dist/resources/Message.js +11 -2
- package/dist/resources/OAuth.js +156 -39
- package/dist/resources/OAuthClient.js +1 -1
- package/dist/resources/OrgEvent.js +292 -29
- 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 +31 -11
- package/dist/resources/PromoteMemoryCandidate.js +8 -2
- package/dist/resources/RecordUsage.js +2 -4
- package/dist/resources/Soul.js +2 -0
- package/dist/resources/SoulFeed.js +2 -1
- package/dist/resources/WorkspaceLatest.js +4 -0
- package/dist/resources/XAA.js +36 -10
- 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 +98 -68
- 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 +166 -42
- 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/embeddings-provider.js +25 -0
- package/dist/resources/federation-classify.js +89 -0
- package/dist/resources/federation-retry-lib.js +6 -81
- package/dist/resources/health.js +75 -19
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- package/dist/resources/in-process-api.js +74 -11
- package/dist/resources/in-process.js +24 -22
- package/dist/resources/instruction-version-record.js +251 -7
- package/dist/resources/internal-authority.js +13 -0
- package/dist/resources/mcp-client-metadata-fields.js +4 -0
- package/dist/resources/mcp-handler.js +146 -13
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +446 -53
- package/dist/resources/mcp-tool-scopes.js +69 -0
- package/dist/resources/mcp-tools.js +70 -22
- package/dist/resources/memory-declared-attributes.js +1 -0
- package/dist/resources/memory-embed-hash.js +56 -0
- package/dist/resources/memory-host-source.js +5 -2
- package/dist/resources/memory-reflect-lib.js +1 -1
- package/dist/resources/memory-write-lock.js +202 -23
- package/dist/resources/memory-write-response.js +1 -1
- 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 +16 -3
- package/dist/resources/migrations/dir-safety.js +60 -2
- package/dist/resources/migrations/embedding-stamp.js +315 -49
- package/dist/resources/migrations/graph-heal.js +9 -2
- package/dist/resources/migrations/ledger.js +5 -2
- package/dist/resources/migrations/lock.js +867 -80
- package/dist/resources/migrations/progress.js +71 -10
- package/dist/resources/migrations/runner.js +212 -18
- package/dist/resources/migrations/state.js +36 -1
- package/dist/resources/migrations/status.js +2 -13
- package/dist/resources/migrations/synthetic-test-migration.js +78 -12
- package/dist/resources/migrations/types.js +26 -1
- package/dist/resources/migrations/visibility-backfill.js +111 -70
- package/dist/resources/oauth-discovery.js +0 -5
- package/dist/resources/object-body-guard.js +12 -5
- package/dist/resources/org-event-reserved.js +92 -0
- package/dist/resources/org-event-write-fault.js +19 -0
- package/dist/resources/owner-field-guard.js +1 -1
- package/dist/resources/owner-scoped-write-policy.js +65 -21
- package/dist/resources/owner-scoped-writes.js +37 -6
- package/dist/resources/path-id-rewrite.js +76 -0
- package/dist/resources/presence-internal.js +5 -5
- package/dist/resources/promotion-binding.js +43 -0
- package/dist/resources/promotion-stamp.js +124 -33
- package/dist/resources/protocol-context.js +189 -0
- package/dist/resources/record-type-kit.js +2 -4
- package/dist/resources/request-target.js +28 -1
- package/dist/resources/request-transaction.js +11 -1
- package/dist/resources/seed-reservation.js +1 -2
- package/dist/resources/semantic-retrieval-core.js +7 -6
- package/dist/resources/server-row-validation.js +71 -0
- package/dist/resources/skill-manifest.js +4 -3
- package/dist/resources/skill-version-write.js +400 -27
- package/dist/resources/skill-write-fault.js +6 -3
- package/dist/resources/skill-write-policy.js +2 -1
- package/dist/resources/soul-write-policy.js +26 -7
- package/dist/resources/table-helpers.js +1 -1
- package/dist/resources/table-subscription-policy.js +518 -85
- package/dist/resources/table-subscriptions.js +20 -7
- package/dist/resources/txn-pause-point.js +122 -5
- package/dist/resources/usage-recording.js +54 -46
- package/dist/resources/write-back.js +176 -11
- package/dist/resources/write-journal-context.js +5 -0
- package/dist/resources/write-journal.js +289 -0
- package/dist/src/keystore.js +77 -10
- package/dist/src/lib/agent-id-rule.js +44 -2
- package/dist/src/lib/atomic-write.js +3 -3
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/key-dir.js +203 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/open-live-row.js +20 -0
- package/dist/src/lib/scheduler-platform.js +13 -0
- package/dist/src/lib/soul-scope-fields.js +26 -0
- package/dist/src/rem/promote-policy.js +3 -3
- package/dist/src/rem/scheduler.js +21 -4
- package/docs/access-control.md +39 -21
- package/docs/api-reference.md +161 -52
- package/docs/auth.md +69 -38
- package/docs/claude-code.md +3 -3
- package/docs/deploying-on-fabric.md +118 -2
- package/docs/deployment.md +17 -0
- package/docs/embedding-in-a-harper-app.md +23 -21
- package/docs/entity-vocabulary.md +7 -11
- package/docs/federation.md +29 -2
- package/docs/hosted-on-fabric.md +1 -1
- package/docs/integrations.md +11 -11
- package/docs/mcp-clients.md +7 -5
- package/docs/notes/mcp-agent-auth-consumer.md +4 -9
- package/docs/notes/mcp-oauth-model2.md +6 -6
- package/docs/openclaw.md +1 -1
- package/docs/quickstart-fabric.md +2 -2
- package/docs/quickstart.md +3 -3
- package/docs/releasing.md +13 -13
- package/docs/rem.md +24 -3
- package/docs/secrets-and-keys.md +9 -14
- package/docs/standalone-local.md +29 -2
- package/docs/supply-chain-policy.md +28 -20
- package/docs/the-team.md +2 -2
- package/docs/upgrade.md +29 -5
- package/package.json +18 -11
- package/schemas/agent.graphql +3 -3
- package/schemas/federation.graphql +10 -7
- package/schemas/memory.graphql +7 -2
- 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
|
@@ -44,7 +44,7 @@ export const RESTORE_PRESERVED_FIELDS = Object.freeze({
|
|
|
44
44
|
"id", "agentId", "content", "contentHash", "trigger", "visibility",
|
|
45
45
|
"tags", "durability", "source", "type",
|
|
46
46
|
"createdAt", "expiresAt", "usageCount", "promotionStatus", "promotedAt",
|
|
47
|
-
"promotedBy", "archived", "archivedAt", "archivedBy", "parentId",
|
|
47
|
+
"promotedBy", "promotionContentHash", "archived", "archivedAt", "archivedBy", "parentId",
|
|
48
48
|
"derivedFrom", "sessionId", "lastReflected", "supersedes", "subject",
|
|
49
49
|
"summary", "validFrom", "validTo", "metadata", "entities",
|
|
50
50
|
"meta", "kind",
|
|
@@ -477,6 +477,19 @@ export function describeScheduledDriverFinding(f) {
|
|
|
477
477
|
};
|
|
478
478
|
}
|
|
479
479
|
// Loaded from here down.
|
|
480
|
+
if (f.shimMissingNode) {
|
|
481
|
+
const m = f.shimMissingNode;
|
|
482
|
+
return {
|
|
483
|
+
state: "degraded",
|
|
484
|
+
icon: "error",
|
|
485
|
+
isIssue: true,
|
|
486
|
+
message: `${f.label} DEGRADED — the shim its unit file names execs a node binary that does not exist (${m.nodeBin})`,
|
|
487
|
+
detail: [
|
|
488
|
+
`${m.unitPath} names ${m.shimPath} as its program; the shim's exec line names ${m.nodeBin}, which does not exist.`,
|
|
489
|
+
`Fix: flair init # then check: ${f.statusCommand}`,
|
|
490
|
+
],
|
|
491
|
+
};
|
|
492
|
+
}
|
|
480
493
|
const le = f.lastExit;
|
|
481
494
|
if (!le || le.state === "unavailable") {
|
|
482
495
|
return {
|
|
@@ -45,10 +45,15 @@
|
|
|
45
45
|
* - the old tree's flair version (or this CLI's) cannot be read, is not strict
|
|
46
46
|
* semver, or is newer by semver ordering (0.57.0-beta.1 is older than 0.57.0)
|
|
47
47
|
* → refused: a downgrade cannot be ruled out;
|
|
48
|
-
* - it serves THIS CLI's tree with an existing, different
|
|
49
|
-
*
|
|
48
|
+
* - with valid targets, it serves THIS CLI's tree with an existing, different
|
|
49
|
+
* node and its other runtime paths exist → `pinned-node`, apart from the
|
|
50
|
+
* launchd Homebrew case below; systemd refuses missing runtime paths;
|
|
50
51
|
* - launchd only: it serves this CLI's tree and one of its runtime paths no
|
|
51
|
-
* longer exists →
|
|
52
|
+
* longer exists → the missing path is replaced (systemd: refused);
|
|
53
|
+
* - launchd only: it serves this CLI's tree with an existing node path in
|
|
54
|
+
* Homebrew's Cellar whose `opt/<formula>` alias resolves to the same
|
|
55
|
+
* binary → that node path is replaced by the alias, including in the same
|
|
56
|
+
* write as a missing runtime path (flair#3056).
|
|
52
57
|
*
|
|
53
58
|
* Every refusal names the unit file, what did not match, and the remedy — the
|
|
54
59
|
* paths to set by hand, an update, or a reinstall.
|
|
@@ -395,13 +400,17 @@ export function planPlistRuntimeRepoint(raw, t, deps, plistPath, owner) {
|
|
|
395
400
|
const next = { ...current };
|
|
396
401
|
const sameTree = deps.samePath(oldTree, t.workingDirectory);
|
|
397
402
|
if (sameTree) {
|
|
398
|
-
// Same tree: replace
|
|
403
|
+
// Same tree: replace what no longer exists, and an existing Homebrew Cellar
|
|
404
|
+
// node whose opt alias resolves to the same binary (flair#3056); any other
|
|
405
|
+
// existing different node is a deliberate pin.
|
|
399
406
|
if (!deps.exists(current.launcher))
|
|
400
407
|
next.launcher = t.launcher;
|
|
401
408
|
if (!deps.exists(current.harperBin))
|
|
402
409
|
next.harperBin = t.harperBin;
|
|
403
410
|
if (!deps.exists(current.nodeBin))
|
|
404
411
|
next.nodeBin = t.nodeBin;
|
|
412
|
+
else
|
|
413
|
+
next.nodeBin = deps.homebrewOptAlias(current.nodeBin) ?? current.nodeBin;
|
|
405
414
|
}
|
|
406
415
|
else {
|
|
407
416
|
const refusal = treeGate(oldTree, t, deps, unit, true);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill-assignment-preflight.ts — the CLI-side copy of the server's
|
|
3
|
+
* `refuseSkillAssignmentWrite` (resources/skill-provenance.ts) used by
|
|
4
|
+
* non-dry-run `flair restore --replace` before any delete.
|
|
5
|
+
*
|
|
6
|
+
* A copy, not an import: `src/` must not import `resources/` (those imports do
|
|
7
|
+
* not survive npm packaging). test/unit/skill-assignment-preflight.test.ts
|
|
8
|
+
* pins this copy to the server module over a shared fixture table.
|
|
9
|
+
*/
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { isAbsolute, resolve, sep } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
export const SKILL_ASSIGNMENT_KEY = "skill-assignment";
|
|
14
|
+
export function parseSkillMetadata(metadata) {
|
|
15
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
16
|
+
return metadata;
|
|
17
|
+
}
|
|
18
|
+
if (typeof metadata === "string" && metadata.length > 0) {
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(metadata);
|
|
21
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
/* opaque / corrupt blob — no source */
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
export function skillSourceOf(record) {
|
|
32
|
+
const src = parseSkillMetadata(record.metadata).source;
|
|
33
|
+
return typeof src === "string" && src.trim().length > 0 ? src.trim() : undefined;
|
|
34
|
+
}
|
|
35
|
+
const SCHEME = /^([a-zA-Z][a-zA-Z0-9+.-]*):/;
|
|
36
|
+
function isWindowsDrivePath(source) {
|
|
37
|
+
return /^[a-zA-Z]:[\\/]/.test(source);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* If `source` names a filesystem path (absolute, relative, or `file:` URL),
|
|
41
|
+
* return that path. Scheme-bearing identifiers (`npm:`, `https:`, …) are
|
|
42
|
+
* not filesystem paths. A bare name is not a path.
|
|
43
|
+
*/
|
|
44
|
+
export function filesystemPathFromSkillSource(source) {
|
|
45
|
+
const trimmed = source.trim();
|
|
46
|
+
if (!trimmed)
|
|
47
|
+
return null;
|
|
48
|
+
if (trimmed.startsWith("file:")) {
|
|
49
|
+
try {
|
|
50
|
+
return fileURLToPath(trimmed);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
const rest = trimmed.replace(/^file:\/\//, "").replace(/^file:/, "");
|
|
54
|
+
return rest.length > 0 ? rest : null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (SCHEME.test(trimmed) && !isWindowsDrivePath(trimmed))
|
|
58
|
+
return null;
|
|
59
|
+
if (isAbsolute(trimmed) || trimmed.startsWith(".") || /[\\/]/.test(trimmed)) {
|
|
60
|
+
return trimmed;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function tempRoots() {
|
|
65
|
+
const roots = new Set();
|
|
66
|
+
const add = (p) => {
|
|
67
|
+
if (!p || typeof p !== "string" || p.length === 0)
|
|
68
|
+
return;
|
|
69
|
+
try {
|
|
70
|
+
roots.add(resolve(p));
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* ignore unresolvable */
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
add(tmpdir());
|
|
77
|
+
add("/tmp");
|
|
78
|
+
add("/private/tmp");
|
|
79
|
+
add("/var/tmp");
|
|
80
|
+
add(process.env.TMPDIR);
|
|
81
|
+
add(process.env.TMP);
|
|
82
|
+
add(process.env.TEMP);
|
|
83
|
+
return [...roots];
|
|
84
|
+
}
|
|
85
|
+
export function isNonDurableFilesystemPath(fsPath) {
|
|
86
|
+
let resolved;
|
|
87
|
+
try {
|
|
88
|
+
resolved = resolve(fsPath);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
for (const root of tempRoots()) {
|
|
94
|
+
if (resolved === root || resolved.startsWith(root + sep))
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
export function isDurableSkillSource(source) {
|
|
100
|
+
const fsPath = filesystemPathFromSkillSource(source);
|
|
101
|
+
if (fsPath == null)
|
|
102
|
+
return true;
|
|
103
|
+
return !isNonDurableFilesystemPath(fsPath);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Whether `record` is a skill-assignment row whose source is a filesystem path.
|
|
107
|
+
* Parsing the source is environment-independent; the durability verdict for a
|
|
108
|
+
* filesystem path is not (it reads this process's temp roots).
|
|
109
|
+
*/
|
|
110
|
+
export function skillSourceIsFilesystemPath(record) {
|
|
111
|
+
if (record.key !== SKILL_ASSIGNMENT_KEY)
|
|
112
|
+
return false;
|
|
113
|
+
const source = skillSourceOf(record);
|
|
114
|
+
return source !== undefined && filesystemPathFromSkillSource(source) !== null;
|
|
115
|
+
}
|
|
116
|
+
export function registerSkillAssignment(input) {
|
|
117
|
+
const key = typeof input.key === "string" ? input.key : SKILL_ASSIGNMENT_KEY;
|
|
118
|
+
if (key !== SKILL_ASSIGNMENT_KEY)
|
|
119
|
+
return { ok: true };
|
|
120
|
+
const source = skillSourceOf(input);
|
|
121
|
+
if (!source)
|
|
122
|
+
return { ok: true };
|
|
123
|
+
if (isDurableSkillSource(source))
|
|
124
|
+
return { ok: true };
|
|
125
|
+
return {
|
|
126
|
+
ok: false,
|
|
127
|
+
error: "skill_source_not_durable",
|
|
128
|
+
path: source,
|
|
129
|
+
message: `skill source is not durable: ${source}`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function assignmentKey(content, existing) {
|
|
133
|
+
const key = content?.key ?? existing?.key;
|
|
134
|
+
return typeof key === "string" ? key : undefined;
|
|
135
|
+
}
|
|
136
|
+
/** Soul post/put/patch gate. `existing` supplies omitted fields on PATCH. */
|
|
137
|
+
export function refuseSkillAssignmentWrite(content, existing) {
|
|
138
|
+
if (assignmentKey(content, existing) !== SKILL_ASSIGNMENT_KEY)
|
|
139
|
+
return null;
|
|
140
|
+
const metadata = content?.metadata !== undefined ? content.metadata : existing?.metadata;
|
|
141
|
+
// flair#2141 S1: `metadata.optOut`, when present, is a boolean.
|
|
142
|
+
const parsed = parseSkillMetadata(metadata);
|
|
143
|
+
if (Object.hasOwn(parsed, "optOut") && typeof parsed.optOut !== "boolean") {
|
|
144
|
+
return new Response(JSON.stringify({ error: "skill_opt_out_not_boolean", message: "metadata.optOut must be true or false" }), { status: 400, headers: { "content-type": "application/json" } });
|
|
145
|
+
}
|
|
146
|
+
const result = registerSkillAssignment({
|
|
147
|
+
key: SKILL_ASSIGNMENT_KEY,
|
|
148
|
+
value: content?.value ?? existing?.value,
|
|
149
|
+
priority: content?.priority ?? existing?.priority,
|
|
150
|
+
metadata,
|
|
151
|
+
});
|
|
152
|
+
if (!("error" in result))
|
|
153
|
+
return null;
|
|
154
|
+
return new Response(JSON.stringify({
|
|
155
|
+
error: result.error,
|
|
156
|
+
path: result.path,
|
|
157
|
+
message: result.message,
|
|
158
|
+
}), { status: 400, headers: { "content-type": "application/json" } });
|
|
159
|
+
}
|
package/dist/lib/skill-seed.js
CHANGED
|
@@ -58,7 +58,8 @@ export const SEED_ASSIGNMENT_PRIORITY = "standard";
|
|
|
58
58
|
*/
|
|
59
59
|
export const SEED_REQUEST_TIMEOUT_MS = 15_000;
|
|
60
60
|
/**
|
|
61
|
-
* The bound on the skill row's write
|
|
61
|
+
* The bound on the skill row's write, counted from its first attempt (see
|
|
62
|
+
* runSkillSeed for the retries it bounds). The instance embeds a skill row as it
|
|
62
63
|
* writes it (`Memory.put` awaits `getEmbedding`), and the first embed awaits
|
|
63
64
|
* the embedding model's readiness: the model may need to download (~80 MB) or
|
|
64
65
|
* load in the background, and Harper can report healthy before that ends. So
|
|
@@ -70,6 +71,20 @@ export const SEED_REQUEST_TIMEOUT_MS = 15_000;
|
|
|
70
71
|
export const SEED_SKILL_WRITE_TIMEOUT_MS = 180_000;
|
|
71
72
|
/** How long the skill row's write runs before init says what it is waiting on. */
|
|
72
73
|
export const SEED_SKILL_WRITE_NOTICE_MS = 5_000;
|
|
74
|
+
/**
|
|
75
|
+
* The wait before the seed tries the skill row's write again after the
|
|
76
|
+
* instance refused it with 503 `memory_provider_timeout`, which states nothing
|
|
77
|
+
* was written. The seed tries again only while the skill-write bound
|
|
78
|
+
* ({@link SEED_SKILL_WRITE_TIMEOUT_MS} by default), counted from the first
|
|
79
|
+
* attempt, leaves time for this wait.
|
|
80
|
+
*/
|
|
81
|
+
export const SEED_SKILL_WRITE_RETRY_BACKOFF_MS = 2_000;
|
|
82
|
+
/** The server's error code for an embedding call that outlasted its bound. */
|
|
83
|
+
const MEMORY_PROVIDER_TIMEOUT = "memory_provider_timeout";
|
|
84
|
+
const REAL_CLOCK = {
|
|
85
|
+
now: () => Date.now(),
|
|
86
|
+
pause: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
87
|
+
};
|
|
73
88
|
/** The shipped `using-flair` skill as this build defines it. */
|
|
74
89
|
export function currentSeed() {
|
|
75
90
|
return {
|
|
@@ -144,8 +159,54 @@ const ROW_REMEDY = `Inspect it (GET ${ROW_PATH}), delete it with the operator's
|
|
|
144
159
|
"then re-run 'flair init'";
|
|
145
160
|
const ASSIGNMENT_REMEDY = `Inspect it (GET ${ASSIGNMENT_PATH}), correct or delete it with the operator's Basic credentials, ` +
|
|
146
161
|
"then re-run 'flair init'";
|
|
147
|
-
/**
|
|
148
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Apply the seed rule over `io`. Preflight reads and checks pass before either
|
|
164
|
+
* write. When the instance refuses the skill row's write with 503
|
|
165
|
+
* `memory_provider_timeout`, the seed waits {@link SEED_SKILL_WRITE_RETRY_BACKOFF_MS}
|
|
166
|
+
* and runs the whole pass again, reads and checks included, while the io's
|
|
167
|
+
* skill-write bound, counted from the first attempt, leaves time for that wait.
|
|
168
|
+
* Each attempt's write waits at most the time left in that bound. When the
|
|
169
|
+
* bound leaves no time for another wait, passes before a retried pass's write,
|
|
170
|
+
* or ends a write that got no answer, the refusal names the attempts and the
|
|
171
|
+
* time spent.
|
|
172
|
+
*/
|
|
173
|
+
export async function runSkillSeed(io, current, clock = REAL_CLOCK) {
|
|
174
|
+
const boundMs = io.skillWriteTimeoutMs ?? SEED_SKILL_WRITE_TIMEOUT_MS;
|
|
175
|
+
let firstWriteAt;
|
|
176
|
+
const rowWriteBudget = () => {
|
|
177
|
+
firstWriteAt ??= clock.now();
|
|
178
|
+
return firstWriteAt + boundMs - clock.now();
|
|
179
|
+
};
|
|
180
|
+
let attempts = 0;
|
|
181
|
+
const boundPassed = (end) => refused("skill_seed_write_failed", `writing the "${SEED_SKILL_ID}" skill row did not finish within its ${seconds(boundMs)} bound: ${attempts} ` +
|
|
182
|
+
`${attempts === 1 ? "attempt" : "attempts"} over ${seconds(clock.now() - (firstWriteAt ?? clock.now()))}; ` +
|
|
183
|
+
`${end}; the org assignment was not written. Re-run 'flair init'`);
|
|
184
|
+
const refusedEach = () => `${attempts === 1 ? "it was" : "each was"} refused with 503 memory_provider_timeout`;
|
|
185
|
+
for (;;) {
|
|
186
|
+
const outcome = await seedPass(io, current, rowWriteBudget);
|
|
187
|
+
if (outcome.kind === "no_time") {
|
|
188
|
+
return boundPassed(`${refusedEach()}, and the bound passed while the seed re-read the instance`);
|
|
189
|
+
}
|
|
190
|
+
if (outcome.kind === "no_answer") {
|
|
191
|
+
attempts++;
|
|
192
|
+
return boundPassed(`${attempts === 1 ? "it" : "the last"} got ${outcome.detail}`);
|
|
193
|
+
}
|
|
194
|
+
if (outcome.kind !== "provider_timeout")
|
|
195
|
+
return outcome;
|
|
196
|
+
attempts++;
|
|
197
|
+
if (clock.now() - (firstWriteAt ?? clock.now()) + SEED_SKILL_WRITE_RETRY_BACKOFF_MS >= boundMs) {
|
|
198
|
+
return boundPassed(`${refusedEach()}, and no time is left for another (last: ${outcome.detail})`);
|
|
199
|
+
}
|
|
200
|
+
await clock.pause(SEED_SKILL_WRITE_RETRY_BACKOFF_MS);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The seed's reads and refusals, with no write. {@link seedPass} runs it before
|
|
205
|
+
* its writes, and {@link checkUsingFlairSkill} runs it alone as init's
|
|
206
|
+
* preflight; the two calls use the same checks and message templates (expiry
|
|
207
|
+
* checks read the real clock on each pass).
|
|
208
|
+
*/
|
|
209
|
+
async function checkSeed(io, current) {
|
|
149
210
|
const rowRead = await io.readRow();
|
|
150
211
|
if (!rowRead.ok) {
|
|
151
212
|
return refused("skill_seed_row_unreadable", `the "${SEED_SKILL_ID}" Memory row could not be read (${rowRead.detail ?? "no detail"}); ${NOTHING_WRITTEN}. ` +
|
|
@@ -188,10 +249,25 @@ export async function runSkillSeed(io, current) {
|
|
|
188
249
|
return refused("skill_seed_assignment_mismatch", `the "${SEED_ASSIGNMENT_ID}" org assignment ${problems.join("; ")}; ${NOTHING_WRITTEN}. ${ASSIGNMENT_REMEDY}`);
|
|
189
250
|
}
|
|
190
251
|
}
|
|
252
|
+
return { kind: "ready", storedContent, assignment: assignRead.row ?? null };
|
|
253
|
+
}
|
|
254
|
+
async function seedPass(io, current, rowWriteBudget) {
|
|
255
|
+
const checked = await checkSeed(io, current);
|
|
256
|
+
if (checked.kind !== "ready")
|
|
257
|
+
return checked;
|
|
258
|
+
const { storedContent, assignment } = checked;
|
|
191
259
|
const action = decideSkillSeed(storedContent, current.content, current.hashes);
|
|
192
260
|
if (action === "create" || action === "replace") {
|
|
193
|
-
const
|
|
261
|
+
const budgetMs = rowWriteBudget();
|
|
262
|
+
if (budgetMs <= 0)
|
|
263
|
+
return { kind: "no_time" };
|
|
264
|
+
const write = await io.putRow(budgetMs);
|
|
194
265
|
if (!write.ok) {
|
|
266
|
+
if (write.status === 503 && write.code === MEMORY_PROVIDER_TIMEOUT) {
|
|
267
|
+
return { kind: "provider_timeout", detail: write.detail ?? "no detail" };
|
|
268
|
+
}
|
|
269
|
+
if (write.timedOut)
|
|
270
|
+
return { kind: "no_answer", detail: write.detail ?? "no detail" };
|
|
195
271
|
return refused("skill_seed_write_failed", `writing the "${SEED_SKILL_ID}" skill row failed (${write.detail ?? "no detail"}); the org assignment was not ` +
|
|
196
272
|
"written. Re-run 'flair init'");
|
|
197
273
|
}
|
|
@@ -211,8 +287,8 @@ export async function runSkillSeed(io, current) {
|
|
|
211
287
|
`${problems.join("; ")}; the org assignment was not written. Check the Memory table and re-run 'flair init'`);
|
|
212
288
|
}
|
|
213
289
|
}
|
|
214
|
-
let assignmentId = String(
|
|
215
|
-
if (!
|
|
290
|
+
let assignmentId = String(assignment?.id ?? "");
|
|
291
|
+
if (!assignment) {
|
|
216
292
|
const write = await io.putAssignment();
|
|
217
293
|
if (!write.ok) {
|
|
218
294
|
return refused("skill_seed_write_failed", `writing the "${SEED_ASSIGNMENT_ID}" org assignment failed (${write.detail ?? "no detail"}); re-run 'flair init'`);
|
|
@@ -245,6 +321,16 @@ function detailOf(err) {
|
|
|
245
321
|
function isTimeout(err) {
|
|
246
322
|
return typeof err === "object" && err !== null && err.name === "TimeoutError";
|
|
247
323
|
}
|
|
324
|
+
/** The string `error` field of a JSON object body, or undefined. */
|
|
325
|
+
function errorCodeOf(text) {
|
|
326
|
+
try {
|
|
327
|
+
const body = JSON.parse(text);
|
|
328
|
+
return body && typeof body === "object" && typeof body.error === "string" ? body.error : undefined;
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
248
334
|
function seconds(ms) {
|
|
249
335
|
return `${Math.round(ms / 100) / 10} s`;
|
|
250
336
|
}
|
|
@@ -312,12 +398,17 @@ export function skillSeedRestIo(opts, current = currentSeed()) {
|
|
|
312
398
|
}
|
|
313
399
|
catch (err) {
|
|
314
400
|
if (isTimeout(err))
|
|
315
|
-
return { ok: false, detail: onTimeout(timeoutMs) };
|
|
401
|
+
return { ok: false, detail: onTimeout(timeoutMs), timedOut: true };
|
|
316
402
|
return { ok: false, detail: `the request failed: ${detailOf(err)}` };
|
|
317
403
|
}
|
|
318
404
|
if (!res.ok) {
|
|
319
405
|
const text = await res.text().catch(() => "");
|
|
320
|
-
return {
|
|
406
|
+
return {
|
|
407
|
+
ok: false,
|
|
408
|
+
detail: `HTTP ${res.status}${text ? `: ${text.slice(0, 200)}` : ""}`,
|
|
409
|
+
status: res.status,
|
|
410
|
+
code: errorCodeOf(text),
|
|
411
|
+
};
|
|
321
412
|
}
|
|
322
413
|
return { ok: true };
|
|
323
414
|
};
|
|
@@ -327,14 +418,18 @@ export function skillSeedRestIo(opts, current = currentSeed()) {
|
|
|
327
418
|
// instance, which may still land it. The id is fixed, so a re-run updates
|
|
328
419
|
// that row rather than adding one; a re-run started while the first write is
|
|
329
420
|
// still pending can send a second PUT to the same id.
|
|
330
|
-
|
|
421
|
+
let noticed = false;
|
|
422
|
+
const putRow = async (timeoutMs = skillWriteMs) => {
|
|
331
423
|
const notice = setTimeout(() => {
|
|
424
|
+
if (noticed)
|
|
425
|
+
return;
|
|
426
|
+
noticed = true;
|
|
332
427
|
opts.notify?.(`using-flair skill: still writing "${SEED_SKILL_ID}" — the instance embeds a skill row as it writes it, ` +
|
|
333
428
|
`and it may need to download (~80 MB) or load the embedding model first; waiting up to ${seconds(skillWriteMs)}`);
|
|
334
429
|
}, skillNoticeMs);
|
|
335
430
|
notice.unref?.();
|
|
336
431
|
try {
|
|
337
|
-
return await putById("Memory", SEED_SKILL_ID, seedSkillBody(opts.user, current),
|
|
432
|
+
return await putById("Memory", SEED_SKILL_ID, seedSkillBody(opts.user, current), timeoutMs, (ms) => `no answer within ${seconds(ms)} — the instance embeds a skill row as it writes it, so this write also ` +
|
|
338
433
|
`waits for its embedding model, which may need to download or load; 'flair doctor' reports embeddings. The write may ` +
|
|
339
434
|
`still land; the id is fixed, so a re-run updates that row rather than adding one`);
|
|
340
435
|
}
|
|
@@ -348,6 +443,7 @@ export function skillSeedRestIo(opts, current = currentSeed()) {
|
|
|
348
443
|
readAssignment: () => readById("OrgSkillAssignment", SEED_ASSIGNMENT_ID),
|
|
349
444
|
readOperatorAgent: () => readById("Agent", opts.user),
|
|
350
445
|
putRow,
|
|
446
|
+
skillWriteTimeoutMs: skillWriteMs,
|
|
351
447
|
putAssignment: () => putById("OrgSkillAssignment", SEED_ASSIGNMENT_ID, {
|
|
352
448
|
skillName: current.name,
|
|
353
449
|
skillRef: SEED_SKILL_ID,
|
|
@@ -363,3 +459,22 @@ export function skillSeedRestIo(opts, current = currentSeed()) {
|
|
|
363
459
|
export function seedUsingFlairSkill(opts) {
|
|
364
460
|
return runSkillSeed(skillSeedRestIo(opts), currentSeed());
|
|
365
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* Run the seed's reads and refusals on the instance at `baseUrl` without
|
|
464
|
+
* writing anything. `flair init` calls it before the role, shared-user and
|
|
465
|
+
* Agent writes in `finishRemoteInit`, and before the local agent write when it
|
|
466
|
+
* starts its own instance; the seed re-runs the same checks when it writes.
|
|
467
|
+
*/
|
|
468
|
+
export async function checkUsingFlairSkill(opts) {
|
|
469
|
+
const current = currentSeed();
|
|
470
|
+
const checked = await checkSeed(skillSeedRestIo(opts), current);
|
|
471
|
+
if (checked.kind !== "ready")
|
|
472
|
+
return checked;
|
|
473
|
+
return {
|
|
474
|
+
kind: "ok",
|
|
475
|
+
action: decideSkillSeed(checked.storedContent, current.content, current.hashes),
|
|
476
|
+
skillId: SEED_SKILL_ID,
|
|
477
|
+
assignmentId: String(checked.assignment?.id ?? ""),
|
|
478
|
+
message: "the using-flair skill seed passed its checks",
|
|
479
|
+
};
|
|
480
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill-tombstone-doctor.ts — the `flair doctor` check for skill subjects whose
|
|
3
|
+
* newest InstructionVersion is a `delete` tombstone while the skill's Memory
|
|
4
|
+
* row is still open-live (flair#2662).
|
|
5
|
+
*
|
|
6
|
+
* A skill DELETE appends a tombstone and closes the live Memory row. When the
|
|
7
|
+
* post-commit confirmation cannot read the close, the tombstone can commit
|
|
8
|
+
* while the row stays open-live. This check reports that inconsistency; it
|
|
9
|
+
* never repairs it.
|
|
10
|
+
*
|
|
11
|
+
* "Open-live" is the skill writer's own predicate (isOpenLiveRow): not
|
|
12
|
+
* archived, not expired, and no `validTo`. An archived or expired row under a
|
|
13
|
+
* tombstone is not reported.
|
|
14
|
+
*
|
|
15
|
+
* The decision reads only the row fields and the current time. The reads use the operations API and return null on a
|
|
16
|
+
* failed read (never an empty list), so a doctor that cannot read the tables
|
|
17
|
+
* reports the check as unrun rather than passed when this section runs. When
|
|
18
|
+
* Harper is not responding, the enclosing gate skips the section and doctor
|
|
19
|
+
* reports the server problem elsewhere.
|
|
20
|
+
*/
|
|
21
|
+
import { isOpenLiveRow } from "./open-live-row.js";
|
|
22
|
+
export const SKILL_TOMBSTONE_VERSION_ROWS_SQL = "SELECT id, subjectType, subjectId, version, kind, rowId FROM flair.InstructionVersion WHERE subjectType = 'skill'";
|
|
23
|
+
export const SKILL_TOMBSTONE_MEMORY_ROWS_SQL = "SELECT id, skillSubjectId, validTo, archived, expiresAt FROM flair.Memory";
|
|
24
|
+
function versionSequence(value) {
|
|
25
|
+
if (typeof value === "bigint")
|
|
26
|
+
return value;
|
|
27
|
+
if (typeof value === "number")
|
|
28
|
+
return Number.isInteger(value) ? BigInt(value) : null;
|
|
29
|
+
if (typeof value === "string" && /^\d+$/.test(value))
|
|
30
|
+
return BigInt(value);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/** The skill writer's open-live predicate, applied to a row read from Memory. */
|
|
34
|
+
function memoryRowIsOpenLive(row) {
|
|
35
|
+
return isOpenLiveRow(row);
|
|
36
|
+
}
|
|
37
|
+
function rowIdOf(row) {
|
|
38
|
+
return typeof row.id === "string" && row.id.length > 0 ? row.id : null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Every skill subject whose newest InstructionVersion is a `delete` tombstone
|
|
42
|
+
* and whose Memory row is still open-live, sorted by subject id. A closed,
|
|
43
|
+
* archived, expired or absent Memory row passes.
|
|
44
|
+
*/
|
|
45
|
+
export function findLiveSkillTombstones(versions, memories) {
|
|
46
|
+
const heads = new Map();
|
|
47
|
+
for (const row of versions) {
|
|
48
|
+
if (!row || typeof row !== "object" || row.subjectType !== "skill")
|
|
49
|
+
continue;
|
|
50
|
+
if (typeof row.subjectId !== "string" || row.subjectId.length === 0)
|
|
51
|
+
continue;
|
|
52
|
+
const version = versionSequence(row.version);
|
|
53
|
+
if (version === null)
|
|
54
|
+
continue;
|
|
55
|
+
const current = heads.get(row.subjectId);
|
|
56
|
+
if (!current || version > current.version)
|
|
57
|
+
heads.set(row.subjectId, { version, row });
|
|
58
|
+
}
|
|
59
|
+
const liveRowIdBySubject = new Map();
|
|
60
|
+
const liveRowsById = new Map();
|
|
61
|
+
for (const memory of memories) {
|
|
62
|
+
if (!memory || typeof memory !== "object" || !memoryRowIsOpenLive(memory))
|
|
63
|
+
continue;
|
|
64
|
+
const id = rowIdOf(memory);
|
|
65
|
+
if (id === null)
|
|
66
|
+
continue;
|
|
67
|
+
liveRowsById.set(id, memory);
|
|
68
|
+
if (typeof memory.skillSubjectId !== "string")
|
|
69
|
+
continue;
|
|
70
|
+
const current = liveRowIdBySubject.get(memory.skillSubjectId);
|
|
71
|
+
if (current === undefined || id < current)
|
|
72
|
+
liveRowIdBySubject.set(memory.skillSubjectId, id);
|
|
73
|
+
}
|
|
74
|
+
const findings = [];
|
|
75
|
+
for (const [subjectId, { row }] of heads) {
|
|
76
|
+
if (row.kind !== "delete")
|
|
77
|
+
continue;
|
|
78
|
+
const tombstoneRowId = typeof row.rowId === "string" && row.rowId.length > 0 ? row.rowId : null;
|
|
79
|
+
let liveRowId = liveRowIdBySubject.get(subjectId);
|
|
80
|
+
if (tombstoneRowId !== null && liveRowsById.has(tombstoneRowId) &&
|
|
81
|
+
(liveRowId === undefined || tombstoneRowId < liveRowId))
|
|
82
|
+
liveRowId = tombstoneRowId;
|
|
83
|
+
if (liveRowId === undefined)
|
|
84
|
+
continue;
|
|
85
|
+
findings.push({
|
|
86
|
+
subjectId,
|
|
87
|
+
tombstoneId: rowIdOf(row) ?? "(no id)",
|
|
88
|
+
liveRowId,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return findings.sort((a, b) => (a.subjectId < b.subjectId ? -1 : a.subjectId > b.subjectId ? 1 : 0));
|
|
92
|
+
}
|
|
93
|
+
/** The doctor line for a live-tombstone set: null when the store is clean. */
|
|
94
|
+
export function describeLiveSkillTombstones(versions, memories) {
|
|
95
|
+
const findings = findLiveSkillTombstones(versions, memories);
|
|
96
|
+
if (findings.length === 0)
|
|
97
|
+
return null;
|
|
98
|
+
const rows = findings
|
|
99
|
+
.map(({ subjectId, tombstoneId, liveRowId }) => `${subjectId} (tombstone ${tombstoneId}, live row ${liveRowId})`)
|
|
100
|
+
.join(", ");
|
|
101
|
+
const noun = findings.length === 1 ? "subject" : "subjects";
|
|
102
|
+
const verb = findings.length === 1 ? "has" : "have";
|
|
103
|
+
return `${findings.length} skill ${noun} whose newest InstructionVersion is a delete tombstone still ${verb} an open-live Memory row: ${rows}`;
|
|
104
|
+
}
|
|
105
|
+
/** Read both tables through the ops API; null when either read fails. */
|
|
106
|
+
export async function readSkillTombstoneTables(args) {
|
|
107
|
+
const fetchImpl = args.fetchImpl ?? fetch;
|
|
108
|
+
const read = async (sql) => {
|
|
109
|
+
try {
|
|
110
|
+
const res = await fetchImpl(args.opsUrl, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: { "Content-Type": "application/json", Authorization: args.authHeader },
|
|
113
|
+
body: JSON.stringify({ operation: "sql", sql }),
|
|
114
|
+
signal: AbortSignal.timeout(args.timeoutMs ?? 5000),
|
|
115
|
+
});
|
|
116
|
+
if (!res.ok)
|
|
117
|
+
return null;
|
|
118
|
+
const data = await res.json();
|
|
119
|
+
return Array.isArray(data) ? data : Array.isArray(data?.results) ? data.results : null;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const versions = await read(SKILL_TOMBSTONE_VERSION_ROWS_SQL);
|
|
126
|
+
const memories = await read(SKILL_TOMBSTONE_MEMORY_ROWS_SQL);
|
|
127
|
+
if (versions === null || memories === null)
|
|
128
|
+
return null;
|
|
129
|
+
return {
|
|
130
|
+
versions: versions,
|
|
131
|
+
memories: memories,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soul is scoped to an `agentId` and has no dedicated or enforced per-user
|
|
3
|
+
* scope field (schemas/memory.graphql).
|
|
4
|
+
* A write that would store a non-empty `scopeTag` or a non-empty `tags` array
|
|
5
|
+
* is refused by name when earlier guards permit the request, whatever the tag's
|
|
6
|
+
* prefix: POST and PUT check the request body, PATCH the merged row
|
|
7
|
+
* (flair#1540).
|
|
8
|
+
*
|
|
9
|
+
* The predicate runs in the server's write policy. The refusal name is
|
|
10
|
+
* imported by `flair import` and `flair restore`, which report a row refused
|
|
11
|
+
* with it; `flair rem restore` reports its generic HTTP error and imports
|
|
12
|
+
* neither.
|
|
13
|
+
*/
|
|
14
|
+
/** The named refusal for a Soul write that would store a non-empty `scopeTag` or a non-empty `tags` array. */
|
|
15
|
+
export const SOUL_SCOPE_FIELDS_REFUSAL = "soul_scope_fields_not_writable";
|
|
16
|
+
/**
|
|
17
|
+
* Whether a row would carry a non-empty `scopeTag` or a non-empty `tags`
|
|
18
|
+
* array. POST and PUT pass the request body; PATCH passes the merged row.
|
|
19
|
+
*/
|
|
20
|
+
export function suppliesSoulScopeFields(content) {
|
|
21
|
+
const scopeTag = content?.scopeTag;
|
|
22
|
+
if (scopeTag !== undefined && scopeTag !== null && scopeTag !== "")
|
|
23
|
+
return true;
|
|
24
|
+
const tags = content?.tags;
|
|
25
|
+
return Array.isArray(tags) && tags.length > 0;
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* terminal-text.ts — escape six Unicode categories in a dynamic fragment
|
|
3
|
+
* before it is printed to a terminal.
|
|
4
|
+
*
|
|
5
|
+
* A stored value (an Agent id, a Soul key, an embedding-model name, a
|
|
6
|
+
* federation field, a server warning) is data, not layout. Printed raw, a
|
|
7
|
+
* control character can move the cursor or erase a line, and a bidi override
|
|
8
|
+
* can reorder one so the row reads differently from the bytes. This renders
|
|
9
|
+
* such a value for a HUMAN: a code point in control (Cc), format (Cf,
|
|
10
|
+
* including bidi overrides), surrogate (Cs), unassigned (Cn), line separator
|
|
11
|
+
* (Zl) or paragraph separator (Zp) is shown as a visible `\u{...}` escape, and
|
|
12
|
+
* every other code point is unchanged.
|
|
13
|
+
*
|
|
14
|
+
* This is display only: callers keep the stored value for JSON output and
|
|
15
|
+
* request bodies, so those stay byte-identical. It deliberately does not
|
|
16
|
+
* reuse boundServerText (auth-resolve.ts), which collapses whitespace and
|
|
17
|
+
* truncates — either would change an id's spelling.
|
|
18
|
+
*/
|
|
19
|
+
const ESCAPED_CATEGORIES = /[\p{Cc}\p{Cf}\p{Cs}\p{Cn}\p{Zl}\p{Zp}]/u;
|
|
20
|
+
export function escapeTerminalText(value) {
|
|
21
|
+
let out = "";
|
|
22
|
+
for (const ch of value) {
|
|
23
|
+
if (ESCAPED_CATEGORIES.test(ch)) {
|
|
24
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
25
|
+
out += `\\u{${cp.toString(16).padStart(2, "0")}}`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
out += ch;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|