@memfork/cli 0.1.44 → 0.1.45
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/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/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"));
|