@datamini/passmem-cli 0.0.0-stage → 0.1.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/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "@datamini/passmem-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "PassMem CLI and Skill for memory channels",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/DataMini/passmem.git",
9
+ "directory": "cli"
10
+ },
11
+ "bin": {
12
+ "passmem": "public/passmem-cli.mjs"
13
+ },
14
+ "files": [
15
+ "public/passmem-cli.mjs",
16
+ "skills/passmem/SKILL.md"
17
+ ],
18
+ "engines": {
19
+ "node": ">=24"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ }
24
+ }
@@ -0,0 +1,420 @@
1
+ #!/usr/bin/env node
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { openAsBlob } from 'node:fs';
4
+ import { lstat, mkdir, open, readFile, rename, rm, writeFile } from 'node:fs/promises';
5
+ import { homedir } from 'node:os';
6
+ import { basename, join, resolve } from 'node:path';
7
+ import { emitKeypressEvents } from 'node:readline';
8
+ import { Readable } from 'node:stream';
9
+ import { parseArgs, stripVTControlCharacters } from 'node:util';
10
+
11
+ const memIdPattern = /^[1-9A-HJ-NP-Za-km-z]{14}$/;
12
+ const uuidPattern = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
13
+ const personalKeyPattern = /^pmk_[A-Za-z0-9_-]{43}$/;
14
+ const channelKeyPattern = /^pmc_[A-Za-z0-9_-]{43}$/;
15
+ const sharePathPattern = /^\/f\/pmf_[A-Za-z0-9_-]{43}$/;
16
+ const agent = '/api/agent';
17
+ const defaultSite = 'http://127.0.0.1:3000';
18
+ const skillHeader = /^---\r?\nname: passmem\r?\n/;
19
+
20
+ class CommandError extends Error {}
21
+ function requireValue(value, message) {
22
+ if (!value) throw new CommandError(message);
23
+ return value;
24
+ }
25
+ function uuid(value, label) {
26
+ if (!uuidPattern.test(value ?? '')) throw new CommandError(`请提供有效的${label}。`);
27
+ return value;
28
+ }
29
+
30
+ const help = `PassMem CLI
31
+ 用法:passmem [--site 站点] <命令> [选项]
32
+
33
+ get-skill [--install 技能目录] 输出或安装 PassMem Skill
34
+ login (--email 邮箱 | --key-stdin) 验证邮箱或导入网页生成的 API Key
35
+ whoami 查看账号和组织
36
+ logout 撤销个人 Agent Key
37
+ send (--mem-id-file 路径 | --mem-id-stdin) [--body 文本 | --body-file 路径]
38
+ [--file 路径]... [--signed] [--request-id UUID]
39
+ channel list | show <通道 ID> [--before 序号]
40
+ channel create --name 名称 [--out MemID文件]
41
+ channel rename <通道 ID> --name 名称
42
+ channel pause | resume <通道 ID>
43
+ channel mem-id | rotate <通道 ID> --out MemID文件
44
+ channel download | share | unshare <通道 ID> <文件 ID> [--out 路径]
45
+ channel connections <通道 ID>
46
+ channel connect <通道 ID> --name 名称 --out 凭证文件
47
+ channel disconnect <通道 ID> <连接 ID>
48
+ inbox next [--key-file 凭证文件] [--json] 取一条待确认消息
49
+ inbox download <文件 ID> --out 路径 下载消息附件
50
+ inbox ack <消息 ID> 确认消息已处理
51
+ shared download (--link-file 路径 | --link-stdin) --out 路径
52
+
53
+ 收件命令用 --key-file 或 PASSMEM_CHANNEL_KEY 提供连接凭证。终端直接显示来件,程序可用 --json。
54
+ 通道命令可用 --org 指定组织。凭证只从私有文件、环境变量或标准输入读取。`;
55
+
56
+ function siteOrigin(value) {
57
+ const url = URL.parse(value);
58
+ const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(url?.hostname);
59
+ if (!url || url.origin !== url.href.slice(0, -1) || (url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback))) {
60
+ throw new CommandError('请提供 HTTPS 站点地址,或本机 HTTP 地址。');
61
+ }
62
+ return url.origin;
63
+ }
64
+
65
+ async function request(site, path, { key, json, multipart, headers } = {}) {
66
+ const requestHeaders = new Headers(headers);
67
+ if (key) requestHeaders.set('Authorization', `Bearer ${key}`);
68
+ if (json !== undefined) requestHeaders.set('Content-Type', 'application/json');
69
+ if (multipart) requestHeaders.set('X-Passmem-Upload', '1');
70
+ const response = await fetch(site + path, {
71
+ method: multipart || json !== undefined ? 'POST' : 'GET',
72
+ headers: requestHeaders, redirect: 'error', body: multipart ?? (json === undefined ? undefined : JSON.stringify(json)),
73
+ signal: AbortSignal.timeout(120_000),
74
+ });
75
+ if (!response.ok) {
76
+ const payload = await response.json().catch(() => null);
77
+ const message = typeof payload?.error === 'string' ? payload.error : 'PassMem 请求失败。';
78
+ throw new CommandError(message);
79
+ }
80
+ return response;
81
+ }
82
+ const readJson = (site, path, options) => request(site, path, options).then((response) => response.json());
83
+
84
+ async function getSkill(site, installRoot) {
85
+ let content;
86
+ try {
87
+ content = await readFile(new URL('../skills/passmem/SKILL.md', import.meta.url), 'utf8');
88
+ } catch (error) {
89
+ if (error.code !== 'ENOENT') throw error;
90
+ content = await (await request(site, '/downloads/passmem-skill.md')).text();
91
+ }
92
+ if (!skillHeader.test(content)) throw new CommandError('无法获取有效的 PassMem Skill。');
93
+ content = content.replaceAll(defaultSite, () => site);
94
+ if (installRoot === undefined) {
95
+ process.stdout.write(content);
96
+ return;
97
+ }
98
+
99
+ const directory = resolve(requireValue(installRoot, '请指定技能目录。'), 'passmem');
100
+ await mkdir(directory, { recursive: true, mode: 0o700 });
101
+ if (!(await lstat(directory)).isDirectory()) throw new CommandError('PassMem Skill 目录是链接,请更新它指向的技能。');
102
+ const target = join(directory, 'SKILL.md');
103
+ const existing = await lstat(target).catch((error) => {
104
+ if (error.code !== 'ENOENT') throw error;
105
+ });
106
+ if (existing && (!existing.isFile() || !skillHeader.test(await readFile(target, 'utf8')))) {
107
+ throw new CommandError('目标已有其他文件,请选择新的技能目录。');
108
+ }
109
+ const temporary = join(directory, `.SKILL.${randomUUID()}.tmp`);
110
+ try {
111
+ await writeFile(temporary, content, { flag: 'wx', mode: 0o600 });
112
+ await rename(temporary, target);
113
+ } finally {
114
+ await rm(temporary, { force: true });
115
+ }
116
+ return { path: target };
117
+ }
118
+
119
+ async function readStdin(prompt) {
120
+ if (!process.stdin.isTTY) {
121
+ let value = '';
122
+ process.stdin.setEncoding('utf8');
123
+ for await (const chunk of process.stdin) {
124
+ value += chunk;
125
+ if (value.length > 4096) throw new CommandError('输入过长。');
126
+ }
127
+ return value.trim();
128
+ }
129
+ process.stderr.write(prompt);
130
+ emitKeypressEvents(process.stdin);
131
+ process.stdin.setRawMode(true);
132
+ process.stdin.resume();
133
+ let value = '';
134
+ try {
135
+ return await new Promise((resolve, reject) => {
136
+ function keypress(text, key) {
137
+ if (key.ctrl && key.name === 'c') {
138
+ process.stdin.off('keypress', keypress);
139
+ reject(new CommandError('操作已取消。'));
140
+ } else if (key.name === 'return' || key.name === 'enter') {
141
+ process.stdin.off('keypress', keypress);
142
+ resolve(value.trim());
143
+ } else if (key.name === 'backspace') value = value.slice(0, -1);
144
+ else if (!key.ctrl && !key.meta && text && value.length + text.length <= 4096) value += text;
145
+ }
146
+ process.stdin.on('keypress', keypress);
147
+ });
148
+ } finally {
149
+ process.stdin.setRawMode(false);
150
+ process.stdin.pause();
151
+ process.stderr.write('\n');
152
+ }
153
+ }
154
+
155
+ const configDirectory = () => process.env.PASSMEM_CONFIG_DIR || join(homedir(), '.passmem');
156
+ const keyPath = (site) => join(configDirectory(), createHash('sha256').update(site).digest('hex') + '.key');
157
+ async function keyFromFile(path) {
158
+ const file = await open(path, 'r');
159
+ try {
160
+ const status = await file.stat();
161
+ if (!status.isFile() || (process.platform !== 'win32' && (status.mode & 0o077))) {
162
+ throw new CommandError('请使用权限为 0600 的私有凭证文件。');
163
+ }
164
+ return (await file.readFile('utf8')).trim();
165
+ } finally { await file.close(); }
166
+ }
167
+ async function accountKey(site) {
168
+ const key = process.env.PASSMEM_AGENT_KEY || await keyFromFile(keyPath(site)).catch((error) => {
169
+ if (error.code === 'ENOENT') throw new CommandError('请先运行 passmem login 获取个人 Agent Key。');
170
+ throw error;
171
+ });
172
+ if (!personalKeyPattern.test(key)) throw new CommandError('个人 Agent Key 格式无效,请重新登录。');
173
+ return key;
174
+ }
175
+ async function connectionKey(options) {
176
+ const key = options['key-file'] ? await keyFromFile(options['key-file']) : process.env.PASSMEM_CHANNEL_KEY;
177
+ if (!channelKeyPattern.test(key ?? '')) throw new CommandError('请通过 --key-file 或 PASSMEM_CHANNEL_KEY 提供通道连接凭证。');
178
+ return key;
179
+ }
180
+
181
+ async function withOutput(path, operation) {
182
+ requireValue(path, '请用 --out 指定输出文件。');
183
+ const output = await open(path, 'wx', 0o600);
184
+ try {
185
+ const result = await operation(output);
186
+ await output.close();
187
+ return result;
188
+ } catch (error) {
189
+ await output.close().catch(() => {});
190
+ await rm(path, { force: true }).catch(() => {});
191
+ throw error;
192
+ }
193
+ }
194
+
195
+ async function exportSecret(path, operation, pattern) {
196
+ return withOutput(path, async (output) => {
197
+ const { secret, ...result } = await operation();
198
+ if (!pattern.test(secret ?? '')) throw new CommandError('PassMem 返回的凭证格式无效。');
199
+ await output.writeFile(secret + '\n');
200
+ return { ...result, output: path };
201
+ });
202
+ }
203
+ async function saveDownload(path, operation) {
204
+ return withOutput(path, async (output) => {
205
+ const response = await operation();
206
+ await output.writeFile(Readable.fromWeb(response.body));
207
+ return { output: path };
208
+ });
209
+ }
210
+ async function provideSecret(path, useStdin, prompt) {
211
+ if (Boolean(path) === Boolean(useStdin)) throw new CommandError('请选择文件或标准输入提供凭证。');
212
+ return path ? keyFromFile(path) : readStdin(prompt);
213
+ }
214
+
215
+ async function savePersonalKey(site, issue) {
216
+ await mkdir(configDirectory(), { recursive: true, mode: 0o700 });
217
+ const target = keyPath(site);
218
+ const temporary = target + '.' + randomUUID();
219
+ try {
220
+ const { output, ...result } = await exportSecret(temporary, issue, personalKeyPattern);
221
+ await rename(temporary, target);
222
+ return result;
223
+ } finally { await rm(temporary, { force: true }); }
224
+ }
225
+
226
+ async function login(site, options) {
227
+ if (Boolean(options.email) === Boolean(options['key-stdin'])) {
228
+ throw new CommandError('请选择 --email 邮箱或 --key-stdin。');
229
+ }
230
+ if (options['key-stdin']) {
231
+ const key = await readStdin('粘贴从 PassMem 网页复制的 API Key:');
232
+ if (!personalKeyPattern.test(key)) throw new CommandError('请输入有效格式的个人 API Key。');
233
+ const { user } = await readJson(site, agent + '/me', { key });
234
+ return savePersonalKey(site, () => ({ secret: key, email: user.email }));
235
+ }
236
+ const email = options.email;
237
+ await readJson(site, agent + '/auth/email/send', { json: { email } });
238
+ const code = await readStdin('输入邮箱收到的 8 位 Agent 验证码:');
239
+ if (!/^\d{8}$/.test(code)) throw new CommandError('请输入 8 位邮箱验证码。');
240
+ return savePersonalKey(site, async () => {
241
+ const { key: secret, expiresAt } = await readJson(site, agent + '/auth/email/verify', { json: { email, code } });
242
+ return { secret, email, expiresAt };
243
+ });
244
+ }
245
+
246
+ async function filesForm(manifest, files) {
247
+ const multipart = new FormData();
248
+ multipart.set('manifest', JSON.stringify(manifest));
249
+ for (const [index, path] of files.entries()) {
250
+ multipart.set(`file-${index}`, await openAsBlob(path), basename(path));
251
+ }
252
+ return multipart;
253
+ }
254
+
255
+ async function deliver(site, options) {
256
+ const address = await provideSecret(options['mem-id-file'], options['mem-id-stdin'], '输入 Mem ID:');
257
+ if (!memIdPattern.test(address)) throw new CommandError('请输入 14 位 Mem ID,注意区分大小写。');
258
+ if (options.body !== undefined && options['body-file']) throw new CommandError('请在 --body 和 --body-file 中选择一项。');
259
+ const body = options['body-file'] ? await readFile(options['body-file'], 'utf8') : options.body ?? '';
260
+ const files = options.file ?? [];
261
+ if (!body.trim() && !files.length) throw new CommandError('请提供正文或附件。');
262
+ const requestId = options['request-id'] ?? randomUUID();
263
+ if (!/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(requestId)) {
264
+ throw new CommandError('请用 UUID v4 作为 --request-id。');
265
+ }
266
+ const multipart = await filesForm({ requestId, body, fileCount: files.length }, files);
267
+ const key = options.signed ? await accountKey(site) : undefined;
268
+ try {
269
+ const receipt = await readJson(site, agent + '/channel-deliveries', { key, multipart, headers: { 'X-Passmem-Mem-Id': address } });
270
+ return { ...receipt, requestId };
271
+ } catch (error) {
272
+ const message = error instanceof CommandError ? error.message : '投递状态未确认,请用原内容重试。';
273
+ throw new CommandError(`${message} 请求 ID ${requestId}`);
274
+ }
275
+ }
276
+
277
+ async function orgScope(site, options) {
278
+ const key = await accountKey(site);
279
+ if (options.org) return { key, org: uuid(options.org, '组织 ID') };
280
+ const { organizations } = await readJson(site, agent + '/me', { key });
281
+ if (organizations?.length !== 1) throw new CommandError('请用 passmem whoami 查看组织,并用 --org 指定组织 ID。');
282
+ return { key, org: uuid(organizations[0].id, '组织 ID') };
283
+ }
284
+
285
+ async function channelCommand(site, options, [action, channel, child]) {
286
+ const { key, org } = await orgScope(site, options);
287
+ const base = `${agent}/organizations/${org}/channels`;
288
+ const pageLink = (channelId) => `${site}/?org=${org}&channel=${uuid(channelId, '通道 ID')}`;
289
+ const get = (path) => readJson(site, path, { key });
290
+ const post = (path, json = {}) => readJson(site, path, { key, json });
291
+ const details = ({ memId: secret, ...info }) => ({ secret, ...info, url: pageLink(info.id) });
292
+ const publicDetails = (data) => { const { secret, ...info } = details(data); return info; };
293
+
294
+ if (action === 'list') return get(base);
295
+ if (action === 'create') {
296
+ const create = () => post(base, { name: requireValue(options.name, '请提供 --name。') });
297
+ return options.out ? exportSecret(options.out, async () => details(await create()), memIdPattern) : publicDetails(await create());
298
+ }
299
+ const path = `${base}/${uuid(channel, '通道 ID')}`;
300
+ switch (action) {
301
+ case 'show': {
302
+ const cursor = options.before ? '?' + new URLSearchParams({ before: options.before }) : '';
303
+ const data = await get(path + cursor);
304
+ return { ...data, channel: publicDetails(data.channel) };
305
+ }
306
+ case 'mem-id': return exportSecret(options.out, async () => details((await get(path)).channel), memIdPattern);
307
+ case 'rotate': return exportSecret(options.out, async () => details(await post(path + '/rotate')), memIdPattern);
308
+ case 'rename': return publicDetails(await post(path + '/rename', { name: requireValue(options.name, '请提供 --name。') }));
309
+ case 'pause':
310
+ case 'resume': return publicDetails(await post(path + '/receiving', { receiving: action === 'resume' }));
311
+ case 'connections': return get(path + '/connections');
312
+ case 'connect': return exportSecret(options.out, async () => {
313
+ const { key: secret, ...connection } = await post(path + '/connections', { name: requireValue(options.name, '请提供 --name。') });
314
+ return { secret, ...connection };
315
+ }, channelKeyPattern);
316
+ case 'disconnect': return post(path + `/connections/${uuid(child, '连接 ID')}/revoke`);
317
+ case 'download':
318
+ case 'share':
319
+ case 'unshare': {
320
+ const file = path + `/files/${uuid(child, '文件 ID')}`;
321
+ if (action === 'download') return saveDownload(options.out, () => request(site, file + '/download', { key }));
322
+ if (action === 'unshare') return post(file + '/revoke');
323
+ return exportSecret(options.out, async () => {
324
+ const { path: shared } = await post(file + '/share');
325
+ if (!sharePathPattern.test(shared ?? '')) throw new CommandError('PassMem 返回了无效的文件链接。');
326
+ return { secret: site + shared };
327
+ }, /\/f\/pmf_[A-Za-z0-9_-]{43}$/);
328
+ }
329
+ default: throw new CommandError('未知通道命令,运行 passmem --help 查看用法。');
330
+ }
331
+ }
332
+
333
+ async function readShare(site, options) {
334
+ const link = await provideSecret(options['link-file'], options['link-stdin'], '输入只读链接:');
335
+ const url = URL.parse(link);
336
+ if (!url || url.origin !== site || url.username || url.password || url.search || url.hash || !sharePathPattern.test(url.pathname)) {
337
+ throw new CommandError('请提供当前 PassMem 站点的文件只读链接。');
338
+ }
339
+ return saveDownload(options.out, () => request(site, url.pathname + '/download'));
340
+ }
341
+
342
+ function printInboxMessage(message) {
343
+ if (!message) {
344
+ console.log('暂无待确认的消息。');
345
+ return;
346
+ }
347
+
348
+ const { id, sender, receivedAt, body, files } = message;
349
+ const lines = [`消息 ID:${id}`, `发送人:${sender ?? '匿名投递'}`, `收到时间:${receivedAt}`];
350
+ if (body) lines.push('', body);
351
+ if (files.length) lines.push('', '附件', ...files.map((file) => `- ${file.name}(${file.id})`));
352
+
353
+ // Message text and filenames can come from anonymous senders.
354
+ const output = stripVTControlCharacters(lines.join('\n')).replace(/\p{Cc}/gu, (character) =>
355
+ character === '\n' || character === '\t' ? character : '');
356
+ console.log(output);
357
+ }
358
+
359
+ async function inboxCommand(site, options, [action, id]) {
360
+ const key = await connectionKey(options);
361
+ const path = agent + '/channel/';
362
+ switch (action) {
363
+ case 'next': {
364
+ const result = await readJson(site, path + 'next', { key });
365
+ if (options.json || !process.stdout.isTTY) return result;
366
+ printInboxMessage(result.message);
367
+ return;
368
+ }
369
+ case 'ack': return readJson(site, path + 'ack', { key, json: { messageId: uuid(id, '消息 ID') } });
370
+ case 'download': return saveDownload(options.out, () => request(site, path + 'files/' + uuid(id, '文件 ID'), { key }));
371
+ default: throw new CommandError('未知收件命令,运行 passmem --help 查看用法。');
372
+ }
373
+ }
374
+
375
+ async function main(argv) {
376
+ const { values, positionals: [command, ...rest] } = parseArgs({
377
+ args: argv, allowPositionals: true,
378
+ options: {
379
+ help: { type: 'boolean', short: 'h' }, site: { type: 'string' }, email: { type: 'string' },
380
+ 'key-stdin': { type: 'boolean' }, json: { type: 'boolean' },
381
+ name: { type: 'string' }, org: { type: 'string' }, out: { type: 'string' }, before: { type: 'string' },
382
+ 'mem-id-file': { type: 'string' }, 'mem-id-stdin': { type: 'boolean' }, signed: { type: 'boolean' },
383
+ body: { type: 'string' }, 'body-file': { type: 'string' }, file: { type: 'string', multiple: true },
384
+ 'request-id': { type: 'string' }, 'link-file': { type: 'string' }, 'link-stdin': { type: 'boolean' },
385
+ 'key-file': { type: 'string' }, install: { type: 'string' },
386
+ },
387
+ });
388
+ if (values.help || !command) { console.log(help); return; }
389
+ const site = siteOrigin(values.site ?? process.env.PASSMEM_SITE ?? defaultSite);
390
+ let result;
391
+ switch (command) {
392
+ case 'get-skill': result = await getSkill(site, values.install); break;
393
+ case 'login': result = await login(site, values); break;
394
+ case 'whoami': result = await readJson(site, agent + '/me', { key: await accountKey(site) }); break;
395
+ case 'logout': {
396
+ result = await readJson(site, agent + '/auth/revoke', { key: await accountKey(site), json: {} });
397
+ if (!process.env.PASSMEM_AGENT_KEY) await rm(keyPath(site), { force: true });
398
+ break;
399
+ }
400
+ case 'send': result = await deliver(site, values); break;
401
+ case 'channel': result = await channelCommand(site, values, rest); break;
402
+ case 'inbox': result = await inboxCommand(site, values, rest); break;
403
+ case 'shared':
404
+ if (rest[0] !== 'download') throw new CommandError('请使用 passmem shared download。');
405
+ result = await readShare(site, values);
406
+ break;
407
+ default: throw new CommandError('未知命令,运行 passmem --help 查看用法。');
408
+ }
409
+ if (result !== undefined) console.log(JSON.stringify(result, null, 2));
410
+ }
411
+
412
+ main(process.argv.slice(2)).catch((error) => {
413
+ const message = error instanceof CommandError ? error.message
414
+ : error.code === 'EEXIST' ? '输出文件已存在,请选择新的路径。'
415
+ : error.code === 'ENOENT' ? '找不到指定的本地文件。'
416
+ : error.code?.startsWith('ERR_PARSE_ARGS') ? '命令参数无效,运行 passmem --help 查看用法。'
417
+ : '操作失败,请检查连接、输入和本地文件。';
418
+ console.error(message);
419
+ process.exitCode = 1;
420
+ });
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: passmem
3
+ description: 使用 PassMem CLI 创建记忆通道、投递消息和文件、代所有者接收来件及分享单个文件。
4
+ ---
5
+
6
+ # PassMem
7
+
8
+ 在终端使用 PassMem CLI 执行业务操作。网页用于登录、查看通道、预览和下载附件及管理组织。用下面的命令投递、管理通道和分享文件。
9
+
10
+ ## 运行 CLI 和登录
11
+
12
+ PassMem 站点为 `http://127.0.0.1:3000`。使用 Node.js 24 或更高版本。下文的 `passmem` 指已安装的 npm CLI;如果用 `npx` 获取本 Skill,后续命令也可以用同一个 npm 包或安装包来执行,并用 `--site` 指定站点。
13
+
14
+ 从 PassMem 站点下载单文件 CLI 时,用以下命令准备当前终端:
15
+
16
+ ```sh
17
+ export PASSMEM_SITE='http://127.0.0.1:3000'
18
+ umask 077
19
+ mkdir -p "$HOME/.passmem"
20
+ curl --fail --silent --show-error "$PASSMEM_SITE/passmem-cli.mjs" -o "$HOME/.passmem/passmem-cli.mjs"
21
+ passmem() { node "$HOME/.passmem/passmem-cli.mjs" "$@"; }
22
+ ```
23
+
24
+ 站点不同可用 `--site` 指定。CLI 禁止 HTTP 重定向。匿名投递和用链接读取单个文件无需登录。其他账号操作需要个人 API Key。用户可在工作台右上角点「API Key」直接查看和复制 Key,也可在页面生成,再亲自在终端执行 `passmem login --key-stdin` 并隐藏粘贴。也可运行 `passmem login --email 注册邮箱`,在终端隐藏输入 8 位验证码。CLI 把 Key 保存到权限为 `0600` 的站点专用文件,也支持从私有环境变量 `PASSMEM_AGENT_KEY` 读取。用 `passmem whoami` 核对账号和组织,多个组织时用 `--org 组织ID`。任何入口生成的新 Key 都会替换旧 Key,`passmem logout` 可撤销当前 Key。
25
+
26
+ 将 Mem ID、验证码、Key 和完整文件分享链接视为私有凭证。用权限为 `0600` 的文件、私有环境变量或隐藏终端输入传递。凭证不得进入聊天、命令参数或日志。输出文件放在可控目录。获得用户明确授权后再执行发送、修改、分享或删除。
27
+
28
+ ## 通道与投递
29
+
30
+ - `passmem channel create --name '项目交接' --out /私有目录/mem-id` 创建通道并将 14 位 Mem ID 写入私有文件。终端结果包含通道 ID 和可在网页打开的通道地址。
31
+ - `passmem channel list` 查找通道。用 `passmem channel show 通道ID` 查看来件和文件 ID,使用返回的 `before` 通过 `--before` 向前翻页。
32
+ - `passmem send --mem-id-file /私有目录/mem-id --body-file /路径/交接.md --file /路径/成果.pptx` 投递正文和附件。可重复使用 `--file`。用 `--mem-id-stdin` 可在终端隐藏输入 Mem ID,正文也可用 `--body` 提供。要署名时加 `--signed`。正文或附件至少一项。每次最多 20 个文件,单个最多 25 MiB,Markdown 最多 256 KiB,合计最多 100 MiB。
33
+ - 成功后向用户提供回执。网络中断时,保持正文和附件不变,用 `--request-id` 传入 CLI 提示的原请求 ID 重试。
34
+ - `passmem channel rename 通道ID --name 新名称` 改名。用 `channel pause 通道ID` 暂停接收,`channel resume 通道ID` 恢复。用 `channel mem-id 通道ID --out 新文件` 导出当前地址,或用 `channel rotate 通道ID --out 新文件` 更换地址。
35
+
36
+ ## Agent 代收与文件分享
37
+
38
+ - `passmem channel connect 通道ID --name '接收 Agent' --out /私有目录/connection.key` 创建连接。用 `channel connections 通道ID` 查看连接和最近收件时间,`channel disconnect 通道ID 连接ID` 撤销连接。
39
+ - `passmem inbox next --key-file /私有目录/connection.key` 每次取一条待确认消息并退出。终端直接显示正文、附件名和对应 ID。Agent 可加 `--json`,无来件时返回 `{"message":null}`。凭证也可通过私有环境变量 `PASSMEM_CHANNEL_KEY` 提供。
40
+ - 用 `passmem inbox download 文件ID --key-file 凭证文件 --out 本地文件` 下载所需原件。处理成功后用 `passmem inbox ack 消息ID --key-file 凭证文件` 确认,再取后一条。重复取件会返回同一条未确认消息,用消息 ID 核对重试时的外部写入结果。由 Agent 或宿主决定何时调用。
41
+ - `passmem channel download 通道ID 文件ID --out 本地文件` 下载原件。用 `passmem channel share 通道ID 文件ID --out /私有目录/share-link` 为单个文件生成链接。取得明确授权后,通过用户指定的方式把链接交给接收方。用 `channel unshare 通道ID 文件ID` 撤销。
42
+ - 收到链接的人或 Agent 可用 `passmem shared download --link-file /私有目录/share-link --out 本地文件` 读取原件,或使用 `--link-stdin` 隐藏输入链接。
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.