@memfork/cli 0.1.17 → 0.1.19
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/cli.js +3 -3
- package/dist/commands/ops.d.ts +1 -1
- package/dist/commands/ops.js +25 -11
- package/dist/commands/ui-server.js +1 -1
- package/dist/config.d.ts +6 -6
- package/dist/config.js +37 -42
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -89,9 +89,9 @@ program
|
|
|
89
89
|
.action(wrap((opts) => cmdCommit(opts)));
|
|
90
90
|
program
|
|
91
91
|
.command("merge <from> <into>")
|
|
92
|
-
.description("
|
|
93
|
-
.
|
|
94
|
-
.option("--ttl <ms>", "TTL in milliseconds", parseInt, 86_400_000)
|
|
92
|
+
.description("merge memory from one branch into another")
|
|
93
|
+
.option("-r, --resolver <id>", "ResolverRef object ID (default: LastWriteWins, or MEMFORK_RESOLVER_ID env var)")
|
|
94
|
+
.option("--ttl <ms>", "proposal TTL in milliseconds", parseInt, 86_400_000)
|
|
95
95
|
.action(wrap((from, into, opts) => cmdMerge(from, into, opts)));
|
|
96
96
|
program
|
|
97
97
|
.command("proposals")
|
package/dist/commands/ops.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function cmdCommit(opts: {
|
|
|
20
20
|
autoExtract?: boolean;
|
|
21
21
|
}): Promise<void>;
|
|
22
22
|
export declare function cmdMerge(from: string, into: string, opts: {
|
|
23
|
-
resolver
|
|
23
|
+
resolver?: string;
|
|
24
24
|
ttl?: number;
|
|
25
25
|
}): Promise<void>;
|
|
26
26
|
export declare function cmdProposals(): Promise<void>;
|
package/dist/commands/ops.js
CHANGED
|
@@ -126,20 +126,34 @@ export async function cmdCommit(opts) {
|
|
|
126
126
|
}
|
|
127
127
|
// ─── merge ────────────────────────────────────────────────────────────────────
|
|
128
128
|
export async function cmdMerge(from, into, opts) {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
const cfg = resolveConfig();
|
|
130
|
+
const clientCfg = {
|
|
131
|
+
...toClientConfig(cfg),
|
|
132
|
+
// --resolver flag overrides MEMFORK_RESOLVER_ID env var for this call
|
|
133
|
+
...(opts.resolver ? { defaultResolverId: opts.resolver } : {}),
|
|
134
|
+
};
|
|
135
|
+
const client = await MemForksClient.connect(clientCfg);
|
|
136
|
+
const governed = !!(opts.resolver ?? process.env["MEMFORK_RESOLVER_ID"]);
|
|
137
|
+
process.stdout.write(chalk.dim(`Merging ${chalk.green(from)} → ${chalk.green(into)}`) +
|
|
138
|
+
chalk.dim(governed ? " (governed — awaiting resolver…)" : " (LWW — self-finalizing…)") +
|
|
139
|
+
" ");
|
|
140
|
+
const { digest, mergedCount, blobId, proposalId } = await client.merge(from, into);
|
|
137
141
|
console.log(chalk.green("done"));
|
|
138
142
|
console.log("");
|
|
139
|
-
console.log(chalk.dim(`
|
|
143
|
+
console.log(chalk.dim(` facts merged: ${mergedCount}`));
|
|
144
|
+
if (blobId)
|
|
145
|
+
console.log(chalk.dim(` blob: ${blobId}`));
|
|
146
|
+
if (digest)
|
|
147
|
+
console.log(chalk.dim(` tx: ${digest}`));
|
|
148
|
+
if (proposalId)
|
|
149
|
+
console.log(chalk.dim(` proposal: ${proposalId}`));
|
|
140
150
|
console.log("");
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
if (governed) {
|
|
152
|
+
console.log(chalk.dim("Resolver finalized. Use `memfork log --branch " + into + "` to verify."));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
console.log(chalk.dim("Merge anchor written on-chain. Use `memfork log --branch " + into + "` to verify."));
|
|
156
|
+
}
|
|
143
157
|
console.log("");
|
|
144
158
|
}
|
|
145
159
|
// ─── proposals ────────────────────────────────────────────────────────────────
|
|
@@ -49,7 +49,7 @@ async function handleApiConfig(res) {
|
|
|
49
49
|
const stored = treeId ? creds.trees[treeId] : undefined;
|
|
50
50
|
json(res, {
|
|
51
51
|
treeId,
|
|
52
|
-
packageId: project?.packageId ?? "
|
|
52
|
+
packageId: project?.packageId ?? "0xc13cc014fb8084b3468f6e5ffdc272e64ef35b7a912332eba7a0d44dd66b3121",
|
|
53
53
|
network,
|
|
54
54
|
rpcUrl: project?.rpcUrl ?? null,
|
|
55
55
|
hasMemwal: !!(stored?.memwalKey && stored?.memwalAccountId),
|
package/dist/config.d.ts
CHANGED
|
@@ -25,22 +25,22 @@
|
|
|
25
25
|
export declare const MEMWAL_CONSTANTS: {
|
|
26
26
|
readonly testnet: {
|
|
27
27
|
readonly packageId: "0xcf6ad755a1cdff7217865c796778fabe5aa399cb0cf2eba986f4b582047229c6";
|
|
28
|
-
readonly memforksPackageId: "
|
|
28
|
+
readonly memforksPackageId: "0x185e765a4979fb9d9089374f822485c88b9d0b2f91f9b1313a73043d5ef2357f";
|
|
29
29
|
readonly registryId: "0xe80f2feec1c139616a86c9f71210152e2a7ca552b20841f2e192f99f75864437";
|
|
30
|
-
readonly relayer: "https://relayer
|
|
30
|
+
readonly relayer: "https://relayer-staging.memory.walrus.xyz";
|
|
31
31
|
};
|
|
32
32
|
readonly mainnet: {
|
|
33
33
|
readonly packageId: "0xcee7a6fd8de52ce645c38332bde23d4a30fd9426bc4681409733dd50958a24c6";
|
|
34
|
-
readonly memforksPackageId: "
|
|
34
|
+
readonly memforksPackageId: "0xc13cc014fb8084b3468f6e5ffdc272e64ef35b7a912332eba7a0d44dd66b3121";
|
|
35
35
|
readonly registryId: "0x0da982cefa26864ae834a8a0504b904233d49e20fcc17c373c8bed99c75a7edd";
|
|
36
|
-
readonly relayer: "https://relayer.
|
|
36
|
+
readonly relayer: "https://relayer.memory.walrus.xyz";
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
39
|
export interface ProjectConfig {
|
|
40
40
|
/** Sui MemoryTree object ID. */
|
|
41
41
|
treeId?: string;
|
|
42
42
|
/** Sui network. Default: "mainnet". */
|
|
43
|
-
network?:
|
|
43
|
+
network?: 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
44
44
|
/** Default branch name. Default: "main". */
|
|
45
45
|
defaultBranch?: string;
|
|
46
46
|
/** Override Sui RPC URL. */
|
|
@@ -70,7 +70,7 @@ export interface ResolvedConfig {
|
|
|
70
70
|
memwalAccountId: string;
|
|
71
71
|
memwalKey: string;
|
|
72
72
|
memwalRelayer: string;
|
|
73
|
-
network:
|
|
73
|
+
network: 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
74
74
|
defaultBranch: string;
|
|
75
75
|
rpcUrl?: string;
|
|
76
76
|
packageId?: string;
|
package/dist/config.js
CHANGED
|
@@ -22,32 +22,32 @@
|
|
|
22
22
|
*
|
|
23
23
|
* Plugins and hooks call the CLI binary and never read credentials themselves.
|
|
24
24
|
*/
|
|
25
|
-
import fs from
|
|
26
|
-
import path from
|
|
27
|
-
import os from
|
|
25
|
+
import fs from 'node:fs';
|
|
26
|
+
import path from 'node:path';
|
|
27
|
+
import os from 'node:os';
|
|
28
28
|
// ─── Public network constants ─────────────────────────────────────────────────
|
|
29
29
|
// Sources: https://docs.memwal.ai/contract/overview
|
|
30
30
|
export const MEMWAL_CONSTANTS = {
|
|
31
31
|
testnet: {
|
|
32
|
-
packageId:
|
|
33
|
-
memforksPackageId:
|
|
34
|
-
registryId:
|
|
35
|
-
relayer:
|
|
32
|
+
packageId: '0xcf6ad755a1cdff7217865c796778fabe5aa399cb0cf2eba986f4b582047229c6',
|
|
33
|
+
memforksPackageId: '0x185e765a4979fb9d9089374f822485c88b9d0b2f91f9b1313a73043d5ef2357f',
|
|
34
|
+
registryId: '0xe80f2feec1c139616a86c9f71210152e2a7ca552b20841f2e192f99f75864437',
|
|
35
|
+
relayer: 'https://relayer-staging.memory.walrus.xyz',
|
|
36
36
|
},
|
|
37
37
|
mainnet: {
|
|
38
|
-
packageId:
|
|
39
|
-
memforksPackageId:
|
|
40
|
-
registryId:
|
|
41
|
-
relayer:
|
|
38
|
+
packageId: '0xcee7a6fd8de52ce645c38332bde23d4a30fd9426bc4681409733dd50958a24c6',
|
|
39
|
+
memforksPackageId: '0xc13cc014fb8084b3468f6e5ffdc272e64ef35b7a912332eba7a0d44dd66b3121',
|
|
40
|
+
registryId: '0x0da982cefa26864ae834a8a0504b904233d49e20fcc17c373c8bed99c75a7edd',
|
|
41
|
+
relayer: 'https://relayer.memory.walrus.xyz',
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
// ─── Paths ────────────────────────────────────────────────────────────────────
|
|
45
45
|
function defaultRelayer(network) {
|
|
46
|
-
return MEMWAL_CONSTANTS[network]?.relayer
|
|
47
|
-
|
|
46
|
+
return (MEMWAL_CONSTANTS[network]?.relayer ??
|
|
47
|
+
MEMWAL_CONSTANTS.mainnet.relayer);
|
|
48
48
|
}
|
|
49
49
|
export function projectConfigPath(cwd = process.cwd()) {
|
|
50
|
-
return path.join(cwd,
|
|
50
|
+
return path.join(cwd, '.memfork', 'config.json');
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Walk up the directory tree from `cwd` looking for a `.memfork/config.json`,
|
|
@@ -56,7 +56,7 @@ export function projectConfigPath(cwd = process.cwd()) {
|
|
|
56
56
|
function findProjectConfigPath(cwd = process.cwd()) {
|
|
57
57
|
let dir = cwd;
|
|
58
58
|
while (true) {
|
|
59
|
-
const candidate = path.join(dir,
|
|
59
|
+
const candidate = path.join(dir, '.memfork', 'config.json');
|
|
60
60
|
if (fs.existsSync(candidate))
|
|
61
61
|
return candidate;
|
|
62
62
|
const parent = path.dirname(dir);
|
|
@@ -66,7 +66,7 @@ function findProjectConfigPath(cwd = process.cwd()) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
export function credentialsPath() {
|
|
69
|
-
return path.join(os.homedir(),
|
|
69
|
+
return path.join(os.homedir(), '.memfork', 'credentials.json');
|
|
70
70
|
}
|
|
71
71
|
// ─── Read helpers ─────────────────────────────────────────────────────────────
|
|
72
72
|
export function readProjectConfig(cwd = process.cwd()) {
|
|
@@ -74,7 +74,7 @@ export function readProjectConfig(cwd = process.cwd()) {
|
|
|
74
74
|
if (!p)
|
|
75
75
|
return null;
|
|
76
76
|
try {
|
|
77
|
-
return JSON.parse(fs.readFileSync(p,
|
|
77
|
+
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
78
78
|
}
|
|
79
79
|
catch {
|
|
80
80
|
return null;
|
|
@@ -85,7 +85,7 @@ export function readCredentials() {
|
|
|
85
85
|
if (!fs.existsSync(p))
|
|
86
86
|
return { trees: {} };
|
|
87
87
|
try {
|
|
88
|
-
return JSON.parse(fs.readFileSync(p,
|
|
88
|
+
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
89
89
|
}
|
|
90
90
|
catch {
|
|
91
91
|
return { trees: {} };
|
|
@@ -94,14 +94,14 @@ export function readCredentials() {
|
|
|
94
94
|
// ─── Write helpers ────────────────────────────────────────────────────────────
|
|
95
95
|
export function writeProjectConfig(cfg, cwd = process.cwd()) {
|
|
96
96
|
const root = findGitRoot(cwd) ?? cwd;
|
|
97
|
-
const dir = path.join(root,
|
|
97
|
+
const dir = path.join(root, '.memfork');
|
|
98
98
|
fs.mkdirSync(dir, { recursive: true });
|
|
99
|
-
fs.writeFileSync(path.join(root,
|
|
99
|
+
fs.writeFileSync(path.join(root, '.memfork', 'config.json'), JSON.stringify(cfg, null, 2) + '\n', 'utf8');
|
|
100
100
|
}
|
|
101
101
|
function findGitRoot(cwd) {
|
|
102
102
|
let dir = cwd;
|
|
103
103
|
while (true) {
|
|
104
|
-
if (fs.existsSync(path.join(dir,
|
|
104
|
+
if (fs.existsSync(path.join(dir, '.git')))
|
|
105
105
|
return dir;
|
|
106
106
|
const parent = path.dirname(dir);
|
|
107
107
|
if (parent === dir)
|
|
@@ -110,10 +110,10 @@ function findGitRoot(cwd) {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
export function writeCredentials(creds) {
|
|
113
|
-
const dir = path.join(os.homedir(),
|
|
113
|
+
const dir = path.join(os.homedir(), '.memfork');
|
|
114
114
|
fs.mkdirSync(dir, { recursive: true });
|
|
115
115
|
const p = credentialsPath();
|
|
116
|
-
fs.writeFileSync(p, JSON.stringify(creds, null, 2) +
|
|
116
|
+
fs.writeFileSync(p, JSON.stringify(creds, null, 2) + '\n', 'utf8');
|
|
117
117
|
// 600: owner read+write only — no other users can read private keys.
|
|
118
118
|
fs.chmodSync(p, 0o600);
|
|
119
119
|
}
|
|
@@ -133,7 +133,7 @@ export function setDefaultTree(treeId) {
|
|
|
133
133
|
export class ConfigError extends Error {
|
|
134
134
|
constructor(message) {
|
|
135
135
|
super(message);
|
|
136
|
-
this.name =
|
|
136
|
+
this.name = 'ConfigError';
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
@@ -145,21 +145,15 @@ export function resolveConfig(opts = {}) {
|
|
|
145
145
|
const creds = readCredentials();
|
|
146
146
|
const env = process.env;
|
|
147
147
|
// ── Resolve treeId ──────────────────────────────────────────────────────────
|
|
148
|
-
const treeId = env[
|
|
149
|
-
opts.treeId ??
|
|
150
|
-
project?.treeId ??
|
|
151
|
-
creds.default;
|
|
148
|
+
const treeId = env['MEMFORK_TREE_ID'] ?? opts.treeId ?? project?.treeId ?? creds.default;
|
|
152
149
|
if (!treeId) {
|
|
153
|
-
throw new ConfigError(
|
|
150
|
+
throw new ConfigError('No MemoryTree found. Run `memfork init` to create or link one.');
|
|
154
151
|
}
|
|
155
152
|
// ── Resolve credentials ────────────────────────────────────────────────────
|
|
156
153
|
const stored = creds.trees[treeId];
|
|
157
|
-
const privateKey = env[
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
stored?.memwalAccountId;
|
|
161
|
-
const memwalKey = env["MEMFORK_MEMWAL_KEY"] ??
|
|
162
|
-
stored?.memwalKey;
|
|
154
|
+
const privateKey = env['MEMFORK_PRIVATE_KEY'] ?? stored?.privateKey;
|
|
155
|
+
const memwalAccountId = env['MEMFORK_MEMWAL_ACCOUNT'] ?? stored?.memwalAccountId;
|
|
156
|
+
const memwalKey = env['MEMFORK_MEMWAL_KEY'] ?? stored?.memwalKey;
|
|
163
157
|
if (!privateKey) {
|
|
164
158
|
throw new ConfigError(`No private key for tree ${treeId}. Run \`memfork init\` or set MEMFORK_PRIVATE_KEY.`);
|
|
165
159
|
}
|
|
@@ -170,22 +164,23 @@ export function resolveConfig(opts = {}) {
|
|
|
170
164
|
throw new ConfigError(`No MemWal delegate key for tree ${treeId}. Run \`memfork init\` or set MEMFORK_MEMWAL_KEY.`);
|
|
171
165
|
}
|
|
172
166
|
// ── Merge non-secret config ────────────────────────────────────────────────
|
|
173
|
-
const network = (env[
|
|
167
|
+
const network = (env['MEMFORK_NETWORK'] ??
|
|
174
168
|
project?.network ??
|
|
175
|
-
|
|
169
|
+
'mainnet');
|
|
176
170
|
return {
|
|
177
171
|
treeId,
|
|
178
172
|
privateKey,
|
|
179
173
|
memwalAccountId,
|
|
180
174
|
memwalKey,
|
|
181
|
-
memwalRelayer: env[
|
|
175
|
+
memwalRelayer: env['MEMFORK_RELAYER_URL'] ??
|
|
182
176
|
stored?.memwalRelayer ??
|
|
183
177
|
defaultRelayer(network),
|
|
184
178
|
network,
|
|
185
|
-
defaultBranch: project?.defaultBranch ??
|
|
186
|
-
rpcUrl: env[
|
|
187
|
-
packageId: env[
|
|
188
|
-
sponsorUrl: env[
|
|
179
|
+
defaultBranch: project?.defaultBranch ?? 'main',
|
|
180
|
+
rpcUrl: env['MEMFORK_RPC_URL'] ?? project?.rpcUrl,
|
|
181
|
+
packageId: env['MEMFORK_PACKAGE_ID'] ?? project?.packageId,
|
|
182
|
+
sponsorUrl: env['MEMFORK_SPONSOR_URL'] ??
|
|
183
|
+
project?.['sponsorUrl'],
|
|
189
184
|
};
|
|
190
185
|
}
|
|
191
186
|
/**
|