@tpsdev-ai/flair 0.54.1 → 0.55.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/dist/build-info.json +3 -3
- package/dist/cli.js +774 -176
- package/dist/commands/doctor.js +73 -2
- package/dist/commands/federation.js +131 -36
- package/dist/commands/hook.js +20 -10
- package/dist/commands/init.js +193 -67
- package/dist/commands/service.js +16 -12
- package/dist/commands/soul.js +10 -5
- package/dist/commands/status.js +80 -8
- package/dist/commands/upgrade.js +41 -5
- package/dist/doctor-client.js +118 -32
- package/dist/engine-version.js +12 -4
- package/dist/fabric-upgrade.js +30 -15
- package/dist/hook-install.js +170 -16
- package/dist/lib/doctor-run.js +49 -3
- package/dist/lib/embed-gpu-doctor.js +30 -0
- package/dist/lib/federation-pair-access.js +118 -0
- package/dist/lib/harper-port-value.js +43 -0
- package/dist/lib/http-bind.js +227 -0
- package/dist/lib/init-admin-pass.js +316 -0
- package/dist/lib/launchd-management.js +16 -0
- package/dist/lib/launchd-repair.js +122 -1
- package/dist/lib/npm-registry.js +578 -0
- package/dist/lib/owned-pins.js +54 -1
- package/dist/lib/process-start-time.js +82 -0
- package/dist/lib/scratch-owner.js +124 -10
- package/dist/lib/stale-client-pin.js +26 -0
- package/dist/rem/runner.js +10 -1
- package/dist/resources/AdminInstance.js +8 -2
- package/dist/resources/Memory.js +36 -1
- package/dist/resources/MemoryBootstrap.js +23 -32
- package/dist/resources/MemoryFeed.js +4 -1
- package/dist/resources/MemoryReflect.js +121 -93
- package/dist/resources/SkillScan.js +13 -11
- package/dist/resources/Soul.js +15 -1
- package/dist/resources/XAA.js +16 -1
- package/dist/resources/a2a-url.js +5 -2
- package/dist/resources/client-version-gate.js +144 -0
- package/dist/resources/embed-gpu.js +241 -0
- package/dist/resources/embeddings-boot.js +34 -42
- package/dist/resources/federation-peer-liveness.js +7 -1
- package/dist/resources/health.js +12 -3
- package/dist/resources/mcp-tools.js +8 -3
- package/dist/resources/memory-reflect-lib.js +66 -0
- package/dist/resources/memory-reflect-models.js +9 -0
- package/dist/resources/migrations/embedding-stamp.js +32 -4
- package/dist/resources/oauth-discovery.js +3 -1
- package/dist/resources/record-type-kit.js +59 -0
- package/dist/resources/scan/skill-markdown.js +166 -0
- package/dist/resources/scan/skill-scanner.js +89 -68
- package/dist/resources/skill-provenance.js +273 -0
- package/dist/resources/skill-write.js +26 -7
- package/{node_modules/@tpsdev-ai/flair-tool-descriptors/dist → dist/resources/tool-descriptors}/index.js +4 -0
- package/dist/src/lib/harper-port-value.js +43 -0
- package/dist/version-check.js +29 -8
- package/docs/api-reference.md +35 -2
- package/docs/deployment.md +1 -1
- package/docs/federation.md +18 -7
- package/docs/mcp-clients.md +19 -6
- package/docs/releasing.md +96 -24
- package/docs/rem.md +1 -1
- package/docs/secrets-and-keys.md +1 -0
- package/docs/standalone-local.md +1 -1
- package/docs/troubleshooting.md +17 -0
- package/package.json +4 -9
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/LICENSE +0 -19
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/README.md +0 -22
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/dist/index.d.ts +0 -70
- package/node_modules/@tpsdev-ai/flair-tool-descriptors/package.json +0 -46
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live-process start time in epoch ms.
|
|
3
|
+
*
|
|
4
|
+
* Parsers and the ±2s match live in `daemon-liveness.ts` (pure). This file
|
|
5
|
+
* is the I/O adapter those parsers need: Linux `/proc/<pid>/stat` field 22
|
|
6
|
+
* plus `/proc/uptime`, macOS `ps -o lstart=`. One reader for the production
|
|
7
|
+
* daemon identity check and the harness scratch-owner stamp (flair#1372).
|
|
8
|
+
*
|
|
9
|
+
* Darwin `ps -o lstart=` prints local time without a zone. `Date.parse` of
|
|
10
|
+
* that string uses the JS engine's zone — and `bun test` forces UTC even
|
|
11
|
+
* when the host is not (Kern on #1708: a PDT parent stamp vs a UTC sweep
|
|
12
|
+
* was 7h off). Self-calibrate against this process: parse our own lstart,
|
|
13
|
+
* subtract our true start (`Date.now() - process.uptime()*1000`), and apply
|
|
14
|
+
* that offset to the target. Kern wrote `offset = parse(ownLstart) - Date.now()`;
|
|
15
|
+
* without uptime that offset is process age, not zone skew, and owner
|
|
16
|
+
* stamps would drift. Uptime is what makes the offset the parser's zone
|
|
17
|
+
* error. Linux `/proc` is already zone-independent.
|
|
18
|
+
*
|
|
19
|
+
* A null answer is "unverified" — it never decides a verdict toward a
|
|
20
|
+
* destructive branch.
|
|
21
|
+
*/
|
|
22
|
+
import { execFileSync } from "node:child_process";
|
|
23
|
+
import { readFileSync } from "node:fs";
|
|
24
|
+
import { parseProcStatStartTime, parsePsLstart, procStartTimeToEpochMs, } from "./daemon-liveness.js";
|
|
25
|
+
/**
|
|
26
|
+
* Undo a zone-skewed `parsePsLstart` using this process as the reference.
|
|
27
|
+
*
|
|
28
|
+
* `offset = ownParsedMs - ownTrueStartMs`. Subtract that from the target
|
|
29
|
+
* parse so a 7h PDT-vs-UTC bun-test skew (Kern #1708) cancels out.
|
|
30
|
+
*/
|
|
31
|
+
export function applyLstartZoneOffset(targetParsedMs, ownParsedMs, ownTrueStartMs) {
|
|
32
|
+
return targetParsedMs - (ownParsedMs - ownTrueStartMs);
|
|
33
|
+
}
|
|
34
|
+
function readPsLstart(pid) {
|
|
35
|
+
try {
|
|
36
|
+
return execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
37
|
+
encoding: "utf-8",
|
|
38
|
+
env: { ...process.env, LC_ALL: "C" },
|
|
39
|
+
timeout: 2000,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function readProcessStartTimeMs(pid) {
|
|
47
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
48
|
+
return null;
|
|
49
|
+
if (process.platform === "linux") {
|
|
50
|
+
try {
|
|
51
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
52
|
+
const starttime = parseProcStatStartTime(stat);
|
|
53
|
+
if (starttime === null)
|
|
54
|
+
return null;
|
|
55
|
+
const uptimeRaw = readFileSync("/proc/uptime", "utf-8").trim().split(/\s+/)[0];
|
|
56
|
+
const uptime = Number(uptimeRaw);
|
|
57
|
+
if (!Number.isFinite(uptime))
|
|
58
|
+
return null;
|
|
59
|
+
return procStartTimeToEpochMs(starttime, uptime, Date.now());
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (process.platform === "darwin") {
|
|
66
|
+
const targetRaw = readPsLstart(pid);
|
|
67
|
+
if (targetRaw === null)
|
|
68
|
+
return null;
|
|
69
|
+
const targetParsed = parsePsLstart(targetRaw);
|
|
70
|
+
if (targetParsed === null)
|
|
71
|
+
return null;
|
|
72
|
+
const ownRaw = pid === process.pid ? targetRaw : readPsLstart(process.pid);
|
|
73
|
+
if (ownRaw === null)
|
|
74
|
+
return null;
|
|
75
|
+
const ownParsed = parsePsLstart(ownRaw);
|
|
76
|
+
if (ownParsed === null)
|
|
77
|
+
return null;
|
|
78
|
+
const ownTrueStartMs = Date.now() - process.uptime() * 1000;
|
|
79
|
+
return applyLstartZoneOffset(targetParsed, ownParsed, ownTrueStartMs);
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Owner stamp for harness scratch directories (flair#1032).
|
|
2
|
+
* Owner stamp for harness scratch directories (flair#1032 / flair#1372).
|
|
3
3
|
*
|
|
4
4
|
* Directory mtime is not a liveness signal: on Linux, appending to files
|
|
5
5
|
* inside subdirectories does not update the parent. The stamp records the
|
|
6
|
-
* creating process; a sweep may
|
|
7
|
-
*
|
|
6
|
+
* creating process *and* its start time; a sweep may treat a tree as live
|
|
7
|
+
* only when that pid is still alive AND the live start time matches the
|
|
8
|
+
* stamp. A recycled pid therefore fails closed (dead), never "live forever".
|
|
9
|
+
*
|
|
10
|
+
* Harper identity (Kern A1) is the same model: `harperPid` + `harperStartedAt`.
|
|
11
|
+
* Start-time matching reuses `daemon-liveness` (`isStartTimeMatch`, ±2s) and
|
|
12
|
+
* `readProcessStartTimeMs` — no second parser.
|
|
13
|
+
*
|
|
14
|
+
* Invariant: a start-time **mismatch** verdict (`already-gone`) removes the
|
|
15
|
+
* tree and may leave a still-live process whose identity did not match —
|
|
16
|
+
* correct for pid recycling. That is safe only because the shared reader is
|
|
17
|
+
* zone-stable (darwin self-calibrates `ps lstart` against this process). A
|
|
18
|
+
* TZ-skewed parse that looked like a mismatch would delete the stamp and
|
|
19
|
+
* hide a real orphan from the next sweep (Kern #1708).
|
|
8
20
|
*/
|
|
9
21
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
22
|
import { join } from "node:path";
|
|
23
|
+
import { isStartTimeMatch } from "./daemon-liveness.js";
|
|
24
|
+
import { readProcessStartTimeMs } from "./process-start-time.js";
|
|
11
25
|
export const SCRATCH_OWNER_FILE = ".flair-scratch-owner";
|
|
12
|
-
export function writeScratchOwnerStamp(dir,
|
|
13
|
-
|
|
26
|
+
export function writeScratchOwnerStamp(dir, stamp = {}) {
|
|
27
|
+
const ownerPid = stamp.ownerPid ?? process.pid;
|
|
28
|
+
const ownerStartedAt = stamp.ownerStartedAt ?? readProcessStartTimeMs(ownerPid) ?? undefined;
|
|
29
|
+
const rec = { ownerPid };
|
|
30
|
+
if (ownerStartedAt != null)
|
|
31
|
+
rec.ownerStartedAt = ownerStartedAt;
|
|
32
|
+
if (stamp.harperPid != null)
|
|
33
|
+
rec.harperPid = stamp.harperPid;
|
|
34
|
+
if (stamp.harperStartedAt != null)
|
|
35
|
+
rec.harperStartedAt = stamp.harperStartedAt;
|
|
36
|
+
writeFileSync(join(dir, SCRATCH_OWNER_FILE), `${JSON.stringify(rec)}\n`, { encoding: "utf-8" });
|
|
14
37
|
}
|
|
15
38
|
export function isPidAlive(pid) {
|
|
16
39
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
@@ -32,18 +55,109 @@ function readPidFile(path) {
|
|
|
32
55
|
return null;
|
|
33
56
|
}
|
|
34
57
|
}
|
|
58
|
+
function parseScratchOwnerStamp(content) {
|
|
59
|
+
const trimmed = content.trim();
|
|
60
|
+
if (!trimmed)
|
|
61
|
+
return null;
|
|
62
|
+
if (trimmed.startsWith("{")) {
|
|
63
|
+
try {
|
|
64
|
+
const obj = JSON.parse(trimmed);
|
|
65
|
+
const ownerPid = Number(obj.ownerPid);
|
|
66
|
+
if (!Number.isInteger(ownerPid) || ownerPid <= 0)
|
|
67
|
+
return null;
|
|
68
|
+
const stamp = { ownerPid };
|
|
69
|
+
const ownerStartedAt = Number(obj.ownerStartedAt);
|
|
70
|
+
if (Number.isFinite(ownerStartedAt))
|
|
71
|
+
stamp.ownerStartedAt = ownerStartedAt;
|
|
72
|
+
const harperPid = Number(obj.harperPid);
|
|
73
|
+
if (Number.isInteger(harperPid) && harperPid > 0)
|
|
74
|
+
stamp.harperPid = harperPid;
|
|
75
|
+
const harperStartedAt = Number(obj.harperStartedAt);
|
|
76
|
+
if (Number.isFinite(harperStartedAt))
|
|
77
|
+
stamp.harperStartedAt = harperStartedAt;
|
|
78
|
+
return stamp;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Legacy pid-only stamp. No started-at → cannot verify identity.
|
|
85
|
+
const pid = Number(trimmed);
|
|
86
|
+
if (Number.isInteger(pid) && pid > 0)
|
|
87
|
+
return { ownerPid: pid };
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
export function readScratchOwnerStamp(dir) {
|
|
91
|
+
try {
|
|
92
|
+
return parseScratchOwnerStamp(readFileSync(join(dir, SCRATCH_OWNER_FILE), "utf-8"));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
35
98
|
export function readScratchOwnerPid(dir) {
|
|
36
|
-
return
|
|
99
|
+
return readScratchOwnerStamp(dir)?.ownerPid ?? null;
|
|
37
100
|
}
|
|
38
101
|
export function hasScratchOwnerStamp(dir) {
|
|
39
102
|
return existsSync(join(dir, SCRATCH_OWNER_FILE));
|
|
40
103
|
}
|
|
41
|
-
|
|
104
|
+
export function readHdbPid(dir) {
|
|
105
|
+
return readPidFile(join(dir, "hdb.pid"));
|
|
106
|
+
}
|
|
107
|
+
function pidMatchesStamp(pid, recordedStartedAt) {
|
|
108
|
+
if (recordedStartedAt == null)
|
|
109
|
+
return false;
|
|
110
|
+
const actual = readProcessStartTimeMs(pid);
|
|
111
|
+
if (actual == null)
|
|
112
|
+
return false;
|
|
113
|
+
return isStartTimeMatch(actual, recordedStartedAt);
|
|
114
|
+
}
|
|
115
|
+
/** True when the creating process is still alive AND its start time matches. */
|
|
42
116
|
export function scratchOwnerIsLive(dir) {
|
|
43
|
-
const
|
|
44
|
-
|
|
117
|
+
const stamp = readScratchOwnerStamp(dir);
|
|
118
|
+
if (!stamp || !isPidAlive(stamp.ownerPid))
|
|
119
|
+
return false;
|
|
120
|
+
return pidMatchesStamp(stamp.ownerPid, stamp.ownerStartedAt);
|
|
45
121
|
}
|
|
46
122
|
export function hdbPidIsLive(dir) {
|
|
47
|
-
const pid =
|
|
123
|
+
const pid = readHdbPid(dir);
|
|
48
124
|
return pid !== null && isPidAlive(pid);
|
|
49
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Whether a dead-owner tree's Harper pid may be killed.
|
|
128
|
+
*
|
|
129
|
+
* Kill only when `hdb.pid` (or stamped `harperPid`) is alive AND its start
|
|
130
|
+
* time matches `harperStartedAt`. A mismatch is already-gone (the original
|
|
131
|
+
* Harper is not that pid): the tree is removed and a live mismatched-identity
|
|
132
|
+
* process is left alone — correct for pid recycling, and safe only because
|
|
133
|
+
* the start-time reader is zone-stable. Disagreement between the two names,
|
|
134
|
+
* or a stampless tree with a live `hdb.pid`, is unverified — fail closed.
|
|
135
|
+
*/
|
|
136
|
+
export function classifyOrphanHarperKill(dir) {
|
|
137
|
+
const stamp = readScratchOwnerStamp(dir);
|
|
138
|
+
const hdbPid = readHdbPid(dir);
|
|
139
|
+
if (!stamp) {
|
|
140
|
+
if (hdbPid !== null && isPidAlive(hdbPid)) {
|
|
141
|
+
return { kind: "unverified", reason: "stampless tree with live hdb.pid" };
|
|
142
|
+
}
|
|
143
|
+
return { kind: "already-gone" };
|
|
144
|
+
}
|
|
145
|
+
if (hdbPid !== null && stamp.harperPid != null && hdbPid !== stamp.harperPid) {
|
|
146
|
+
return { kind: "pid-disagreement", hdbPid, harperPid: stamp.harperPid };
|
|
147
|
+
}
|
|
148
|
+
const target = hdbPid ?? stamp.harperPid ?? null;
|
|
149
|
+
if (target === null || !isPidAlive(target)) {
|
|
150
|
+
return { kind: "already-gone" };
|
|
151
|
+
}
|
|
152
|
+
if (stamp.harperStartedAt == null) {
|
|
153
|
+
return { kind: "unverified", reason: "stamp has no harperStartedAt" };
|
|
154
|
+
}
|
|
155
|
+
const actual = readProcessStartTimeMs(target);
|
|
156
|
+
if (actual === null) {
|
|
157
|
+
return { kind: "unverified", reason: `could not read the start time of pid ${target}` };
|
|
158
|
+
}
|
|
159
|
+
if (!isStartTimeMatch(actual, stamp.harperStartedAt)) {
|
|
160
|
+
return { kind: "already-gone" };
|
|
161
|
+
}
|
|
162
|
+
return { kind: "kill", pid: target, startedAt: stamp.harperStartedAt };
|
|
163
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stale-client-pin.ts — flair#1383
|
|
3
|
+
*
|
|
4
|
+
* `flair doctor` reads the actual `flair-mcp` / `flair-client` pins in
|
|
5
|
+
* wired host configs and cwd package.json. A pre-0.18.0 pin is not just
|
|
6
|
+
* "behind the CLI" — it silently drops writes, including against another
|
|
7
|
+
* agent's shared memories, and upgrading the *server* does not fix it.
|
|
8
|
+
*
|
|
9
|
+
* This helper is the loud, specific finding. Threshold matches
|
|
10
|
+
* `resources/client-version-gate.ts` (`MIN_SAFE_FLAIR_CLIENT`). Duplicated
|
|
11
|
+
* here because the CLI must not import server resources.
|
|
12
|
+
*/
|
|
13
|
+
import { parseSemverCore, semverGte } from "../fabric-upgrade.js";
|
|
14
|
+
export const MIN_SAFE_FLAIR_ADAPTER = "0.18.0";
|
|
15
|
+
export const STALE_CLIENT_WRITE_HAZARD = "this adapter silently drops writes (including against another agent's shared memories). Upgrade the adapter, not the server";
|
|
16
|
+
/** True when `pin` is parseable and strictly older than 0.18.0. */
|
|
17
|
+
export function isUnsafeAdapterPin(pin) {
|
|
18
|
+
if (!pin)
|
|
19
|
+
return false;
|
|
20
|
+
if (!parseSemverCore(pin))
|
|
21
|
+
return false;
|
|
22
|
+
return !semverGte(pin, MIN_SAFE_FLAIR_ADAPTER);
|
|
23
|
+
}
|
|
24
|
+
export function unsafeAdapterPinDetail(surface, id, pin, pkg = "flair-mcp") {
|
|
25
|
+
return `${surface} (${id}): pinned to ${pkg}@${pin} — ${STALE_CLIENT_WRITE_HAZARD}`;
|
|
26
|
+
}
|
package/dist/rem/runner.js
CHANGED
|
@@ -863,7 +863,16 @@ export async function runNightlyCycle(opts) {
|
|
|
863
863
|
const row = {
|
|
864
864
|
...baseRow,
|
|
865
865
|
slice: sliceLabel,
|
|
866
|
-
|
|
866
|
+
// flair#924 (defect 1): a run whose recorded `errors[]` is non-empty must
|
|
867
|
+
// NOT report success. A core stage that could not run — distillation with
|
|
868
|
+
// no generative backend, a per-tag distill failure, the dedup stat, an
|
|
869
|
+
// operator-aborted distill — is already pushed into `errors`; if any error
|
|
870
|
+
// stands, the run FAILED. Before this, a distillation-disabled cycle logged
|
|
871
|
+
// `status: "completed"` next to a populated `Errors:` block while the CLI
|
|
872
|
+
// exited 1 (src/commands/rem.ts), so the one signal a service manager can
|
|
873
|
+
// act on disagreed with the reported status. A populated errors[] can never
|
|
874
|
+
// coexist with "completed" again (regression-tested in rem-runner.test.ts).
|
|
875
|
+
status: errors.length > 0 ? "failed" : opts.dryRun ? "dry-run" : "completed",
|
|
867
876
|
dryRun: opts.dryRun || undefined,
|
|
868
877
|
snapshotPath,
|
|
869
878
|
memoryCount,
|
|
@@ -6,6 +6,8 @@ import { join, dirname } from "node:path";
|
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { allowAdmin } from "./agent-auth.js";
|
|
9
|
+
import { harperPortValue } from "../src/lib/harper-port-value.js";
|
|
10
|
+
import { DEFAULT_HTTP_PORT } from "./a2a-url.js";
|
|
9
11
|
/**
|
|
10
12
|
* Resolve the public URL operators reach this Flair on.
|
|
11
13
|
*
|
|
@@ -21,6 +23,10 @@ import { allowAdmin } from "./agent-auth.js";
|
|
|
21
23
|
* — derives from how the operator actually reached the page
|
|
22
24
|
* 3. `http://127.0.0.1:${HTTP_PORT}` — local-only installs fallback
|
|
23
25
|
*
|
|
26
|
+
* Exported for direct unit testing: the Resource class pulls Harper at import
|
|
27
|
+
* time, so a test mocks `harper` and calls this pure resolver directly rather
|
|
28
|
+
* than re-deriving its predicate and drifting from it.
|
|
29
|
+
*
|
|
24
30
|
* The request-header path closes the common case from flair#404:
|
|
25
31
|
* remote/Fabric deployments without FLAIR_PUBLIC_URL set rendered
|
|
26
32
|
* localhost URLs that operators couldn't copy-paste. Trusting the Host
|
|
@@ -28,7 +34,7 @@ import { allowAdmin } from "./agent-auth.js";
|
|
|
28
34
|
* reverse proxy that doesn't set X-Forwarded-* headers correctly, the
|
|
29
35
|
* operator should set FLAIR_PUBLIC_URL explicitly (which wins).
|
|
30
36
|
*/
|
|
31
|
-
function resolvePublicUrl(request) {
|
|
37
|
+
export function resolvePublicUrl(request) {
|
|
32
38
|
if (process.env.FLAIR_PUBLIC_URL) {
|
|
33
39
|
return process.env.FLAIR_PUBLIC_URL.replace(/\/$/, "");
|
|
34
40
|
}
|
|
@@ -58,7 +64,7 @@ function resolvePublicUrl(request) {
|
|
|
58
64
|
const effectiveScheme = fwdProto ? scheme : (host.includes(":") ? "http" : scheme);
|
|
59
65
|
return `${effectiveScheme}://${host}`;
|
|
60
66
|
}
|
|
61
|
-
return `http://127.0.0.1:${process.env.HTTP_PORT ??
|
|
67
|
+
return `http://127.0.0.1:${harperPortValue(process.env.HTTP_PORT) ?? DEFAULT_HTTP_PORT}`;
|
|
62
68
|
}
|
|
63
69
|
/**
|
|
64
70
|
* Read the runtime package version from the bundled package.json so the
|
package/dist/resources/Memory.js
CHANGED
|
@@ -12,7 +12,7 @@ import { invalidEntitiesResponse } from "./entity-vocab.js";
|
|
|
12
12
|
import { checkRateLimit, rateLimitResponse } from "./rate-limiter.js";
|
|
13
13
|
import { assertValidVisibility, assertVisibilityAllowedForDurability } from "./memory-visibility.js";
|
|
14
14
|
import { assertValidDurability } from "./memory-durability.js";
|
|
15
|
-
import { enforceSkillDurability, rejectSkillWritePath, skillEmbedText, skillScanGate } from "./skill-write.js";
|
|
15
|
+
import { enforceSkillDurability, rejectSkillWritePath, refuseSkillWriteSource, skillEmbedText, skillScanGate } from "./skill-write.js";
|
|
16
16
|
import { DEDUP_COSINE_THRESHOLD_DEFAULT, DEDUP_LEXICAL_THRESHOLD_DEFAULT, DEDUP_MIN_CONTENT_LENGTH, computeMatchConfidence, cosineSimilarity, isConservativeMatch, } from "./dedup.js";
|
|
17
17
|
import { buildProvenance, makeAuthGate, makeReadScope, makeByIdReadGate, makeScopedSearch, resolveAuthGate, stampAttribution, FORBIDDEN, UNAUTH, } from "./record-type-kit.js";
|
|
18
18
|
import { RECORD_TYPES } from "./record-types.js";
|
|
@@ -20,6 +20,7 @@ import { attachTrust } from "./trust-block.js";
|
|
|
20
20
|
import { recordCitations } from "./usage-recording.js";
|
|
21
21
|
import { noteMemoryUpsert, noteMemoryDelete } from "./bm25-index-service.js";
|
|
22
22
|
import { applyHitStats, clearHitStats, overlayHitStatsResult } from "./hit-tracking.js";
|
|
23
|
+
import { refuseStaleClientWrite, stripClientVersionPassthrough } from "./client-version-gate.js";
|
|
23
24
|
/**
|
|
24
25
|
* flair#744 slice 1 — read the opt-in `includeTrust` flag for a by-id get.
|
|
25
26
|
* Two entry shapes: an in-process caller (resources/mcp-tools.ts's memory_get)
|
|
@@ -626,6 +627,16 @@ export class Memory extends databases.flair.Memory {
|
|
|
626
627
|
if (auth.kind === "anonymous") {
|
|
627
628
|
return UNAUTH();
|
|
628
629
|
}
|
|
630
|
+
// flair#1383: an identified pre-0.18.0 flair-client silently drops
|
|
631
|
+
// writes client-side (including against another agent's shared
|
|
632
|
+
// memories). Refuse the write path loudly; missing version is not
|
|
633
|
+
// treated as old (current published clients do not send one yet).
|
|
634
|
+
{
|
|
635
|
+
const stale = refuseStaleClientWrite(ctx?.request, content);
|
|
636
|
+
if (stale)
|
|
637
|
+
return stale;
|
|
638
|
+
}
|
|
639
|
+
stripClientVersionPassthrough(content);
|
|
629
640
|
// No-forge attribution — mode/field drawn from RECORD_TYPES.Memory
|
|
630
641
|
// (record-types slice 2, flair#520) rather than a hand-typed literal.
|
|
631
642
|
// "validate-truthy" (see record-type-kit.ts's stampAttribution doc):
|
|
@@ -792,6 +803,11 @@ export class Memory extends databases.flair.Memory {
|
|
|
792
803
|
if (skillScanDenial)
|
|
793
804
|
return skillScanDenial;
|
|
794
805
|
}
|
|
806
|
+
{
|
|
807
|
+
const skillSourceDenial = refuseSkillWriteSource(content);
|
|
808
|
+
if (skillSourceDenial)
|
|
809
|
+
return skillSourceDenial;
|
|
810
|
+
}
|
|
795
811
|
// Server-side conservative-duplicate gate (memory-integrity fix). A
|
|
796
812
|
// supersede write is an intentional version-link, not an ambiguous "is
|
|
797
813
|
// this a duplicate of something else" situation — bypass the gate for it
|
|
@@ -875,6 +891,13 @@ export class Memory extends databases.flair.Memory {
|
|
|
875
891
|
const authorityDenial = await guardAuthorityFields(() => super.get(), content, "Memory");
|
|
876
892
|
if (authorityDenial)
|
|
877
893
|
return authorityDenial;
|
|
894
|
+
// flair#1383 — patch() routes past put(), so it needs its own refuse.
|
|
895
|
+
{
|
|
896
|
+
const stale = refuseStaleClientWrite(this.getContext?.()?.request, content);
|
|
897
|
+
if (stale)
|
|
898
|
+
return stale;
|
|
899
|
+
}
|
|
900
|
+
stripClientVersionPassthrough(content);
|
|
878
901
|
const denial = await guardOwnerFieldImmutable(this, () => super.get(), content, "agentId");
|
|
879
902
|
if (denial)
|
|
880
903
|
return denial;
|
|
@@ -939,6 +962,13 @@ export class Memory extends databases.flair.Memory {
|
|
|
939
962
|
if (auth.kind === "anonymous") {
|
|
940
963
|
return UNAUTH();
|
|
941
964
|
}
|
|
965
|
+
// flair#1383 — same write-path refuse as post().
|
|
966
|
+
{
|
|
967
|
+
const stale = refuseStaleClientWrite(ctx?.request, content);
|
|
968
|
+
if (stale)
|
|
969
|
+
return stale;
|
|
970
|
+
}
|
|
971
|
+
stripClientVersionPassthrough(content);
|
|
942
972
|
// No-forge attribution — mode/field drawn from RECORD_TYPES.Memory,
|
|
943
973
|
// same rule as post(). "validate-truthy" (see record-type-kit.ts's
|
|
944
974
|
// stampAttribution doc).
|
|
@@ -1098,6 +1128,11 @@ export class Memory extends databases.flair.Memory {
|
|
|
1098
1128
|
if (skillScanDenial)
|
|
1099
1129
|
return skillScanDenial;
|
|
1100
1130
|
}
|
|
1131
|
+
{
|
|
1132
|
+
const skillSourceDenial = refuseSkillWriteSource(content);
|
|
1133
|
+
if (skillSourceDenial)
|
|
1134
|
+
return skillSourceDenial;
|
|
1135
|
+
}
|
|
1101
1136
|
// Server-side conservative-duplicate gate (memory-integrity fix). PUT is
|
|
1102
1137
|
// an upsert: only run the gate for a FRESH create (target id does not yet
|
|
1103
1138
|
// exist) that is NOT a supersede-link write. An update of an EXISTING id
|
|
@@ -22,6 +22,7 @@ import { estimateTokens } from "./token-estimate.js";
|
|
|
22
22
|
import { initialPosition, ORG_EVENT_STREAM } from "./agent-read-position-lib.js";
|
|
23
23
|
import { defaultReadPositionTable, ensureReadPosition } from "./agent-read-position.js";
|
|
24
24
|
import { catchupSeekTimestamp, isCatchupEligible } from "./org-event-catchup-lib.js";
|
|
25
|
+
import { resolveActiveSkills } from "./skill-provenance.js";
|
|
25
26
|
/**
|
|
26
27
|
* POST /MemoryBootstrap
|
|
27
28
|
*
|
|
@@ -519,12 +520,27 @@ export class BootstrapMemories extends Resource {
|
|
|
519
520
|
}
|
|
520
521
|
// Sort by priority (lower = more important)
|
|
521
522
|
soulEntries.sort((a, b) => a.priority - b.priority);
|
|
523
|
+
// flair#1431 — collapse VERBATIM duplicates. The live payload shipped the
|
|
524
|
+
// same IDENTITY.md body three times (`identity`, a second `identity`, and
|
|
525
|
+
// `identity-file`) and `user-context` twice: different soul keys holding
|
|
526
|
+
// byte-identical content. Dedupe by content (not by key) so the
|
|
527
|
+
// higher-priority key wins and the budget is not spent re-saying the same
|
|
528
|
+
// thing. (Roster/template-text cleanup is separate.)
|
|
529
|
+
const seenSoulValues = new Set();
|
|
530
|
+
const admittedSoulEntries = [];
|
|
531
|
+
for (const entry of soulEntries) {
|
|
532
|
+
const valueKey = JSON.stringify(entry.value ?? null);
|
|
533
|
+
if (seenSoulValues.has(valueKey))
|
|
534
|
+
continue;
|
|
535
|
+
seenSoulValues.add(valueKey);
|
|
536
|
+
admittedSoulEntries.push(entry);
|
|
537
|
+
}
|
|
522
538
|
// flair#1371 — the structured `soul` map follows the admission decision.
|
|
523
539
|
// Filling it during the scan (flair#1182) shipped every key even when
|
|
524
540
|
// this loop dropped the entry, so sections.soul / soulTokens / the
|
|
525
541
|
// context pointer described N while `soul` delivered N+1 (delivered
|
|
526
542
|
// but not counted or charged — the #1206 mirror).
|
|
527
|
-
for (const entry of
|
|
543
|
+
for (const entry of admittedSoulEntries) {
|
|
528
544
|
if (soulTokens + entry.tokens > soulMaxTokens) {
|
|
529
545
|
// Skip large entries that exceed budget — truncate or skip
|
|
530
546
|
if (entry.priority >= 90)
|
|
@@ -547,38 +563,13 @@ export class BootstrapMemories extends Resource {
|
|
|
547
563
|
tokenBudget -= entry.tokens; // #1199 — soul draws from the shared budget
|
|
548
564
|
}
|
|
549
565
|
}
|
|
550
|
-
// --- 1b. Skill assignments (
|
|
566
|
+
// --- 1b. Skill assignments (durable source + stated conflict outcome) ---
|
|
567
|
+
// flair#1433: do not report-and-load-both. resolveActiveSkills decides
|
|
568
|
+
// (unique priority wins; equal-priority same-name tie refuses) and
|
|
569
|
+
// states the decision on the line. Non-durable sources are refused.
|
|
551
570
|
if (skillAssignments.length > 0) {
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
const pa = priorityOrder[a.priority ?? "standard"] ?? 2;
|
|
555
|
-
const pb = priorityOrder[b.priority ?? "standard"] ?? 2;
|
|
556
|
-
return pa - pb;
|
|
557
|
-
});
|
|
558
|
-
// Detect conflicts at same priority level
|
|
559
|
-
const byPriority = new Map();
|
|
560
|
-
for (const skill of skillAssignments) {
|
|
561
|
-
const p = skill.priority ?? "standard";
|
|
562
|
-
if (!byPriority.has(p))
|
|
563
|
-
byPriority.set(p, []);
|
|
564
|
-
byPriority.get(p).push(skill);
|
|
565
|
-
}
|
|
566
|
-
for (const skill of skillAssignments) {
|
|
567
|
-
const p = skill.priority ?? "standard";
|
|
568
|
-
let meta = {};
|
|
569
|
-
try {
|
|
570
|
-
meta = typeof skill.metadata === "string" ? JSON.parse(skill.metadata) : (skill.metadata ?? {});
|
|
571
|
-
}
|
|
572
|
-
catch { }
|
|
573
|
-
const source = meta.source ? `, source: ${meta.source}` : "";
|
|
574
|
-
let line = `- ${skill.value} (${p} priority${source})`;
|
|
575
|
-
// Flag conflicts at same priority level
|
|
576
|
-
const peers = byPriority.get(p) ?? [];
|
|
577
|
-
if (peers.length > 1) {
|
|
578
|
-
line += " [SKILL_CONFLICT]";
|
|
579
|
-
}
|
|
580
|
-
sections.skills.push(line);
|
|
581
|
-
}
|
|
571
|
+
const resolved = resolveActiveSkills(skillAssignments);
|
|
572
|
+
sections.skills.push(...resolved.lines);
|
|
582
573
|
}
|
|
583
574
|
// --- 1c. Team roster + cross-agent search nudge ---
|
|
584
575
|
// Soul is still caller-own-only (unaffected here). Memory loading below
|
|
@@ -5,7 +5,7 @@ import { FORBIDDEN, UNAUTH, stampAttribution } from "./record-type-kit.js";
|
|
|
5
5
|
import { guardAuthorityFields, stripAuthorityFields } from "./authority-field-guard.js";
|
|
6
6
|
import { assertValidVisibility, assertVisibilityAllowedForDurability, PRIVATE_VISIBILITY } from "./memory-visibility.js";
|
|
7
7
|
import { assertValidDurability } from "./memory-durability.js";
|
|
8
|
-
import { enforceSkillDurability, skillScanGate } from "./skill-write.js";
|
|
8
|
+
import { enforceSkillDurability, refuseSkillWriteSource, skillScanGate } from "./skill-write.js";
|
|
9
9
|
import { noteMemoryUpsert } from "./bm25-index-service.js";
|
|
10
10
|
export class FeedMemories extends Resource {
|
|
11
11
|
// Self-authorize via the Ed25519 agent verify (the auth reshape removes the
|
|
@@ -68,6 +68,9 @@ export class FeedMemories extends Resource {
|
|
|
68
68
|
const skillScanDenial = skillScanGate(content);
|
|
69
69
|
if (skillScanDenial)
|
|
70
70
|
return skillScanDenial;
|
|
71
|
+
const skillSourceDenial = refuseSkillWriteSource(content);
|
|
72
|
+
if (skillSourceDenial)
|
|
73
|
+
return skillSourceDenial;
|
|
71
74
|
const skillDurabilityDenial = enforceSkillDurability(content);
|
|
72
75
|
if (skillDurabilityDenial)
|
|
73
76
|
return skillDurabilityDenial;
|