@memfork/cli 0.1.44 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/branch.d.ts +4 -0
- package/dist/branch.js +23 -2
- package/dist/commands/doctor.js +70 -3
- package/dist/commands/install.js +35 -3
- package/package.json +1 -1
package/dist/branch.d.ts
CHANGED
|
@@ -48,9 +48,13 @@ export declare function pickBranch(sources: BranchSources): string;
|
|
|
48
48
|
/**
|
|
49
49
|
* Resolve the branch a command should operate on, applying the full
|
|
50
50
|
* precedence chain (reads MEMFORK_BRANCH and the current git branch).
|
|
51
|
+
*
|
|
52
|
+
* Prints a warning when no git branch is detected and no fallback is
|
|
53
|
+
* configured — the caller will operate on "main" which may be unintended.
|
|
51
54
|
*/
|
|
52
55
|
export declare function resolveBranch(opts?: {
|
|
53
56
|
explicit?: string;
|
|
54
57
|
configDefault?: string;
|
|
55
58
|
cwd?: string;
|
|
59
|
+
silent?: boolean;
|
|
56
60
|
}): string;
|
package/dist/branch.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* the core guarantees those integrations are unaffected by this logic.
|
|
19
19
|
*/
|
|
20
20
|
import { execSync } from "node:child_process";
|
|
21
|
+
import chalk from "chalk";
|
|
21
22
|
/**
|
|
22
23
|
* Read the current git branch, or undefined when there is no usable answer.
|
|
23
24
|
*
|
|
@@ -63,12 +64,32 @@ export function pickBranch(sources) {
|
|
|
63
64
|
/**
|
|
64
65
|
* Resolve the branch a command should operate on, applying the full
|
|
65
66
|
* precedence chain (reads MEMFORK_BRANCH and the current git branch).
|
|
67
|
+
*
|
|
68
|
+
* Prints a warning when no git branch is detected and no fallback is
|
|
69
|
+
* configured — the caller will operate on "main" which may be unintended.
|
|
66
70
|
*/
|
|
67
71
|
export function resolveBranch(opts = {}) {
|
|
68
|
-
|
|
72
|
+
const git = gitBranch(opts.cwd);
|
|
73
|
+
const branch = pickBranch({
|
|
69
74
|
explicit: opts.explicit,
|
|
70
75
|
env: process.env["MEMFORK_BRANCH"],
|
|
71
|
-
git
|
|
76
|
+
git,
|
|
72
77
|
configDefault: opts.configDefault,
|
|
73
78
|
});
|
|
79
|
+
// Warn when we fell all the way through to "main" because there is no git
|
|
80
|
+
// repo and no other source — this is almost always unintended.
|
|
81
|
+
if (!opts.silent &&
|
|
82
|
+
branch === "main" &&
|
|
83
|
+
!opts.explicit &&
|
|
84
|
+
!process.env["MEMFORK_BRANCH"] &&
|
|
85
|
+
!git &&
|
|
86
|
+
!opts.configDefault) {
|
|
87
|
+
process.stderr.write(chalk.yellow("⚠") +
|
|
88
|
+
" No git branch detected — committing to " +
|
|
89
|
+
chalk.bold("main") +
|
|
90
|
+
". Run " +
|
|
91
|
+
chalk.dim("git init && git checkout -b <branch>") +
|
|
92
|
+
" to use branch-scoped memory.\n");
|
|
93
|
+
}
|
|
94
|
+
return branch;
|
|
74
95
|
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -125,8 +125,10 @@ export async function cmdDoctor() {
|
|
|
125
125
|
process.exit(1);
|
|
126
126
|
}
|
|
127
127
|
// ── 5. MemoryTree on-chain ──────────────────────────────────────────────────
|
|
128
|
+
let treeOwner;
|
|
128
129
|
try {
|
|
129
130
|
const tree = await client.getTree();
|
|
131
|
+
treeOwner = tree.owner;
|
|
130
132
|
checks.push({
|
|
131
133
|
label: "MemoryTree on-chain",
|
|
132
134
|
status: "ok",
|
|
@@ -141,7 +143,72 @@ export async function cmdDoctor() {
|
|
|
141
143
|
fix: "Check the treeId in .memfork/config.json or run `memfork init`",
|
|
142
144
|
});
|
|
143
145
|
}
|
|
144
|
-
// ── 6. Signer
|
|
146
|
+
// ── 6. Signer role (owner vs delegate) ──────────────────────────────────────
|
|
147
|
+
const signerAddr = client.keypair.toSuiAddress();
|
|
148
|
+
if (treeOwner) {
|
|
149
|
+
if (signerAddr === treeOwner) {
|
|
150
|
+
checks.push({
|
|
151
|
+
label: "Signer role",
|
|
152
|
+
status: "ok",
|
|
153
|
+
detail: `owner (${signerAddr.slice(0, 10)}…)`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// Look for a DelegateCap owned by this signer for this tree.
|
|
158
|
+
try {
|
|
159
|
+
if (!cfg.packageId)
|
|
160
|
+
throw new Error("packageId unknown");
|
|
161
|
+
const capType = `${cfg.packageId}::tree::DelegateCap`;
|
|
162
|
+
const owned = await client.suiClient.getOwnedObjects({
|
|
163
|
+
owner: signerAddr,
|
|
164
|
+
filter: { StructType: capType },
|
|
165
|
+
options: { showContent: true },
|
|
166
|
+
});
|
|
167
|
+
const cap = owned.data.find((o) => {
|
|
168
|
+
if (!o.data?.content || o.data.content.dataType !== "moveObject")
|
|
169
|
+
return false;
|
|
170
|
+
const f = o.data.content.fields;
|
|
171
|
+
return f["tree_id"] === cfg.treeId && !f["revoked"];
|
|
172
|
+
});
|
|
173
|
+
if (cap && cap.data?.content && cap.data.content.dataType === "moveObject") {
|
|
174
|
+
const f = cap.data.content.fields;
|
|
175
|
+
const raw = Number(f["permissions"] ?? 0);
|
|
176
|
+
const labels = [];
|
|
177
|
+
if (raw & 0x01)
|
|
178
|
+
labels.push("READ");
|
|
179
|
+
if (raw & 0x02)
|
|
180
|
+
labels.push("WRITE");
|
|
181
|
+
if (raw & 0x04)
|
|
182
|
+
labels.push("FORK");
|
|
183
|
+
if (raw & 0x08)
|
|
184
|
+
labels.push("MERGE");
|
|
185
|
+
if (raw & 0x10)
|
|
186
|
+
labels.push("PROPOSE");
|
|
187
|
+
checks.push({
|
|
188
|
+
label: "Signer role",
|
|
189
|
+
status: "ok",
|
|
190
|
+
detail: `delegate · ${labels.join(" · ") || "no permissions"} (${signerAddr.slice(0, 10)}…)`,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
checks.push({
|
|
195
|
+
label: "Signer role",
|
|
196
|
+
status: "warn",
|
|
197
|
+
detail: `no delegate cap found for this tree (${signerAddr.slice(0, 10)}…)`,
|
|
198
|
+
fix: "Ask the tree owner to run: memfork grant --agent " + signerAddr,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
checks.push({
|
|
204
|
+
label: "Signer role",
|
|
205
|
+
status: "skip",
|
|
206
|
+
detail: "could not query delegate cap",
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// ── 7. Signer balance (warn if low) ─────────────────────────────────────────
|
|
145
212
|
try {
|
|
146
213
|
const addr = client.keypair.toSuiAddress();
|
|
147
214
|
const balance = await client.suiClient.getBalance({ owner: addr });
|
|
@@ -157,7 +224,7 @@ export async function cmdDoctor() {
|
|
|
157
224
|
catch {
|
|
158
225
|
checks.push({ label: "Signer balance", status: "skip", detail: "could not fetch" });
|
|
159
226
|
}
|
|
160
|
-
// ──
|
|
227
|
+
// ── 8. MemWal reachable ──────────────────────────────────────────────────────
|
|
161
228
|
try {
|
|
162
229
|
const resp = await fetch(cfg.memwalRelayer + "/health", { signal: AbortSignal.timeout(5000) });
|
|
163
230
|
checks.push({
|
|
@@ -175,7 +242,7 @@ export async function cmdDoctor() {
|
|
|
175
242
|
fix: "Check your network. MemWal read/write will be unavailable.",
|
|
176
243
|
});
|
|
177
244
|
}
|
|
178
|
-
// ──
|
|
245
|
+
// ── 9. Artifact storage (optional) ──────────────────────────────────────────
|
|
179
246
|
if (cfg.artifacts.enabled) {
|
|
180
247
|
// Artifacts require WAL tokens. Fetch the signer's WAL coin balance.
|
|
181
248
|
// The WAL package ID is identical on mainnet and testnet.
|
package/dist/commands/install.js
CHANGED
|
@@ -163,9 +163,41 @@ function installCodex(cwd) {
|
|
|
163
163
|
console.log(dim(` Run manually: codex plugin add memforks@memforks`));
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
// ──
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
// ── 3. Project-scoped Codex config (.codex/config.toml) ──────────────────
|
|
167
|
+
//
|
|
168
|
+
// Codex defaults to read-only sandbox, which blocks `memfork commit` (it
|
|
169
|
+
// needs to write ~/.memfork/ and hit the network). A project-level override
|
|
170
|
+
// turns on workspace-write + network without touching the user's global
|
|
171
|
+
// Codex config or any other project.
|
|
172
|
+
const projectCodexDir = path.join(cwd, ".codex");
|
|
173
|
+
const projectCodexCfg = path.join(projectCodexDir, "config.toml");
|
|
174
|
+
fs.mkdirSync(projectCodexDir, { recursive: true });
|
|
175
|
+
const sandboxBlock = `# Written by memfork install codex
|
|
176
|
+
# workspace-write + network_access lets the agent run \`memfork commit\`
|
|
177
|
+
# without escalation prompts, scoped to this project only.
|
|
178
|
+
sandbox_mode = "workspace-write"
|
|
179
|
+
|
|
180
|
+
[sandbox_workspace_write]
|
|
181
|
+
network_access = true
|
|
182
|
+
`;
|
|
183
|
+
if (!fs.existsSync(projectCodexCfg)) {
|
|
184
|
+
fs.writeFileSync(projectCodexCfg, sandboxBlock, "utf8");
|
|
185
|
+
console.log(ok(`Sandbox: ${dim(projectCodexCfg)} (workspace-write + network)`));
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// File already exists — only patch if the keys are missing.
|
|
189
|
+
const existing = fs.readFileSync(projectCodexCfg, "utf8");
|
|
190
|
+
let patched = existing;
|
|
191
|
+
if (!existing.includes("sandbox_mode")) {
|
|
192
|
+
patched += "\n" + sandboxBlock;
|
|
193
|
+
fs.writeFileSync(projectCodexCfg, patched, "utf8");
|
|
194
|
+
console.log(ok(`Sandbox: ${dim(projectCodexCfg)} (patched workspace-write + network)`));
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.log(ok(`Sandbox: ${dim(projectCodexCfg)} (already configured)`));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// ── Summary (Codex) ────────────────────────────────────────────────────────
|
|
169
201
|
console.log("");
|
|
170
202
|
console.log(tip("The agent now has:"));
|
|
171
203
|
console.log(dim(" memwal_recall / memwal_remember — memory storage via MemWal MCP"));
|