@staix/agent-mem 0.23.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/hook-transcript.ts +3 -3
- package/src/hooks.ts +2 -2
- package/src/index.ts +1 -1
- package/src/memory/config.ts +5 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Curated memory with append-only JSONL logs, a derived SQLite index, short- and long-term tiers, a typed graph, goals with leases, and git sync between machines. Extracted from [agent-hub](https://github.com/STAIxBWLB/agent-hub), with compatible storage and entry IDs.
|
|
4
4
|
|
|
5
5
|
<!-- facts:version -->
|
|
6
|
-
Version: 0.23.
|
|
6
|
+
Version: 0.23.1. Requires Bun 1.4.2 or later; no runtime dependencies.
|
|
7
7
|
<!-- /facts:version -->
|
|
8
8
|
|
|
9
9
|
## Quick start
|
|
@@ -573,7 +573,7 @@ Search gives these events the existing 1.25 conversation weight and session grou
|
|
|
573
573
|
|
|
574
574
|
Since 0.23.0, native Claude SessionStart can prepend the package-owned `RECORD_INSTRUCTION` before the untrusted memory header, including on resume. Its three lines occupy 331 UTF-8 bytes, or 332 with the separator, reserved from the existing 1,200-byte context budget. The metric reports the actual emitted `recordInstructionBytes` and `recordInstructionEstimatedTokens` (83 when emitted, an approximation). The full block is omitted when it cannot fit; it never turns a failed or timed-out hook into valid context. Set `records: false` in the home's `amem.config.json` or the repository's `.amem/config` to disable the instruction and new extraction; false wins across both files.
|
|
575
575
|
|
|
576
|
-
At Stop/SessionEnd, complete native assistant text can yield `Record` capture events through the existing transcript scan. `parseRecordLines` and `
|
|
576
|
+
At Stop/SessionEnd, complete native assistant text can yield `Record` capture events through the existing transcript scan. `parseRecordLines`, `RECORD_INSTRUCTION` and `recordsEnabled(base, cwd?)` are public root exports; hosts check `recordsEnabled` before emitting the instruction or capturing parsed Records. The canonical grammar is maintained in `src/hook-record.ts`. The parser checks format and explicit text exclusions; hosts still apply their capture privacy policy before storage. It accepts the five kinds decision/fix/fail/contract/finding, repository-relative anchors and at most 300 text characters, excludes fenced/quoted examples, and requires the fix/fail relation. Missing native row time or stable `message.id` refuses extraction. At most two syntactically valid record lines are considered per stable message per scan call, with no persisted count. Whole records are declined on a denied anchor, policy refusal, truncation or redaction; no partial record is saved.
|
|
577
577
|
|
|
578
578
|
Records stay machine-local capture, not curated evidence or review candidates. They reuse Title/Recap/Compact staging, deterministic receipts and replay, with canonical line content and the native row timestamp; no Record-only receipt or capture-row schema is added. Source-row privacy flags are screened before capture, and replay refuses to clip or remove anchors from a pending Record when caps change. A slow replay opportunity cannot strand the second Record in the same transcript row. A crash after staging but before cursor save retains the existing duplicate window. A message-ID/ordinal receipt is a future upgrade if the AC6 duplicate experiment requires it. Record-to-candidate conversion and other ingest/Jcode paths remain outside this change; AC6 and real-home rollout are person-run checks.
|
|
579
579
|
|
package/package.json
CHANGED
package/src/hook-transcript.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { createHash } from "node:crypto";
|
|
|
6
6
|
import { chmodSync, closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { canonicalPath, realPath } from "./memory/platform.ts";
|
|
9
|
-
import { configuredPolicyOptions,
|
|
9
|
+
import { configuredPolicyOptions, recordsEnabled } from "./memory/config.ts";
|
|
10
10
|
import { createStandalonePolicy, type StandalonePolicyOptions } from "./memory/policy.ts";
|
|
11
11
|
import { HookSpoolFull, stageTranscriptCapture, type PendingHookCapture } from "./hook-spool.ts";
|
|
12
12
|
import { appendMetrics } from "./memory/metrics.ts";
|
|
@@ -124,7 +124,7 @@ export async function scanHookTranscriptTail(input: unknown, options: Options):
|
|
|
124
124
|
if (value.cwd !== undefined && (typeof value.cwd !== "string" || realPath(value.cwd) !== cwd)) return;
|
|
125
125
|
const policy = createStandalonePolicy(configuredPolicyOptions(base, cwd, options.policy));
|
|
126
126
|
if (!await policy.screen(value)) return;
|
|
127
|
-
const
|
|
127
|
+
const captureRecords = recordsEnabled(base, cwd)
|
|
128
128
|
&& !(typeof value.agent_id === "string" && value.agent_id.length > 0);
|
|
129
129
|
const session = hash(`amem-session\0${value.session_id}`).slice(0, 16);
|
|
130
130
|
if (lstatSync(value.transcript_path).isSymbolicLink()) throw new Error("transcript unavailable");
|
|
@@ -184,7 +184,7 @@ export async function scanHookTranscriptTail(input: unknown, options: Options):
|
|
|
184
184
|
try { line = new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(start, newline)); }
|
|
185
185
|
catch { start = newline + 1; continue; }
|
|
186
186
|
let records: ReturnType<typeof transcriptRecords>;
|
|
187
|
-
if (
|
|
187
|
+
if (captureRecords) try { records = transcriptRecords(line, due); } catch { /* Malformed native JSON is not a record source. */ }
|
|
188
188
|
// Privacy flags and policy metadata belong to the source row, not just its extracted text.
|
|
189
189
|
if (records && !await policy.screen(JSON.parse(line))) { dropRecord("record_policy", Math.max(1, records.parsed.records.length)); records = undefined; }
|
|
190
190
|
let recordPublication: PendingHookCapture | undefined;
|
package/src/hooks.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { jcodeHookCapture, jcodeJournalTarget } from "./hook-jcode.ts";
|
|
|
12
12
|
import { memoryHome } from "./memory/home.ts";
|
|
13
13
|
import { canonicalPath, realPath } from "./memory/platform.ts";
|
|
14
14
|
import { createStandalonePolicy, type MemoryPolicy, type StandalonePolicyOptions } from "./memory/policy.ts";
|
|
15
|
-
import { configuredPolicyOptions, loadAmemConfig, repoConfigRoot } from "./memory/config.ts";
|
|
15
|
+
import { configuredPolicyOptions, loadAmemConfig, recordsEnabled, repoConfigRoot } from "./memory/config.ts";
|
|
16
16
|
|
|
17
17
|
import { HOOK_EVENTS, HOOK_INPUT_BYTES, HOOK_CONTEXT_BYTES, HOOK_OUTPUT_BYTES, isHookTranscriptProgress, type HookTranscriptProgress } from "./hook-contract.ts";
|
|
18
18
|
export { HOOK_EVENTS, HOOK_INPUT_BYTES, HOOK_CONTEXT_BYTES, HOOK_OUTPUT_BYTES, type HookEvent } from "./hook-contract.ts";
|
|
@@ -244,7 +244,7 @@ function sessionNoticeAndLimit(base: string, cwd: string, options: HookOptions,
|
|
|
244
244
|
const configuredBrief = config.briefBytes;
|
|
245
245
|
const contextLimit = Math.min(HOOK_CONTEXT_BYTES, configuredBrief ?? HOOK_CONTEXT_BYTES, Math.max(1, Number.isFinite(options.maxTokens) ? Math.floor(options.maxTokens!) : HOOK_CONTEXT_BYTES));
|
|
246
246
|
const prefix = `${RECORD_INSTRUCTION}\n`;
|
|
247
|
-
const instruction =
|
|
247
|
+
const instruction = recordsEnabled(base, cwd) && Buffer.byteLength(prefix) + Buffer.byteLength(header) + Buffer.byteLength(dropNotice) + (dropNotice ? 1 : 0) <= contextLimit ? prefix : "";
|
|
248
248
|
return { dropNotice, contextLimit: contextLimit - Buffer.byteLength(instruction), instruction };
|
|
249
249
|
}
|
|
250
250
|
|
package/src/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export * from "./memory/shard-migration.ts";
|
|
|
41
41
|
export * from "./mcp.ts";
|
|
42
42
|
export * from "./mcp-memory.ts";
|
|
43
43
|
export * from "./memory/policy.ts";
|
|
44
|
-
export { configuredPolicy } from "./memory/config.ts";
|
|
44
|
+
export { configuredPolicy, recordsEnabled } from "./memory/config.ts";
|
|
45
45
|
export * from "./memory/work-lists.ts";
|
|
46
46
|
export * from "./memory/vault.ts";
|
|
47
47
|
|
package/src/memory/config.ts
CHANGED
|
@@ -160,6 +160,11 @@ export function loadAmemConfig(base: string, repoRoot?: string): LoadedConfig {
|
|
|
160
160
|
return { config, source: { machine: machineRaw === undefined ? null : machinePath, repo: repoPath } };
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/** Effective Record instruction/capture opt-in. Either configuration may disable it; malformed configuration throws. */
|
|
164
|
+
export function recordsEnabled(base: string, cwd?: string): boolean {
|
|
165
|
+
return loadAmemConfig(base, cwd === undefined ? undefined : repoConfigRoot(cwd)).config.records !== false;
|
|
166
|
+
}
|
|
167
|
+
|
|
163
168
|
/**
|
|
164
169
|
* The standalone policy as configured. A host policy passed through the library still wins: it is composed in, never replaced, so the result
|
|
165
170
|
* declines whatever either declines (`createStandalonePolicy` screens the config, then asks the host).
|