foretext 0.8.0-bootstrap.0 → 0.8.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 -4
- package/claude-scaffold/SKILL.md +13 -13
- package/claude-scaffold/bin/{engram → foretext} +7 -7
- package/claude-scaffold/references/review.md +24 -24
- package/claude-scaffold/references/search.md +23 -23
- package/claude-scaffold/references/setup.md +28 -28
- package/dist/capture-adapter.js +2 -2
- package/dist/{capture-admission-Dnu2eW39.js → capture-admission-DqhzaMDY.js} +2 -2
- package/dist/{contextual-recall-AR3ign-H.js → contextual-recall-DF8e3Oa_.js} +99 -97
- package/dist/index.js +357 -274
- package/dist/opencode-plugin.js +47 -47
- package/dist/pi-extension.js +71 -71
- package/dist/{src-CRnWgfbx.js → src-DjnbdRrt.js} +176 -151
- package/package.json +3 -5
- package/skills/{engram → foretext}/SKILL.md +11 -11
- package/skills/{engram → foretext}/references/review.md +27 -27
- package/skills/{engram → foretext}/references/search.md +23 -23
- package/skills/{engram → foretext}/references/setup.md +28 -28
package/dist/opencode-plugin.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as stageCapture } from "./capture-admission-
|
|
1
|
+
import { At as NOTE_STATUSES, M as CaptureMessageId, Nt as SOURCE_TYPES, jt as NOTE_TYPES, s as evaluateCapture, u as MainLiveAt } from "./src-DjnbdRrt.js";
|
|
2
|
+
import { S as reportAutomaticContext, a as autoContextOp, d as searchOp, f as showOp, g as recordAutomaticContextUsage, i as addOp, j as runOpAtDirectory, m as elapsedUsageMs, n as contextualRecallOp, o as contextDigest, s as editOp, t as CONTEXTUAL_RECALL_LIMITS, x as compactAutomaticContext } from "./contextual-recall-DF8e3Oa_.js";
|
|
3
|
+
import { t as stageCapture } from "./capture-admission-DqhzaMDY.js";
|
|
4
4
|
import { Effect, Option, Schema } from "effect";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { isAbsolute, resolve } from "node:path";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
//#region ../harnesses/src/opencode/capture-command.ts
|
|
9
|
-
const NAME = "
|
|
10
|
-
const TEMPLATE = "
|
|
9
|
+
const NAME = "foretext-capture";
|
|
10
|
+
const TEMPLATE = "Note handles this command locally. Direct the user to the Note notification.";
|
|
11
11
|
const MAX_SESSIONS$1 = 100;
|
|
12
12
|
const MAX_MESSAGES = 64;
|
|
13
13
|
const MAX_PROPOSALS = 8;
|
|
@@ -29,7 +29,7 @@ function createCaptureCommand({ client, directory, project }, onWriteSuccess) {
|
|
|
29
29
|
value.command ??= {};
|
|
30
30
|
if (Object.hasOwn(value.command, NAME)) return;
|
|
31
31
|
value.command[NAME] = {
|
|
32
|
-
description: "Capture
|
|
32
|
+
description: "Capture Foretext memory suggestions for project review or opt-in recording",
|
|
33
33
|
template: TEMPLATE
|
|
34
34
|
};
|
|
35
35
|
registered = true;
|
|
@@ -60,7 +60,7 @@ function createCaptureCommand({ client, directory, project }, onWriteSuccess) {
|
|
|
60
60
|
const notify = (message, variant = "info") => {
|
|
61
61
|
Promise.resolve().then(() => client?.tui?.showToast({
|
|
62
62
|
body: {
|
|
63
|
-
title: "
|
|
63
|
+
title: "Note capture",
|
|
64
64
|
message,
|
|
65
65
|
variant
|
|
66
66
|
},
|
|
@@ -79,12 +79,12 @@ function createCaptureCommand({ client, directory, project }, onWriteSuccess) {
|
|
|
79
79
|
}
|
|
80
80
|
if (command !== NAME || !isId(sessionID)) return;
|
|
81
81
|
if (args.trim() || parts.length !== 1) {
|
|
82
|
-
notify("Use /
|
|
82
|
+
notify("Use /foretext-capture without arguments.", "warning");
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
if (parts[0].type !== "text" || parts[0].text !== TEMPLATE) return;
|
|
86
86
|
if (active.has(sessionID)) {
|
|
87
|
-
notify("
|
|
87
|
+
notify("Note capture is already running.");
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
const observed = sessions.get(sessionID);
|
|
@@ -169,12 +169,12 @@ function createCaptureCommand({ client, directory, project }, onWriteSuccess) {
|
|
|
169
169
|
}, CAPTURE_MS);
|
|
170
170
|
});
|
|
171
171
|
const result = await Promise.race([capture(), deadline]);
|
|
172
|
-
if (recorded > 0) notify(`
|
|
173
|
-
if (count) notify(`
|
|
174
|
-
if (result === "unavailable") notify("
|
|
175
|
-
else if (!count && !recorded) notify("
|
|
172
|
+
if (recorded > 0) notify(`Note automatically recorded ${recorded} ${recorded === 1 ? "memory" : "memories"}.`);
|
|
173
|
+
if (count) notify(`Note staged ${count} ${count === 1 ? "candidate" : "candidates"} for review. Run foretext pending list --scope all.`);
|
|
174
|
+
if (result === "unavailable") notify("Note capture could not complete for this session.", "warning");
|
|
175
|
+
else if (!count && !recorded) notify("Note found no new eligible candidates.");
|
|
176
176
|
} catch {
|
|
177
|
-
notify("
|
|
177
|
+
notify("Note capture could not complete. Run foretext pending list --scope all.", "warning");
|
|
178
178
|
} finally {
|
|
179
179
|
clearTimeout(timer);
|
|
180
180
|
active.delete(sessionID);
|
|
@@ -350,9 +350,9 @@ const toOpencodeResult = (title, r) => ({
|
|
|
350
350
|
//#endregion
|
|
351
351
|
//#region ../harnesses/src/opencode/tools.ts
|
|
352
352
|
/**
|
|
353
|
-
*
|
|
353
|
+
* foretext_* tool definitions for opencode.
|
|
354
354
|
*
|
|
355
|
-
* Thin adapters over @
|
|
355
|
+
* Thin adapters over @foretext/harnesses/shared ops: zod arg shapes with
|
|
356
356
|
* per-field descriptions and bounds, mirroring the Pi typebox schemas.
|
|
357
357
|
* Keep descriptions in sync with src/pi/tools.ts.
|
|
358
358
|
*/
|
|
@@ -361,23 +361,23 @@ const scopeFilter = (description) => z.enum([
|
|
|
361
361
|
"personal",
|
|
362
362
|
"both"
|
|
363
363
|
]).optional().describe(description);
|
|
364
|
-
const
|
|
365
|
-
const
|
|
364
|
+
const noteTypes = NOTE_TYPES;
|
|
365
|
+
const noteStatuses = NOTE_STATUSES;
|
|
366
366
|
const sourceTypes = SOURCE_TYPES;
|
|
367
|
-
const
|
|
368
|
-
description: "Refresh the recorded memory digest for this workspace: decisions, pinned notes, gotchas, conventions. OpenCode can load relevant memory or a compact digest automatically for the current request. Use this tool for an overview, additional pages, or when automatic context is unavailable. Returns compact one-line entries (id, type, title, tags) with decisions and pinned entries first; read a full entry with
|
|
367
|
+
const noteContextTool = {
|
|
368
|
+
description: "Refresh the recorded memory digest for this workspace: decisions, pinned notes, gotchas, conventions. OpenCode can load relevant memory or a compact digest automatically for the current request. Use this tool for an overview, additional pages, or when automatic context is unavailable. Returns compact one-line entries (id, type, title, tags) with decisions and pinned entries first; read a full entry with foretext_show. Results are paginated - when truncated, the footer names the exact next call.",
|
|
369
369
|
args: {
|
|
370
370
|
scope: scopeFilter(`Which memory scope to read. Default "both" (falls back to personal-only with a note outside a project).`),
|
|
371
371
|
limit: z.number().int().min(1).max(100).optional().describe(`Max entries per page. Default 25.`),
|
|
372
372
|
offset: z.number().int().min(0).optional().describe("0-based page offset for pagination."),
|
|
373
|
-
tokens: z.number().int().min(512).optional().describe("Budget the digest text using
|
|
373
|
+
tokens: z.number().int().min(512).optional().describe("Budget the digest text using Foretext's versioned token accounting.")
|
|
374
374
|
},
|
|
375
375
|
async execute(args, context) {
|
|
376
|
-
return toOpencodeResult("
|
|
376
|
+
return toOpencodeResult("Note Context", await runOpAtDirectory(context.directory, contextDigest(args)));
|
|
377
377
|
}
|
|
378
378
|
};
|
|
379
|
-
const
|
|
380
|
-
description: "Keyword-search recorded
|
|
379
|
+
const noteSearchTool = {
|
|
380
|
+
description: "Keyword-search recorded notes (tags score highest, then aliases, titles, types, bodies). Use when you need specifics beyond the digest - \"auth\", \"migrations\", the name of a library. Returns bounded matching snippets and relevance reasons framed as untrusted memory data, plus structured score summaries; read one with foretext_show. Results are paginated. Set explain to include matched fields and score contributions in metadata.",
|
|
381
381
|
args: {
|
|
382
382
|
query: z.string().describe("Search keywords (matched against tags, aliases, titles, types, and bodies)."),
|
|
383
383
|
explain: z.boolean().optional().describe("Include matched fields, normalized query tokens, and score contributions in metadata. Default false."),
|
|
@@ -386,57 +386,57 @@ const engramSearchTool = {
|
|
|
386
386
|
offset: z.number().int().min(0).optional().describe("0-based page offset for pagination.")
|
|
387
387
|
},
|
|
388
388
|
async execute(args, context) {
|
|
389
|
-
return toOpencodeResult("
|
|
389
|
+
return toOpencodeResult("Note Search", await runOpAtDirectory(context.directory, searchOp(args)));
|
|
390
390
|
}
|
|
391
391
|
};
|
|
392
|
-
const
|
|
393
|
-
description: "Read one full
|
|
392
|
+
const noteShowTool = {
|
|
393
|
+
description: "Read one full note by id (unique prefixes work, e.g. \"12\" for \"0012\"): frontmatter (type, tags, dates, author, scope) plus the complete body. Use after foretext_context or foretext_search picked an entry worth reading. Very long bodies are sliced - the footer names the exact next call.",
|
|
394
394
|
args: {
|
|
395
|
-
id: z.string().describe("
|
|
395
|
+
id: z.string().describe("Note id or unique prefix, e.g. \"0012\" or \"12\"."),
|
|
396
396
|
scope: z.enum(["project", "personal"]).optional().describe("Where to look. Default: project inside a project, personal otherwise."),
|
|
397
397
|
offset: z.number().int().min(0).optional().describe("0-based char offset into the body."),
|
|
398
398
|
limit: z.number().int().min(1).optional().describe("Max body chars to return.")
|
|
399
399
|
},
|
|
400
400
|
async execute(args, context) {
|
|
401
|
-
return toOpencodeResult("
|
|
401
|
+
return toOpencodeResult("Note Show", await runOpAtDirectory(context.directory, showOp(args)));
|
|
402
402
|
}
|
|
403
403
|
};
|
|
404
|
-
const
|
|
404
|
+
const noteAddTool = {
|
|
405
405
|
description: `Record a durable fact, decision, gotcha, or convention to shared memory. Use type "decision" for important choices (state the rationale and alternatives in the body), and record gotchas that cost debugging time. Do not record transient state, secrets, or anything the user says not to store. Project scope is committed to git and shared with the team; pass scope "personal" only for notes that must stay on this machine. Optional lifecycle/provenance metadata (status, supersedes, reviewAfter, expires, sourceType, sourceRef) is an unauthenticated claim, not a verified truth. Optional related links exact same-scope entry ids as directional metadata: the whole list is stored as given, and missing targets only dangle as a warning. Optional aliases are alternate names for the entry (max 20, 80 characters each); the store trims, lowercases, and deduplicates them.`,
|
|
406
406
|
args: {
|
|
407
407
|
title: z.string().describe("Short, descriptive title (one line)."),
|
|
408
408
|
body: z.string().describe("Full content: rationale, context, details."),
|
|
409
|
-
type: z.enum(
|
|
409
|
+
type: z.enum(noteTypes).optional().describe(`Entry kind. Default: the project config defaultType ("note" unless configured).`),
|
|
410
410
|
scope: z.enum(["project", "personal"]).optional().describe("Default \"project\" (team-shared, git-committed)."),
|
|
411
411
|
tags: z.array(z.string()).optional().describe("Searchable tags, e.g. [\"auth\", \"deps\"]."),
|
|
412
412
|
pinned: z.boolean().optional().describe("Pin to the top of the digest for high-value entries."),
|
|
413
|
-
status: z.enum(
|
|
413
|
+
status: z.enum(noteStatuses).optional().describe("Lifecycle status: active | superseded | archived. Optional; not set unless passed."),
|
|
414
414
|
supersedes: z.string().optional().describe("Id of the older entry this one replaces. Optional; validated when saved."),
|
|
415
415
|
reviewAfter: z.string().optional().describe("ISO 8601 timestamp with an explicit zone, e.g. 2026-01-01T00:00:00.000Z. Optional; validated when saved."),
|
|
416
416
|
expires: z.string().optional().describe("ISO 8601 timestamp with an explicit zone, e.g. 2026-06-01T00:00:00.000Z. Optional; validated when saved."),
|
|
417
417
|
sourceType: z.enum(sourceTypes).optional().describe("Provenance shape: conversation | file | url | command | other. Optional."),
|
|
418
418
|
sourceRef: z.string().optional().describe("Source reference: path, URL, command, or conversation note. Optional; validated when saved."),
|
|
419
|
-
related: z.array(z.string()).optional().describe("Exact
|
|
419
|
+
related: z.array(z.string()).optional().describe("Exact note ids in the same scope, e.g. [\"0002\"]. Replaces the whole list in this order; duplicates are rejected. Missing targets are advisory (a warning on check, not an error). Optional."),
|
|
420
420
|
aliases: z.array(z.string().max(80)).max(20).optional().describe("Alternate names for this entry, e.g. [\"pg\", \"postgres row level security\"]. The store trims, lowercases, and deduplicates them (first occurrence wins); the whole set is replaced. Optional."),
|
|
421
421
|
confirmWrite: z.boolean().optional().describe("Proceed after the user reviews and accepts a write advisory."),
|
|
422
422
|
allowSecrets: z.boolean().optional().describe("Write even if the secret scanner flags this content (project writes block by default). Optional.")
|
|
423
423
|
},
|
|
424
424
|
async execute(args, context) {
|
|
425
|
-
return toOpencodeResult("
|
|
425
|
+
return toOpencodeResult("Note Add", await runOpAtDirectory(context.directory, addOp(args)));
|
|
426
426
|
}
|
|
427
427
|
};
|
|
428
|
-
const
|
|
429
|
-
description: "Update an existing
|
|
428
|
+
const noteEditTool = {
|
|
429
|
+
description: "Update an existing note by id (unique prefixes work). Ordinary fields (title, type, tags, body, pinned, author) are replaced when passed and preserved when omitted. The six lifecycle fields (status, supersedes, reviewAfter, expires, sourceType, sourceRef) are three-state: a concrete value replaces, null clears, omission preserves. related is three-state the same way: an array replaces the whole list with exact same-scope ids, null clears it, omission preserves; links are directional and may dangle with a warning. aliases is three-state too: an array replaces the whole set, null clears it, omission preserves. Use this to correct a title or tags, change a type, pin or unpin, or clear a lifecycle field after acting on it. Scope defaults to project inside a project and personal outside one.",
|
|
430
430
|
args: {
|
|
431
|
-
id: z.string().describe("
|
|
431
|
+
id: z.string().describe("Note id or unique prefix, e.g. \"0012\" or \"12\". Required."),
|
|
432
432
|
scope: z.enum(["project", "personal"]).optional().describe("Where to edit. Default: project inside a project, personal otherwise."),
|
|
433
433
|
title: z.string().optional().describe("New title. Omit to preserve."),
|
|
434
|
-
type: z.enum(
|
|
434
|
+
type: z.enum(noteTypes).optional().describe("Replace entry kind. Omit to preserve."),
|
|
435
435
|
tags: z.array(z.string()).optional().describe("Replace the whole tag set, e.g. [\"auth\", \"deps\"]. Omit to preserve."),
|
|
436
436
|
body: z.string().optional().describe("New body content. Omit to preserve."),
|
|
437
437
|
pinned: z.boolean().optional().describe("True pins, false unpins. Omit to preserve."),
|
|
438
438
|
author: z.string().optional().describe("Replace author. Omit to preserve."),
|
|
439
|
-
status: z.enum(
|
|
439
|
+
status: z.enum(noteStatuses).nullable().optional().describe("Lifecycle status: active | superseded | archived. Null clears; omit to preserve."),
|
|
440
440
|
supersedes: z.string().nullable().optional().describe("Id of the older entry this one replaces. Null clears; omit to preserve. Validated when saved."),
|
|
441
441
|
reviewAfter: z.string().nullable().optional().describe("ISO 8601 timestamp with an explicit zone, e.g. 2027-01-01T00:00:00.000Z. Null clears; omit to preserve. Validated when saved."),
|
|
442
442
|
expires: z.string().nullable().optional().describe("ISO 8601 timestamp with an explicit zone, e.g. 2027-06-01T00:00:00.000Z. Null clears; omit to preserve. Validated when saved."),
|
|
@@ -448,12 +448,12 @@ const engramEditTool = {
|
|
|
448
448
|
allowSecrets: z.boolean().optional().describe("Write even if the secret scanner flags the resulting entry (project writes block by default). Optional.")
|
|
449
449
|
},
|
|
450
450
|
async execute(args, context) {
|
|
451
|
-
return toOpencodeResult("
|
|
451
|
+
return toOpencodeResult("Note Edit", await runOpAtDirectory(context.directory, editOp(args)));
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
454
|
//#endregion
|
|
455
455
|
//#region ../harnesses/src/opencode/index.ts
|
|
456
|
-
const
|
|
456
|
+
const notePlugin = async (input) => {
|
|
457
457
|
const autoContext = createContextTransform(resolveActiveRequest(input.client));
|
|
458
458
|
const capture = createCaptureCommand(input, autoContext.invalidate);
|
|
459
459
|
const writeToolWithRefresh = (base) => ({
|
|
@@ -466,11 +466,11 @@ const engramPlugin = async (input) => {
|
|
|
466
466
|
});
|
|
467
467
|
return {
|
|
468
468
|
tool: {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
469
|
+
foretext_context: noteContextTool,
|
|
470
|
+
foretext_search: noteSearchTool,
|
|
471
|
+
foretext_show: noteShowTool,
|
|
472
|
+
foretext_add: writeToolWithRefresh(noteAddTool),
|
|
473
|
+
foretext_edit: writeToolWithRefresh(noteEditTool)
|
|
474
474
|
},
|
|
475
475
|
config: capture.config,
|
|
476
476
|
"chat.message": capture.observe,
|
|
@@ -485,4 +485,4 @@ const engramPlugin = async (input) => {
|
|
|
485
485
|
};
|
|
486
486
|
};
|
|
487
487
|
//#endregion
|
|
488
|
-
export {
|
|
488
|
+
export { notePlugin as default };
|
package/dist/pi-extension.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A as
|
|
3
|
-
import { t as stageCapture } from "./capture-admission-
|
|
1
|
+
import { At as NOTE_STATUSES, Nt as SOURCE_TYPES, Vt as splitAliasList, jt as NOTE_TYPES, s as evaluateCapture, u as MainLiveAt } from "./src-DjnbdRrt.js";
|
|
2
|
+
import { A as runOp, S as reportAutomaticContext, c as initOp, d as searchOp, f as showOp, g as recordAutomaticContextUsage, i as addOp, j as runOpAtDirectory, l as linksOp, m as elapsedUsageMs, n as contextualRecallOp, o as contextDigest, s as editOp, t as CONTEXTUAL_RECALL_LIMITS, u as relatedOp, x as compactAutomaticContext } from "./contextual-recall-DF8e3Oa_.js";
|
|
3
|
+
import { t as stageCapture } from "./capture-admission-DqhzaMDY.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import { Type } from "typebox";
|
|
6
6
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
@@ -81,8 +81,8 @@ function registerCapture(pi, onWriteSuccess) {
|
|
|
81
81
|
} catch {} finally {
|
|
82
82
|
clearTimeout(timer);
|
|
83
83
|
}
|
|
84
|
-
if (recorded > 0 && ctx.hasUI) ctx.ui.notify(`
|
|
85
|
-
if (staged > 0 && ctx.hasUI) ctx.ui.notify(`
|
|
84
|
+
if (recorded > 0 && ctx.hasUI) ctx.ui.notify(`Note automatically recorded ${recorded} ${recorded === 1 ? "memory" : "memories"}.`, "info");
|
|
85
|
+
if (staged > 0 && ctx.hasUI) ctx.ui.notify(`Note staged ${staged} ${staged === 1 ? "candidate" : "candidates"} for review. Run foretext pending list --scope all.`, "info");
|
|
86
86
|
};
|
|
87
87
|
pi.on("agent_settled", (event, ctx) => flush(event.type, ctx));
|
|
88
88
|
pi.on("session_before_compact", (event, ctx) => flush(event.type, ctx, event.signal));
|
|
@@ -94,7 +94,7 @@ const defaultLoader = (directory, prompt) => runOpAtDirectory(directory, context
|
|
|
94
94
|
prompt,
|
|
95
95
|
intent: "task"
|
|
96
96
|
}, true));
|
|
97
|
-
const LOAD_FAILED_WARNING = "
|
|
97
|
+
const LOAD_FAILED_WARNING = "Note automatic context could not be loaded for this session; call foretext_context to load memory manually if needed.";
|
|
98
98
|
function registerAutoContext(pi, opts = {}) {
|
|
99
99
|
const load = opts.load ?? defaultLoader;
|
|
100
100
|
const onDiagnostics = opts.onDiagnostics ?? reportAutomaticContext;
|
|
@@ -185,23 +185,23 @@ const toToolResult = (r) => ({
|
|
|
185
185
|
//#endregion
|
|
186
186
|
//#region ../harnesses/src/pi/commands.ts
|
|
187
187
|
const HELP = [
|
|
188
|
-
"
|
|
188
|
+
"note - git-native memory for you and your team",
|
|
189
189
|
"",
|
|
190
|
-
" /
|
|
191
|
-
" /
|
|
192
|
-
" /
|
|
193
|
-
" /
|
|
194
|
-
" /
|
|
195
|
-
" /
|
|
190
|
+
" /foretext show the context digest (decisions & pinned first)",
|
|
191
|
+
" /foretext context [scope] digest for scope: project | personal | both",
|
|
192
|
+
" /foretext search <query> keyword search across recorded notes",
|
|
193
|
+
" /foretext show <id> read one full entry (unique prefixes work)",
|
|
194
|
+
" /foretext related <id> lifecycle lineage + explicit links (exact id)",
|
|
195
|
+
" /foretext links <id> link graph: outgoing related + incoming backlinks (exact id)",
|
|
196
196
|
" flags: --scope project|personal --offset n --limit n (max 100)",
|
|
197
|
-
" /
|
|
197
|
+
" /foretext add [--confirm-write] <title> -- <body> record an entry",
|
|
198
198
|
" flags: --type decision|fact|preference|note|issue|context",
|
|
199
199
|
" --scope project|personal --tags a,b --aliases a,b --pinned",
|
|
200
200
|
" --status active|superseded|archived --supersedes <id>",
|
|
201
201
|
" --review-after <ts> --expires <ts>",
|
|
202
202
|
" --source-type conversation|file|url|command|other",
|
|
203
203
|
" --source-ref <ref> quote it if it contains spaces",
|
|
204
|
-
" /
|
|
204
|
+
" /foretext edit <id> [flags] [-- <body>] edit an entry (unique prefixes work)",
|
|
205
205
|
" flags: --title <title> --type decision|fact|preference|note|issue|context",
|
|
206
206
|
" --tags a,b --aliases a,b --scope project|personal --pinned | --no-pinned",
|
|
207
207
|
" --author <name> --confirm-write",
|
|
@@ -212,9 +212,9 @@ const HELP = [
|
|
|
212
212
|
" clear a field: --clear-status --clear-supersedes",
|
|
213
213
|
" --clear-review-after --clear-expires --clear-source-type",
|
|
214
214
|
" --clear-source-ref --clear-aliases",
|
|
215
|
-
" /
|
|
215
|
+
" /foretext init [tracked|untracked] initialize project memory here",
|
|
216
216
|
"",
|
|
217
|
-
"Agents: prefer the
|
|
217
|
+
"Agents: prefer the foretext_context / foretext_search / foretext_show / foretext_add / foretext_edit tools."
|
|
218
218
|
].join("\n");
|
|
219
219
|
const parseAddError = (error) => ({
|
|
220
220
|
ok: false,
|
|
@@ -236,7 +236,7 @@ function parseAdd(rest) {
|
|
|
236
236
|
};
|
|
237
237
|
const type = flag("--type");
|
|
238
238
|
if (type !== null) {
|
|
239
|
-
if (!
|
|
239
|
+
if (!NOTE_TYPES.includes(type)) return parseAddError(`Invalid --type "${type}". Valid: ${NOTE_TYPES.join(" | ")}`);
|
|
240
240
|
parsed.type = type;
|
|
241
241
|
}
|
|
242
242
|
const scope = flag("--scope");
|
|
@@ -246,7 +246,7 @@ function parseAdd(rest) {
|
|
|
246
246
|
}
|
|
247
247
|
const status = flag("--status");
|
|
248
248
|
if (status !== null) {
|
|
249
|
-
if (!
|
|
249
|
+
if (!NOTE_STATUSES.includes(status)) return parseAddError(`Invalid --status "${status}". Valid: ${NOTE_STATUSES.join(" | ")}`);
|
|
250
250
|
parsed.status = status;
|
|
251
251
|
}
|
|
252
252
|
const sourceType = flag("--source-type");
|
|
@@ -354,7 +354,7 @@ const LIFECYCLE_FLAG_PAIRS = [
|
|
|
354
354
|
field: "sourceRef"
|
|
355
355
|
}
|
|
356
356
|
];
|
|
357
|
-
const EDIT_USAGE = "Usage: /
|
|
357
|
+
const EDIT_USAGE = "Usage: /foretext edit <id> [flags] [-- <body>]";
|
|
358
358
|
/** Every recognized flag spelling. A bare token with one of these raw forms
|
|
359
359
|
* can never be a flag's value: the value is simply missing. Quoting is the
|
|
360
360
|
* way to pass flag-looking text — the tokenizer keeps the quote characters
|
|
@@ -375,7 +375,7 @@ const FLAG_SPELLINGS = /* @__PURE__ */ new Set([
|
|
|
375
375
|
"--confirm-write",
|
|
376
376
|
...LIFECYCLE_FLAG_PAIRS.flatMap((p) => [p.value, p.clear])
|
|
377
377
|
]);
|
|
378
|
-
/** Parse `/
|
|
378
|
+
/** Parse `/foretext edit` arguments: the first token is the id (or unique
|
|
379
379
|
* prefix), then field flags, then an optional ` -- <body>` delimiter. The
|
|
380
380
|
* body is everything after the first bare `--` token, verbatim, so
|
|
381
381
|
* flag-looking text inside it is never parsed as flags. All conflicts and
|
|
@@ -434,7 +434,7 @@ function parseEdit(rest) {
|
|
|
434
434
|
case "--type": {
|
|
435
435
|
const v = nextValue();
|
|
436
436
|
if (v === null) return parseEditError("Missing value for --type.");
|
|
437
|
-
if (!
|
|
437
|
+
if (!NOTE_TYPES.includes(v)) return parseEditError(`Invalid --type "${v}". Valid: ${NOTE_TYPES.join(" | ")}`);
|
|
438
438
|
parsed.type = v;
|
|
439
439
|
break;
|
|
440
440
|
}
|
|
@@ -485,7 +485,7 @@ function parseEdit(rest) {
|
|
|
485
485
|
if (fieldCount === 0 && !bodyPresent) return parseEditError(`Nothing to edit. Pass a field flag or a " -- " body. ${EDIT_USAGE}`);
|
|
486
486
|
return parsed;
|
|
487
487
|
}
|
|
488
|
-
const LINKS_USAGE = "Usage: /
|
|
488
|
+
const LINKS_USAGE = "Usage: /foretext links <id> [--scope project|personal] [--offset n] [--limit n]";
|
|
489
489
|
/** Recognized links flags: a bare one is a missing value, never a literal. */
|
|
490
490
|
const LINKS_FLAGS = /* @__PURE__ */ new Set([
|
|
491
491
|
"--scope",
|
|
@@ -497,7 +497,7 @@ const parseLinksError = (error) => ({
|
|
|
497
497
|
error
|
|
498
498
|
});
|
|
499
499
|
const isNonNegativeInteger = (v) => /^\d+$/.test(v) && Number.isSafeInteger(Number(v));
|
|
500
|
-
/** Parse `/
|
|
500
|
+
/** Parse `/foretext links` arguments: exact id first, then value flags. Rejects
|
|
501
501
|
* missing ids, unknown flags, repeated value flags, non-integers, negative
|
|
502
502
|
* offsets, zero or excessive limits, and trailing positional arguments —
|
|
503
503
|
* all before the operation runs. Exact ids only: graph semantics, no
|
|
@@ -548,14 +548,14 @@ async function dispatch(args, ctx, onWriteSuccess) {
|
|
|
548
548
|
let tracked = true;
|
|
549
549
|
if (remainder === "untracked") tracked = false;
|
|
550
550
|
else if (remainder === "tracked") tracked = true;
|
|
551
|
-
else if (ctx.hasUI) tracked = await ctx.ui.confirm("
|
|
551
|
+
else if (ctx.hasUI) tracked = await ctx.ui.confirm("foretext init", "Track the team note in git? (shared with your team; answer No to gitignore it)");
|
|
552
552
|
const r = await runOp(initOp({ tracked }));
|
|
553
553
|
notify(r.text, r.isError ? "error" : "info");
|
|
554
554
|
return;
|
|
555
555
|
}
|
|
556
556
|
if (sub === "search") {
|
|
557
557
|
if (!remainder) {
|
|
558
|
-
notify("Usage: /
|
|
558
|
+
notify("Usage: /foretext search <query>", "error");
|
|
559
559
|
return;
|
|
560
560
|
}
|
|
561
561
|
const r = await runOp(searchOp({ query: remainder }));
|
|
@@ -564,7 +564,7 @@ async function dispatch(args, ctx, onWriteSuccess) {
|
|
|
564
564
|
}
|
|
565
565
|
if (sub === "show") {
|
|
566
566
|
if (!remainder) {
|
|
567
|
-
notify("Usage: /
|
|
567
|
+
notify("Usage: /foretext show <id>", "error");
|
|
568
568
|
return;
|
|
569
569
|
}
|
|
570
570
|
const r = await runOp(showOp({ id: remainder }));
|
|
@@ -578,7 +578,7 @@ async function dispatch(args, ctx, onWriteSuccess) {
|
|
|
578
578
|
}
|
|
579
579
|
const parsed = parseLinks(remainder);
|
|
580
580
|
if ("error" in parsed) {
|
|
581
|
-
notify(parsed.error.replace("/
|
|
581
|
+
notify(parsed.error.replace("/foretext links", `/foretext ${sub}`), "error");
|
|
582
582
|
return;
|
|
583
583
|
}
|
|
584
584
|
const r = await runOp(sub === "related" ? relatedOp(parsed) : linksOp(parsed));
|
|
@@ -592,7 +592,7 @@ async function dispatch(args, ctx, onWriteSuccess) {
|
|
|
592
592
|
return;
|
|
593
593
|
}
|
|
594
594
|
if (!parsed.title) {
|
|
595
|
-
notify("Usage: /
|
|
595
|
+
notify("Usage: /foretext add [--confirm-write] <title> -- <body> [--type X] [--scope Y] [--tags a,b]", "error");
|
|
596
596
|
return;
|
|
597
597
|
}
|
|
598
598
|
const r = await runOp(addOp(parsed, "--confirm-write before the title"));
|
|
@@ -618,9 +618,9 @@ async function dispatch(args, ctx, onWriteSuccess) {
|
|
|
618
618
|
const r = await runOp(contextDigest({ scope: remainder === "project" || remainder === "personal" || remainder === "both" ? remainder : void 0 }));
|
|
619
619
|
notify(r.text, r.isError ? "error" : "info");
|
|
620
620
|
}
|
|
621
|
-
function
|
|
622
|
-
pi.registerCommand("
|
|
623
|
-
description: "
|
|
621
|
+
function registerNoteCommand(pi, opts = {}) {
|
|
622
|
+
pi.registerCommand("foretext", {
|
|
623
|
+
description: "note memory: context | search | show | links | related | add | edit | init | help",
|
|
624
624
|
handler: async (args, ctx) => {
|
|
625
625
|
await dispatch(args, ctx, opts.onWriteSuccess);
|
|
626
626
|
}
|
|
@@ -629,9 +629,9 @@ function registerEngramCommand(pi, opts = {}) {
|
|
|
629
629
|
//#endregion
|
|
630
630
|
//#region ../harnesses/src/pi/tools.ts
|
|
631
631
|
/**
|
|
632
|
-
*
|
|
632
|
+
* foretext_* tool definitions for the Pi coding agent.
|
|
633
633
|
*
|
|
634
|
-
* Thin adapters over @
|
|
634
|
+
* Thin adapters over @foretext/harnesses/shared ops: typebox schemas with
|
|
635
635
|
* per-field descriptions and bounds, rich descriptions + promptSnippets.
|
|
636
636
|
*/
|
|
637
637
|
const scopeFilter = (description) => Type.Optional(StringEnum([
|
|
@@ -639,10 +639,10 @@ const scopeFilter = (description) => Type.Optional(StringEnum([
|
|
|
639
639
|
"personal",
|
|
640
640
|
"both"
|
|
641
641
|
], { description }));
|
|
642
|
-
const
|
|
643
|
-
name: "
|
|
644
|
-
label: "
|
|
645
|
-
description: "Refresh the recorded memory digest for this workspace: decisions, pinned notes, gotchas, conventions. Pi recalls confident matches for the current prompt automatically. Use this tool to browse the workspace digest, page deeper, or recover when automatic recall failed or is unavailable. Returns compact one-line entries (id, type, title, tags) with decisions and pinned entries first; read a full entry with
|
|
642
|
+
const noteContextTool = {
|
|
643
|
+
name: "foretext_context",
|
|
644
|
+
label: "Note Context",
|
|
645
|
+
description: "Refresh the recorded memory digest for this workspace: decisions, pinned notes, gotchas, conventions. Pi recalls confident matches for the current prompt automatically. Use this tool to browse the workspace digest, page deeper, or recover when automatic recall failed or is unavailable. Returns compact one-line entries (id, type, title, tags) with decisions and pinned entries first; read a full entry with foretext_show. Results are paginated - when truncated, the footer names the exact next call.",
|
|
646
646
|
promptSnippet: "Relevant memory is recalled automatically; use this to browse the digest, page deeper, or recover when recall is unavailable.",
|
|
647
647
|
parameters: Type.Object({
|
|
648
648
|
scope: scopeFilter(`Which memory scope to read. Default "both" (falls back to personal-only with a note outside a project).`),
|
|
@@ -658,7 +658,7 @@ const engramContextTool = {
|
|
|
658
658
|
tokens: Type.Optional(Type.Integer({
|
|
659
659
|
minimum: 512,
|
|
660
660
|
maximum: Number.MAX_SAFE_INTEGER,
|
|
661
|
-
description: "Budget the digest text using
|
|
661
|
+
description: "Budget the digest text using Foretext's versioned token accounting."
|
|
662
662
|
}))
|
|
663
663
|
}),
|
|
664
664
|
async execute(_id, params) {
|
|
@@ -670,10 +670,10 @@ const engramContextTool = {
|
|
|
670
670
|
})));
|
|
671
671
|
}
|
|
672
672
|
};
|
|
673
|
-
const
|
|
674
|
-
name: "
|
|
675
|
-
label: "
|
|
676
|
-
description: "Keyword-search recorded
|
|
673
|
+
const noteSearchTool = {
|
|
674
|
+
name: "foretext_search",
|
|
675
|
+
label: "Note Search",
|
|
676
|
+
description: "Keyword-search recorded notes (tags score highest, then aliases, titles, types, bodies). Use when you need specifics beyond the digest - \"auth\", \"migrations\", the name of a library. Returns bounded matching snippets and relevance reasons framed as untrusted memory data, plus structured score summaries; read one with foretext_show. Results are paginated. Set explain to include matched fields and score contributions in metadata.",
|
|
677
677
|
promptSnippet: "Use to pull specific recorded knowledge by keyword instead of re-deriving it.",
|
|
678
678
|
parameters: Type.Object({
|
|
679
679
|
query: Type.String({ description: "Search keywords (matched against tags, aliases, titles, types, and bodies)." }),
|
|
@@ -699,13 +699,13 @@ const engramSearchTool = {
|
|
|
699
699
|
})));
|
|
700
700
|
}
|
|
701
701
|
};
|
|
702
|
-
const
|
|
703
|
-
name: "
|
|
704
|
-
label: "
|
|
705
|
-
description: "Read one full
|
|
702
|
+
const noteShowTool = {
|
|
703
|
+
name: "foretext_show",
|
|
704
|
+
label: "Note Show",
|
|
705
|
+
description: "Read one full note by id (unique prefixes work, e.g. \"12\" for \"0012\"): frontmatter (type, tags, dates, author, scope) plus the complete body. Use after foretext_context or foretext_search picked an entry worth reading. Very long bodies are sliced - the footer names the exact next call.",
|
|
706
706
|
promptSnippet: "Read full recorded entries by id after spotting them in context or search.",
|
|
707
707
|
parameters: Type.Object({
|
|
708
|
-
id: Type.String({ description: "
|
|
708
|
+
id: Type.String({ description: "Note id or unique prefix, e.g. \"0012\" or \"12\"." }),
|
|
709
709
|
scope: Type.Optional(StringEnum(["project", "personal"], { description: "Where to look. Default: project inside a project, personal otherwise." })),
|
|
710
710
|
offset: Type.Optional(Type.Integer({
|
|
711
711
|
minimum: 0,
|
|
@@ -725,25 +725,25 @@ const engramShowTool = {
|
|
|
725
725
|
})));
|
|
726
726
|
}
|
|
727
727
|
};
|
|
728
|
-
const
|
|
729
|
-
name: "
|
|
730
|
-
label: "
|
|
728
|
+
const noteAddTool = {
|
|
729
|
+
name: "foretext_add",
|
|
730
|
+
label: "Note Add",
|
|
731
731
|
description: `Record a durable fact, decision, gotcha, or convention to shared memory. Use type "decision" for important choices (state the rationale and alternatives in the body), and record gotchas that cost debugging time. Do not record transient state, secrets, or anything the user says not to store. Project scope is committed to git and shared with the team; pass scope "personal" only for notes that must stay on this machine. Optional lifecycle/provenance metadata (status, supersedes, reviewAfter, expires, sourceType, sourceRef) is an unauthenticated claim, not a verified truth. Optional related links exact same-scope entry ids as directional metadata: the whole list is stored as given, and missing targets only dangle as a warning. Optional aliases are alternate names for the entry (max 20, 80 characters each); the store trims, lowercases, and deduplicates them.`,
|
|
732
732
|
promptSnippet: "Record durable decisions (with rationale), gotchas, and conventions as you discover them; ask scope personal only for machine-private notes.",
|
|
733
733
|
parameters: Type.Object({
|
|
734
734
|
title: Type.String({ description: "Short, descriptive title (one line)." }),
|
|
735
735
|
body: Type.String({ description: "Full content: rationale, context, details." }),
|
|
736
|
-
type: Type.Optional(StringEnum([...
|
|
736
|
+
type: Type.Optional(StringEnum([...NOTE_TYPES], { description: `Entry kind. Default: the project config defaultType ("note" unless configured).` })),
|
|
737
737
|
scope: Type.Optional(StringEnum(["project", "personal"], { description: "Default \"project\" (team-shared, git-committed)." })),
|
|
738
738
|
tags: Type.Optional(Type.Array(Type.String(), { description: "Searchable tags, e.g. [\"auth\", \"deps\"]." })),
|
|
739
739
|
pinned: Type.Optional(Type.Boolean({ description: "Pin to the top of the digest for high-value entries." })),
|
|
740
|
-
status: Type.Optional(StringEnum([...
|
|
740
|
+
status: Type.Optional(StringEnum([...NOTE_STATUSES], { description: "Lifecycle status: active | superseded | archived. Optional; not set unless passed." })),
|
|
741
741
|
supersedes: Type.Optional(Type.String({ description: "Id of the older entry this one replaces. Optional; validated when saved." })),
|
|
742
742
|
reviewAfter: Type.Optional(Type.String({ description: "ISO 8601 timestamp with an explicit zone, e.g. 2026-01-01T00:00:00.000Z. Optional; validated when saved." })),
|
|
743
743
|
expires: Type.Optional(Type.String({ description: "ISO 8601 timestamp with an explicit zone, e.g. 2026-06-01T00:00:00.000Z. Optional; validated when saved." })),
|
|
744
744
|
sourceType: Type.Optional(StringEnum([...SOURCE_TYPES], { description: "Provenance shape: conversation | file | url | command | other. Optional." })),
|
|
745
745
|
sourceRef: Type.Optional(Type.String({ description: "Source reference: path, URL, command, or conversation note. Optional; validated when saved." })),
|
|
746
|
-
related: Type.Optional(Type.Array(Type.String(), { description: "Exact
|
|
746
|
+
related: Type.Optional(Type.Array(Type.String(), { description: "Exact note ids in the same scope, e.g. [\"0002\"]. Replaces the whole list in this order; duplicates are rejected. Missing targets are advisory (a warning on check, not an error). Optional." })),
|
|
747
747
|
aliases: Type.Optional(Type.Array(Type.String({ maxLength: 80 }), {
|
|
748
748
|
maxItems: 20,
|
|
749
749
|
description: "Alternate names for this entry, e.g. [\"pg\", \"postgres row level security\"]. The store trims, lowercases, and deduplicates them (first occurrence wins); the whole set is replaced. Optional."
|
|
@@ -772,21 +772,21 @@ const engramAddTool = {
|
|
|
772
772
|
})));
|
|
773
773
|
}
|
|
774
774
|
};
|
|
775
|
-
const
|
|
776
|
-
name: "
|
|
777
|
-
label: "
|
|
778
|
-
description: "Update an existing
|
|
775
|
+
const noteEditTool = {
|
|
776
|
+
name: "foretext_edit",
|
|
777
|
+
label: "Note Edit",
|
|
778
|
+
description: "Update an existing note by id (unique prefixes work). Ordinary fields (title, type, tags, body, pinned, author) are replaced when passed and preserved when omitted. The six lifecycle fields (status, supersedes, reviewAfter, expires, sourceType, sourceRef) are three-state: a concrete value replaces, null clears, omission preserves. related is three-state the same way: an array replaces the whole list with exact same-scope ids, null clears it, omission preserves; links are directional and may dangle with a warning. aliases is three-state too: an array replaces the whole set, null clears it, omission preserves. Use this to correct a title or tags, change a type, pin or unpin, or clear a lifecycle field after acting on it. Scope defaults to project inside a project and personal outside one.",
|
|
779
779
|
promptSnippet: "Update an existing entry: ordinary fields replace when passed, lifecycle fields are three-state (null clears, omission preserves).",
|
|
780
780
|
parameters: Type.Object({
|
|
781
|
-
id: Type.String({ description: "
|
|
781
|
+
id: Type.String({ description: "Note id or unique prefix, e.g. \"0012\" or \"12\". Required." }),
|
|
782
782
|
scope: Type.Optional(StringEnum(["project", "personal"], { description: "Where to edit. Default: project inside a project, personal otherwise." })),
|
|
783
783
|
title: Type.Optional(Type.String({ description: "New title. Omit to preserve." })),
|
|
784
|
-
type: Type.Optional(StringEnum([...
|
|
784
|
+
type: Type.Optional(StringEnum([...NOTE_TYPES], { description: "Replace entry kind. Omit to preserve." })),
|
|
785
785
|
tags: Type.Optional(Type.Array(Type.String(), { description: "Replace the whole tag set, e.g. [\"auth\", \"deps\"]. Omit to preserve." })),
|
|
786
786
|
body: Type.Optional(Type.String({ description: "New body content. Omit to preserve." })),
|
|
787
787
|
pinned: Type.Optional(Type.Boolean({ description: "True pins, false unpins. Omit to preserve." })),
|
|
788
788
|
author: Type.Optional(Type.String({ description: "Replace author. Omit to preserve." })),
|
|
789
|
-
status: Type.Optional(Type.Union([StringEnum([...
|
|
789
|
+
status: Type.Optional(Type.Union([StringEnum([...NOTE_STATUSES]), Type.Null()], { description: "Lifecycle status: active | superseded | archived. Null clears; omit to preserve." })),
|
|
790
790
|
supersedes: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: "Id of the older entry this one replaces. Null clears; omit to preserve. Validated when saved." })),
|
|
791
791
|
reviewAfter: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: "ISO 8601 timestamp with an explicit zone, e.g. 2027-01-01T00:00:00.000Z. Null clears; omit to preserve. Validated when saved." })),
|
|
792
792
|
expires: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: "ISO 8601 timestamp with an explicit zone, e.g. 2027-06-01T00:00:00.000Z. Null clears; omit to preserve. Validated when saved." })),
|
|
@@ -833,21 +833,21 @@ const toolWithRefresh = (base, onWriteSuccess) => ({
|
|
|
833
833
|
return result;
|
|
834
834
|
}
|
|
835
835
|
});
|
|
836
|
-
function
|
|
837
|
-
pi.registerTool(
|
|
838
|
-
pi.registerTool(
|
|
839
|
-
pi.registerTool(
|
|
836
|
+
function registerNoteTools(pi, opts = {}) {
|
|
837
|
+
pi.registerTool(noteContextTool);
|
|
838
|
+
pi.registerTool(noteSearchTool);
|
|
839
|
+
pi.registerTool(noteShowTool);
|
|
840
840
|
const notify = opts.onWriteSuccess;
|
|
841
|
-
pi.registerTool(notify ? toolWithRefresh(
|
|
842
|
-
pi.registerTool(notify ? toolWithRefresh(
|
|
841
|
+
pi.registerTool(notify ? toolWithRefresh(noteAddTool, notify) : noteAddTool);
|
|
842
|
+
pi.registerTool(notify ? toolWithRefresh(noteEditTool, notify) : noteEditTool);
|
|
843
843
|
}
|
|
844
844
|
//#endregion
|
|
845
845
|
//#region ../harnesses/src/pi/index.ts
|
|
846
|
-
function
|
|
846
|
+
function noteExtension(pi) {
|
|
847
847
|
const autoContext = registerAutoContext(pi);
|
|
848
848
|
registerCapture(pi, autoContext.invalidate);
|
|
849
|
-
|
|
850
|
-
|
|
849
|
+
registerNoteTools(pi, { onWriteSuccess: autoContext.invalidate });
|
|
850
|
+
registerNoteCommand(pi, { onWriteSuccess: autoContext.invalidate });
|
|
851
851
|
}
|
|
852
852
|
//#endregion
|
|
853
|
-
export {
|
|
853
|
+
export { noteExtension as default };
|