open-memex 0.4.0-alpha.4 → 0.4.0-alpha.5
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/AGENTS.md +1 -1
- package/README.md +9 -7
- package/README.zh-CN.md +6 -4
- package/dist/cli.js +10 -10
- package/dist/init.js +11 -9
- package/dist/mcp.js +11 -5
- package/dist/submit.js +23 -15
- package/dist/tools/ops.js +10 -8
- package/docs/USER-GUIDE.md +10 -8
- package/docs/USER-GUIDE.zh-CN.md +7 -6
- package/docs/V2-DESIGN.md +12 -0
- package/package.json +1 -1
- package/src/cli.ts +10 -10
- package/src/init.ts +11 -9
- package/src/mcp.ts +11 -5
- package/src/submit.ts +30 -17
- package/src/tools/ops.ts +11 -8
package/AGENTS.md
CHANGED
|
@@ -31,7 +31,7 @@ npm run typecheck # tsc --noEmit — the only
|
|
|
31
31
|
npm run cli -- where | list | search "q" | add ... | forget <id> | reindex
|
|
32
32
|
npm run cli -- <command> --help # per-command help (AI assistants discover flags this way)
|
|
33
33
|
npm run cli -- sync-status # last sync time/kind + outbox drafts + repo review states + uncommitted files
|
|
34
|
-
npm run cli -- submit <id...> [--
|
|
34
|
+
npm run cli -- submit <id...> [--branch <name>] [--base <branch>] # drafts → .ai/open-memex/ (current branch + local commit; never auto-branches)
|
|
35
35
|
npm run cli -- propose <id...> --to project [--local-approve] # copy personal → project outbox (batch OK)
|
|
36
36
|
npm run cli -- promote <id> [--reject] [--resubmit] [--note "..."] # proposed → approved → published (audit trail appended)
|
|
37
37
|
npm run cli -- pr-status [--apply] # map branch PR's GitHub state onto review_state (report; apply = local only)
|
package/README.md
CHANGED
|
@@ -295,14 +295,16 @@ open-memex sync-status
|
|
|
295
295
|
# (draft / proposed / approved / published / rejected),
|
|
296
296
|
# and any uncommitted repo memory files.
|
|
297
297
|
|
|
298
|
-
open-memex submit <id...> [--
|
|
298
|
+
open-memex submit <id...> [--branch <name>] [--base <branch>]
|
|
299
299
|
# move your named drafts into .ai/open-memex/ as "proposed":
|
|
300
|
-
#
|
|
301
|
-
#
|
|
302
|
-
# (
|
|
303
|
-
#
|
|
304
|
-
#
|
|
305
|
-
#
|
|
300
|
+
# copies, flips review_state, local git commit ON THE CURRENT BRANCH.
|
|
301
|
+
# Never creates a branch on its own — branch creation is your call
|
|
302
|
+
# (or the agent's, only with your explicit approval for the full chain).
|
|
303
|
+
# All-or-nothing; conflicts (same id, different content) abort cleanly.
|
|
304
|
+
# Prints the push + gh pr commands; an agent holding your Yes carries
|
|
305
|
+
# through push/PR itself. --branch <name> creates the branch first
|
|
306
|
+
# (agent full-chain path). Default PR base is the current branch; --base
|
|
307
|
+
# redirects to main or your integration branch.
|
|
306
308
|
|
|
307
309
|
open-memex pr-status [--apply]
|
|
308
310
|
# read the branch's GitHub PR and map its state onto each in-repo memory:
|
package/README.zh-CN.md
CHANGED
|
@@ -291,11 +291,13 @@ open-memex sync-status
|
|
|
291
291
|
# (draft / proposed / approved / published / rejected),
|
|
292
292
|
# 以及 repo 里还没 commit 的记忆文件。
|
|
293
293
|
|
|
294
|
-
open-memex submit <id...> [--
|
|
294
|
+
open-memex submit <id...> [--branch <name>] [--base <branch>]
|
|
295
295
|
# 把你点名的草稿移入 .ai/open-memex/,状态变为 proposed:
|
|
296
|
-
#
|
|
297
|
-
#
|
|
298
|
-
#
|
|
296
|
+
# 复制、改 review_state、在当前分支本地 git commit。
|
|
297
|
+
# 永不自动建分支——建分支是你说了算(或 Agent 拿到你明确批准走全链时)。
|
|
298
|
+
# 全有或全无;冲突(同 id 不同内容)干净回滚。
|
|
299
|
+
# 打印 push + gh pr 命令;Agent 拿到你的 Yes 后会自己走完 push/PR。
|
|
300
|
+
# --branch <name> 先建分支再提交(Agent 全链路径)。
|
|
299
301
|
# PR 默认 base 是当前分支;--base 可改到 main 或集成支。
|
|
300
302
|
|
|
301
303
|
open-memex pr-status [--apply]
|
package/dist/cli.js
CHANGED
|
@@ -106,17 +106,17 @@ and what triggered it, drafts waiting in the outbox (appdata), memories in the
|
|
|
106
106
|
repo awaiting review or published, and repo files not yet committed.
|
|
107
107
|
|
|
108
108
|
Usage: open-memex sync-status`,
|
|
109
|
-
submit: `Move outbox drafts into
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
explicit approval and are never run automatically.
|
|
109
|
+
submit: `Move outbox drafts into the repo for review: copies the drafts into
|
|
110
|
+
the repo memory dir as proposed (a local-approved copy keeps its approval),
|
|
111
|
+
commits locally on the CURRENT branch, and moves the outbox originals out.
|
|
112
|
+
Never creates a branch on its own — branch creation is your call.
|
|
114
113
|
|
|
115
|
-
Usage: open-memex submit <id...> [--
|
|
114
|
+
Usage: open-memex submit <id...> [--branch <name>] [--base <branch>]
|
|
116
115
|
|
|
117
116
|
Flags:
|
|
118
|
-
--
|
|
119
|
-
|
|
117
|
+
--branch create this branch and submit onto it (only with your explicit
|
|
118
|
+
approval for the full chain); default: stay on current branch
|
|
119
|
+
--base PR base override (default: the branch you're on)
|
|
120
120
|
|
|
121
121
|
Example:
|
|
122
122
|
open-memex submit 01ABC 01DEF`,
|
|
@@ -195,7 +195,7 @@ Usage:
|
|
|
195
195
|
open-memex promote <id> [--reject] [--resubmit] [--note "..."] [--by NAME]
|
|
196
196
|
open-memex resolve [id-or-path]
|
|
197
197
|
open-memex sync-status
|
|
198
|
-
open-memex submit <id...> [--
|
|
198
|
+
open-memex submit <id...> [--branch <name>] [--base <branch>]
|
|
199
199
|
open-memex pr-status [--apply]
|
|
200
200
|
open-memex reindex
|
|
201
201
|
open-memex scopes
|
|
@@ -811,7 +811,7 @@ async function main() {
|
|
|
811
811
|
usage();
|
|
812
812
|
syncScope(project.key, "submit");
|
|
813
813
|
try {
|
|
814
|
-
const r = submitMemories(ids, {
|
|
814
|
+
const r = submitMemories(ids, { branch: flags.branch, base: flags.base });
|
|
815
815
|
for (const s of r.submitted) {
|
|
816
816
|
console.log(`submitted ${s.id} → ${path.relative(process.cwd(), s.filePath)} [${s.reviewState}]`);
|
|
817
817
|
}
|
package/dist/init.js
CHANGED
|
@@ -59,20 +59,22 @@ You have a local memory MCP server (\`open-memex\`) with eleven tools:
|
|
|
59
59
|
Project memories you save land in a local outbox first — they are NOT in git yet.
|
|
60
60
|
Syncing them into the repo for review is an explicit, user-approved step:
|
|
61
61
|
|
|
62
|
-
- At session start,
|
|
62
|
+
- At session start, when you finish a meaningful chunk of work, after the user
|
|
63
|
+
commits (git commit), and after any memory_* action completes, call
|
|
63
64
|
\`memory_status\`. If the outbox has drafts, summarize them (one line each) and ask
|
|
64
65
|
the user which ones to sync. Sync NOTHING the user did not name.
|
|
65
66
|
- When the user says "sync memory" (or "同步记忆"), treat it as a request to run
|
|
66
67
|
the sync flow above: call \`memory_status\`, summarize the outbox drafts, and ask
|
|
67
68
|
which ones to sync.
|
|
68
|
-
- When the user approves,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
- When the user approves, call \`memory_submit\` with the approved ids. It copies
|
|
70
|
+
the drafts into the repo as \`proposed\`, commits locally on the CURRENT branch,
|
|
71
|
+
and prints the push + PR commands. It NEVER creates a branch on its own.
|
|
72
|
+
- After the submit, ask ONE follow-up: "want me to create a branch + push +
|
|
73
|
+
open the PR, or will you handle it yourself?" A "yes, you do it" answer covers
|
|
74
|
+
the whole chain — branch creation, push, PR creation — do NOT re-ask at each
|
|
75
|
+
step. If the user says they will do it themselves, hand them the printed
|
|
76
|
+
push/PR commands and do nothing. NEVER create branches, push, or open PRs
|
|
77
|
+
without their explicit approval.
|
|
76
78
|
- Base branch for the memory PR defaults to the branch you are on; the user may
|
|
77
79
|
redirect it to the integration branch (main) for branch-independent knowledge.
|
|
78
80
|
- If anything conflicts (same id with different content, push rejected), STOP and
|
package/dist/mcp.js
CHANGED
|
@@ -37,13 +37,19 @@ const SERVER_INSTRUCTIONS = `You are connected to an open-memex local memory MCP
|
|
|
37
37
|
(eleven memory_* tools: add, search, list, supersede, forget, status, submit,
|
|
38
38
|
propose, promote, resolve, pr_status).
|
|
39
39
|
|
|
40
|
-
- At the START of this session,
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
- At the START of this session, when you finish a meaningful chunk of work,
|
|
41
|
+
after the user commits (git commit), and after any memory_* action completes,
|
|
42
|
+
call memory_status. If the project outbox has drafts waiting for review,
|
|
43
|
+
summarize them (one line each) and ask the user which ones to sync into the
|
|
44
|
+
repo. Sync NOTHING the user did not name.
|
|
43
45
|
- When the user says "sync memory" (or "同步记忆"), treat it as a request to run
|
|
44
46
|
the sync flow: call memory_status, summarize the outbox drafts, and ask which
|
|
45
|
-
ones to sync.
|
|
46
|
-
|
|
47
|
+
ones to sync. ALWAYS use the memory_status tool for this — never browse the
|
|
48
|
+
appdata directory directly.
|
|
49
|
+
- After memory_submit, ask ONE follow-up: "want me to create a branch + push +
|
|
50
|
+
open the PR, or will you handle it yourself?" NEVER create branches, push, or
|
|
51
|
+
open PRs without the user's explicit approval. A "yes, you do it" covers the
|
|
52
|
+
whole chain — do NOT re-ask at each step.
|
|
47
53
|
- BE PROACTIVE: when the user shares something worth remembering across sessions
|
|
48
54
|
(a decision, a preference, a project convention, a fix and its cause), call
|
|
49
55
|
memory_add without being asked. Keep each memory to one self-contained statement.
|
package/dist/submit.js
CHANGED
|
@@ -150,7 +150,8 @@ export function submitMemories(ids, opts = {}) {
|
|
|
150
150
|
if (ids.length === 0)
|
|
151
151
|
fail("submit needs at least one memory id");
|
|
152
152
|
const root = projectRoot();
|
|
153
|
-
// submit needs a git repo — the
|
|
153
|
+
// submit needs a git repo — the memories land in .ai/open-memex/ and are
|
|
154
|
+
// committed locally. Branch creation is never automatic (D36).
|
|
154
155
|
git(root, ["rev-parse", "--git-dir"]);
|
|
155
156
|
const scope = resolveProjectScope(root);
|
|
156
157
|
const cfg = loadConfig();
|
|
@@ -197,26 +198,26 @@ export function submitMemories(ids, opts = {}) {
|
|
|
197
198
|
fail(`submit aborted — nothing was written:\n ${problems.join("\n ")}`);
|
|
198
199
|
}
|
|
199
200
|
// 2. Resolve the target branch.
|
|
201
|
+
// D36: submit never creates a branch on its own — it works on the branch
|
|
202
|
+
// you're already on. Pass --branch <name> (explicitly) only when the user
|
|
203
|
+
// approved the full chain (branch + push + PR).
|
|
200
204
|
const startBranch = git(root, ["branch", "--show-current"]) || git(root, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
201
|
-
let branch;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
branch = opts.onto;
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
const stamp = new Date().toISOString().replace(/[-:]/g, "").slice(0, 15);
|
|
210
|
-
branch = `mem/sync-${stamp}`;
|
|
205
|
+
let branch = startBranch;
|
|
206
|
+
let createdBranch = false;
|
|
207
|
+
if (opts.branch) {
|
|
208
|
+
branch = opts.branch;
|
|
211
209
|
let n = 0;
|
|
210
|
+
let candidate = branch;
|
|
212
211
|
while (true) {
|
|
213
|
-
const exists = git(root, ["branch", "--list",
|
|
212
|
+
const exists = git(root, ["branch", "--list", candidate]);
|
|
214
213
|
if (!exists)
|
|
215
214
|
break;
|
|
216
215
|
n++;
|
|
217
|
-
|
|
216
|
+
candidate = `${branch}-${n}`;
|
|
218
217
|
}
|
|
218
|
+
branch = candidate;
|
|
219
219
|
git(root, ["checkout", "-b", branch]);
|
|
220
|
+
createdBranch = true;
|
|
220
221
|
}
|
|
221
222
|
const base = opts.base ?? startBranch;
|
|
222
223
|
const author = currentAuthor();
|
|
@@ -278,7 +279,7 @@ export function submitMemories(ids, opts = {}) {
|
|
|
278
279
|
}
|
|
279
280
|
// If we created the branch and never committed, remove it too — an
|
|
280
281
|
// aborted submit leaves no trace.
|
|
281
|
-
if (
|
|
282
|
+
if (createdBranch) {
|
|
282
283
|
try {
|
|
283
284
|
git(root, ["checkout", "--quiet", startBranch]);
|
|
284
285
|
git(root, ["branch", "--quiet", "-D", branch]);
|
|
@@ -327,13 +328,20 @@ export function submitMemories(ids, opts = {}) {
|
|
|
327
328
|
removed: 0,
|
|
328
329
|
scanned: validated.length,
|
|
329
330
|
});
|
|
331
|
+
// D36: no auto-branch — the commit sits on the branch you were already on.
|
|
332
|
+
// Next steps are printed, not run. For a separate memory PR, create a branch
|
|
333
|
+
// first (the commit comes along), then push + open the PR.
|
|
334
|
+
const branchCmd = `git checkout -b mem/sync-YYYYMMDD`;
|
|
330
335
|
return {
|
|
331
336
|
branch,
|
|
332
337
|
base,
|
|
333
338
|
submitted,
|
|
334
339
|
skippedIdentical,
|
|
335
340
|
committed,
|
|
341
|
+
createdBranch,
|
|
336
342
|
pushCommand: `git push -u origin ${branch}`,
|
|
337
|
-
prCommand:
|
|
343
|
+
prCommand: createdBranch
|
|
344
|
+
? `gh pr create --base ${base} --title "mem: review ${validated.length} ${validated.length === 1 ? "memory" : "memories"}" --body "Submitted from the open-memex outbox: ${ids8}."`
|
|
345
|
+
: `${branchCmd} # if you want a separate memory PR (else push ${branch} directly)\n git push -u origin <new-branch> && gh pr create --base ${base} --title "mem: review ${validated.length}" --body "Submitted from the open-memex outbox: ${ids8}."`,
|
|
338
346
|
};
|
|
339
347
|
}
|
package/dist/tools/ops.js
CHANGED
|
@@ -26,7 +26,7 @@ export const TOOL_DESCRIPTIONS = {
|
|
|
26
26
|
memory_supersede: "Replace an existing memory with a newer version. The old memory is kept as history (status: superseded) and retrieval returns the new one. Use when a saved fact becomes outdated and should be replaced rather than duplicated.",
|
|
27
27
|
memory_forget: "Delete a memory by id. Use when the user asks to forget something.",
|
|
28
28
|
memory_status: "Show the project memory sync pipeline: drafts waiting in the outbox (appdata), memories in the repo awaiting review or published, and any repo files not yet committed. Call this at session start and at task checkpoints, then ask the user which drafts to sync. The user may also trigger this flow by saying 'sync memory' (or '同步记忆').",
|
|
29
|
-
memory_submit: "Move outbox drafts into
|
|
29
|
+
memory_submit: "Move outbox drafts into the repo memory dir for review: copies the drafts in as proposed (or keeps a local approval), commits locally on the current branch, and moves the outbox originals out. Never creates a branch on its own — pass branch= only with the user's explicit approval for the full chain. Prints the push and PR commands — those need the user's explicit approval and are never run automatically.",
|
|
30
30
|
memory_propose: "Copy personal memories into the project outbox as review drafts. The personal originals stay put.",
|
|
31
31
|
memory_promote: "Advance a project memory one step up the review ladder (proposed → approved → published), or reject it with a note. Rejected memories are never deleted — they can be revised and resubmitted.",
|
|
32
32
|
memory_resolve: "List git-conflicted memory files, or attempt a field-level 3-way merge of one. Semantic conflicts are reported, never auto-resolved.",
|
|
@@ -78,14 +78,14 @@ export const memoryForgetArgs = {
|
|
|
78
78
|
export const memoryStatusArgs = {};
|
|
79
79
|
export const memorySubmitArgs = {
|
|
80
80
|
ids: z.array(z.string().min(1)).min(1).describe("Outbox draft ids to submit."),
|
|
81
|
-
|
|
81
|
+
branch: z
|
|
82
82
|
.string()
|
|
83
83
|
.optional()
|
|
84
|
-
.describe("
|
|
84
|
+
.describe("Create this branch and submit onto it. If omitted, submit stays on the current branch — branches are never auto-created. Only pass this when the user explicitly approved the full chain (branch + push + PR)."),
|
|
85
85
|
base: z
|
|
86
86
|
.string()
|
|
87
87
|
.optional()
|
|
88
|
-
.describe("PR base branch override. Default: the branch the submit
|
|
88
|
+
.describe("PR base branch override. Default: the branch the submit ran on."),
|
|
89
89
|
};
|
|
90
90
|
export const memoryProposeArgs = {
|
|
91
91
|
ids: z.array(z.string().min(1)).min(1).describe("Personal memory ids to copy into the project outbox."),
|
|
@@ -260,16 +260,18 @@ export async function statusMemories() {
|
|
|
260
260
|
};
|
|
261
261
|
}
|
|
262
262
|
export async function submitMemoriesOp(args) {
|
|
263
|
-
const r = submitMemories(args.ids, {
|
|
263
|
+
const r = submitMemories(args.ids, { branch: args.branch, base: args.base });
|
|
264
264
|
const lines = [];
|
|
265
265
|
for (const s of r.submitted)
|
|
266
266
|
lines.push(`submitted ${s.id} [${s.reviewState}]`);
|
|
267
267
|
for (const id of r.skippedIdentical)
|
|
268
268
|
lines.push(`already on branch: ${id} (outbox copy removed)`);
|
|
269
|
-
lines.push(r.committed ? `committed on ${r.branch}.` : `nothing new to commit on ${r.branch}.`);
|
|
270
|
-
lines.push(`Next
|
|
269
|
+
lines.push(r.committed ? `committed on ${r.branch} (you are still on this branch).` : `nothing new to commit on ${r.branch}.`);
|
|
270
|
+
lines.push(`Next — ask the user: "want me to create a branch + push + open the PR, or will you handle it yourself?"`);
|
|
271
|
+
lines.push(`Never create branches, push, or open PRs without their explicit approval. If they handle it themselves, hand them these:`);
|
|
271
272
|
lines.push(` ${r.pushCommand}`);
|
|
272
|
-
|
|
273
|
+
for (const l of r.prCommand.split("\n"))
|
|
274
|
+
lines.push(` ${l}`);
|
|
273
275
|
return { title: `memory: submitted ${r.submitted.length}`, output: lines.join("\n") };
|
|
274
276
|
}
|
|
275
277
|
export async function proposeMemoriesOp(args) {
|
package/docs/USER-GUIDE.md
CHANGED
|
@@ -99,13 +99,15 @@ personal idea ──propose──▶ outbox draft ──submit──▶ proposed
|
|
|
99
99
|
what triggered it — session start, a request, a CLI run, a submit), the
|
|
100
100
|
outbox (pending sync), the repo review states
|
|
101
101
|
(`draft / proposed / approved / published / rejected`), and any uncommitted
|
|
102
|
-
repo memory files. Your agent calls this at session start
|
|
103
|
-
checkpoints,
|
|
102
|
+
repo memory files. Your agent calls this at session start, at meaningful
|
|
103
|
+
checkpoints, after you commit, and after memory actions — then asks which
|
|
104
|
+
drafts (if any) you want synced. You can also just say "sync memory".
|
|
104
105
|
- `open-memex submit <id...>`: moves **your named drafts** into
|
|
105
|
-
`<repo>/.ai/open-memex/` as `proposed`. It
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
`<repo>/.ai/open-memex/` as `proposed`. It copies the files, flips
|
|
107
|
+
`review_state`, and makes a **local** git commit **on your current branch** —
|
|
108
|
+
it never creates a branch on its own (branch creation is your call, or your
|
|
109
|
+
agent's with your explicit approval via `--branch <name>`).
|
|
110
|
+
All-or-nothing, idempotent, crash-safe. It prints the `git push` +
|
|
109
111
|
`gh pr create` commands; if your agent already has your Yes for this sync,
|
|
110
112
|
it carries through push and PR itself. The PR base defaults to the current
|
|
111
113
|
branch; `--base` redirects to `main` or your integration branch.
|
|
@@ -120,8 +122,8 @@ personal idea ──propose──▶ outbox draft ──submit──▶ proposed
|
|
|
120
122
|
(push, PR, merge).
|
|
121
123
|
- A standalone memory PR contains **only memory files, no code**, reviewed and
|
|
122
124
|
audited separately from code PRs. Reviewers check "is this true? is it safe
|
|
123
|
-
to share? any secrets?" — things a code PR's CI never checks. You
|
|
124
|
-
|
|
125
|
+
to share? any secrets?" — things a code PR's CI never checks. You create the
|
|
126
|
+
branch yourself when you want one (or your agent does, with your approval).
|
|
125
127
|
- "Request changes" needs no command: while the PR is open, the author edits
|
|
126
128
|
the same file (directly, or by asking their agent in chat), commits, and
|
|
127
129
|
pushes. The state stays `proposed`; the PR is the review mechanism.
|
package/docs/USER-GUIDE.zh-CN.md
CHANGED
|
@@ -87,12 +87,13 @@ server 不能主动推送,调不调 `memory_search` 全看 model 的判断。
|
|
|
87
87
|
- `open-memex sync-status`:看索引**上次同步的时间和触发方**(会话开始、
|
|
88
88
|
请求、CLI、submit)、草稿箱(待同步)、repo 里的评审状态
|
|
89
89
|
(`draft / proposed / approved / published / rejected`),以及 repo 里还没
|
|
90
|
-
commit 的记忆文件。你的 agent
|
|
91
|
-
|
|
90
|
+
commit 的记忆文件。你的 agent 会在会话开始、关键节点、你 commit 之后、
|
|
91
|
+
记忆动作之后跑这个,然后问你哪些草稿(如果有)要同步。你也可以直接说"同步记忆"。
|
|
92
92
|
- `open-memex submit <id...>`:把**你点名的草稿**移入 `<repo>/.ai/open-memex/`,
|
|
93
|
-
状态变为 `proposed
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
状态变为 `proposed`。它复制文件、改 `review_state`、在**当前分支**做一次
|
|
94
|
+
**本地** git commit——永不自动建分支(建分支你说了算,或 agent 拿到你明确
|
|
95
|
+
批准走全链时用 `--branch <name>`)。
|
|
96
|
+
全有或全无、幂等、crash-safe。它打印 `git push` +
|
|
96
97
|
`gh pr create` 命令;如果你的 agent 已经拿到你这次的 Yes,它会自己走完
|
|
97
98
|
push 和 PR。PR 默认 base 是当前分支;`--base` 可改到 `main` 或集成支。
|
|
98
99
|
分支上同 id 但内容不同——**直接中止**,等人裁决,绝不覆盖。
|
|
@@ -104,7 +105,7 @@ server 不能主动推送,调不调 `memory_search` 全看 model 的判断。
|
|
|
104
105
|
**git 负责运输**(push、PR、合并)。
|
|
105
106
|
- 独立的记忆 PR **只含记忆文件,不含代码**,跟代码 PR 分开评审、分开审计。
|
|
106
107
|
审的是"这条是真的吗?能给全团队看吗?有没有 secret?"——代码 PR 的 CI 不会查这些。
|
|
107
|
-
|
|
108
|
+
想开分支时你自己建(或 agent 拿到批准后建)。
|
|
108
109
|
- "要求修改"不需要命令:PR 开着的时候,作者直接改同一个文件(自己改,
|
|
109
110
|
或在 chat 里让 agent 改),commit、push。状态一直是 `proposed`,
|
|
110
111
|
PR 本身就是评审机制。
|
package/docs/V2-DESIGN.md
CHANGED
|
@@ -714,6 +714,18 @@ requirement: personal data never touches third-party services). Benchmarks to tr
|
|
|
714
714
|
init-written instruction files, and the `memory_status` tool description.
|
|
715
715
|
*Rationale: the user should not have to remember command names to sync;
|
|
716
716
|
saying it in words must work. Approved 2026-09-28.*
|
|
717
|
+
- **D36** — `submit` never creates a branch on its own (revises D26/D27): it
|
|
718
|
+
copies the named drafts into `.ai/open-memex/`, commits locally on the
|
|
719
|
+
CURRENT branch, and prints next-step commands. Branch creation is the human's
|
|
720
|
+
call — or the agent's, only with explicit approval for the full chain, via
|
|
721
|
+
`submit --branch <name>` / `memory_submit(branch=...)`. *Rationale: an
|
|
722
|
+
auto-created branch strands the user on it — they forget to switch back.
|
|
723
|
+
After a submit the agent asks ONE follow-up ("want me to create a branch +
|
|
724
|
+
push + open the PR, or will you handle it yourself?") instead of branching
|
|
725
|
+
silently. Checkpoints that trigger `memory_status`: session start, end of a
|
|
726
|
+
work chunk, after the user commits, and after any memory_* action.
|
|
727
|
+
The "sync memory" trigger ALWAYS goes through the `memory_status` tool —
|
|
728
|
+
never by browsing the appdata directory directly. Approved 2026-09-28.*
|
|
717
729
|
- **D33** — Every CLI command answers `open-memex <command> --help` (and `-h`)
|
|
718
730
|
with its own usage, flags, and examples; checked before config/DB load so
|
|
719
731
|
help works even in a broken environment. Unknown commands with `--help`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "open-memex",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.5",
|
|
4
4
|
"description": "Local-first memory layer and protocol for AI coding agents. Markdown source of truth, SQLite FTS5 index, zero cloud.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
package/src/cli.ts
CHANGED
|
@@ -124,17 +124,17 @@ repo awaiting review or published, and repo files not yet committed.
|
|
|
124
124
|
|
|
125
125
|
Usage: open-memex sync-status`,
|
|
126
126
|
|
|
127
|
-
submit: `Move outbox drafts into
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
explicit approval and are never run automatically.
|
|
127
|
+
submit: `Move outbox drafts into the repo for review: copies the drafts into
|
|
128
|
+
the repo memory dir as proposed (a local-approved copy keeps its approval),
|
|
129
|
+
commits locally on the CURRENT branch, and moves the outbox originals out.
|
|
130
|
+
Never creates a branch on its own — branch creation is your call.
|
|
132
131
|
|
|
133
|
-
Usage: open-memex submit <id...> [--
|
|
132
|
+
Usage: open-memex submit <id...> [--branch <name>] [--base <branch>]
|
|
134
133
|
|
|
135
134
|
Flags:
|
|
136
|
-
--
|
|
137
|
-
|
|
135
|
+
--branch create this branch and submit onto it (only with your explicit
|
|
136
|
+
approval for the full chain); default: stay on current branch
|
|
137
|
+
--base PR base override (default: the branch you're on)
|
|
138
138
|
|
|
139
139
|
Example:
|
|
140
140
|
open-memex submit 01ABC 01DEF`,
|
|
@@ -223,7 +223,7 @@ Usage:
|
|
|
223
223
|
open-memex promote <id> [--reject] [--resubmit] [--note "..."] [--by NAME]
|
|
224
224
|
open-memex resolve [id-or-path]
|
|
225
225
|
open-memex sync-status
|
|
226
|
-
open-memex submit <id...> [--
|
|
226
|
+
open-memex submit <id...> [--branch <name>] [--base <branch>]
|
|
227
227
|
open-memex pr-status [--apply]
|
|
228
228
|
open-memex reindex
|
|
229
229
|
open-memex scopes
|
|
@@ -883,7 +883,7 @@ function positionalArgs(argv: string[]): string[] {
|
|
|
883
883
|
if (ids.length === 0) usage();
|
|
884
884
|
syncScope(project.key, "submit");
|
|
885
885
|
try {
|
|
886
|
-
const r = submitMemories(ids, {
|
|
886
|
+
const r = submitMemories(ids, { branch: flags.branch, base: flags.base });
|
|
887
887
|
for (const s of r.submitted) {
|
|
888
888
|
console.log(`submitted ${s.id} → ${path.relative(process.cwd(), s.filePath)} [${s.reviewState}]`);
|
|
889
889
|
}
|
package/src/init.ts
CHANGED
|
@@ -70,20 +70,22 @@ You have a local memory MCP server (\`open-memex\`) with eleven tools:
|
|
|
70
70
|
Project memories you save land in a local outbox first — they are NOT in git yet.
|
|
71
71
|
Syncing them into the repo for review is an explicit, user-approved step:
|
|
72
72
|
|
|
73
|
-
- At session start,
|
|
73
|
+
- At session start, when you finish a meaningful chunk of work, after the user
|
|
74
|
+
commits (git commit), and after any memory_* action completes, call
|
|
74
75
|
\`memory_status\`. If the outbox has drafts, summarize them (one line each) and ask
|
|
75
76
|
the user which ones to sync. Sync NOTHING the user did not name.
|
|
76
77
|
- When the user says "sync memory" (or "同步记忆"), treat it as a request to run
|
|
77
78
|
the sync flow above: call \`memory_status\`, summarize the outbox drafts, and ask
|
|
78
79
|
which ones to sync.
|
|
79
|
-
- When the user approves,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
- When the user approves, call \`memory_submit\` with the approved ids. It copies
|
|
81
|
+
the drafts into the repo as \`proposed\`, commits locally on the CURRENT branch,
|
|
82
|
+
and prints the push + PR commands. It NEVER creates a branch on its own.
|
|
83
|
+
- After the submit, ask ONE follow-up: "want me to create a branch + push +
|
|
84
|
+
open the PR, or will you handle it yourself?" A "yes, you do it" answer covers
|
|
85
|
+
the whole chain — branch creation, push, PR creation — do NOT re-ask at each
|
|
86
|
+
step. If the user says they will do it themselves, hand them the printed
|
|
87
|
+
push/PR commands and do nothing. NEVER create branches, push, or open PRs
|
|
88
|
+
without their explicit approval.
|
|
87
89
|
- Base branch for the memory PR defaults to the branch you are on; the user may
|
|
88
90
|
redirect it to the integration branch (main) for branch-independent knowledge.
|
|
89
91
|
- If anything conflicts (same id with different content, push rejected), STOP and
|
package/src/mcp.ts
CHANGED
|
@@ -64,13 +64,19 @@ const SERVER_INSTRUCTIONS = `You are connected to an open-memex local memory MCP
|
|
|
64
64
|
(eleven memory_* tools: add, search, list, supersede, forget, status, submit,
|
|
65
65
|
propose, promote, resolve, pr_status).
|
|
66
66
|
|
|
67
|
-
- At the START of this session,
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
- At the START of this session, when you finish a meaningful chunk of work,
|
|
68
|
+
after the user commits (git commit), and after any memory_* action completes,
|
|
69
|
+
call memory_status. If the project outbox has drafts waiting for review,
|
|
70
|
+
summarize them (one line each) and ask the user which ones to sync into the
|
|
71
|
+
repo. Sync NOTHING the user did not name.
|
|
70
72
|
- When the user says "sync memory" (or "同步记忆"), treat it as a request to run
|
|
71
73
|
the sync flow: call memory_status, summarize the outbox drafts, and ask which
|
|
72
|
-
ones to sync.
|
|
73
|
-
|
|
74
|
+
ones to sync. ALWAYS use the memory_status tool for this — never browse the
|
|
75
|
+
appdata directory directly.
|
|
76
|
+
- After memory_submit, ask ONE follow-up: "want me to create a branch + push +
|
|
77
|
+
open the PR, or will you handle it yourself?" NEVER create branches, push, or
|
|
78
|
+
open PRs without the user's explicit approval. A "yes, you do it" covers the
|
|
79
|
+
whole chain — do NOT re-ask at each step.
|
|
74
80
|
- BE PROACTIVE: when the user shares something worth remembering across sessions
|
|
75
81
|
(a decision, a preference, a project convention, a fix and its cause), call
|
|
76
82
|
memory_add without being asked. Keep each memory to one self-contained statement.
|
package/src/submit.ts
CHANGED
|
@@ -191,15 +191,19 @@ export function formatSyncStatus(st: SyncStatus): string {
|
|
|
191
191
|
// ---------------------------------------------------------------------------
|
|
192
192
|
|
|
193
193
|
export interface SubmitOptions {
|
|
194
|
-
/**
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
/** Create this branch and submit onto it. If omitted, submit stays on the
|
|
195
|
+
current branch — D36: no auto-created branches; branch creation is the
|
|
196
|
+
human's call (or the agent's, only with explicit approval). */
|
|
197
|
+
branch?: string;
|
|
198
|
+
/** PR base override (default: the branch the submit ran on). */
|
|
197
199
|
base?: string;
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
export interface SubmitResult {
|
|
201
203
|
branch: string;
|
|
202
204
|
base: string;
|
|
205
|
+
/** true when --branch created a new branch for this submit */
|
|
206
|
+
createdBranch: boolean;
|
|
203
207
|
submitted: Array<{ id: string; filePath: string; reviewState: ReviewState }>;
|
|
204
208
|
/** already on the branch with identical content — outbox move completed */
|
|
205
209
|
skippedIdentical: string[];
|
|
@@ -219,7 +223,8 @@ interface Validated {
|
|
|
219
223
|
export function submitMemories(ids: string[], opts: SubmitOptions = {}): SubmitResult {
|
|
220
224
|
if (ids.length === 0) fail("submit needs at least one memory id");
|
|
221
225
|
const root = projectRoot();
|
|
222
|
-
// submit needs a git repo — the
|
|
226
|
+
// submit needs a git repo — the memories land in .ai/open-memex/ and are
|
|
227
|
+
// committed locally. Branch creation is never automatic (D36).
|
|
223
228
|
git(root, ["rev-parse", "--git-dir"]);
|
|
224
229
|
|
|
225
230
|
const scope = resolveProjectScope(root);
|
|
@@ -269,24 +274,25 @@ export function submitMemories(ids: string[], opts: SubmitOptions = {}): SubmitR
|
|
|
269
274
|
}
|
|
270
275
|
|
|
271
276
|
// 2. Resolve the target branch.
|
|
277
|
+
// D36: submit never creates a branch on its own — it works on the branch
|
|
278
|
+
// you're already on. Pass --branch <name> (explicitly) only when the user
|
|
279
|
+
// approved the full chain (branch + push + PR).
|
|
272
280
|
const startBranch = git(root, ["branch", "--show-current"]) || git(root, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
273
|
-
let branch: string;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
branch = opts.onto;
|
|
279
|
-
} else {
|
|
280
|
-
const stamp = new Date().toISOString().replace(/[-:]/g, "").slice(0, 15);
|
|
281
|
-
branch = `mem/sync-${stamp}`;
|
|
281
|
+
let branch: string = startBranch;
|
|
282
|
+
let createdBranch = false;
|
|
283
|
+
if (opts.branch) {
|
|
284
|
+
branch = opts.branch;
|
|
282
285
|
let n = 0;
|
|
286
|
+
let candidate = branch;
|
|
283
287
|
while (true) {
|
|
284
|
-
const exists = git(root, ["branch", "--list",
|
|
288
|
+
const exists = git(root, ["branch", "--list", candidate]);
|
|
285
289
|
if (!exists) break;
|
|
286
290
|
n++;
|
|
287
|
-
|
|
291
|
+
candidate = `${branch}-${n}`;
|
|
288
292
|
}
|
|
293
|
+
branch = candidate;
|
|
289
294
|
git(root, ["checkout", "-b", branch]);
|
|
295
|
+
createdBranch = true;
|
|
290
296
|
}
|
|
291
297
|
const base = opts.base ?? startBranch;
|
|
292
298
|
const author = currentAuthor();
|
|
@@ -348,7 +354,7 @@ export function submitMemories(ids: string[], opts: SubmitOptions = {}): SubmitR
|
|
|
348
354
|
}
|
|
349
355
|
// If we created the branch and never committed, remove it too — an
|
|
350
356
|
// aborted submit leaves no trace.
|
|
351
|
-
if (
|
|
357
|
+
if (createdBranch) {
|
|
352
358
|
try {
|
|
353
359
|
git(root, ["checkout", "--quiet", startBranch]);
|
|
354
360
|
git(root, ["branch", "--quiet", "-D", branch]);
|
|
@@ -399,13 +405,20 @@ export function submitMemories(ids: string[], opts: SubmitOptions = {}): SubmitR
|
|
|
399
405
|
removed: 0,
|
|
400
406
|
scanned: validated.length,
|
|
401
407
|
});
|
|
408
|
+
// D36: no auto-branch — the commit sits on the branch you were already on.
|
|
409
|
+
// Next steps are printed, not run. For a separate memory PR, create a branch
|
|
410
|
+
// first (the commit comes along), then push + open the PR.
|
|
411
|
+
const branchCmd = `git checkout -b mem/sync-YYYYMMDD`;
|
|
402
412
|
return {
|
|
403
413
|
branch,
|
|
404
414
|
base,
|
|
405
415
|
submitted,
|
|
406
416
|
skippedIdentical,
|
|
407
417
|
committed,
|
|
418
|
+
createdBranch,
|
|
408
419
|
pushCommand: `git push -u origin ${branch}`,
|
|
409
|
-
prCommand:
|
|
420
|
+
prCommand: createdBranch
|
|
421
|
+
? `gh pr create --base ${base} --title "mem: review ${validated.length} ${validated.length === 1 ? "memory" : "memories"}" --body "Submitted from the open-memex outbox: ${ids8}."`
|
|
422
|
+
: `${branchCmd} # if you want a separate memory PR (else push ${branch} directly)\n git push -u origin <new-branch> && gh pr create --base ${base} --title "mem: review ${validated.length}" --body "Submitted from the open-memex outbox: ${ids8}."`,
|
|
410
423
|
};
|
|
411
424
|
}
|
package/src/tools/ops.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const TOOL_DESCRIPTIONS = {
|
|
|
53
53
|
memory_status:
|
|
54
54
|
"Show the project memory sync pipeline: drafts waiting in the outbox (appdata), memories in the repo awaiting review or published, and any repo files not yet committed. Call this at session start and at task checkpoints, then ask the user which drafts to sync. The user may also trigger this flow by saying 'sync memory' (or '同步记忆').",
|
|
55
55
|
memory_submit:
|
|
56
|
-
"Move outbox drafts into
|
|
56
|
+
"Move outbox drafts into the repo memory dir for review: copies the drafts in as proposed (or keeps a local approval), commits locally on the current branch, and moves the outbox originals out. Never creates a branch on its own — pass branch= only with the user's explicit approval for the full chain. Prints the push and PR commands — those need the user's explicit approval and are never run automatically.",
|
|
57
57
|
memory_propose:
|
|
58
58
|
"Copy personal memories into the project outbox as review drafts. The personal originals stay put.",
|
|
59
59
|
memory_promote:
|
|
@@ -125,14 +125,16 @@ export type MemoryStatusArgs = z.infer<z.ZodObject<typeof memoryStatusArgs>>;
|
|
|
125
125
|
|
|
126
126
|
export const memorySubmitArgs = {
|
|
127
127
|
ids: z.array(z.string().min(1)).min(1).describe("Outbox draft ids to submit."),
|
|
128
|
-
|
|
128
|
+
branch: z
|
|
129
129
|
.string()
|
|
130
130
|
.optional()
|
|
131
|
-
.describe(
|
|
131
|
+
.describe(
|
|
132
|
+
"Create this branch and submit onto it. If omitted, submit stays on the current branch — branches are never auto-created. Only pass this when the user explicitly approved the full chain (branch + push + PR).",
|
|
133
|
+
),
|
|
132
134
|
base: z
|
|
133
135
|
.string()
|
|
134
136
|
.optional()
|
|
135
|
-
.describe("PR base branch override. Default: the branch the submit
|
|
137
|
+
.describe("PR base branch override. Default: the branch the submit ran on."),
|
|
136
138
|
};
|
|
137
139
|
export type MemorySubmitArgs = z.infer<z.ZodObject<typeof memorySubmitArgs>>;
|
|
138
140
|
|
|
@@ -359,14 +361,15 @@ export async function statusMemories(): Promise<ToolResult> {
|
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
export async function submitMemoriesOp(args: MemorySubmitArgs): Promise<ToolResult> {
|
|
362
|
-
const r = submitMemories(args.ids, {
|
|
364
|
+
const r = submitMemories(args.ids, { branch: args.branch, base: args.base });
|
|
363
365
|
const lines: string[] = [];
|
|
364
366
|
for (const s of r.submitted) lines.push(`submitted ${s.id} [${s.reviewState}]`);
|
|
365
367
|
for (const id of r.skippedIdentical) lines.push(`already on branch: ${id} (outbox copy removed)`);
|
|
366
|
-
lines.push(r.committed ? `committed on ${r.branch}.` : `nothing new to commit on ${r.branch}.`);
|
|
367
|
-
lines.push(`Next
|
|
368
|
+
lines.push(r.committed ? `committed on ${r.branch} (you are still on this branch).` : `nothing new to commit on ${r.branch}.`);
|
|
369
|
+
lines.push(`Next — ask the user: "want me to create a branch + push + open the PR, or will you handle it yourself?"`);
|
|
370
|
+
lines.push(`Never create branches, push, or open PRs without their explicit approval. If they handle it themselves, hand them these:`);
|
|
368
371
|
lines.push(` ${r.pushCommand}`);
|
|
369
|
-
lines.push(` ${
|
|
372
|
+
for (const l of r.prCommand.split("\n")) lines.push(` ${l}`);
|
|
370
373
|
return { title: `memory: submitted ${r.submitted.length}`, output: lines.join("\n") };
|
|
371
374
|
}
|
|
372
375
|
|