@tpsdev-ai/flair 0.59.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 +4 -4
- package/SECURITY.md +36 -0
- package/config.yaml +12 -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 +991 -248
- package/dist/commands/agent.js +224 -43
- 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 +592 -146
- 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 +97 -35
- 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 +41 -10
- package/dist/lib/doctor-run.js +75 -37
- package/dist/lib/durability-copy.js +10 -0
- package/dist/lib/embedding-space-doctor.js +75 -0
- package/dist/lib/flair-agent-role.js +4 -0
- package/dist/lib/hub-url.js +12 -0
- package/dist/lib/init-admin-pass.js +88 -12
- package/dist/lib/init-listener-environ.js +1 -2
- package/dist/lib/init-occupied-listener.js +15 -111
- package/dist/lib/init-spawn-attribution.js +73 -0
- package/dist/lib/init-tcp-probe.js +33 -0
- package/dist/lib/instance-identity-row.js +20 -0
- package/dist/lib/launchd-management.js +24 -0
- 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 +1168 -326
- 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 +76 -12
- 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 +321 -1
- package/dist/resources/AgentKeyRegister.js +214 -0
- package/dist/resources/AgentKeyRegistration.js +28 -0
- package/dist/resources/AgentSeed.js +10 -4
- package/dist/resources/AutoPromoteCandidates.js +7 -1
- package/dist/resources/Credential.js +177 -2
- package/dist/resources/Federation.js +751 -143
- 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 +110 -39
- 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/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 +181 -63
- package/dist/resources/agent-auth.js +40 -15
- package/dist/resources/auth-middleware.js +400 -161
- 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 +72 -0
- package/dist/resources/federation-crypto.js +5 -5
- package/dist/resources/federation-retry-lib.js +135 -0
- package/dist/resources/grant-visibility.js +135 -0
- package/dist/resources/harper-routing.js +83 -0
- package/dist/resources/health.js +120 -18
- 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 +3 -3
- package/dist/resources/mcp-handler.js +36 -8
- package/dist/resources/mcp-oauth-env-guard.js +36 -0
- package/dist/resources/mcp-oauth.js +23 -6
- package/dist/resources/mcp-tool-arguments.js +4 -6
- package/dist/resources/mcp-tools.js +128 -19
- 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/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 +1 -1
- package/dist/resources/relay-ops.js +78 -6
- package/dist/resources/replay-store.js +96 -19
- 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 +20 -11
- 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 +4 -0
- package/dist/src/lib/idp-mapping-rule.js +81 -0
- package/dist/src/lib/instance-identity-row.js +20 -0
- package/dist/src/lib/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 +146 -45
- package/docs/api-reference.md +46 -11
- package/docs/auth.md +6 -12
- package/docs/bridges.md +11 -0
- package/docs/claude-code.md +34 -4
- 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 +5 -5
- package/docs/mcp-clients.md +5 -2
- 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 +12 -6
- 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 +10 -5
- package/schemas/agent-key-registration.graphql +22 -0
- package/schemas/agent.graphql +3 -0
- package/schemas/federation.graphql +38 -1
- package/schemas/memory.graphql +84 -5
- package/schemas/oauth.graphql +19 -0
- package/schemas/schema.graphql +2 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* team-directory.ts — the ONE team-directory resolver (flair#2141 S3a).
|
|
3
|
+
*
|
|
4
|
+
* Answers "who is in this office, and how do I reach them" from Flair's own
|
|
5
|
+
* records: the active agent-kind principals, joined to their published
|
|
6
|
+
* `tps-mail` `Integration` contact. One resolver serves the `team_directory`
|
|
7
|
+
* MCP tool, `GET /TeamDirectory` and the flair client.
|
|
8
|
+
*
|
|
9
|
+
* ─── Authority (the directory-specific verified-active-reader gate) ─────────
|
|
10
|
+
* The resolver does NOT go through `Integration`'s owner-only REST scope: it
|
|
11
|
+
* reads the tables in-process (`databases.flair.*`), exactly as bootstrap's
|
|
12
|
+
* roster join does (resources/MemoryBootstrap.ts). Authority is instead the
|
|
13
|
+
* gate below: `resolveAgentAuth` must return a VERIFIED agent — `anonymous`,
|
|
14
|
+
* `internal`, and a MISSING context (which resolves to `internal`) all grant
|
|
15
|
+
* nothing — and a FRESH local `Agent` read must show that same principal as an
|
|
16
|
+
* active agent-kind row.
|
|
17
|
+
*
|
|
18
|
+
* ─── Unavailable is never a cached success ──────────────────────────────────
|
|
19
|
+
* A failed or unreadable Agent/Integration read returns an explicit
|
|
20
|
+
* `unavailable` refusal (503), never an empty directory. "No teammates" and
|
|
21
|
+
* "the store could not be read" are different answers and must not collapse.
|
|
22
|
+
*
|
|
23
|
+
* ─── Filtering happens BEFORE pagination ────────────────────────────────────
|
|
24
|
+
* Only active agent-kind principals with a matching contact owner, a `tps-mail`
|
|
25
|
+
* platform, and a VALID publication stamp enter the list. Tombstones (a null or
|
|
26
|
+
* absent `directoryPublishedAt`) never do. One channel per agent: a principal
|
|
27
|
+
* with several published `tps-mail` rows contributes the most recently
|
|
28
|
+
* published one, compared by publication time in epoch milliseconds rather
|
|
29
|
+
* than as strings (a stored stamp may be any parseable date string).
|
|
30
|
+
*
|
|
31
|
+
* ─── Caps (fixed, applied before anything is returned) ──────────────────────
|
|
32
|
+
* 50 entries per response, one channel per agent, 256 UTF-8 bytes for
|
|
33
|
+
* agentId, name and email, 64 KiB serialized response.
|
|
34
|
+
*
|
|
35
|
+
* Scope note: this slice is LOCAL only and reads no Peer rows, so it does not
|
|
36
|
+
* call `isPeerMemberStatus` (src/lib/peer-status.ts); federation membership
|
|
37
|
+
* lands in S3b/S3c.
|
|
38
|
+
*/
|
|
39
|
+
import { databases } from "harper";
|
|
40
|
+
import { resolveAgentAuth } from "./agent-auth.js";
|
|
41
|
+
import { UNAUTH } from "./record-type-kit.js";
|
|
42
|
+
import { localInstanceId } from "./instance-identity.js";
|
|
43
|
+
/** The platform whose published Integration row is a directory contact. */
|
|
44
|
+
export const TEAM_DIRECTORY_PLATFORM = "tps-mail";
|
|
45
|
+
/** Maximum entries any single page returns, regardless of a larger `limit`. */
|
|
46
|
+
export const TEAM_DIRECTORY_MAX_ENTRIES = 50;
|
|
47
|
+
/** Maximum UTF-8 bytes of agentId, name and email. */
|
|
48
|
+
export const TEAM_DIRECTORY_MAX_STRING_BYTES = 256;
|
|
49
|
+
/** Maximum serialized bytes of the whole response. */
|
|
50
|
+
export const TEAM_DIRECTORY_MAX_RESPONSE_BYTES = 64 * 1024;
|
|
51
|
+
/** Default page size when the caller does not pass `limit`. */
|
|
52
|
+
export const TEAM_DIRECTORY_DEFAULT_LIMIT = 50;
|
|
53
|
+
const JSON_HEADERS = { "Content-Type": "application/json" };
|
|
54
|
+
function forbidden(error) {
|
|
55
|
+
return new Response(JSON.stringify({ error }), { status: 403, headers: JSON_HEADERS });
|
|
56
|
+
}
|
|
57
|
+
function unavailable(error) {
|
|
58
|
+
return new Response(JSON.stringify({ error }), { status: 503, headers: JSON_HEADERS });
|
|
59
|
+
}
|
|
60
|
+
function badLimit() {
|
|
61
|
+
return new Response(JSON.stringify({ error: "invalid_limit" }), { status: 400, headers: JSON_HEADERS });
|
|
62
|
+
}
|
|
63
|
+
/** UTF-8 byte length of a string. */
|
|
64
|
+
export function utf8Bytes(value) {
|
|
65
|
+
return Buffer.byteLength(value, "utf8");
|
|
66
|
+
}
|
|
67
|
+
/** Missing kind/status fields retain legacy agent/active compatibility. */
|
|
68
|
+
export function isActiveAgentPrincipal(record) {
|
|
69
|
+
if (!record || typeof record.id !== "string" || record.id === "")
|
|
70
|
+
return false;
|
|
71
|
+
if (record.kind !== undefined && record.kind !== "agent")
|
|
72
|
+
return false;
|
|
73
|
+
if (record.status !== undefined && record.status !== "active")
|
|
74
|
+
return false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
/** A publication stamp is valid when it is a parseable date string. */
|
|
78
|
+
export function isValidPublicationStamp(value) {
|
|
79
|
+
if (typeof value !== "string" || value === "")
|
|
80
|
+
return false;
|
|
81
|
+
return Number.isFinite(Date.parse(value));
|
|
82
|
+
}
|
|
83
|
+
/** Cut `value` to at most `max` UTF-8 bytes without splitting a code point. */
|
|
84
|
+
export function cutToUtf8Bytes(value, max) {
|
|
85
|
+
const bytes = Buffer.from(value, "utf8");
|
|
86
|
+
if (bytes.length <= max)
|
|
87
|
+
return value;
|
|
88
|
+
let end = max;
|
|
89
|
+
while (end > 0 && (bytes[end] & 0xc0) === 0x80)
|
|
90
|
+
end -= 1;
|
|
91
|
+
return bytes.subarray(0, end).toString("utf8");
|
|
92
|
+
}
|
|
93
|
+
/** The display label for an agent row: its name, else its id. */
|
|
94
|
+
export function agentDisplayName(agent) {
|
|
95
|
+
if (typeof agent.name === "string" && agent.name !== "")
|
|
96
|
+
return agent.name;
|
|
97
|
+
return typeof agent.id === "string" ? agent.id : "";
|
|
98
|
+
}
|
|
99
|
+
/** Normalize a requested limit to an integer within [1, MAX_ENTRIES]. */
|
|
100
|
+
export function normalizeLimit(raw) {
|
|
101
|
+
if (raw === undefined || raw === null || raw === "")
|
|
102
|
+
return TEAM_DIRECTORY_DEFAULT_LIMIT;
|
|
103
|
+
const n = typeof raw === "number" ? raw : Number(raw);
|
|
104
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1)
|
|
105
|
+
return null;
|
|
106
|
+
return Math.min(n, TEAM_DIRECTORY_MAX_ENTRIES);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The verified-active-reader gate. Returns the reader's agent id, or a
|
|
110
|
+
* `Response` refusal. A missing context resolves to `internal` and grants
|
|
111
|
+
* nothing, exactly like anonymous.
|
|
112
|
+
*/
|
|
113
|
+
export async function resolveDirectoryReader(context) {
|
|
114
|
+
const auth = await resolveAgentAuth(context);
|
|
115
|
+
if (auth.kind === "anonymous")
|
|
116
|
+
return UNAUTH();
|
|
117
|
+
if (auth.kind !== "agent")
|
|
118
|
+
return forbidden("team_directory_requires_verified_agent");
|
|
119
|
+
let reader;
|
|
120
|
+
try {
|
|
121
|
+
reader = await databases.flair.Agent.get(auth.agentId);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return unavailable("team_directory_unavailable");
|
|
125
|
+
}
|
|
126
|
+
if (!isActiveAgentPrincipal(reader) || reader.id !== auth.agentId) {
|
|
127
|
+
return forbidden("team_directory_reader_not_active");
|
|
128
|
+
}
|
|
129
|
+
return { agentId: auth.agentId };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Read every directory candidate entry from local records. Returns a `Response`
|
|
133
|
+
* on an unreadable store.
|
|
134
|
+
*/
|
|
135
|
+
async function collectEntries() {
|
|
136
|
+
const active = new Map();
|
|
137
|
+
try {
|
|
138
|
+
for await (const record of databases.flair.Agent.search()) {
|
|
139
|
+
if (isActiveAgentPrincipal(record))
|
|
140
|
+
active.set(record.id, record);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return unavailable("team_directory_agent_store_unavailable");
|
|
145
|
+
}
|
|
146
|
+
const byAgent = new Map();
|
|
147
|
+
const byAgentTimeMs = new Map();
|
|
148
|
+
try {
|
|
149
|
+
for await (const row of databases.flair.Integration.search({
|
|
150
|
+
select: ["agentId", "platform", "email", "directoryPublishedAt"],
|
|
151
|
+
})) {
|
|
152
|
+
const r = row;
|
|
153
|
+
if (r.platform !== TEAM_DIRECTORY_PLATFORM)
|
|
154
|
+
continue;
|
|
155
|
+
if (!isValidPublicationStamp(r.directoryPublishedAt))
|
|
156
|
+
continue;
|
|
157
|
+
if (typeof r.email !== "string" || r.email === "")
|
|
158
|
+
continue;
|
|
159
|
+
const owner = active.get(r.agentId);
|
|
160
|
+
if (!owner)
|
|
161
|
+
continue; // contact owner must be an active agent-kind principal
|
|
162
|
+
if (utf8Bytes(r.agentId) > TEAM_DIRECTORY_MAX_STRING_BYTES)
|
|
163
|
+
continue;
|
|
164
|
+
if (utf8Bytes(r.email) > TEAM_DIRECTORY_MAX_STRING_BYTES)
|
|
165
|
+
continue;
|
|
166
|
+
// Normalize the publication time to epoch milliseconds before choosing
|
|
167
|
+
// the most recent: a stored stamp may be any parseable date string, and
|
|
168
|
+
// string order is not time order ("10/03/2026" sorts before "2026-10-01").
|
|
169
|
+
const publishedMs = Date.parse(r.directoryPublishedAt);
|
|
170
|
+
const entry = {
|
|
171
|
+
agentId: r.agentId,
|
|
172
|
+
name: cutToUtf8Bytes(agentDisplayName(owner), TEAM_DIRECTORY_MAX_STRING_BYTES),
|
|
173
|
+
platform: r.platform,
|
|
174
|
+
email: r.email,
|
|
175
|
+
publishedAt: new Date(publishedMs).toISOString(),
|
|
176
|
+
homeInstanceId: null, // stamped below from the resolved local instance
|
|
177
|
+
};
|
|
178
|
+
// One channel per agent: keep the most recently published row.
|
|
179
|
+
const prevMs = byAgentTimeMs.get(entry.agentId);
|
|
180
|
+
if (prevMs === undefined || publishedMs > prevMs) {
|
|
181
|
+
byAgent.set(entry.agentId, entry);
|
|
182
|
+
byAgentTimeMs.set(entry.agentId, publishedMs);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return unavailable("team_directory_contact_store_unavailable");
|
|
188
|
+
}
|
|
189
|
+
return [...byAgent.values()].sort((a, b) => compareAgentIds(a.agentId, b.agentId));
|
|
190
|
+
}
|
|
191
|
+
function compareAgentIds(a, b) {
|
|
192
|
+
const left = Array.from(a), right = Array.from(b);
|
|
193
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
194
|
+
const difference = left[i].codePointAt(0) - right[i].codePointAt(0);
|
|
195
|
+
if (difference !== 0)
|
|
196
|
+
return difference;
|
|
197
|
+
}
|
|
198
|
+
return left.length - right.length;
|
|
199
|
+
}
|
|
200
|
+
/** Drop the fewest trailing entries needed to fit the serialized response cap. */
|
|
201
|
+
function clampResponse(result) {
|
|
202
|
+
while (result.entries.length > 0 && utf8Bytes(JSON.stringify(result)) > TEAM_DIRECTORY_MAX_RESPONSE_BYTES) {
|
|
203
|
+
const entries = result.entries.slice(0, -1);
|
|
204
|
+
result = { ...result, entries, nextCursor: entries.at(-1)?.agentId ?? null, hasMore: true };
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Resolve a page of the team directory. The caller is responsible for passing
|
|
210
|
+
* a context that resolves to a verified active agent (see
|
|
211
|
+
* `resolveDirectoryReader`); this function enforces it itself, so every surface
|
|
212
|
+
* that shares the resolver shares the gate.
|
|
213
|
+
*/
|
|
214
|
+
export async function resolveTeamDirectory(context, query = {}) {
|
|
215
|
+
const reader = await resolveDirectoryReader(context);
|
|
216
|
+
if (reader instanceof Response)
|
|
217
|
+
return reader;
|
|
218
|
+
const limit = normalizeLimit(query.limit);
|
|
219
|
+
if (limit === null)
|
|
220
|
+
return badLimit();
|
|
221
|
+
const collected = await collectEntries();
|
|
222
|
+
if (collected instanceof Response)
|
|
223
|
+
return collected;
|
|
224
|
+
const idFilter = typeof query.id === "string" && query.id !== "" ? query.id : null;
|
|
225
|
+
const nameFilter = typeof query.name === "string" && query.name !== "" ? query.name : null;
|
|
226
|
+
let candidates = collected;
|
|
227
|
+
if (idFilter)
|
|
228
|
+
candidates = candidates.filter((e) => e.agentId === idFilter);
|
|
229
|
+
if (nameFilter) {
|
|
230
|
+
const needle = nameFilter.toLowerCase();
|
|
231
|
+
candidates = candidates.filter((e) => e.name.toLowerCase().includes(needle));
|
|
232
|
+
}
|
|
233
|
+
const cursor = typeof query.cursor === "string" && query.cursor !== "" ? query.cursor : null;
|
|
234
|
+
if (cursor)
|
|
235
|
+
candidates = candidates.filter((e) => compareAgentIds(e.agentId, cursor) > 0);
|
|
236
|
+
const page = candidates.slice(0, limit);
|
|
237
|
+
const hasMore = candidates.length > page.length;
|
|
238
|
+
const nextCursor = hasMore && page.length > 0 ? page[page.length - 1].agentId : null;
|
|
239
|
+
const homeInstanceId = await localInstanceId().catch(() => null);
|
|
240
|
+
const entries = page.map((e) => ({ ...e, homeInstanceId }));
|
|
241
|
+
return clampResponse({
|
|
242
|
+
entries,
|
|
243
|
+
nextCursor,
|
|
244
|
+
hasMore,
|
|
245
|
+
limit,
|
|
246
|
+
generatedAt: new Date().toISOString(),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
@@ -48,6 +48,15 @@ export function toStdioMcpToolDef(d) {
|
|
|
48
48
|
export function descriptorNames(descriptors) {
|
|
49
49
|
return descriptors.map((d) => d.name);
|
|
50
50
|
}
|
|
51
|
+
/** Memory tier statements and caveat used by the durability schema description. */
|
|
52
|
+
export const DURABILITY_TIER_GUARANTEES = [
|
|
53
|
+
"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.",
|
|
54
|
+
"persistent — routine maintenance never reaps or age-archives it (an expired validTo archives an eligible row; an acquired expiresAt never reaps it).",
|
|
55
|
+
"standard — routine maintenance archives it once its validTo passes or, as a session note, after 30 days.",
|
|
56
|
+
"ephemeral — routine maintenance reaps it once its TTL (24h by default) passes.",
|
|
57
|
+
];
|
|
58
|
+
/** The one-sentence limit every durability tier shares. */
|
|
59
|
+
export const DURABILITY_CAVEAT = "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.";
|
|
51
60
|
export const TOOL_DESCRIPTORS = [
|
|
52
61
|
{
|
|
53
62
|
"name": "memory_search",
|
|
@@ -80,7 +89,7 @@ export const TOOL_DESCRIPTORS = [
|
|
|
80
89
|
"query"
|
|
81
90
|
]
|
|
82
91
|
},
|
|
83
|
-
"outputShape": "{ results: MemoryRecord[] } — semantic hits subject to the caller's read scope; each hit carries content, never the raw embedding.",
|
|
92
|
+
"outputShape": "{ results: MemoryRecord[] } — semantic hits subject to the caller's read scope; each hit carries content, never the raw embedding. A hit whose record has a bound host-source pointer carries `hostSource`: the pointer object for a reader allowed to see it, or the literal \"withheld\" for one who may read the record but not the pointer. hostSource is the writer's unverified claim about an external source, stored with the writer's authenticated agent id; Flair does not verify it.",
|
|
84
93
|
"annotations": {
|
|
85
94
|
"readOnlyHint": true
|
|
86
95
|
},
|
|
@@ -92,7 +101,7 @@ export const TOOL_DESCRIPTORS = [
|
|
|
92
101
|
},
|
|
93
102
|
{
|
|
94
103
|
"name": "memory_store",
|
|
95
|
-
"description": "Save information to persistent memory. Use for lessons, decisions, preferences, facts. Attributed to your authenticated agent.",
|
|
104
|
+
"description": "Save information to persistent memory. Use for lessons, decisions, preferences, facts. Attributed to your authenticated agent. hostSource is the writer's unverified claim about an external source, stored with the writer's authenticated agent id; Flair does not verify it.",
|
|
96
105
|
"inputSchema": {
|
|
97
106
|
"type": "object",
|
|
98
107
|
"properties": {
|
|
@@ -120,7 +129,10 @@ export const TOOL_DESCRIPTORS = [
|
|
|
120
129
|
"standard",
|
|
121
130
|
"ephemeral"
|
|
122
131
|
],
|
|
123
|
-
"description": "
|
|
132
|
+
"description": "Durability tier. "
|
|
133
|
+
+ DURABILITY_TIER_GUARANTEES.join(" ")
|
|
134
|
+
+ " " + DURABILITY_CAVEAT
|
|
135
|
+
+ " (default standard)"
|
|
124
136
|
},
|
|
125
137
|
"tags": {
|
|
126
138
|
"type": "array",
|
|
@@ -143,13 +155,33 @@ export const TOOL_DESCRIPTORS = [
|
|
|
143
155
|
"type": "string"
|
|
144
156
|
},
|
|
145
157
|
"description": "IDs of memories that informed this write (citation-on-write). Credited via the same deduped usage ledger as record_usage. Optional."
|
|
158
|
+
},
|
|
159
|
+
"hostSource": {
|
|
160
|
+
"type": "object",
|
|
161
|
+
"description": "Optional host-object pointer: the host object this memory is claimed to come from, as { v: 1, host, kind, id, url? } (host/kind from a closed set, e.g. openclaw/run; id matches a fixed grammar; url https-only). Validated server-side by the same validator as the REST write — an invalid pointer is refused, never coerced. hostSource is the writer's unverified claim about an external source, stored with the writer's authenticated agent id; Flair does not verify it."
|
|
162
|
+
},
|
|
163
|
+
"hostSourceScope": {
|
|
164
|
+
"type": "string",
|
|
165
|
+
"enum": [
|
|
166
|
+
"record"
|
|
167
|
+
],
|
|
168
|
+
"description": "Opt the hostSource pointer into the record's own read scope. Omit for author-only (the pointer is then visible only to the writing agent). Any wider scope is refused."
|
|
169
|
+
},
|
|
170
|
+
"sessionId": {
|
|
171
|
+
"type": "string",
|
|
172
|
+
"description": "Optional originating-session id, stored on the record. Omit to leave it unset."
|
|
146
173
|
}
|
|
147
174
|
},
|
|
148
175
|
"required": [
|
|
149
176
|
"content"
|
|
150
177
|
]
|
|
151
178
|
},
|
|
152
|
-
"outputShape": "Write echo { id, written:true, deduplicated } — the new id + confirmation. No internal embedding fields; round-trips via memory_get."
|
|
179
|
+
"outputShape": "Write echo { id, written:true, deduplicated } — the new id + confirmation. No internal embedding fields; round-trips via memory_get. After a server-side redaction the echo also carries `redactedValues` and the stored `content` (with `summary`/`trigger` when written) from the write's own response; if that response returned no stored `content`, the echo omits those fields and sets `contentWithheld:true`.",
|
|
180
|
+
"stdioOmitProperties": [
|
|
181
|
+
"hostSource",
|
|
182
|
+
"hostSourceScope",
|
|
183
|
+
"sessionId"
|
|
184
|
+
]
|
|
153
185
|
},
|
|
154
186
|
{
|
|
155
187
|
"name": "skill_store",
|
|
@@ -185,7 +217,7 @@ export const TOOL_DESCRIPTORS = [
|
|
|
185
217
|
"content"
|
|
186
218
|
]
|
|
187
219
|
},
|
|
188
|
-
"outputShape": "Write
|
|
220
|
+
"outputShape": "Write result { id, written:true, visibility } for the skill-tagged memory. No internal embedding fields; round-trips via memory_get. After a server-side redaction the echo also carries `redactedValues` and the stored text from the write's own response: `content` (with `summary`/`trigger` when written, and `name`/`description`/`tags` for the skill when supplied); if that response returned no stored `content`, the echo omits those fields and sets `contentWithheld:true`."
|
|
189
221
|
},
|
|
190
222
|
{
|
|
191
223
|
"name": "skill_search",
|
|
@@ -255,7 +287,7 @@ export const TOOL_DESCRIPTORS = [
|
|
|
255
287
|
"content"
|
|
256
288
|
]
|
|
257
289
|
},
|
|
258
|
-
"outputShape": "Write echo { id, written:true } for the in-place overwrite (or supersede). No internal embedding fields; the change round-trips via memory_get.",
|
|
290
|
+
"outputShape": "Write echo { id, written:true } for the in-place overwrite (or supersede). No internal embedding fields; the change round-trips via memory_get. After a server-side redaction the echo also carries `redactedValues` and the stored `content` (with `summary`/`trigger` when written) from the write's own response; if that response returned no stored `content`, the echo omits those fields and sets `contentWithheld:true`.",
|
|
259
291
|
"stdioExtraProperties": {
|
|
260
292
|
"usedMemoryIds": {
|
|
261
293
|
"type": "array",
|
|
@@ -281,7 +313,7 @@ export const TOOL_DESCRIPTORS = [
|
|
|
281
313
|
"id"
|
|
282
314
|
]
|
|
283
315
|
},
|
|
284
|
-
"outputShape": "Write
|
|
316
|
+
"outputShape": "Write result for the archive operation; read the persisted archive state through memory_get. No internal embedding fields; the flip round-trips via memory_get. After a server-side redaction the echo also carries `redactedValues` and the stored `content` (with `summary`/`trigger` when the row carries them) from the write's own response; if that response returned no stored `content`, the echo omits those fields and sets `contentWithheld:true`.",
|
|
285
317
|
"stdio": false
|
|
286
318
|
},
|
|
287
319
|
{
|
|
@@ -299,7 +331,7 @@ export const TOOL_DESCRIPTORS = [
|
|
|
299
331
|
"id"
|
|
300
332
|
]
|
|
301
333
|
},
|
|
302
|
-
"outputShape": "Write
|
|
334
|
+
"outputShape": "Write result for the restore operation; read the persisted archive state through memory_get. No internal embedding fields; the flip round-trips via memory_get. After a server-side redaction the echo also carries `redactedValues` and the stored `content` (with `summary`/`trigger` when the row carries them) from the write's own response; if that response returned no stored `content`, the echo omits those fields and sets `contentWithheld:true`.",
|
|
303
335
|
"stdio": false
|
|
304
336
|
},
|
|
305
337
|
{
|
|
@@ -634,6 +666,35 @@ export const TOOL_DESCRIPTORS = [
|
|
|
634
666
|
},
|
|
635
667
|
"stdio": false
|
|
636
668
|
},
|
|
669
|
+
{
|
|
670
|
+
"name": "team_directory",
|
|
671
|
+
"description": "List active agent-kind principals with published tps-mail contacts. Filter by id or name; page with cursor and limit.",
|
|
672
|
+
"inputSchema": {
|
|
673
|
+
"type": "object",
|
|
674
|
+
"properties": {
|
|
675
|
+
"id": {
|
|
676
|
+
"type": "string",
|
|
677
|
+
"description": "Filter by stable Agent ID."
|
|
678
|
+
},
|
|
679
|
+
"name": {
|
|
680
|
+
"type": "string",
|
|
681
|
+
"description": "Filter by a case-insensitive substring of the display label."
|
|
682
|
+
},
|
|
683
|
+
"cursor": {
|
|
684
|
+
"type": "string",
|
|
685
|
+
"description": "Opaque cursor from a prior page's nextCursor."
|
|
686
|
+
},
|
|
687
|
+
"limit": {
|
|
688
|
+
"type": "number",
|
|
689
|
+
"description": "Max entries per page (default 50, max 50)."
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
},
|
|
693
|
+
"outputShape": "{ entries: TeamDirectoryEntry[], nextCursor, hasMore, limit, generatedAt } — active agent-kind principals with a published tps-mail contact.",
|
|
694
|
+
"annotations": {
|
|
695
|
+
"readOnlyHint": true
|
|
696
|
+
}
|
|
697
|
+
},
|
|
637
698
|
{
|
|
638
699
|
"name": "record_usage",
|
|
639
700
|
"description": "Report that one or more memories were actually USED — cited or relied on to ground an answer or decision. Distinct from search (surfacing a memory is not usage). Drives the recall-quality usage signal; dedup'd (you can only count once per memory) and rate-limited. When both memoryId and memoryIds are supplied they are merged (union, then deduped) — a caller who passes both means both.",
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test pause for owned transactions (flair#2307), enabled by process environment.
|
|
3
|
+
* Claims an arm file, writes pause/release markers, and waits for go or its limit.
|
|
4
|
+
* Pinned by test/unit/txn-pause-point.test.ts and used by
|
|
5
|
+
* test/integration/supersede-close-contention-2307.test.ts,
|
|
6
|
+
* test/integration/embedding-stamp-contention-2307.test.ts,
|
|
7
|
+
* test/integration/owner-delete-recheck-2355.test.ts and
|
|
8
|
+
* test/integration/integration-row-write-serialization-2340.test.ts.
|
|
9
|
+
*/
|
|
10
|
+
import { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, realpathSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
13
|
+
export const TEST_FAULT_INJECTION_ENV = "FLAIR_ENABLE_TEST_FAULT_INJECTION";
|
|
14
|
+
export const TEST_PAUSE_DIR_ENV = "FLAIR_TEST_PAUSE_DIR";
|
|
15
|
+
export const PAUSE_LIMIT_MS = 20_000;
|
|
16
|
+
const POLL_MS = 20;
|
|
17
|
+
/**
|
|
18
|
+
* The shape of a pause-point name: lowercase words joined by single hyphens
|
|
19
|
+
* (flair#2382). Removing the shared union list removes that merge conflict.
|
|
20
|
+
* Valid names keep their pause behaviour; malformed names throw
|
|
21
|
+
* `InvalidPausePointError` before the fault-injection gate.
|
|
22
|
+
*
|
|
23
|
+
* flair#2355 — a non-admin owner-scoped delete. Each delete has a `-pre` point
|
|
24
|
+
* (after the pre-existing ownership read, before the delete's transactional
|
|
25
|
+
* re-read or staging) and an in-transaction point (between that transaction's
|
|
26
|
+
* ownership re-read and its delete), so both interleavings of a concurrent
|
|
27
|
+
* owner change can be exercised. The write transaction is one the delete
|
|
28
|
+
* owns, except Memory's ordinary delete: withSharedWriteTransaction JOINS a
|
|
29
|
+
* request-owned transaction when one exists and creates one otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export const PAUSE_POINT_PATTERN = /^[a-z]+(?:-[a-z]+)*$/;
|
|
32
|
+
/** The named error a pause-point name that does not match `PAUSE_POINT_PATTERN` is refused with (flair#2382). */
|
|
33
|
+
export class InvalidPausePointError extends Error {
|
|
34
|
+
constructor(point) {
|
|
35
|
+
super(`invalid pause point name: ${JSON.stringify(point)}`);
|
|
36
|
+
this.name = "InvalidPausePointError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function isInside(parent, child) {
|
|
40
|
+
const rel = relative(parent, child);
|
|
41
|
+
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
42
|
+
}
|
|
43
|
+
let refusalLogged = false;
|
|
44
|
+
function logRefusal() {
|
|
45
|
+
if (refusalLogged)
|
|
46
|
+
return;
|
|
47
|
+
refusalLogged = true;
|
|
48
|
+
console.warn("txn-pause-point: filesystem check failed; hook inert");
|
|
49
|
+
}
|
|
50
|
+
export function txnPausePoint(point, env = process.env, limitMs = PAUSE_LIMIT_MS) {
|
|
51
|
+
if (!PAUSE_POINT_PATTERN.test(point))
|
|
52
|
+
throw new InvalidPausePointError(point);
|
|
53
|
+
if (env[TEST_FAULT_INJECTION_ENV] !== "1")
|
|
54
|
+
return undefined;
|
|
55
|
+
let armFd;
|
|
56
|
+
let pausedFd;
|
|
57
|
+
let releasedFd;
|
|
58
|
+
let dir;
|
|
59
|
+
try {
|
|
60
|
+
const configured = env[TEST_PAUSE_DIR_ENV];
|
|
61
|
+
if (!configured || !isAbsolute(configured) || !process.getuid || !constants.O_NOFOLLOW)
|
|
62
|
+
throw new Error();
|
|
63
|
+
dir = realpathSync(configured);
|
|
64
|
+
const info = statSync(dir);
|
|
65
|
+
if (lstatSync(configured).isSymbolicLink() || !isInside(realpathSync(tmpdir()), dir) ||
|
|
66
|
+
!info.isDirectory() || info.uid !== process.getuid() || (info.mode & 0o022) !== 0)
|
|
67
|
+
throw new Error();
|
|
68
|
+
const armPath = join(dir, `arm.${point}`);
|
|
69
|
+
try {
|
|
70
|
+
armFd = openSync(armPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.code === "ENOENT")
|
|
74
|
+
return undefined;
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
if (!fstatSync(armFd).isFile())
|
|
78
|
+
throw new Error();
|
|
79
|
+
const flags = constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW;
|
|
80
|
+
const claimedFd = openSync(join(dir, `claimed.${point}`), flags, 0o600);
|
|
81
|
+
closeSync(claimedFd);
|
|
82
|
+
pausedFd = openSync(join(dir, `paused.${point}`), flags, 0o600);
|
|
83
|
+
releasedFd = openSync(join(dir, `released.${point}`), flags, 0o600);
|
|
84
|
+
writeFileSync(pausedFd, String(Date.now()));
|
|
85
|
+
unlinkSync(armPath);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
if (pausedFd !== undefined)
|
|
89
|
+
closeSync(pausedFd);
|
|
90
|
+
if (releasedFd !== undefined)
|
|
91
|
+
closeSync(releasedFd);
|
|
92
|
+
logRefusal();
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
if (armFd !== undefined)
|
|
97
|
+
closeSync(armFd);
|
|
98
|
+
}
|
|
99
|
+
const paused = pausedFd;
|
|
100
|
+
const released = releasedFd;
|
|
101
|
+
return (async () => {
|
|
102
|
+
try {
|
|
103
|
+
const go = join(dir, `go.${point}`);
|
|
104
|
+
const deadline = Date.now() + limitMs;
|
|
105
|
+
while (!existsSync(go) && Date.now() < deadline) {
|
|
106
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
107
|
+
}
|
|
108
|
+
writeFileSync(released, existsSync(go) ? "go" : "timeout");
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
logRefusal();
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
closeSync(paused);
|
|
115
|
+
closeSync(released);
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
}
|