@meshpoint/cli 1.0.0 → 1.2.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 +14 -1
- package/dist/antigravity/connect.js +5 -1
- package/dist/antigravity/tap.js +3 -0
- package/dist/bin.js +17 -4
- package/dist/claude-code/connect.js +7 -3
- package/dist/claude-code/settings.js +7 -3
- package/dist/claude-code/skill.js +50 -3
- package/dist/claude-code/tap.js +28 -0
- package/dist/codex/connect.js +7 -2
- package/dist/codex/transcript.js +5 -1
- package/dist/context.js +126 -0
- package/dist/cursor/connect.js +8 -3
- package/dist/cursor/tap.js +15 -0
- package/dist/items.js +87 -18
- package/dist/opencode/connect.js +5 -1
- package/dist/opencode/hooks.js +9 -3
- package/dist/pi/connect.js +5 -1
- package/dist/pi/extension.js +12 -0
- package/dist/refs.js +86 -0
- package/dist/runtime.js +6 -1
- package/dist/tap.js +119 -10
- package/dist/touched.js +44 -0
- package/dist/verify.js +52 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# meshpoint clients
|
|
2
2
|
|
|
3
|
-
The `meshpoint` CLI and harness adapters for Meshpoint
|
|
3
|
+
The `meshpoint` CLI and harness adapters for Meshpoint, shared agent memory for developer teams. Adapters: Claude Code, Codex, Cursor, Antigravity, pi, opencode, OpenClaw. Claude Code, Codex, pi, opencode and OpenClaw are verified live against staging; Cursor and Antigravity are ported from their published hook docs and need a live check.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -32,6 +32,9 @@ meshpoint status # config + project id for the current repo
|
|
|
32
32
|
meshpoint items put --item gotcha 'title' 'body' # write items for the current repo and branch
|
|
33
33
|
meshpoint items put < items.json # same, as a JSON array of {kind, title, body}
|
|
34
34
|
meshpoint items retract 3f9c1a2b # retract by id or unique id prefix
|
|
35
|
+
meshpoint items confirm 3f9c1a2b # confirm by id or prefix (counts toward rank)
|
|
36
|
+
meshpoint items put --item decision 'New choice' 'Why.' --supersedes 7d0e44aa # replaces the old item
|
|
37
|
+
meshpoint items put --item convention 'Tests: pnpm test' 'scripts.test' --key test-runner # stable slot
|
|
35
38
|
```
|
|
36
39
|
|
|
37
40
|
`connect <harness>` without `--project` writes to your user config, so every repo you open is on the mesh. `--project <dir>` writes into one repo instead; the files then travel with the repo in git. The meshpoint testbed on the maintainers' machines uses `--project` only.
|
|
@@ -100,6 +103,16 @@ Distillation is agent-side: the platform runs no model. `connect` installs the `
|
|
|
100
103
|
|
|
101
104
|
The session-start inject shows each item's id prefix so the skill can retract what the session made obsolete (`meshpoint items retract <prefix>...`, resolved against a fresh recall; ambiguous prefixes are refused).
|
|
102
105
|
|
|
106
|
+
## Refs, verification and the edit hook
|
|
107
|
+
|
|
108
|
+
`items put` reads repo-relative paths out of each item's title and body (`src/auth.ts`, `package.json`, backticked `Makefile`), keeps the ones that exist as the item's `refs`, attaches the files edited on the branch since the last checkpoint (recorded by every adapter under `~/.local/state/meshpoint/touched/`) as `paths`, and records HEAD as `commit_sha`. Path-like tokens that resolve to nothing print `ref not found: <path>` so the agent can fix a typo.
|
|
109
|
+
|
|
110
|
+
At session start the tap asks for the whole branch, verifies every item with refs against the checkout (no model: `fs.stat` per ref, one `git log --since` per item, two seconds in total), and cuts the inject to 3,000 tokens itself. Verified items confirm; items whose refs changed since are marked `?`; items whose refs are gone move to a "Possibly stale" list the skill tells the agent to resolve. A checkout that does not contain the item's commit skips it. Sightings go to `POST /v1/items/verify`; three users seeing an item stale drop it from recall (the console can restore it).
|
|
111
|
+
|
|
112
|
+
The edit hook runs around file edits: Claude Code and Codex `PreToolUse` (Codex matches `apply_patch` under `Edit|Write` and the tap reads the files out of the patch), opencode `tool.execute.after`, pi `tool_result`, Cursor `postToolUse`. It injects the file's gotcha, decision and convention items (from the session-start cache, two at most) and anyone else who touched the file in the last five minutes on any branch (`GET /v1/context`, one second budget). One notice per file per session, kept in `~/.local/state/meshpoint/edits/`. Every path fails open.
|
|
113
|
+
|
|
114
|
+
A branch with no items and committed instruction files (`git ls-files` over CLAUDE.md, AGENTS.md, `.cursor/rules/*`, `.github/copilot-instructions.md`, `.kiro/steering/*.md` and friends) gets one nudge to run the `meshpoint-import` skill, which `connect` installs next to `meshpoint`.
|
|
115
|
+
|
|
103
116
|
A checkpoint is due after 20 assistant replies or 60k chars of reply text since the later of the last checkpoint and the last nudge (`~/.local/state/meshpoint/nudges/<session>.json`). An ignored nudge is not repeated until the next pile. The benchmark behind this: one-shot items scored 0.67 resume correctness against 0.60 for a freeform summary and 0.32 for a transcript tail (ceiling 0.82).
|
|
104
117
|
|
|
105
118
|
The project id is derived from `git remote get-url origin` (`host--owner--repo`); directories without an origin remote are ignored.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
4
|
+
import { IMPORT_SKILL_NAME, importSkillMarkdown, skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
5
5
|
export const ANTIGRAVITY_TAP_COMMAND = "meshpoint tap antigravity";
|
|
6
6
|
export const MESHPOINT_GROUP = "meshpoint";
|
|
7
7
|
export const ANTIGRAVITY_EVENTS = ["SessionStart", "PreInvocation", "Stop"];
|
|
@@ -40,11 +40,15 @@ export function connectAntigravity(opts) {
|
|
|
40
40
|
else
|
|
41
41
|
rmSync(paths.hooks, { force: true });
|
|
42
42
|
rmSync(paths.skillDir, { recursive: true, force: true });
|
|
43
|
+
rmSync(path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME), { recursive: true, force: true });
|
|
43
44
|
return `removed the ${MESHPOINT_GROUP} hook group from ${paths.hooks} and ${paths.skillDir}`;
|
|
44
45
|
}
|
|
45
46
|
mkdirSync(path.dirname(paths.hooks), { recursive: true });
|
|
46
47
|
writeFileSync(paths.hooks, `${JSON.stringify(installAntigravityHooks(file), null, 2)}\n`);
|
|
47
48
|
mkdirSync(paths.skillDir, { recursive: true });
|
|
48
49
|
writeFileSync(path.join(paths.skillDir, "SKILL.md"), skillMarkdown({ allowedTools: false }));
|
|
50
|
+
const importDir = path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME);
|
|
51
|
+
mkdirSync(importDir, { recursive: true });
|
|
52
|
+
writeFileSync(path.join(importDir, "SKILL.md"), importSkillMarkdown({ allowedTools: false }));
|
|
49
53
|
return `installed the ${MESHPOINT_GROUP} hook group in ${paths.hooks} (${ANTIGRAVITY_EVENTS.join(", ")}) and ${paths.skillDir}/SKILL.md. Antigravity loads hooks.json on the next conversation; toggle it under Customizations > Hooks.`;
|
|
50
54
|
}
|
package/dist/antigravity/tap.js
CHANGED
|
@@ -70,6 +70,9 @@ export async function runAntigravityTap(payload, deps) {
|
|
|
70
70
|
...(deps.fetch ? { fetch: deps.fetch } : {}),
|
|
71
71
|
...(deps.presenceWaitMs !== undefined ? { presenceWaitMs: deps.presenceWaitMs } : {}),
|
|
72
72
|
...(deps.refresh ? { refresh: deps.refresh } : {}),
|
|
73
|
+
...(deps.touched ? { touched: deps.touched } : {}),
|
|
74
|
+
...(deps.cache ? { cache: deps.cache } : {}),
|
|
75
|
+
...(deps.local ? { local: deps.local(repo.root) } : {}),
|
|
73
76
|
});
|
|
74
77
|
const conversations = new Conversations(deps.stateDir);
|
|
75
78
|
const transcript = () => {
|
package/dist/bin.js
CHANGED
|
@@ -16,11 +16,14 @@ import { ReplyLog, runOpenclawTap } from "./openclaw/tap.js";
|
|
|
16
16
|
import { connectPi } from "./pi/connect.js";
|
|
17
17
|
import { Checkpoints } from "./checkpoints.js";
|
|
18
18
|
import { configPath, deleteConfig, loadConfig, repoContext, saveConfig, spoolDir, stateDir } from "./config.js";
|
|
19
|
+
import { SessionCache } from "./context.js";
|
|
20
|
+
import { localChecks } from "./tap.js";
|
|
21
|
+
import { Touched } from "./touched.js";
|
|
19
22
|
import { MeshpointError } from "@meshpoint/sdk";
|
|
20
23
|
import { api, ApiError, canOpenBrowser, deviceLogin, freshConfig, login } from "./control.js";
|
|
21
24
|
import { detectHarnesses, renderDetected } from "./detect.js";
|
|
22
25
|
import { renderDoctor, runDoctor } from "./doctor.js";
|
|
23
|
-
import { parseItemArgs, parseItems, putItems, retractItems } from "./items.js";
|
|
26
|
+
import { confirmItems, parseItemArgs, parseItems, putItems, retractItems } from "./items.js";
|
|
24
27
|
import { Spool } from "./spool.js";
|
|
25
28
|
const USAGE = `meshpoint <command>
|
|
26
29
|
|
|
@@ -68,6 +71,7 @@ const USAGE = `meshpoint <command>
|
|
|
68
71
|
write items for the current repo and branch; the file or
|
|
69
72
|
stdin form takes a JSON array of {kind, title, body}
|
|
70
73
|
items retract <id>... retract items on the current branch; an id may be a prefix
|
|
74
|
+
items confirm <id>... confirm items on the current branch (counts toward their rank)
|
|
71
75
|
tap claude-code | codex | cursor | antigravity [<event>] | openclaw
|
|
72
76
|
hook entry point; reads one hook payload on stdin
|
|
73
77
|
`;
|
|
@@ -231,8 +235,8 @@ async function main(argv) {
|
|
|
231
235
|
return 0;
|
|
232
236
|
}
|
|
233
237
|
case "items": {
|
|
234
|
-
if (rest[0] !== "put" && rest[0] !== "retract")
|
|
235
|
-
throw new Error("items supports: put, retract");
|
|
238
|
+
if (rest[0] !== "put" && rest[0] !== "retract" && rest[0] !== "confirm")
|
|
239
|
+
throw new Error("items supports: put, retract, confirm");
|
|
236
240
|
const config = await requireConfig();
|
|
237
241
|
const repo = repoContext(process.cwd());
|
|
238
242
|
if (!repo)
|
|
@@ -241,9 +245,15 @@ async function main(argv) {
|
|
|
241
245
|
console.log(JSON.stringify(await withAuth(config, (c) => retractItems(rest.slice(1), { config: c, repo }))));
|
|
242
246
|
return 0;
|
|
243
247
|
}
|
|
248
|
+
if (rest[0] === "confirm") {
|
|
249
|
+
console.log(JSON.stringify(await withAuth(config, (c) => confirmItems(rest.slice(1), { config: c, repo }))));
|
|
250
|
+
return 0;
|
|
251
|
+
}
|
|
244
252
|
const file = flag(rest, "--file");
|
|
245
253
|
const drafts = rest.includes("--item") ? parseItemArgs(rest.slice(1)) : parseItems(file ? readFileSync(file, "utf8") : await readStdin());
|
|
246
|
-
const out = await withAuth(config, (c) => putItems(drafts, { config: c, repo, checkpoints: new Checkpoints(stateDir()) }));
|
|
254
|
+
const { missing, ...out } = await withAuth(config, (c) => putItems(drafts, { config: c, repo, checkpoints: new Checkpoints(stateDir()), touched: new Touched(stateDir()) }));
|
|
255
|
+
for (const m of missing)
|
|
256
|
+
console.error(`ref not found: ${m}`);
|
|
247
257
|
console.log(JSON.stringify({ ...out, project: repo.project, branch: repo.branch }));
|
|
248
258
|
return 0;
|
|
249
259
|
}
|
|
@@ -270,6 +280,9 @@ async function main(argv) {
|
|
|
270
280
|
readTranscript: (file) => readFileSync(file, "utf8"),
|
|
271
281
|
spool: new Spool(spoolDir()),
|
|
272
282
|
checkpoints: new Checkpoints(stateDir()),
|
|
283
|
+
touched: new Touched(stateDir()),
|
|
284
|
+
cache: new SessionCache(stateDir()),
|
|
285
|
+
local: (root) => localChecks(root),
|
|
273
286
|
});
|
|
274
287
|
// Each harness has its own "do nothing" answer, needed even without a login.
|
|
275
288
|
if (harness === "cursor") {
|
|
@@ -2,7 +2,7 @@ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { installTapHooks, removeTapHooks } from "./settings.js";
|
|
5
|
-
import { SKILL_MD, SKILL_NAME } from "./skill.js";
|
|
5
|
+
import { IMPORT_SKILL_MD, IMPORT_SKILL_NAME, SKILL_MD, SKILL_NAME } from "./skill.js";
|
|
6
6
|
export function claudeConfigDir(env = process.env, home = homedir()) {
|
|
7
7
|
return env.CLAUDE_CONFIG_DIR || path.join(home, ".claude");
|
|
8
8
|
}
|
|
@@ -12,6 +12,7 @@ export function connectClaudeCode(opts) {
|
|
|
12
12
|
const configDir = opts.configDir ?? claudeConfigDir();
|
|
13
13
|
const settingsPath = path.join(configDir, "settings.json");
|
|
14
14
|
const skillDir = path.join(configDir, "skills", SKILL_NAME);
|
|
15
|
+
const importSkillDir = path.join(configDir, "skills", IMPORT_SKILL_NAME);
|
|
15
16
|
let settings = {};
|
|
16
17
|
try {
|
|
17
18
|
settings = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
@@ -27,9 +28,12 @@ export function connectClaudeCode(opts) {
|
|
|
27
28
|
writeFileSync(settingsPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
28
29
|
if (opts.remove) {
|
|
29
30
|
rmSync(skillDir, { recursive: true, force: true });
|
|
30
|
-
|
|
31
|
+
rmSync(importSkillDir, { recursive: true, force: true });
|
|
32
|
+
return `removed meshpoint hooks from ${settingsPath}, ${skillDir} and ${importSkillDir}`;
|
|
31
33
|
}
|
|
32
34
|
mkdirSync(skillDir, { recursive: true });
|
|
33
35
|
writeFileSync(path.join(skillDir, "SKILL.md"), SKILL_MD);
|
|
34
|
-
|
|
36
|
+
mkdirSync(importSkillDir, { recursive: true });
|
|
37
|
+
writeFileSync(path.join(importSkillDir, "SKILL.md"), IMPORT_SKILL_MD);
|
|
38
|
+
return `installed meshpoint hooks in ${settingsPath} (SessionStart, UserPromptSubmit, PreToolUse on edits, Stop, PreCompact, SessionEnd), ${skillDir}/SKILL.md and ${importSkillDir}/SKILL.md`;
|
|
35
39
|
}
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
// meshpoint tap, so re-running connect upgrades in place and never touches hooks the user wrote.
|
|
3
3
|
export const TAP_COMMAND = "meshpoint tap claude-code";
|
|
4
4
|
const HOOK_TIMEOUT_S = 30;
|
|
5
|
-
|
|
5
|
+
export const EDIT_TOOLS_MATCHER = "Edit|Write|MultiEdit|NotebookEdit";
|
|
6
|
+
const EDIT_HOOK_TIMEOUT_S = 5;
|
|
7
|
+
// SessionStart includes "compact": the items are what survives a context loss. PreToolUse on the
|
|
8
|
+
// editing tools carries the file-level notice (items naming the file, teammates on it).
|
|
6
9
|
export const MANAGED_EVENTS = [
|
|
7
10
|
{ event: "SessionStart", matcher: "startup|resume|clear|compact" },
|
|
8
11
|
{ event: "UserPromptSubmit" },
|
|
12
|
+
{ event: "PreToolUse", matcher: EDIT_TOOLS_MATCHER, timeout: EDIT_HOOK_TIMEOUT_S },
|
|
9
13
|
{ event: "Stop" },
|
|
10
14
|
{ event: "PreCompact" },
|
|
11
15
|
{ event: "SessionEnd" },
|
|
@@ -21,10 +25,10 @@ function withoutManaged(groups) {
|
|
|
21
25
|
}
|
|
22
26
|
export function installTapHooks(settings, spec = CLAUDE_CODE_SPEC) {
|
|
23
27
|
const hooks = { ...settings.hooks };
|
|
24
|
-
for (const { event, matcher } of spec.events) {
|
|
28
|
+
for (const { event, matcher, timeout } of spec.events) {
|
|
25
29
|
hooks[event] = [
|
|
26
30
|
...withoutManaged(hooks[event]),
|
|
27
|
-
{ ...(matcher === undefined ? {} : { matcher }), hooks: [{ type: "command", command: spec.command, timeout: HOOK_TIMEOUT_S, ...spec.extra }] },
|
|
31
|
+
{ ...(matcher === undefined ? {} : { matcher }), hooks: [{ type: "command", command: spec.command, timeout: timeout ?? HOOK_TIMEOUT_S, ...spec.extra }] },
|
|
28
32
|
];
|
|
29
33
|
}
|
|
30
34
|
return { ...settings, hooks };
|
|
@@ -31,17 +31,22 @@ Each item is an object \`{"kind", "title", "body"}\`. \`kind\` is one of:
|
|
|
31
31
|
|
|
32
32
|
- Only what this session established. Never invent.
|
|
33
33
|
- Skip anything already listed under "Team knowledge" in the session-start context unless it changed; a changed decision or status gets a new item.
|
|
34
|
-
-
|
|
34
|
+
- An item that replaces an older one (a changed decision, a convention that moved, a todo now split differently) names the old id: add \`--supersedes <id>\` after the \`--item\`. The old item leaves recall and stays linked to the new one. A \`status\` item always replaces the branch's previous status on its own.
|
|
35
|
+
- Retract items that this session made wrong: a finished todo, a reversed decision with nothing in its place. The first column of "Team knowledge" is the item id.
|
|
36
|
+
- \`status\` and \`todo\` items leave recall on their own after 30 days without confirmation; the durable kinds stay until replaced or retracted.
|
|
37
|
+
- Items under "Possibly stale" name a file that is gone from this checkout. Check whether each still holds; retract it or write a corrected item. Do not leave them.
|
|
38
|
+
- Name files by their repo-relative path (\`src/auth/token.ts\`, not "the token file"). Meshpoint links the item to those files, checks them in later checkouts, and shows the item when someone edits them. The command warns about paths it cannot find.
|
|
35
39
|
- Prefer durable knowledge over moment-to-moment detail. Aim for 5 to 30 items; one \`status\` item at most.
|
|
36
40
|
- No secrets, tokens, or credentials.
|
|
37
41
|
|
|
38
42
|
## Procedure
|
|
39
43
|
|
|
40
|
-
Run \`meshpoint items put\` once, one \`--item kind title body\` per item. Single-quote title and body and keep the single quote character out of them (write "do not", not "don't"). No JSON, no heredoc.
|
|
44
|
+
Run \`meshpoint items put\` once, one \`--item kind title body\` per item, each optionally followed by \`--supersedes <id>\` (the item it replaces) or \`--key <slot>\` (a stable slot such as \`test-runner\`; a later item with the same key replaces this one). Single-quote title and body and keep the single quote character out of them (write "do not", not "don't"). No JSON, no heredoc.
|
|
41
45
|
|
|
42
46
|
\`\`\`bash
|
|
43
47
|
meshpoint items put \\
|
|
44
|
-
--item decision 'Short title' 'What was chosen and why, with file names and values.' \\
|
|
48
|
+
--item decision 'Short title' 'What was chosen and why, with file names and values.' --supersedes 7d0e44aa \\
|
|
49
|
+
--item convention 'Tests run with pnpm test' 'package.json scripts.test; CI runs the same.' --key test-runner \\
|
|
45
50
|
--item gotcha 'Short title' 'What bit and how to avoid it.'
|
|
46
51
|
\`\`\`
|
|
47
52
|
|
|
@@ -54,3 +59,45 @@ meshpoint items retract 3f9c1a2b 7d0e44aa
|
|
|
54
59
|
Then continue the work you were doing.
|
|
55
60
|
`;
|
|
56
61
|
export const SKILL_MD = skillMarkdown({ allowedTools: true });
|
|
62
|
+
// The import skill: seeds a branch with no memory from the repository's committed instruction
|
|
63
|
+
// files. Offered once per branch by the session-start inject.
|
|
64
|
+
export const IMPORT_SKILL_NAME = "meshpoint-import";
|
|
65
|
+
export function importSkillMarkdown(opts) {
|
|
66
|
+
return `---
|
|
67
|
+
name: ${IMPORT_SKILL_NAME}
|
|
68
|
+
description: Seed Meshpoint team knowledge for a branch that has none from the repository's committed instruction files (CLAUDE.md, AGENTS.md, Cursor rules, Copilot instructions). Use when the Meshpoint session-start context says the branch has no team knowledge yet.
|
|
69
|
+
${opts.allowedTools ? "allowed-tools: Bash(meshpoint items put:*), Bash(git ls-files:*)\n" : ""}---
|
|
70
|
+
${IMPORT_SKILL_BODY}`;
|
|
71
|
+
}
|
|
72
|
+
const IMPORT_SKILL_BODY = `
|
|
73
|
+
# Meshpoint import
|
|
74
|
+
|
|
75
|
+
Turn the repository's instruction files into Meshpoint items, once.
|
|
76
|
+
|
|
77
|
+
## Read
|
|
78
|
+
|
|
79
|
+
The session-start context lists the files. Read each one. They are committed files such as \`CLAUDE.md\`, \`AGENTS.md\`, \`.cursor/rules/*\`, \`.github/copilot-instructions.md\`.
|
|
80
|
+
|
|
81
|
+
## Select
|
|
82
|
+
|
|
83
|
+
Keep only statements about this repository that a teammate's agent needs:
|
|
84
|
+
|
|
85
|
+
- \`convention\`: how things are done here ("tests run with \`pnpm test\`", "migrations live in \`db/migrations\`").
|
|
86
|
+
- \`fact\`: a stable truth about the code or environment ("CI pins Node 22").
|
|
87
|
+
- \`gotcha\`: something that bites ("\`npm install\` fails without the private registry token").
|
|
88
|
+
|
|
89
|
+
Skip instructions aimed at the model rather than the repository ("be concise", "ask before refactoring"), prose that only introduces a section, and anything already true of every project. One item per rule. At most 30 items. Name files by their repo-relative path.
|
|
90
|
+
|
|
91
|
+
## Write
|
|
92
|
+
|
|
93
|
+
One command, one \`--item kind title body\` per item. Single quotes; no single quote character inside (write "do not", not "don't").
|
|
94
|
+
|
|
95
|
+
\`\`\`bash
|
|
96
|
+
meshpoint items put \\
|
|
97
|
+
--item convention 'Tests run with pnpm test' 'package.json scripts.test runs vitest; CI runs the same command.' \\
|
|
98
|
+
--item fact 'CI pins Node 22' '.github/workflows/ci.yml uses actions/setup-node with node-version 22.'
|
|
99
|
+
\`\`\`
|
|
100
|
+
|
|
101
|
+
Then continue the work you were doing. Do not run this skill again on this branch.
|
|
102
|
+
`;
|
|
103
|
+
export const IMPORT_SKILL_MD = importSkillMarkdown({ allowedTools: true });
|
package/dist/claude-code/tap.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
import { patchFilePaths } from "../codex/transcript.js";
|
|
1
2
|
import { Tap } from "../tap.js";
|
|
2
3
|
import { lastAssistantTurn, parseTranscript as parseClaudeCodeTranscript } from "./transcript.js";
|
|
3
4
|
export { renderInject } from "../tap.js";
|
|
5
|
+
const TOOL_PATH_KEYS = ["file_path", "path", "notebook_path"];
|
|
6
|
+
// One apply_patch can touch several files; the notice covers the first few.
|
|
7
|
+
const PATCH_FILES_MAX = 3;
|
|
8
|
+
// The files an editing tool call is about: Claude Code names one in tool_input; Codex's
|
|
9
|
+
// apply_patch carries the whole patch in tool_input.command.
|
|
10
|
+
export function toolFilePaths(input) {
|
|
11
|
+
for (const key of TOOL_PATH_KEYS) {
|
|
12
|
+
const v = input?.[key];
|
|
13
|
+
if (typeof v === "string" && v)
|
|
14
|
+
return [v];
|
|
15
|
+
}
|
|
16
|
+
const command = input?.command;
|
|
17
|
+
return typeof command === "string" ? patchFilePaths(command).slice(0, PATCH_FILES_MAX) : [];
|
|
18
|
+
}
|
|
4
19
|
// One hook event in, one JSON answer out. Claude Code and Codex share the hook protocol (event
|
|
5
20
|
// names, payload fields, additionalContext, Stop block), so one wrapper serves both. The Tap
|
|
6
21
|
// swallows mesh failures; this layer only speaks the hook protocol.
|
|
@@ -20,6 +35,9 @@ export async function runClaudeCodeTap(payload, deps) {
|
|
|
20
35
|
...(deps.fetch ? { fetch: deps.fetch } : {}),
|
|
21
36
|
...(deps.presenceWaitMs !== undefined ? { presenceWaitMs: deps.presenceWaitMs } : {}),
|
|
22
37
|
...(deps.refresh ? { refresh: deps.refresh } : {}),
|
|
38
|
+
...(deps.touched ? { touched: deps.touched } : {}),
|
|
39
|
+
...(deps.cache ? { cache: deps.cache } : {}),
|
|
40
|
+
...(deps.local ? { local: deps.local(repo.root) } : {}),
|
|
23
41
|
});
|
|
24
42
|
const transcript = () => {
|
|
25
43
|
if (!payload.transcript_path)
|
|
@@ -39,6 +57,16 @@ export async function runClaudeCodeTap(payload, deps) {
|
|
|
39
57
|
case "UserPromptSubmit":
|
|
40
58
|
await tap.user(payload.prompt ?? "");
|
|
41
59
|
return "{}";
|
|
60
|
+
case "PreToolUse":
|
|
61
|
+
case "PostToolUse": {
|
|
62
|
+
const notices = [];
|
|
63
|
+
for (const file of toolFilePaths(payload.tool_input)) {
|
|
64
|
+
const text = await tap.edit(file);
|
|
65
|
+
if (text)
|
|
66
|
+
notices.push(text);
|
|
67
|
+
}
|
|
68
|
+
return notices.length > 0 ? JSON.stringify({ hookSpecificOutput: { hookEventName: event, additionalContext: notices.join("\n\n") } }) : "{}";
|
|
69
|
+
}
|
|
42
70
|
case "Stop": {
|
|
43
71
|
const entries = transcript();
|
|
44
72
|
const turn = lastAssistantTurn(entries);
|
package/dist/codex/connect.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
4
|
+
import { IMPORT_SKILL_NAME, importSkillMarkdown, skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
5
5
|
import { installTapHooks, removeTapHooks } from "../claude-code/settings.js";
|
|
6
6
|
export const CODEX_TAP_COMMAND = "meshpoint tap codex";
|
|
7
7
|
// Codex truncates additionalContext at 2500 chars by default; a recall inject is up to ~12k.
|
|
8
8
|
const CONTEXT_LIMIT = 100_000;
|
|
9
9
|
export const CODEX_SPEC = {
|
|
10
10
|
command: CODEX_TAP_COMMAND,
|
|
11
|
-
|
|
11
|
+
// Codex matches apply_patch under the Edit|Write aliases; the hook reads the files out of the patch.
|
|
12
|
+
events: [{ event: "SessionStart" }, { event: "UserPromptSubmit" }, { event: "PreToolUse", matcher: "Edit|Write", timeout: 5 }, { event: "Stop" }, { event: "PreCompact" }, { event: "SessionEnd" }],
|
|
12
13
|
extra: { additionalContextLimit: CONTEXT_LIMIT },
|
|
13
14
|
};
|
|
14
15
|
// Codex approves commands by prefix rules, not per skill; "allow" also runs them outside the
|
|
@@ -55,6 +56,7 @@ export function connectCodex(opts) {
|
|
|
55
56
|
rmSync(paths.hooks, { force: true });
|
|
56
57
|
rmSync(paths.rules, { force: true });
|
|
57
58
|
rmSync(paths.skillDir, { recursive: true, force: true });
|
|
59
|
+
rmSync(path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME), { recursive: true, force: true });
|
|
58
60
|
return `removed meshpoint hooks from ${paths.hooks}, ${paths.rules} and ${paths.skillDir}`;
|
|
59
61
|
}
|
|
60
62
|
mkdirSync(path.dirname(paths.hooks), { recursive: true });
|
|
@@ -63,5 +65,8 @@ export function connectCodex(opts) {
|
|
|
63
65
|
writeFileSync(paths.rules, RULES);
|
|
64
66
|
mkdirSync(paths.skillDir, { recursive: true });
|
|
65
67
|
writeFileSync(path.join(paths.skillDir, "SKILL.md"), skillMarkdown({ allowedTools: false }));
|
|
68
|
+
const importDir = path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME);
|
|
69
|
+
mkdirSync(importDir, { recursive: true });
|
|
70
|
+
writeFileSync(path.join(importDir, "SKILL.md"), importSkillMarkdown({ allowedTools: false }));
|
|
66
71
|
return `installed meshpoint hooks in ${paths.hooks}, rules in ${paths.rules} and ${paths.skillDir}/SKILL.md. Project .codex files load only once the project is trusted in config.toml; Codex asks to trust new hooks on the next run (/hooks).`;
|
|
67
72
|
}
|
package/dist/codex/transcript.js
CHANGED
|
@@ -5,6 +5,10 @@ const PATCH_PATH_RE = /^\*\*\* (?:Add|Update|Delete) File: (.+)$/gm;
|
|
|
5
5
|
function isRecord(v) {
|
|
6
6
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7
7
|
}
|
|
8
|
+
// File paths named in an apply_patch body ("*** Update File: src/x.ts").
|
|
9
|
+
export function patchFilePaths(patch) {
|
|
10
|
+
return [...patch.matchAll(PATCH_PATH_RE)].map((m) => m[1].trim()).filter(Boolean);
|
|
11
|
+
}
|
|
8
12
|
function patchPaths(args) {
|
|
9
13
|
if (typeof args !== "string")
|
|
10
14
|
return [];
|
|
@@ -18,7 +22,7 @@ function patchPaths(args) {
|
|
|
18
22
|
const patch = isRecord(input) ? (input.patch ?? input.input) : undefined;
|
|
19
23
|
if (typeof patch !== "string")
|
|
20
24
|
return [];
|
|
21
|
-
return
|
|
25
|
+
return patchFilePaths(patch);
|
|
22
26
|
}
|
|
23
27
|
export function parseCodexTranscript(jsonl) {
|
|
24
28
|
const entries = [];
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isExpired } from "@meshpoint/sdk";
|
|
4
|
+
// Per-session state for the edit hook: the branch's items as seen at session start (with the
|
|
5
|
+
// local verdicts) and the files already noticed, so one file gets one notice per session.
|
|
6
|
+
export const EDIT_ITEMS_MAX = 2;
|
|
7
|
+
export const EDIT_KINDS = new Set(["gotcha", "decision", "convention"]);
|
|
8
|
+
function safe(name) {
|
|
9
|
+
return name.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
10
|
+
}
|
|
11
|
+
export class SessionCache {
|
|
12
|
+
dir;
|
|
13
|
+
constructor(dir) {
|
|
14
|
+
this.dir = dir;
|
|
15
|
+
}
|
|
16
|
+
recallFile(session) {
|
|
17
|
+
return path.join(this.dir, "recall", `${safe(session)}.json`);
|
|
18
|
+
}
|
|
19
|
+
editsFile(session) {
|
|
20
|
+
return path.join(this.dir, "edits", `${safe(session)}.json`);
|
|
21
|
+
}
|
|
22
|
+
write(file, value) {
|
|
23
|
+
mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
24
|
+
writeFileSync(file, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
25
|
+
}
|
|
26
|
+
saveRecall(session, cached) {
|
|
27
|
+
this.write(this.recallFile(session), cached);
|
|
28
|
+
}
|
|
29
|
+
loadRecall(session) {
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(readFileSync(this.recallFile(session), "utf8"));
|
|
32
|
+
return Array.isArray(parsed.items) ? parsed : null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// True the first time a file is seen in the session; false afterwards.
|
|
39
|
+
firstEdit(session, filePath) {
|
|
40
|
+
const file = this.editsFile(session);
|
|
41
|
+
let seen = [];
|
|
42
|
+
try {
|
|
43
|
+
seen = JSON.parse(readFileSync(file, "utf8"));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
seen = [];
|
|
47
|
+
}
|
|
48
|
+
if (seen.includes(filePath))
|
|
49
|
+
return false;
|
|
50
|
+
this.write(file, [...seen, filePath]);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
forget(session) {
|
|
54
|
+
rmSync(this.recallFile(session), { force: true });
|
|
55
|
+
rmSync(this.editsFile(session), { force: true });
|
|
56
|
+
}
|
|
57
|
+
// The import nudge shows once per project branch on this machine. True the first time.
|
|
58
|
+
firstImportNudge(project, branch) {
|
|
59
|
+
const file = path.join(this.dir, "import", `${safe(`${project}--${branch}`)}`);
|
|
60
|
+
try {
|
|
61
|
+
readFileSync(file);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
this.write(file, { at: Date.now() });
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Items worth showing when a file is edited: those naming it, of the kinds that bite, not dropped
|
|
71
|
+
// locally stale, ranked the way recall ranks them (kind weight, then recency, then confirmations).
|
|
72
|
+
const KIND_WEIGHT = { decision: 5, gotcha: 4, convention: 3, fact: 2, status: 2, todo: 1 };
|
|
73
|
+
export function itemsForFile(items, verdicts, filePath, now = Date.now()) {
|
|
74
|
+
return items
|
|
75
|
+
.filter((i) => !i.retracted && i.state !== "dropped" && i.state !== "superseded" && !isExpired(i, now) && EDIT_KINDS.has(i.kind) && verdicts[i.id] !== "stale")
|
|
76
|
+
.filter((i) => i.refs.includes(filePath) || i.paths.includes(filePath))
|
|
77
|
+
.sort((a, b) => (KIND_WEIGHT[b.kind] ?? 0) - (KIND_WEIGHT[a.kind] ?? 0) || b.created_at - a.created_at || b.confirmations - a.confirmations)
|
|
78
|
+
.slice(0, EDIT_ITEMS_MAX);
|
|
79
|
+
}
|
|
80
|
+
function age(ms) {
|
|
81
|
+
const m = Math.floor(ms / 60_000);
|
|
82
|
+
return m < 1 ? "just now" : `${m}m ago`;
|
|
83
|
+
}
|
|
84
|
+
// The notice injected around an edit, or "" when there is nothing to say.
|
|
85
|
+
export function renderEditNotice(filePath, items, presence, now) {
|
|
86
|
+
if (items.length === 0 && presence.length === 0)
|
|
87
|
+
return "";
|
|
88
|
+
const lines = [`Meshpoint, ${filePath}:`];
|
|
89
|
+
for (const p of presence)
|
|
90
|
+
lines.push(`- ${p.user}'s ${p.agent} edited this file ${age(now - p.updated_at)} on ${p.branch}.`);
|
|
91
|
+
for (const i of items)
|
|
92
|
+
lines.push(`- [${i.kind}] ${i.title}: ${i.body}`);
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
// Committed instruction files that can seed a branch with no memory yet. Only tracked files
|
|
96
|
+
// count, so a stray local note never triggers the import nudge.
|
|
97
|
+
export const INSTRUCTION_FILE_PATTERNS = [
|
|
98
|
+
"CLAUDE.md",
|
|
99
|
+
"AGENTS.md",
|
|
100
|
+
"GEMINI.md",
|
|
101
|
+
".cursorrules",
|
|
102
|
+
".claude/CLAUDE.md",
|
|
103
|
+
".claude/rules/*.md",
|
|
104
|
+
".cursor/rules/*",
|
|
105
|
+
".codex/AGENTS.md",
|
|
106
|
+
".github/copilot-instructions.md",
|
|
107
|
+
".kiro/steering/*.md",
|
|
108
|
+
".junie/guidelines.md",
|
|
109
|
+
];
|
|
110
|
+
export function instructionFiles(git) {
|
|
111
|
+
const out = git(["ls-files", "--", ...INSTRUCTION_FILE_PATTERNS]);
|
|
112
|
+
if (!out)
|
|
113
|
+
return [];
|
|
114
|
+
return out
|
|
115
|
+
.split("\n")
|
|
116
|
+
.map((l) => l.trim())
|
|
117
|
+
.filter(Boolean)
|
|
118
|
+
.slice(0, 20);
|
|
119
|
+
}
|
|
120
|
+
export function renderImportNudge(files) {
|
|
121
|
+
return [
|
|
122
|
+
"This branch has no team knowledge yet.",
|
|
123
|
+
`Instruction files found: ${files.join(", ")}.`,
|
|
124
|
+
"Run the meshpoint-import skill once to seed items from them, then continue.",
|
|
125
|
+
].join("\n");
|
|
126
|
+
}
|
package/dist/cursor/connect.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
4
|
+
import { IMPORT_SKILL_NAME, importSkillMarkdown, skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
5
5
|
export const CURSOR_TAP_COMMAND = "meshpoint tap cursor";
|
|
6
6
|
const HOOK_TIMEOUT_S = 30;
|
|
7
|
-
// afterAgentResponse carries the reply text; stop only decides on the checkpoint nudge
|
|
8
|
-
|
|
7
|
+
// afterAgentResponse carries the reply text; stop only decides on the checkpoint nudge;
|
|
8
|
+
// postToolUse is where a file notice can reach the agent (additional_context).
|
|
9
|
+
export const CURSOR_EVENTS = ["sessionStart", "beforeSubmitPrompt", "postToolUse", "afterAgentResponse", "stop", "preCompact", "sessionEnd"];
|
|
9
10
|
function isManaged(hook) {
|
|
10
11
|
return typeof hook.command === "string" && (hook.command.startsWith("meshpoint tap ") || hook.command.startsWith("meshpoint-tap "));
|
|
11
12
|
}
|
|
@@ -53,6 +54,7 @@ export function connectCursor(opts) {
|
|
|
53
54
|
else
|
|
54
55
|
rmSync(paths.hooks, { force: true });
|
|
55
56
|
rmSync(paths.skillDir, { recursive: true, force: true });
|
|
57
|
+
rmSync(path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME), { recursive: true, force: true });
|
|
56
58
|
return `removed meshpoint hooks from ${paths.hooks} and ${paths.skillDir}`;
|
|
57
59
|
}
|
|
58
60
|
mkdirSync(path.dirname(paths.hooks), { recursive: true });
|
|
@@ -60,5 +62,8 @@ export function connectCursor(opts) {
|
|
|
60
62
|
mkdirSync(paths.skillDir, { recursive: true });
|
|
61
63
|
// Cursor's SKILL.md frontmatter takes name and description; allowed-tools is Claude Code only.
|
|
62
64
|
writeFileSync(path.join(paths.skillDir, "SKILL.md"), skillMarkdown({ allowedTools: false }));
|
|
65
|
+
const importDir = path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME);
|
|
66
|
+
mkdirSync(importDir, { recursive: true });
|
|
67
|
+
writeFileSync(path.join(importDir, "SKILL.md"), importSkillMarkdown({ allowedTools: false }));
|
|
63
68
|
return `installed meshpoint hooks in ${paths.hooks} (${CURSOR_EVENTS.join(", ")}) and ${paths.skillDir}/SKILL.md. Cursor reloads hooks.json on save; the Hooks tab under Customize lists them.`;
|
|
64
69
|
}
|
package/dist/cursor/tap.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toolFilePaths } from "../claude-code/tap.js";
|
|
1
2
|
import { lastAssistantTurn } from "../claude-code/transcript.js";
|
|
2
3
|
import { NUDGE_PREFIX, Tap } from "../tap.js";
|
|
3
4
|
import { parseCursorTranscript } from "./transcript.js";
|
|
@@ -22,6 +23,9 @@ export async function runCursorTap(payload, deps) {
|
|
|
22
23
|
...(deps.fetch ? { fetch: deps.fetch } : {}),
|
|
23
24
|
...(deps.presenceWaitMs !== undefined ? { presenceWaitMs: deps.presenceWaitMs } : {}),
|
|
24
25
|
...(deps.refresh ? { refresh: deps.refresh } : {}),
|
|
26
|
+
...(deps.touched ? { touched: deps.touched } : {}),
|
|
27
|
+
...(deps.cache ? { cache: deps.cache } : {}),
|
|
28
|
+
...(deps.local ? { local: deps.local(repo.root) } : {}),
|
|
25
29
|
});
|
|
26
30
|
const transcript = () => {
|
|
27
31
|
if (!payload.transcript_path)
|
|
@@ -44,6 +48,17 @@ export async function runCursorTap(payload, deps) {
|
|
|
44
48
|
await tap.user(prompt.startsWith(NUDGE_PREFIX) ? "" : prompt);
|
|
45
49
|
return CONTINUE;
|
|
46
50
|
}
|
|
51
|
+
case "postToolUse": {
|
|
52
|
+
// After a file edit: the only Cursor event around a tool call that takes additional_context.
|
|
53
|
+
const files = payload.file_path ? [payload.file_path] : toolFilePaths(payload.tool_input);
|
|
54
|
+
const notices = [];
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
const text = await tap.edit(file);
|
|
57
|
+
if (text)
|
|
58
|
+
notices.push(text);
|
|
59
|
+
}
|
|
60
|
+
return notices.length > 0 ? JSON.stringify({ additional_context: notices.join("\n\n") }) : "{}";
|
|
61
|
+
}
|
|
47
62
|
case "afterAgentResponse": {
|
|
48
63
|
// The documented text field is the reply; the transcript, when readable, adds the touched paths.
|
|
49
64
|
await tap.assistant(payload.text ?? "", lastAssistantTurn(transcript())?.paths ?? []);
|
package/dist/items.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { KINDS, MeshpointClient } from "@meshpoint/sdk";
|
|
3
|
+
import { extractRefs, headSha } from "./refs.js";
|
|
3
4
|
export const ITEMS_MAX = 60;
|
|
4
5
|
export const ID_PREFIX_CHARS = 8;
|
|
5
6
|
const ALL_ITEMS_BUDGET = 100_000;
|
|
6
7
|
const TITLE_MAX = 200;
|
|
7
8
|
const BODY_MAX = 2000;
|
|
9
|
+
const KEY_RE = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
10
|
+
const SUPERSEDES_MAX = 20;
|
|
11
|
+
function withKey(d, i, key) {
|
|
12
|
+
if (typeof key !== "string" || !KEY_RE.test(key))
|
|
13
|
+
throw new Error(`item ${i}: key must be 1-128 characters of letters, digits, . _ : / -`);
|
|
14
|
+
return { ...d, key };
|
|
15
|
+
}
|
|
16
|
+
function withSupersedes(d, i, ids) {
|
|
17
|
+
const list = typeof ids === "string" ? ids.split(",") : ids;
|
|
18
|
+
if (!Array.isArray(list) || !list.every((s) => typeof s === "string"))
|
|
19
|
+
throw new Error(`item ${i}: supersedes must be a list of item ids`);
|
|
20
|
+
const clean = list.map((s) => s.trim()).filter(Boolean);
|
|
21
|
+
if (clean.length === 0 || clean.length > SUPERSEDES_MAX)
|
|
22
|
+
throw new Error(`item ${i}: supersedes takes 1 to ${SUPERSEDES_MAX} item ids`);
|
|
23
|
+
return { ...d, supersedes: [...(d.supersedes ?? []), ...clean] };
|
|
24
|
+
}
|
|
8
25
|
function isRecord(v) {
|
|
9
26
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
10
27
|
}
|
|
@@ -17,14 +34,27 @@ function draft(i, kind, title, body) {
|
|
|
17
34
|
throw new Error(`item ${i}: body required`);
|
|
18
35
|
return { kind: kind, title: title.trim().slice(0, TITLE_MAX), body: body.trim().slice(0, BODY_MAX) };
|
|
19
36
|
}
|
|
20
|
-
// `--item <kind> <title> <body>`, repeated
|
|
37
|
+
// `--item <kind> <title> <body>`, repeated, each followed by optional `--key <key>` and
|
|
38
|
+
// `--supersedes <id>[,<id>]` modifiers. Plain arguments: no JSON for a shell guard to object to.
|
|
21
39
|
export function parseItemArgs(args) {
|
|
22
40
|
const drafts = [];
|
|
23
41
|
for (let i = 0; i < args.length; i += 1) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
const arg = args[i];
|
|
43
|
+
const last = drafts.length - 1;
|
|
44
|
+
if (arg === "--item") {
|
|
45
|
+
drafts.push(draft(drafts.length, args[i + 1], args[i + 2], args[i + 3]));
|
|
46
|
+
i += 3;
|
|
47
|
+
}
|
|
48
|
+
else if (arg === "--key" && last >= 0) {
|
|
49
|
+
drafts[last] = withKey(drafts[last], last, args[i + 1]);
|
|
50
|
+
i += 1;
|
|
51
|
+
}
|
|
52
|
+
else if (arg === "--supersedes" && last >= 0) {
|
|
53
|
+
drafts[last] = withSupersedes(drafts[last], last, args[i + 1]);
|
|
54
|
+
i += 1;
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
throw new Error(`unexpected argument ${arg}`);
|
|
28
58
|
}
|
|
29
59
|
if (drafts.length === 0)
|
|
30
60
|
throw new Error("no items");
|
|
@@ -48,7 +78,12 @@ export function parseItems(raw) {
|
|
|
48
78
|
return parsed.map((v, i) => {
|
|
49
79
|
if (!isRecord(v))
|
|
50
80
|
throw new Error(`item ${i}: not an object`);
|
|
51
|
-
|
|
81
|
+
let d = draft(i, v.kind, v.title, v.body);
|
|
82
|
+
if (v.key !== undefined && v.key !== "")
|
|
83
|
+
d = withKey(d, i, v.key);
|
|
84
|
+
if (v.supersedes !== undefined)
|
|
85
|
+
d = withSupersedes(d, i, v.supersedes);
|
|
86
|
+
return d;
|
|
52
87
|
});
|
|
53
88
|
}
|
|
54
89
|
function clientFor(deps) {
|
|
@@ -60,21 +95,37 @@ function clientFor(deps) {
|
|
|
60
95
|
...(deps.fetch ? { fetch: deps.fetch } : {}),
|
|
61
96
|
});
|
|
62
97
|
}
|
|
98
|
+
// Each item gets its refs (paths named in its text that exist in the checkout), the paths edited
|
|
99
|
+
// since the branch's last checkpoint, and HEAD. Path-like tokens that resolve to nothing come
|
|
100
|
+
// back as `missing` so the writer can fix a typo. Supersedes prefixes are resolved against the
|
|
101
|
+
// branch's live items before the write, the way retract resolves them.
|
|
63
102
|
export async function putItems(drafts, deps) {
|
|
64
103
|
const now = deps.now ?? Date.now;
|
|
65
|
-
const
|
|
66
|
-
const out = await clientFor(deps).putItems(items);
|
|
67
|
-
deps.checkpoints.markCheckpoint(deps.repo.project, deps.repo.branch, now());
|
|
68
|
-
return out;
|
|
69
|
-
}
|
|
70
|
-
// The inject shows the first ID_PREFIX_CHARS of each id, so a retract takes a prefix and resolves it
|
|
71
|
-
// against the branch's live items; an ambiguous or unknown prefix is an error, never a guess.
|
|
72
|
-
export async function retractItems(prefixes, deps) {
|
|
73
|
-
if (prefixes.length === 0)
|
|
74
|
-
throw new Error("retract needs at least one item id");
|
|
104
|
+
const { project, branch, root } = deps.repo;
|
|
75
105
|
const client = clientFor(deps);
|
|
106
|
+
const since = deps.checkpoints.lastCheckpoint(project, branch);
|
|
107
|
+
const paths = deps.touched?.since(project, branch, since) ?? [];
|
|
108
|
+
const commit_sha = (deps.sha ?? headSha)(root);
|
|
109
|
+
const missing = new Set();
|
|
110
|
+
const items = [];
|
|
111
|
+
for (const d of drafts) {
|
|
112
|
+
const { supersedes: prefixes, ...rest } = d;
|
|
113
|
+
const found = extractRefs(`${d.title}\n${d.body}`, root, deps.exists);
|
|
114
|
+
for (const m of found.missing)
|
|
115
|
+
missing.add(m);
|
|
116
|
+
const supersedes = prefixes ? await resolveIds(prefixes, deps, client) : undefined;
|
|
117
|
+
items.push({ id: randomUUID(), ...rest, refs: found.refs, paths, ...(commit_sha ? { commit_sha } : {}), ...(supersedes ? { supersedes } : {}) });
|
|
118
|
+
}
|
|
119
|
+
const out = await client.putItems(items);
|
|
120
|
+
deps.checkpoints.markCheckpoint(project, branch, now());
|
|
121
|
+
deps.touched?.clear(project, branch);
|
|
122
|
+
return { ...out, missing: [...missing] };
|
|
123
|
+
}
|
|
124
|
+
// Resolves inject-style id prefixes against the branch's live items; ambiguous or unknown is an
|
|
125
|
+
// error, never a guess.
|
|
126
|
+
async function resolveIds(prefixes, deps, client) {
|
|
76
127
|
const { items } = await client.recall({ budget: ALL_ITEMS_BUDGET, fresh: true });
|
|
77
|
-
|
|
128
|
+
return prefixes.map((prefix) => {
|
|
78
129
|
const matches = items.filter((i) => i.id.startsWith(prefix)).map((i) => i.id);
|
|
79
130
|
if (matches.length === 0)
|
|
80
131
|
throw new Error(`no item on ${deps.repo.branch} starts with ${prefix}`);
|
|
@@ -82,8 +133,26 @@ export async function retractItems(prefixes, deps) {
|
|
|
82
133
|
throw new Error(`${prefix} matches ${matches.length} items; give more characters`);
|
|
83
134
|
return matches[0];
|
|
84
135
|
});
|
|
136
|
+
}
|
|
137
|
+
export async function confirmItems(prefixes, deps) {
|
|
138
|
+
if (prefixes.length === 0)
|
|
139
|
+
throw new Error("confirm needs at least one item id");
|
|
140
|
+
const client = clientFor(deps);
|
|
141
|
+
const confirmed = [];
|
|
142
|
+
for (const id of await resolveIds(prefixes, deps, client)) {
|
|
143
|
+
if ((await client.confirm(id)).found)
|
|
144
|
+
confirmed.push(id);
|
|
145
|
+
}
|
|
146
|
+
return { confirmed };
|
|
147
|
+
}
|
|
148
|
+
// The inject shows the first ID_PREFIX_CHARS of each id, so a retract takes a prefix and resolves it
|
|
149
|
+
// against the branch's live items; an ambiguous or unknown prefix is an error, never a guess.
|
|
150
|
+
export async function retractItems(prefixes, deps) {
|
|
151
|
+
if (prefixes.length === 0)
|
|
152
|
+
throw new Error("retract needs at least one item id");
|
|
153
|
+
const client = clientFor(deps);
|
|
85
154
|
const retracted = [];
|
|
86
|
-
for (const id of
|
|
155
|
+
for (const id of await resolveIds(prefixes, deps, client)) {
|
|
87
156
|
if ((await client.retract(id)).found)
|
|
88
157
|
retracted.push(id);
|
|
89
158
|
}
|
package/dist/opencode/connect.js
CHANGED
|
@@ -2,7 +2,7 @@ import { lstatSync, mkdirSync, rmSync, symlinkSync, writeFileSync } from "node:f
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
5
|
+
import { IMPORT_SKILL_NAME, importSkillMarkdown, skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
6
6
|
export function opencodeConfigDir(env = process.env, home = homedir()) {
|
|
7
7
|
return path.join(env.XDG_CONFIG_HOME || path.join(home, ".config"), "opencode");
|
|
8
8
|
}
|
|
@@ -28,6 +28,7 @@ export function connectOpencode(opts) {
|
|
|
28
28
|
if (opts.remove) {
|
|
29
29
|
rmSync(paths.plugin, { force: true });
|
|
30
30
|
rmSync(paths.skillDir, { recursive: true, force: true });
|
|
31
|
+
rmSync(path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME), { recursive: true, force: true });
|
|
31
32
|
return `removed meshpoint plugin ${paths.plugin} and ${paths.skillDir}`;
|
|
32
33
|
}
|
|
33
34
|
const target = opts.pluginFile ?? PLUGIN_FILE;
|
|
@@ -36,5 +37,8 @@ export function connectOpencode(opts) {
|
|
|
36
37
|
symlinkSync(target, paths.plugin);
|
|
37
38
|
mkdirSync(paths.skillDir, { recursive: true });
|
|
38
39
|
writeFileSync(path.join(paths.skillDir, "SKILL.md"), skillMarkdown({ allowedTools: false }));
|
|
40
|
+
const importDir = path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME);
|
|
41
|
+
mkdirSync(importDir, { recursive: true });
|
|
42
|
+
writeFileSync(path.join(importDir, "SKILL.md"), importSkillMarkdown({ allowedTools: false }));
|
|
39
43
|
return `installed meshpoint plugin ${paths.plugin} -> ${target} and ${paths.skillDir}/SKILL.md. Restart opencode to load it.`;
|
|
40
44
|
}
|
package/dist/opencode/hooks.js
CHANGED
|
@@ -159,13 +159,19 @@ export function createOpencodeHooks(deps) {
|
|
|
159
159
|
}
|
|
160
160
|
await enqueue(s, (tap) => tap.assistant(text, paths));
|
|
161
161
|
},
|
|
162
|
-
"tool.execute.after": async (input) => {
|
|
162
|
+
"tool.execute.after": async (input, output) => {
|
|
163
163
|
const s = tracked(input.sessionID);
|
|
164
164
|
if (!s || !WRITE_TOOLS.has(input.tool) || !isRecord(input.args))
|
|
165
165
|
return;
|
|
166
166
|
const file = input.args.filePath;
|
|
167
|
-
if (typeof file
|
|
168
|
-
|
|
167
|
+
if (typeof file !== "string" || !file)
|
|
168
|
+
return;
|
|
169
|
+
s.paths.push(file);
|
|
170
|
+
// The file notice rides on the tool result, the one place opencode lets a plugin speak mid-run.
|
|
171
|
+
await s.opened;
|
|
172
|
+
const notice = s.tap ? await s.tap.edit(file).catch(() => "") : "";
|
|
173
|
+
if (notice && output && typeof output.output === "string")
|
|
174
|
+
output.output = `${output.output}\n\n${notice}`;
|
|
169
175
|
},
|
|
170
176
|
"experimental.session.compacting": async (input) => {
|
|
171
177
|
const s = tracked(input.sessionID);
|
package/dist/pi/connect.js
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
5
|
+
import { IMPORT_SKILL_NAME, importSkillMarkdown, skillMarkdown, SKILL_NAME } from "../claude-code/skill.js";
|
|
6
6
|
// pi auto-loads every *.js in <agent-dir>/extensions, so no settings.json edit is needed.
|
|
7
7
|
export function piPaths(piDir, env = process.env, home = homedir()) {
|
|
8
8
|
const dir = piDir ?? env.PI_CODING_AGENT_DIR ?? path.join(home, ".pi", "agent");
|
|
@@ -37,6 +37,7 @@ export function connectPi(opts) {
|
|
|
37
37
|
if (opts.remove) {
|
|
38
38
|
rmSync(paths.extension, { force: true });
|
|
39
39
|
rmSync(paths.skillDir, { recursive: true, force: true });
|
|
40
|
+
rmSync(path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME), { recursive: true, force: true });
|
|
40
41
|
return `removed ${paths.extension} and ${paths.skillDir}`;
|
|
41
42
|
}
|
|
42
43
|
const source = opts.source ?? builtExtension();
|
|
@@ -46,5 +47,8 @@ export function connectPi(opts) {
|
|
|
46
47
|
writeFileSync(paths.extension, extensionStub(source));
|
|
47
48
|
mkdirSync(paths.skillDir, { recursive: true });
|
|
48
49
|
writeFileSync(path.join(paths.skillDir, "SKILL.md"), skillMarkdown({ allowedTools: false }));
|
|
50
|
+
const importDir = path.join(path.dirname(paths.skillDir), IMPORT_SKILL_NAME);
|
|
51
|
+
mkdirSync(importDir, { recursive: true });
|
|
52
|
+
writeFileSync(path.join(importDir, "SKILL.md"), importSkillMarkdown({ allowedTools: false }));
|
|
49
53
|
return `wrote ${paths.extension} (loads ${source}) and ${paths.skillDir}/SKILL.md. Restart pi (or /reload) to load it.`;
|
|
50
54
|
}
|
package/dist/pi/extension.js
CHANGED
|
@@ -79,6 +79,18 @@ export function meshpointExtension(pi, deps = {}) {
|
|
|
79
79
|
paths.push(path.resolve(ctx.cwd, p));
|
|
80
80
|
return undefined;
|
|
81
81
|
});
|
|
82
|
+
// The file notice rides on the edit's result: pi lets a handler patch `content`, and a patch
|
|
83
|
+
// without `structuredContent` would drop it, so both go back.
|
|
84
|
+
pi.on("tool_result", (event, ctx) => quiet(async () => {
|
|
85
|
+
const p = event.input.path;
|
|
86
|
+
if (!tap || !EDITING_TOOLS.has(event.toolName) || typeof p !== "string" || !p)
|
|
87
|
+
return undefined;
|
|
88
|
+
const notice = await tap.edit(path.resolve(ctx.cwd, p));
|
|
89
|
+
if (!notice)
|
|
90
|
+
return undefined;
|
|
91
|
+
const content = [...event.content, { type: "text", text: notice }];
|
|
92
|
+
return event.structuredContent === undefined ? { content } : { content, structuredContent: event.structuredContent };
|
|
93
|
+
}));
|
|
82
94
|
pi.on("agent_before_settle", (event) => quiet(async () => {
|
|
83
95
|
if (!tap)
|
|
84
96
|
return undefined;
|
package/dist/refs.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
// Refs are the repository paths an item depends on, read out of its own text. Only paths that
|
|
5
|
+
// exist in the checkout when the item is written count; the rest are reported so the agent can
|
|
6
|
+
// fix a typo. Verification later checks these same paths against other checkouts.
|
|
7
|
+
export const REFS_MAX = 50;
|
|
8
|
+
const KNOWN_EXTENSIONS = new Set([
|
|
9
|
+
"ts", "tsx", "js", "jsx", "mjs", "cjs", "mts", "cts", "json", "jsonc", "md", "mdx", "yml", "yaml", "toml", "ini", "cfg", "conf",
|
|
10
|
+
"py", "rs", "go", "java", "kt", "kts", "rb", "php", "c", "h", "cc", "cpp", "hpp", "cs", "swift", "m", "mm", "scala", "ex", "exs",
|
|
11
|
+
"sh", "bash", "zsh", "fish", "nix", "sql", "html", "css", "scss", "sass", "less", "vue", "svelte", "astro", "txt", "lock", "env",
|
|
12
|
+
"xml", "proto", "graphql", "gql", "tf", "hcl", "tfvars", "dockerfile", "mk", "cmake", "gradle", "properties", "csv", "svg", "wasm",
|
|
13
|
+
]);
|
|
14
|
+
const TOKEN_RE = /[A-Za-z0-9_@~./-]+/g;
|
|
15
|
+
const BACKTICK_RE = /`([^`\n]+)`/g;
|
|
16
|
+
const STRIP_LEAD = /^[([{'"<]+/;
|
|
17
|
+
const STRIP_TRAIL = /[.,;:!?)\]}'">]+$/;
|
|
18
|
+
const VERSION_RE = /^v?\d+(\.\d+)+$/;
|
|
19
|
+
const DOMAIN_RE = /\.(com|dev|io|org|net|ai|app|sh|co|us|uk|de|fr|cloud|edu|gov)$/i;
|
|
20
|
+
function clean(token) {
|
|
21
|
+
return token.replace(STRIP_LEAD, "").replace(STRIP_TRAIL, "");
|
|
22
|
+
}
|
|
23
|
+
// A token is path-like when it has a directory separator or a known file extension. URLs,
|
|
24
|
+
// flags, versions and bare domains are not.
|
|
25
|
+
export function looksLikePath(token) {
|
|
26
|
+
if (!token || token.length > 512)
|
|
27
|
+
return false;
|
|
28
|
+
if (token.includes("://") || token.startsWith("www.") || token.startsWith("-") || token.startsWith("@"))
|
|
29
|
+
return false;
|
|
30
|
+
if (VERSION_RE.test(token))
|
|
31
|
+
return false;
|
|
32
|
+
if (token.includes("/"))
|
|
33
|
+
return !token.split("/").some((seg) => seg === "..");
|
|
34
|
+
const dot = token.lastIndexOf(".");
|
|
35
|
+
if (dot <= 0)
|
|
36
|
+
return false;
|
|
37
|
+
if (DOMAIN_RE.test(token))
|
|
38
|
+
return false;
|
|
39
|
+
return KNOWN_EXTENSIONS.has(token.slice(dot + 1).toLowerCase());
|
|
40
|
+
}
|
|
41
|
+
// Resolves a token against the repo root; null when it leaves the root or does not exist.
|
|
42
|
+
function resolve(token, root, exists) {
|
|
43
|
+
const abs = path.isAbsolute(token) ? token : path.join(root, token.startsWith("~/") ? token.slice(2) : token);
|
|
44
|
+
const rel = path.relative(root, abs);
|
|
45
|
+
if (!rel || rel.startsWith("..") || path.isAbsolute(rel))
|
|
46
|
+
return null;
|
|
47
|
+
return exists(abs) ? rel.split(path.sep).join("/") : null;
|
|
48
|
+
}
|
|
49
|
+
export function extractRefs(text, root, exists = existsSync) {
|
|
50
|
+
const refs = new Set();
|
|
51
|
+
const missing = new Set();
|
|
52
|
+
const consider = (raw, strict) => {
|
|
53
|
+
const token = clean(raw);
|
|
54
|
+
if (!token)
|
|
55
|
+
return;
|
|
56
|
+
const pathLike = looksLikePath(token);
|
|
57
|
+
// Backticked tokens may be bare file names (Makefile); they count only when they exist.
|
|
58
|
+
if (!pathLike && strict)
|
|
59
|
+
return;
|
|
60
|
+
const rel = resolve(token, root, exists);
|
|
61
|
+
if (rel)
|
|
62
|
+
refs.add(rel);
|
|
63
|
+
else if (pathLike)
|
|
64
|
+
missing.add(token);
|
|
65
|
+
};
|
|
66
|
+
for (const m of text.matchAll(BACKTICK_RE)) {
|
|
67
|
+
const span = m[1] ?? "";
|
|
68
|
+
if (!/\s/.test(span.trim()))
|
|
69
|
+
consider(span.trim(), false);
|
|
70
|
+
else
|
|
71
|
+
for (const t of span.match(TOKEN_RE) ?? [])
|
|
72
|
+
consider(t, true);
|
|
73
|
+
}
|
|
74
|
+
for (const t of text.replace(BACKTICK_RE, " ").match(TOKEN_RE) ?? [])
|
|
75
|
+
consider(t, true);
|
|
76
|
+
return { refs: [...refs].slice(0, REFS_MAX), missing: [...missing].slice(0, REFS_MAX) };
|
|
77
|
+
}
|
|
78
|
+
export function headSha(root) {
|
|
79
|
+
try {
|
|
80
|
+
const out = execFileSync("git", ["rev-parse", "HEAD"], { cwd: root, stdio: ["ignore", "pipe", "ignore"], timeout: 2000 }).toString().trim();
|
|
81
|
+
return /^[0-9a-f]{40}$/.test(out) ? out : "";
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
}
|
package/dist/runtime.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Checkpoints } from "./checkpoints.js";
|
|
2
2
|
import { loadConfig, repoContext, spoolDir, stateDir } from "./config.js";
|
|
3
|
+
import { SessionCache } from "./context.js";
|
|
3
4
|
import { freshConfig } from "./control.js";
|
|
4
5
|
import { Spool } from "./spool.js";
|
|
5
|
-
import { Tap } from "./tap.js";
|
|
6
|
+
import { localChecks, Tap } from "./tap.js";
|
|
7
|
+
import { Touched } from "./touched.js";
|
|
6
8
|
// A Tap for one harness session, wired to the stored login and the on-disk spool. Null when the
|
|
7
9
|
// machine is not logged in or the directory is not a repo with an origin remote. In-process
|
|
8
10
|
// adapters (pi, opencode, openclaw) call this once per harness session.
|
|
@@ -21,6 +23,9 @@ export async function openTap(session, cwd) {
|
|
|
21
23
|
session,
|
|
22
24
|
spool: new Spool(spoolDir()),
|
|
23
25
|
checkpoints: new Checkpoints(stateDir()),
|
|
26
|
+
touched: new Touched(stateDir()),
|
|
27
|
+
cache: new SessionCache(stateDir()),
|
|
28
|
+
local: localChecks(repo.root),
|
|
24
29
|
refresh: () => freshConfig(config, { force: true }).catch(() => null),
|
|
25
30
|
});
|
|
26
31
|
}
|
package/dist/tap.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { MeshpointClient, MeshpointError, redact } from "@meshpoint/sdk";
|
|
2
|
+
import { isExpired, MeshpointClient, MeshpointError, redact } from "@meshpoint/sdk";
|
|
3
3
|
import { SKILL_NAME } from "./claude-code/skill.js";
|
|
4
|
+
import { instructionFiles, itemsForFile, renderEditNotice, renderImportNudge } from "./context.js";
|
|
4
5
|
import { ID_PREFIX_CHARS } from "./items.js";
|
|
6
|
+
import { gitRunner, sightings, verifyItems } from "./verify.js";
|
|
7
|
+
export function localChecks(root) {
|
|
8
|
+
const git = gitRunner(root);
|
|
9
|
+
return {
|
|
10
|
+
verify: (items) => verifyItems(items, root, { git }),
|
|
11
|
+
instructionFiles: () => instructionFiles(git),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
5
14
|
const DEFAULT_PRESENCE_WAIT_MS = 1500;
|
|
15
|
+
// The inject is cut to this many tokens of items; the request asks for everything so the
|
|
16
|
+
// verification pass and the edit hook see the whole branch.
|
|
17
|
+
export const INJECT_BUDGET_TOKENS = 3000;
|
|
18
|
+
const ALL_ITEMS_BUDGET = 100_000;
|
|
19
|
+
// Longest the session-start hook waits for the platform to take the sightings.
|
|
20
|
+
const VERIFY_SEND_WAIT_MS = 800;
|
|
21
|
+
// Longest an edit waits for presence from the origin before the local items go out alone.
|
|
22
|
+
const EDIT_WAIT_MS = 1000;
|
|
23
|
+
const STALE_LIST_MAX = 20;
|
|
6
24
|
// Harnesses that feed the nudge back as a user prompt (Cursor) match on this to keep it out of the capture.
|
|
7
25
|
export const NUDGE_PREFIX = "Meshpoint checkpoint due";
|
|
8
26
|
// One harness session's side of the mesh, independent of how the harness delivers events: recall
|
|
@@ -23,24 +41,68 @@ export class Tap {
|
|
|
23
41
|
async start() {
|
|
24
42
|
try {
|
|
25
43
|
const { recall, presence } = await this.client(this.repo.branch)
|
|
26
|
-
.sessionStart()
|
|
44
|
+
.sessionStart({ budget: ALL_ITEMS_BUDGET })
|
|
27
45
|
.catch(async (err) => {
|
|
28
46
|
if (!is401(err) || !(await this.reauth()))
|
|
29
47
|
throw err;
|
|
30
|
-
return this.client(this.repo.branch).sessionStart();
|
|
48
|
+
return this.client(this.repo.branch).sessionStart({ budget: ALL_ITEMS_BUDGET });
|
|
49
|
+
});
|
|
50
|
+
const verdicts = this.deps.local ? this.deps.local.verify(recall.items) : new Map();
|
|
51
|
+
this.deps.cache?.saveRecall(this.deps.session, {
|
|
52
|
+
project: this.repo.project,
|
|
53
|
+
branch: this.repo.branch,
|
|
54
|
+
items: recall.items,
|
|
55
|
+
verdicts: Object.fromEntries(verdicts),
|
|
56
|
+
at: this.now(),
|
|
31
57
|
});
|
|
58
|
+
const report = sightings(verdicts);
|
|
59
|
+
const sent = report.length > 0 ? this.client(this.repo.branch).verify(report).catch(() => undefined) : Promise.resolve(undefined);
|
|
32
60
|
const teammates = await Promise.race([
|
|
33
61
|
presence,
|
|
34
62
|
new Promise((r) => setTimeout(() => r([]), this.deps.presenceWaitMs ?? DEFAULT_PRESENCE_WAIT_MS)),
|
|
35
63
|
]);
|
|
36
|
-
|
|
64
|
+
let text = renderInject(this.repo, recall, teammates, this.now(), verdicts);
|
|
65
|
+
const nudge = this.importNudge(recall);
|
|
66
|
+
if (nudge)
|
|
67
|
+
text = `${text || `# Meshpoint: ${this.repo.project} @ ${this.repo.branch}`}\n\n${nudge}`;
|
|
37
68
|
await this.flush(false);
|
|
69
|
+
await Promise.race([sent, new Promise((r) => setTimeout(r, VERIFY_SEND_WAIT_MS))]);
|
|
38
70
|
return text;
|
|
39
71
|
}
|
|
40
72
|
catch {
|
|
41
73
|
return "";
|
|
42
74
|
}
|
|
43
75
|
}
|
|
76
|
+
// A branch with no memory and committed instruction files gets one invitation to import them.
|
|
77
|
+
importNudge(recall) {
|
|
78
|
+
if (!this.deps.local || !this.deps.cache || recall.items.length > 0 || recall.checkpoint)
|
|
79
|
+
return "";
|
|
80
|
+
const files = this.deps.local.instructionFiles();
|
|
81
|
+
if (files.length === 0 || !this.deps.cache.firstImportNudge(this.repo.project, this.repo.branch))
|
|
82
|
+
return "";
|
|
83
|
+
return renderImportNudge(files);
|
|
84
|
+
}
|
|
85
|
+
// The notice for one file about to be edited (or just edited), or "". Items come from the
|
|
86
|
+
// session-start cache with the local verdicts; presence comes from the origin, briefly.
|
|
87
|
+
async edit(filePath) {
|
|
88
|
+
try {
|
|
89
|
+
const rel = this.relative(filePath);
|
|
90
|
+
if (!rel)
|
|
91
|
+
return "";
|
|
92
|
+
if (this.deps.cache && !this.deps.cache.firstEdit(this.deps.session, rel))
|
|
93
|
+
return "";
|
|
94
|
+
const cached = this.deps.cache?.loadRecall(this.deps.session);
|
|
95
|
+
const ctx = await Promise.race([
|
|
96
|
+
this.client(this.repo.branch).context(rel).catch(() => null),
|
|
97
|
+
new Promise((r) => setTimeout(() => r(null), EDIT_WAIT_MS)),
|
|
98
|
+
]);
|
|
99
|
+
const items = cached ? itemsForFile(cached.items, cached.verdicts, rel) : (ctx?.items ?? []);
|
|
100
|
+
return renderEditNotice(rel, items, ctx?.presence ?? [], this.now());
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return "";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
44
106
|
async user(prompt) {
|
|
45
107
|
if (prompt)
|
|
46
108
|
this.spoolTurn(`[user] ${prompt}`);
|
|
@@ -49,6 +111,7 @@ export class Tap {
|
|
|
49
111
|
async assistant(text, paths = []) {
|
|
50
112
|
if (text || paths.length > 0)
|
|
51
113
|
this.spoolTurn(`[assistant] ${text}`, paths);
|
|
114
|
+
this.deps.touched?.append(this.repo.project, this.repo.branch, this.relativeAll(paths), this.now());
|
|
52
115
|
await this.flush(false);
|
|
53
116
|
}
|
|
54
117
|
// The nudge to show the agent when a checkpoint is due, else null. Recording the nudge keeps an
|
|
@@ -101,10 +164,20 @@ export class Tap {
|
|
|
101
164
|
this.config = next;
|
|
102
165
|
return true;
|
|
103
166
|
}
|
|
167
|
+
// Repo-relative with forward slashes, or null for a path outside the repository.
|
|
168
|
+
relative(p) {
|
|
169
|
+
const rel = path.isAbsolute(p) ? path.relative(this.repo.root, p) : path.normalize(p);
|
|
170
|
+
if (!rel || rel.startsWith("..") || path.isAbsolute(rel))
|
|
171
|
+
return null;
|
|
172
|
+
return rel.split(path.sep).join("/");
|
|
173
|
+
}
|
|
174
|
+
relativeAll(paths) {
|
|
175
|
+
return [...new Set(paths.map((p) => this.relative(p)).filter((p) => p !== null))];
|
|
176
|
+
}
|
|
104
177
|
// Credentials are masked before the turn touches the spool file, so nothing on disk or on the
|
|
105
178
|
// wire holds them. The SDK masks again on send for callers that bypass the spool.
|
|
106
179
|
spoolTurn(body, paths = []) {
|
|
107
|
-
const rel =
|
|
180
|
+
const rel = this.relativeAll(paths);
|
|
108
181
|
const turn = { branch: this.repo.branch, body: redact(body), at: this.now(), ...(rel.length ? { paths: rel } : {}) };
|
|
109
182
|
this.deps.spool.append(this.deps.session, turn);
|
|
110
183
|
}
|
|
@@ -146,7 +219,14 @@ function age(ms) {
|
|
|
146
219
|
const h = Math.floor(m / 60);
|
|
147
220
|
return h < 48 ? `${h}h ago` : `${Math.floor(h / 24)}d ago`;
|
|
148
221
|
}
|
|
149
|
-
|
|
222
|
+
function estimateTokens(item) {
|
|
223
|
+
return Math.ceil((item.title.length + item.body.length) / 4) + 8;
|
|
224
|
+
}
|
|
225
|
+
// Items arrive ranked from the platform; the budget cut happens here. Stale items (a referenced
|
|
226
|
+
// file is gone in this checkout) leave the list for a short section of their own; suspect items
|
|
227
|
+
// (a referenced file changed since) stay, marked. Items the platform already marks suspect from
|
|
228
|
+
// other checkouts carry the mark too.
|
|
229
|
+
export function renderInject(repo, recall, presence, now, verdicts = new Map()) {
|
|
150
230
|
if (recall.items.length === 0 && !recall.checkpoint && presence.length === 0)
|
|
151
231
|
return "";
|
|
152
232
|
const lines = [`# Meshpoint: ${repo.project} @ ${repo.branch}`];
|
|
@@ -158,10 +238,39 @@ export function renderInject(repo, recall, presence, now) {
|
|
|
158
238
|
if (recall.checkpoint) {
|
|
159
239
|
lines.push("", `## Last checkpoint (${age(now - recall.checkpoint.created_at)})`, recall.checkpoint.body);
|
|
160
240
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
241
|
+
// A blob served from the edge may predate an item's expiry or replacement; apply both rules here too.
|
|
242
|
+
const current = recall.items.filter((i) => !i.retracted && i.state !== "dropped" && i.state !== "superseded" && !isExpired(i, now));
|
|
243
|
+
const stale = current.filter((i) => verdicts.get(i.id) === "stale");
|
|
244
|
+
const live = [];
|
|
245
|
+
let used = 0;
|
|
246
|
+
for (const i of current) {
|
|
247
|
+
if (verdicts.get(i.id) === "stale")
|
|
248
|
+
continue;
|
|
249
|
+
const t = estimateTokens(i);
|
|
250
|
+
if (used + t > INJECT_BUDGET_TOKENS)
|
|
251
|
+
break;
|
|
252
|
+
live.push(i);
|
|
253
|
+
used += t;
|
|
254
|
+
}
|
|
255
|
+
if (live.length > 0) {
|
|
256
|
+
const marked = live.some((i) => isSuspect(i, verdicts));
|
|
257
|
+
lines.push("", `## Team knowledge (${live.length}; first column is the item id${marked ? ", ? means a referenced file changed since" : ""})`);
|
|
258
|
+
for (const i of live)
|
|
259
|
+
lines.push(`- ${i.id.slice(0, ID_PREFIX_CHARS)}${isSuspect(i, verdicts) ? "?" : ""} [${i.kind}] ${i.title}: ${i.body}`);
|
|
260
|
+
}
|
|
261
|
+
if (stale.length > 0) {
|
|
262
|
+
lines.push("", "## Possibly stale (a referenced file is gone; verify, then retract or rewrite)");
|
|
263
|
+
for (const i of stale.slice(0, STALE_LIST_MAX))
|
|
264
|
+
lines.push(`- ${i.id.slice(0, ID_PREFIX_CHARS)} [${i.kind}] ${i.title}`);
|
|
165
265
|
}
|
|
166
266
|
return lines.join("\n");
|
|
167
267
|
}
|
|
268
|
+
// A local verdict wins; without one (or when the checkout could not judge) the platform's state stands.
|
|
269
|
+
function isSuspect(item, verdicts) {
|
|
270
|
+
const local = verdicts.get(item.id);
|
|
271
|
+
if (local === "verified")
|
|
272
|
+
return false;
|
|
273
|
+
if (local === "suspect")
|
|
274
|
+
return true;
|
|
275
|
+
return (local === undefined || local === "skipped") && item.state === "suspect";
|
|
276
|
+
}
|
package/dist/touched.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
// Files the agent edited on a project branch, with the time, so a checkpoint can attach the
|
|
4
|
+
// paths worked on since the previous one. Hooks run as separate processes and `items put` runs
|
|
5
|
+
// as the agent's own command, so this lives on disk per project and branch, not per session.
|
|
6
|
+
export const TOUCHED_CAP = 500;
|
|
7
|
+
export class Touched {
|
|
8
|
+
dir;
|
|
9
|
+
constructor(dir) {
|
|
10
|
+
this.dir = dir;
|
|
11
|
+
}
|
|
12
|
+
file(project, branch) {
|
|
13
|
+
return path.join(this.dir, "touched", `${`${project}--${branch}`.replace(/[^A-Za-z0-9._-]/g, "_")}.json`);
|
|
14
|
+
}
|
|
15
|
+
read(file) {
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
18
|
+
return Array.isArray(parsed) ? parsed.filter((e) => typeof e?.path === "string" && typeof e?.at === "number") : [];
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// One entry per path, newest time wins; the oldest entries fall off past the cap.
|
|
25
|
+
append(project, branch, paths, at) {
|
|
26
|
+
if (paths.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
const file = this.file(project, branch);
|
|
29
|
+
const byPath = new Map(this.read(file).map((e) => [e.path, e.at]));
|
|
30
|
+
for (const p of paths)
|
|
31
|
+
byPath.set(p, Math.max(at, byPath.get(p) ?? 0));
|
|
32
|
+
const entries = [...byPath].map(([p, t]) => ({ path: p, at: t })).sort((a, b) => a.at - b.at).slice(-TOUCHED_CAP);
|
|
33
|
+
mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
34
|
+
writeFileSync(file, `${JSON.stringify(entries)}\n`, { mode: 0o600 });
|
|
35
|
+
}
|
|
36
|
+
since(project, branch, at) {
|
|
37
|
+
return this.read(this.file(project, branch))
|
|
38
|
+
.filter((e) => e.at > at)
|
|
39
|
+
.map((e) => e.path);
|
|
40
|
+
}
|
|
41
|
+
clear(project, branch) {
|
|
42
|
+
rmSync(this.file(project, branch), { force: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/verify.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export const VERIFY_BUDGET_MS = 2000;
|
|
5
|
+
export function gitRunner(root) {
|
|
6
|
+
return (args) => {
|
|
7
|
+
try {
|
|
8
|
+
return execFileSync("git", args, { cwd: root, stdio: ["ignore", "pipe", "ignore"], timeout: 2000 }).toString();
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function verifyItems(items, root, opts = {}) {
|
|
16
|
+
const git = opts.git ?? gitRunner(root);
|
|
17
|
+
const exists = opts.exists ?? existsSync;
|
|
18
|
+
const now = opts.now ?? Date.now;
|
|
19
|
+
const started = now();
|
|
20
|
+
const out = new Map();
|
|
21
|
+
let headKnown = null;
|
|
22
|
+
for (const item of items) {
|
|
23
|
+
if (item.retracted || item.refs.length === 0)
|
|
24
|
+
continue;
|
|
25
|
+
if (now() - started > (opts.budgetMs ?? VERIFY_BUDGET_MS))
|
|
26
|
+
break;
|
|
27
|
+
if (item.commit_sha) {
|
|
28
|
+
if (headKnown === null)
|
|
29
|
+
headKnown = git(["rev-parse", "HEAD"]) !== null;
|
|
30
|
+
if (headKnown && git(["merge-base", "--is-ancestor", item.commit_sha, "HEAD"]) === null) {
|
|
31
|
+
out.set(item.id, "skipped");
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (item.refs.some((ref) => !exists(path.join(root, ref)))) {
|
|
36
|
+
out.set(item.id, "stale");
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const since = new Date(item.created_at).toISOString();
|
|
40
|
+
const log = git(["log", "-1", "--format=%H", `--since=${since}`, "--", ...item.refs]);
|
|
41
|
+
out.set(item.id, log === null || log.trim() === "" ? "verified" : "suspect");
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
// Only real verdicts travel to the platform.
|
|
46
|
+
export function sightings(verdicts) {
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const [id, result] of verdicts)
|
|
49
|
+
if (result !== "skipped")
|
|
50
|
+
out.push({ id, result });
|
|
51
|
+
return out;
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshpoint/cli",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Meshpoint CLI and harness adapters",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Meshpoint CLI and harness adapters: shared agent memory for developer teams",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"meshpoint",
|
|
7
7
|
"coding-agents",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"prepublishOnly": "npm run check && npm run build"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@meshpoint/sdk": "^1.
|
|
41
|
+
"@meshpoint/sdk": "^1.2.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^22.0.0",
|