@tpsdev-ai/flair 0.62.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/SECURITY.md +18 -10
- package/config.yaml +11 -11
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +66 -122
- package/dist/commands/agent.js +27 -65
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +37 -33
- package/dist/commands/bootstrap.js +3 -1
- package/dist/commands/deploy.js +37 -7
- package/dist/commands/doctor.js +119 -0
- package/dist/commands/export.js +3 -4
- 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 +131 -19
- package/dist/commands/init.js +7 -7
- package/dist/commands/integrity.js +5 -6
- package/dist/commands/mcp.js +11 -17
- package/dist/commands/memory.js +33 -15
- package/dist/commands/orgevent.js +5 -10
- package/dist/commands/principal.js +13 -25
- package/dist/commands/quality.js +3 -0
- package/dist/commands/rem.js +484 -65
- package/dist/commands/restore.js +352 -44
- package/dist/commands/service.js +84 -2
- package/dist/commands/soul.js +0 -6
- package/dist/commands/status.js +51 -33
- 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 +7 -2
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation-verify.js +269 -177
- package/dist/install/clients.js +171 -35
- package/dist/lib/agent-id-rule.js +44 -2
- package/dist/lib/atomic-write.js +1 -1
- package/dist/lib/auth-resolve.js +1028 -52
- 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/launchd-management.js +14 -3
- 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/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/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +1 -1
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed.js +91 -8
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/mcp-client-assertion.js +2 -10
- 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 +1303 -270
- 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 +43 -4
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- 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-handler.js +106 -12
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +430 -53
- package/dist/resources/mcp-tools.js +60 -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 +384 -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/lib/agent-id-rule.js +44 -2
- package/dist/src/lib/atomic-write.js +1 -1
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/open-live-row.js +20 -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 +18 -9
- package/docs/api-reference.md +126 -28
- package/docs/auth.md +40 -18
- package/docs/claude-code.md +3 -3
- package/docs/deploying-on-fabric.md +108 -0
- package/docs/deployment.md +17 -0
- package/docs/embedding-in-a-harper-app.md +16 -14
- package/docs/entity-vocabulary.md +3 -6
- package/docs/federation.md +29 -2
- 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 +2 -2
- 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 +14 -0
- 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
package/dist/install/clients.js
CHANGED
|
@@ -20,14 +20,16 @@
|
|
|
20
20
|
// per-client locations under $HOME / $XDG_CONFIG_HOME.
|
|
21
21
|
// ---- Detection helpers ----------------------------------------------------------
|
|
22
22
|
import { accessSync, constants, existsSync, mkdirSync } from "node:fs";
|
|
23
|
-
import {
|
|
23
|
+
import { homedir } from "node:os";
|
|
24
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
25
|
+
import { fileURLToPath } from "node:url";
|
|
24
26
|
import { resolveHome } from "../lib/home.js";
|
|
25
27
|
import { FLAIR_MCP_PACKAGE, flairCliVersion, isResolvedVersion, mcpServerSpec } from "../lib/mcp-spec.js";
|
|
26
28
|
import { decodeWiringSpec, wiringPinString } from "../lib/wiring-spec.js";
|
|
27
29
|
import { decidePinWrite } from "../lib/pin-write-guard.js";
|
|
28
30
|
import { pinWriteWouldLowerOrIsUnknown, comparePinVersions } from "../lib/upgrade-status.js";
|
|
29
31
|
import { withConfigCriticalSection } from "../lib/config-critical-section.js";
|
|
30
|
-
import { backupBytesTo, encodeConfig, encodeText, parseSettingsBytes } from "../lib/settings-bytes.js";
|
|
32
|
+
import { backupBytesTo, encodeConfig, encodeText, hookBackupPath, parseSettingsBytes } from "../lib/settings-bytes.js";
|
|
31
33
|
import { readTomlStringArray } from "../lib/toml-string-array.js";
|
|
32
34
|
/**
|
|
33
35
|
* The JSON.parse reason embedded in the shared parser's
|
|
@@ -948,7 +950,7 @@ export function piFlairSpec(version = flairCliVersion()) {
|
|
|
948
950
|
function piAgentDir() {
|
|
949
951
|
const envDir = process.env.PI_CODING_AGENT_DIR;
|
|
950
952
|
if (envDir)
|
|
951
|
-
return envDir;
|
|
953
|
+
return normalizePiPath(envDir, resolveHome());
|
|
952
954
|
return join(resolveHome(), ".pi", "agent");
|
|
953
955
|
}
|
|
954
956
|
/** pi user-scope settings: <agent dir>/settings.json. */
|
|
@@ -964,13 +966,15 @@ export function piPackageEntrySource(entry) {
|
|
|
964
966
|
}
|
|
965
967
|
return null;
|
|
966
968
|
}
|
|
967
|
-
/**
|
|
968
|
-
* (bare `npm:@tpsdev-ai/pi-flair` or any `npm:@tpsdev-ai/pi-flair@<spec>`)? */
|
|
969
|
+
/** Pi trims the npm spec after the literal `npm:` prefix. */
|
|
969
970
|
export function isPiFlairNpmSource(source) {
|
|
970
|
-
if (typeof source !== "string"
|
|
971
|
+
if (typeof source !== "string")
|
|
972
|
+
return false;
|
|
973
|
+
if (!source.startsWith("npm:"))
|
|
971
974
|
return false;
|
|
972
975
|
const spec = source.slice("npm:".length).trim();
|
|
973
|
-
|
|
976
|
+
const prefix = `${PI_FLAIR_PACKAGE}@`;
|
|
977
|
+
return spec === PI_FLAIR_PACKAGE || (spec.startsWith(prefix) && spec.length > prefix.length && !/\s/.test(spec));
|
|
974
978
|
}
|
|
975
979
|
/**
|
|
976
980
|
* The version text of a pinned pi-flair npm source, or null when bare.
|
|
@@ -986,18 +990,50 @@ export function extractPiFlairPin(source) {
|
|
|
986
990
|
return wiringPinString(decodeWiringSpec(source, PI_FLAIR_PACKAGE));
|
|
987
991
|
}
|
|
988
992
|
/**
|
|
989
|
-
*
|
|
990
|
-
*
|
|
991
|
-
* substring heuristic on the package/directory name — the entry is user-
|
|
992
|
-
* written free text, so this is deliberately loose in the direction of
|
|
993
|
-
* REPORTING (doctor names the entry it matched); it never gates anything
|
|
994
|
-
* destructive.
|
|
993
|
+
* Matches non-npm:/git: extension strings containing pi-flair for reporting
|
|
994
|
+
* and existing file-path wiring detection. Unwire uses isFlairOwnedPiEntry.
|
|
995
995
|
*/
|
|
996
996
|
export function isPiFlairExtensionPath(entry) {
|
|
997
997
|
if (typeof entry !== "string" || entry.startsWith("npm:") || entry.startsWith("git:"))
|
|
998
998
|
return false;
|
|
999
999
|
return entry.includes("pi-flair");
|
|
1000
1000
|
}
|
|
1001
|
+
const PI_FLAIR_PACKAGE_SEGMENTS = ["node_modules", "@tpsdev-ai", "pi-flair"];
|
|
1002
|
+
function isPiLocalSource(source) {
|
|
1003
|
+
const trimmed = source.trim();
|
|
1004
|
+
// Preserve these prefixes even when pi's Git parser falls back to local.
|
|
1005
|
+
return !["npm:", "git:", "github:", "http:", "https:", "ssh:"].some(prefix => trimmed.startsWith(prefix));
|
|
1006
|
+
}
|
|
1007
|
+
// Windows split-home rules mirror pi's source; not exercised by a test.
|
|
1008
|
+
function piLocalHome() {
|
|
1009
|
+
return process.env.HOME || homedir();
|
|
1010
|
+
}
|
|
1011
|
+
/** Match package segments in pi-local sources. */
|
|
1012
|
+
export function isInsidePiFlairPackage(entry, homeDir = piLocalHome(), baseDir = piAgentDir()) {
|
|
1013
|
+
if (typeof entry !== "string" || !isPiLocalSource(entry))
|
|
1014
|
+
return false;
|
|
1015
|
+
let resolved;
|
|
1016
|
+
try {
|
|
1017
|
+
resolved = resolvePiExtensionPath(entry, homeDir, baseDir);
|
|
1018
|
+
}
|
|
1019
|
+
catch {
|
|
1020
|
+
return false;
|
|
1021
|
+
}
|
|
1022
|
+
const segments = resolved.split(sep);
|
|
1023
|
+
for (let i = 0; i + PI_FLAIR_PACKAGE_SEGMENTS.length < segments.length; i++) {
|
|
1024
|
+
if (PI_FLAIR_PACKAGE_SEGMENTS.every((segment, offset) => segments[i + offset] === segment))
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
/** Shared pi ownership rule: npm source or resolved package-path segments. */
|
|
1030
|
+
export function isFlairOwnedPiEntry(entry, homeDir = piLocalHome(), baseDir = piAgentDir()) {
|
|
1031
|
+
if (typeof entry !== "string")
|
|
1032
|
+
return false;
|
|
1033
|
+
if (entry.startsWith("npm:"))
|
|
1034
|
+
return isPiFlairNpmSource(entry);
|
|
1035
|
+
return isInsidePiFlairPackage(entry, homeDir, baseDir);
|
|
1036
|
+
}
|
|
1001
1037
|
export function scanPiSettings(raw) {
|
|
1002
1038
|
const empty = { parsed: false, pinnedVersion: null, extensionFilePaths: [], misconfiguredNpmUnderExtensions: [] };
|
|
1003
1039
|
if (!raw || !raw.trim())
|
|
@@ -1038,18 +1074,22 @@ export function scanPiSettings(raw) {
|
|
|
1038
1074
|
}
|
|
1039
1075
|
return { parsed: true, packagesSpec, pinnedVersion, extensionFilePaths, misconfiguredNpmUnderExtensions };
|
|
1040
1076
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1077
|
+
function normalizePiPath(input, homeDir) {
|
|
1078
|
+
let path = input;
|
|
1079
|
+
if (process.platform === "win32" && path.startsWith("/") && !path.startsWith("//") && !path.includes("\\")) {
|
|
1080
|
+
const match = path.match(/^\/(?:mnt\/|cygdrive\/)?([a-z])(?:\/(.*))?$/i);
|
|
1081
|
+
if (match)
|
|
1082
|
+
path = `${match[1].toUpperCase()}:\\${match[2]?.replaceAll("/", "\\") ?? ""}`;
|
|
1083
|
+
}
|
|
1084
|
+
if (path === "~")
|
|
1085
|
+
return homeDir;
|
|
1086
|
+
if (path.startsWith("~/") || (process.platform === "win32" && path.startsWith("~\\")))
|
|
1087
|
+
return join(homeDir, path.slice(2));
|
|
1088
|
+
return path.startsWith("file://") ? fileURLToPath(path) : path;
|
|
1089
|
+
}
|
|
1090
|
+
/** Resolve local entries against pi's settings scope base. */
|
|
1047
1091
|
export function resolvePiExtensionPath(entry, homeDir, baseDir) {
|
|
1048
|
-
|
|
1049
|
-
return join(homeDir, entry.slice(1));
|
|
1050
|
-
if (entry.startsWith("/"))
|
|
1051
|
-
return entry;
|
|
1052
|
-
return join(baseDir, entry);
|
|
1092
|
+
return resolve(normalizePiPath(baseDir, homedir()), normalizePiPath(entry.trim(), homeDir));
|
|
1053
1093
|
}
|
|
1054
1094
|
/** Pretty-printed minimal settings snippet for copy-paste fallbacks. */
|
|
1055
1095
|
function piJsonSnippet() {
|
|
@@ -1083,7 +1123,7 @@ function _wirePi(env) {
|
|
|
1083
1123
|
// atomic rename, with a 0600 `.bak` of the in-lock bytes. The pure helpers are
|
|
1084
1124
|
// unchanged, so the bytes written are exactly today's.
|
|
1085
1125
|
const path = piSettingsPath();
|
|
1086
|
-
const home =
|
|
1126
|
+
const home = piLocalHome();
|
|
1087
1127
|
const display = displayUnderHome(path);
|
|
1088
1128
|
const spec = piFlairSpec();
|
|
1089
1129
|
const envHint = `pi settings carry no env — export FLAIR_AGENT_ID=${env.FLAIR_AGENT_ID} in the shell that launches pi`;
|
|
@@ -1271,6 +1311,47 @@ export function clientConfigPath(id) {
|
|
|
1271
1311
|
return piSettingsPath();
|
|
1272
1312
|
}
|
|
1273
1313
|
}
|
|
1314
|
+
/**
|
|
1315
|
+
* The snapshot `withConfigCriticalSection` writes before it mutates a client
|
|
1316
|
+
* config (settings-bytes `backupBytesTo`): a sibling `<config>.bak`. */
|
|
1317
|
+
export function clientConfigBackupPath(id) {
|
|
1318
|
+
return hookBackupPath(clientConfigPath(id));
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Answer "does this client config carry a Flair entry?" for callers reading a
|
|
1322
|
+
* copy of the config rather than the live file (purge's `.bak` sweep,
|
|
1323
|
+
* flair#2886). `present` and `absent` use the identification that client's
|
|
1324
|
+
* `unwire()` acts on. `path` names the file in an `unknown` reason; malformed
|
|
1325
|
+
* JSON uses fixed text plus that path, never the parser's message.
|
|
1326
|
+
*/
|
|
1327
|
+
export function clientConfigHasFlairEntry(id, bytes, path) {
|
|
1328
|
+
if (id === "codex") {
|
|
1329
|
+
// config.toml is TEXT; its unwire tests the raw string, not JSON, so a
|
|
1330
|
+
// malformed TOML file is still scanned for the header line.
|
|
1331
|
+
return codexConfigHasFlairSection(decodeText(bytes))
|
|
1332
|
+
? { status: "present" }
|
|
1333
|
+
: { status: "absent" };
|
|
1334
|
+
}
|
|
1335
|
+
const read = parseSettingsBytes(bytes, path);
|
|
1336
|
+
if (read.parseError)
|
|
1337
|
+
return { status: "unknown", reason: `malformed JSON: ${path}` };
|
|
1338
|
+
const config = read.parsed;
|
|
1339
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
1340
|
+
return { status: "unknown", reason: `not a JSON object: ${path}` };
|
|
1341
|
+
}
|
|
1342
|
+
if (id === "pi") {
|
|
1343
|
+
// The same home and agent-dir context `_unwirePi` uses for both fields.
|
|
1344
|
+
const scan = piConfigFlairEntryScan(config, piLocalHome(), dirname(piSettingsPath()));
|
|
1345
|
+
if (scan.status === "unrecognized") {
|
|
1346
|
+
return {
|
|
1347
|
+
status: "unknown",
|
|
1348
|
+
reason: `an entry mentions pi-flair without being Flair's own: ${path}`,
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
return { status: scan.status };
|
|
1352
|
+
}
|
|
1353
|
+
return mcpConfigHasFlairEntry(config) ? { status: "present" } : { status: "absent" };
|
|
1354
|
+
}
|
|
1274
1355
|
// ---- Internal wiring functions --------------------------------------------------
|
|
1275
1356
|
//
|
|
1276
1357
|
// Claude Code wiring lives in src/commands/init.ts (it writes ~/.claude.json, the
|
|
@@ -1392,6 +1473,43 @@ function displayUnderHome(configPath) {
|
|
|
1392
1473
|
const home = resolveHome();
|
|
1393
1474
|
return configPath.startsWith(home) ? "~" + configPath.slice(home.length) : configPath;
|
|
1394
1475
|
}
|
|
1476
|
+
/**
|
|
1477
|
+
* The MCP JSON shape that counts as a Flair entry. Shared by the unwire (the
|
|
1478
|
+
* decision it acts on) and by an outside reader of a config snapshot (purge's
|
|
1479
|
+
* client-backup sweep, flair#2886), so the two cannot answer differently.
|
|
1480
|
+
*/
|
|
1481
|
+
function mcpConfigHasFlairEntry(config) {
|
|
1482
|
+
const servers = config.mcpServers;
|
|
1483
|
+
return !!servers && typeof servers === "object" && !Array.isArray(servers) && "flair" in servers;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Scan `packages` strings/object `source` strings and string `extensions`
|
|
1487
|
+
* entries with `isFlairOwnedPiEntry`, using `_unwirePi`'s home and agent-dir
|
|
1488
|
+
* context. If none is Flair-owned, a scanned string containing `pi-flair`
|
|
1489
|
+
* makes the result `unrecognized`. Entry values are not retained.
|
|
1490
|
+
*/
|
|
1491
|
+
function piConfigFlairEntryScan(config, homeDir, baseDir) {
|
|
1492
|
+
const packages = Array.isArray(config.packages) ? config.packages : [];
|
|
1493
|
+
let unrecognized = false;
|
|
1494
|
+
for (const source of packages.map(piPackageEntrySource)) {
|
|
1495
|
+
if (!source)
|
|
1496
|
+
continue;
|
|
1497
|
+
if (isFlairOwnedPiEntry(source, homeDir, baseDir))
|
|
1498
|
+
return { status: "present" };
|
|
1499
|
+
if (source.includes("pi-flair"))
|
|
1500
|
+
unrecognized = true;
|
|
1501
|
+
}
|
|
1502
|
+
const extensions = Array.isArray(config.extensions) ? config.extensions : [];
|
|
1503
|
+
for (const entry of extensions) {
|
|
1504
|
+
if (typeof entry !== "string")
|
|
1505
|
+
continue;
|
|
1506
|
+
if (isFlairOwnedPiEntry(entry, homeDir, baseDir))
|
|
1507
|
+
return { status: "present" };
|
|
1508
|
+
if (entry.includes("pi-flair"))
|
|
1509
|
+
unrecognized = true;
|
|
1510
|
+
}
|
|
1511
|
+
return unrecognized ? { status: "unrecognized" } : { status: "absent" };
|
|
1512
|
+
}
|
|
1395
1513
|
/**
|
|
1396
1514
|
* Remove `mcpServers.flair` from a JSON MCP config. Preserves sibling servers
|
|
1397
1515
|
* and every other top-level key. A no-op when the file or the flair entry is
|
|
@@ -1410,16 +1528,16 @@ function unwireJsonMcp(configPath, label) {
|
|
|
1410
1528
|
outcome = { ok: false, removed: false, message: `${label}: could not unwire ${display}: ${jsonFailureReason(configPath, read.parseError)}` };
|
|
1411
1529
|
return { hold: outcome.message };
|
|
1412
1530
|
}
|
|
1413
|
-
const config = read.parsed
|
|
1531
|
+
const config = read.parsed;
|
|
1414
1532
|
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
1415
1533
|
outcome = { ok: false, removed: false, message: `${label}: refusing to modify a non-object config at ${display}` };
|
|
1416
1534
|
return { hold: outcome.message };
|
|
1417
1535
|
}
|
|
1418
|
-
|
|
1419
|
-
if (!servers || typeof servers !== "object" || Array.isArray(servers) || !("flair" in servers)) {
|
|
1536
|
+
if (!mcpConfigHasFlairEntry(config)) {
|
|
1420
1537
|
outcome = { ok: true, removed: false, message: `${label}: no Flair MCP entry in ${display}` };
|
|
1421
1538
|
return { noop: outcome.message };
|
|
1422
1539
|
}
|
|
1540
|
+
const servers = config.mcpServers;
|
|
1423
1541
|
delete servers.flair;
|
|
1424
1542
|
if (Object.keys(servers).length === 0) {
|
|
1425
1543
|
delete config.mcpServers;
|
|
@@ -1500,6 +1618,12 @@ function _unwirePi() {
|
|
|
1500
1618
|
}
|
|
1501
1619
|
try {
|
|
1502
1620
|
let settled = null;
|
|
1621
|
+
let written = null;
|
|
1622
|
+
// Successful unwire/no-op entries are identified by their position, not their value.
|
|
1623
|
+
const lookalikes = [];
|
|
1624
|
+
const removed = [];
|
|
1625
|
+
const described = () => (removed.length ? `; removed ${removed.join(", ")}` : "") +
|
|
1626
|
+
(lookalikes.length ? `; left ${lookalikes.join(", ")} in place` : "");
|
|
1503
1627
|
const result = withConfigCriticalSection(path, (bytes) => {
|
|
1504
1628
|
if (bytes === null) {
|
|
1505
1629
|
settled = { ok: true, removed: false, message: `pi: no config at ${display}` };
|
|
@@ -1510,16 +1634,22 @@ function _unwirePi() {
|
|
|
1510
1634
|
settled = { ok: false, removed: false, message: `pi: could not unwire ${display}: ${jsonFailureReason(path, read.parseError)}` };
|
|
1511
1635
|
return { hold: settled.message };
|
|
1512
1636
|
}
|
|
1513
|
-
const config = read.parsed
|
|
1637
|
+
const config = read.parsed;
|
|
1514
1638
|
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
1515
1639
|
settled = { ok: false, removed: false, message: `pi: refusing to modify a non-object config at ${display}` };
|
|
1516
1640
|
return { hold: settled.message };
|
|
1517
1641
|
}
|
|
1518
1642
|
let changed = false;
|
|
1519
1643
|
if (Array.isArray(config.packages)) {
|
|
1520
|
-
const kept = config.packages.filter((entry) => {
|
|
1644
|
+
const kept = config.packages.filter((entry, index) => {
|
|
1521
1645
|
const source = piPackageEntrySource(entry);
|
|
1522
|
-
|
|
1646
|
+
if (source && isFlairOwnedPiEntry(source, piLocalHome(), dirname(path))) {
|
|
1647
|
+
removed.push(`packages[${index}]`);
|
|
1648
|
+
return false;
|
|
1649
|
+
}
|
|
1650
|
+
if (source?.includes("pi-flair"))
|
|
1651
|
+
lookalikes.push(`packages[${index}]`);
|
|
1652
|
+
return true;
|
|
1523
1653
|
});
|
|
1524
1654
|
if (kept.length !== config.packages.length) {
|
|
1525
1655
|
config.packages = kept;
|
|
@@ -1527,10 +1657,15 @@ function _unwirePi() {
|
|
|
1527
1657
|
}
|
|
1528
1658
|
}
|
|
1529
1659
|
if (Array.isArray(config.extensions)) {
|
|
1530
|
-
const kept = config.extensions.filter((entry) => {
|
|
1531
|
-
if (typeof entry
|
|
1660
|
+
const kept = config.extensions.filter((entry, index) => {
|
|
1661
|
+
if (typeof entry !== "string")
|
|
1662
|
+
return true;
|
|
1663
|
+
if (isFlairOwnedPiEntry(entry, piLocalHome(), dirname(path))) {
|
|
1664
|
+
removed.push(`extensions[${index}]`);
|
|
1532
1665
|
return false;
|
|
1533
1666
|
}
|
|
1667
|
+
if (entry.includes("pi-flair"))
|
|
1668
|
+
lookalikes.push(`extensions[${index}]`);
|
|
1534
1669
|
return true;
|
|
1535
1670
|
});
|
|
1536
1671
|
if (kept.length !== config.extensions.length) {
|
|
@@ -1539,13 +1674,14 @@ function _unwirePi() {
|
|
|
1539
1674
|
}
|
|
1540
1675
|
}
|
|
1541
1676
|
if (!changed) {
|
|
1542
|
-
settled = { ok: true, removed: false, message: `pi: no Flair extension in ${display}` };
|
|
1677
|
+
settled = { ok: true, removed: false, message: `pi: no Flair extension in ${display}${described()}` };
|
|
1543
1678
|
return { noop: settled.message };
|
|
1544
1679
|
}
|
|
1680
|
+
written = { ok: true, removed: true, message: `pi: unwired ${display}${described()}` };
|
|
1545
1681
|
return { write: encodeConfig(config) };
|
|
1546
1682
|
}, { backup: (bytes) => backupBytesTo(path, bytes) });
|
|
1547
1683
|
if (result.status === "written")
|
|
1548
|
-
return { ok: true, removed: true, message: `pi: unwired ${display}` };
|
|
1684
|
+
return written ?? { ok: true, removed: true, message: `pi: unwired ${display}` };
|
|
1549
1685
|
const s = settled;
|
|
1550
1686
|
if (s)
|
|
1551
1687
|
return s;
|
|
@@ -29,6 +29,18 @@ export const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
|
29
29
|
* refuse with. The CLI and JIT-principal writers refuse with the same message
|
|
30
30
|
* text but not this code. */
|
|
31
31
|
export const AGENT_ID_ERROR = "invalid_agent_id";
|
|
32
|
+
/** The remedy for an id that cannot be used as a JSON integer: a BigInt, which
|
|
33
|
+
* cannot be JSON-serialized, or an integral number outside the safe-integer
|
|
34
|
+
* range, whose value can no longer be trusted to round-trip. */
|
|
35
|
+
export const AGENT_ID_STRING_REMEDY = "send the agent id as a string";
|
|
36
|
+
/** True for an id Harper delivered from a JSON integer whose value JavaScript
|
|
37
|
+
* cannot trust to round-trip. A BigInt is never an agent ID; an unsafe number
|
|
38
|
+
* cannot be trusted when compared or stored, so isValidAgentId refuses it
|
|
39
|
+
* too. */
|
|
40
|
+
export function isUnsafeAgentIdWireValue(id) {
|
|
41
|
+
return (typeof id === "bigint" ||
|
|
42
|
+
(typeof id === "number" && Number.isInteger(id) && !Number.isSafeInteger(id)));
|
|
43
|
+
}
|
|
32
44
|
/**
|
|
33
45
|
* Is `id` an agent ID this rule accepts? A non-string, non-number value —
|
|
34
46
|
* including `null` — is never valid. A write path must distinguish an OMITTED
|
|
@@ -38,9 +50,39 @@ export const AGENT_ID_ERROR = "invalid_agent_id";
|
|
|
38
50
|
export function isValidAgentId(id) {
|
|
39
51
|
if (typeof id !== "string" && typeof id !== "number")
|
|
40
52
|
return false;
|
|
53
|
+
if (typeof id === "number" && !Number.isSafeInteger(id))
|
|
54
|
+
return false;
|
|
41
55
|
return AGENT_ID_PATTERN.test(String(id));
|
|
42
56
|
}
|
|
43
|
-
/** A human-readable refusal
|
|
57
|
+
/** A human-readable refusal. A BigInt or an unsafe integer gets the string
|
|
58
|
+
* remedy alone (no rule). Every other value gets
|
|
59
|
+
* "invalid agent id <shown>: <rule>", where a Symbol or a non-finite number
|
|
60
|
+
* or undefined is shown as String(id) and anything else as JSON.stringify(id); after
|
|
61
|
+
* those branches, if Array.isArray (for a revoked Proxy) or JSON.stringify
|
|
62
|
+
* throws, or JSON.stringify returns undefined, the value is reported by type:
|
|
63
|
+
* "invalid agent id (<type> that cannot be serialized): <rule>"
|
|
64
|
+
* instead. */
|
|
44
65
|
export function invalidAgentIdMessage(id) {
|
|
45
|
-
|
|
66
|
+
if (isUnsafeAgentIdWireValue(id))
|
|
67
|
+
return AGENT_ID_STRING_REMEDY;
|
|
68
|
+
const rule = `an agent id must match ${AGENT_ID_RULE} (1-64 characters: A-Z, a-z, 0-9, _ or -)`;
|
|
69
|
+
let shown;
|
|
70
|
+
let isArray = false;
|
|
71
|
+
if (id === undefined || typeof id === "symbol" || (typeof id === "number" && !Number.isFinite(id))) {
|
|
72
|
+
shown = String(id);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
try {
|
|
76
|
+
isArray = Array.isArray(id);
|
|
77
|
+
shown = JSON.stringify(id);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Array.isArray (for a revoked Proxy) or JSON.stringify can throw; report by type below.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (shown === undefined) {
|
|
84
|
+
const type = isArray ? "an array" : typeof id === "object" ? "an object" : `a ${typeof id}`;
|
|
85
|
+
return `invalid agent id (${type} that cannot be serialized): ${rule}`;
|
|
86
|
+
}
|
|
87
|
+
return `invalid agent id ${shown}: ${rule}`;
|
|
46
88
|
}
|
package/dist/lib/atomic-write.js
CHANGED
|
@@ -148,7 +148,7 @@ function stage(fs, target, content, mode) {
|
|
|
148
148
|
return tmp;
|
|
149
149
|
}
|
|
150
150
|
/** Best-effort directory fsync so the renames themselves are durable. */
|
|
151
|
-
function fsyncDir(dir) {
|
|
151
|
+
export function fsyncDir(dir) {
|
|
152
152
|
try {
|
|
153
153
|
const fd = openSync(dir, "r");
|
|
154
154
|
try {
|