@celljs/ta-secrets 4.17.0 → 4.19.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/README.md +1 -0
- package/extension/index.mjs +285 -5
- package/host/index.mjs +52 -5
- package/package.json +3 -3
- package/web/index.js +16 -2
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ Ta 自带的 pi 包(默认开启,可在 设置 → 扩展 关闭):保险
|
|
|
11
11
|
- **只发往绑定的主机**:给密钥绑定主机后(GitHub、GitLab、Gitee 的 token 默认绑定),命令里拿到的只是占位,它的 HTTPS 经 Ta 本机的代理出去,代理只对这些主机把占位换成真值(请求头和 URL);运行 git 的命令也这样自动拿到 token。需要本机有 `openssl`。
|
|
12
12
|
- **SSH**:私钥由每条可能连 SSH 的命令(ssh、scp、rsync、git)自己的 ssh-agent 持有,不进环境变量,命令结束 agent 就关掉。
|
|
13
13
|
- **最近使用**:每次给出密钥都记下哪些、怎么给的、命令和对话,设置 → 保险箱 里能看到。
|
|
14
|
+
- **Ta 自己用的登录**:远程桌面的账号密码由 Ta 服务经 `TaExtensionHost.credentials` 存取(类型 `sign-in`),列在保险箱里可删;不告诉模型,命令里点名会被拒,页面也建不了这一类。
|
|
14
15
|
- **擦**:工具结果和发给模型的内容里出现的值(原文、base64、URL 编码)都换成名字。
|
|
15
16
|
|
|
16
17
|
## 数据与调用
|
package/extension/index.mjs
CHANGED
|
@@ -273,7 +273,286 @@ var TaLanguageUtil;
|
|
|
273
273
|
TaLanguageUtil2.list = list;
|
|
274
274
|
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
275
275
|
|
|
276
|
+
// ../ta-protocol/esm/common/message-protocol.js
|
|
277
|
+
var TaMessageContext;
|
|
278
|
+
(function(TaMessageContext2) {
|
|
279
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
280
|
+
function wrap(context, message) {
|
|
281
|
+
return `<context>
|
|
282
|
+
${context}
|
|
283
|
+
</context>
|
|
284
|
+
${message}`;
|
|
285
|
+
}
|
|
286
|
+
TaMessageContext2.wrap = wrap;
|
|
287
|
+
function strip(message) {
|
|
288
|
+
return message.replace(BLOCK, "");
|
|
289
|
+
}
|
|
290
|
+
TaMessageContext2.strip = strip;
|
|
291
|
+
function read(message) {
|
|
292
|
+
var _a;
|
|
293
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
294
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
295
|
+
}
|
|
296
|
+
TaMessageContext2.read = read;
|
|
297
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
298
|
+
var TaMessageSource;
|
|
299
|
+
(function(TaMessageSource2) {
|
|
300
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
301
|
+
const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
302
|
+
function mark(message, from, detail) {
|
|
303
|
+
return marked(message, line(from, detail));
|
|
304
|
+
}
|
|
305
|
+
TaMessageSource2.mark = mark;
|
|
306
|
+
function notice(message, from, detail) {
|
|
307
|
+
return marked(message, line(from, detail, true));
|
|
308
|
+
}
|
|
309
|
+
TaMessageSource2.notice = notice;
|
|
310
|
+
function line(from, detail, notice2 = false) {
|
|
311
|
+
return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
312
|
+
}
|
|
313
|
+
TaMessageSource2.line = line;
|
|
314
|
+
function of(message) {
|
|
315
|
+
const context = TaMessageContext.read(message);
|
|
316
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
317
|
+
return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
|
|
318
|
+
}
|
|
319
|
+
TaMessageSource2.of = of;
|
|
320
|
+
function isNotice(message) {
|
|
321
|
+
var _a;
|
|
322
|
+
return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
|
|
323
|
+
}
|
|
324
|
+
TaMessageSource2.isNotice = isNotice;
|
|
325
|
+
TaMessageSource2.SECTION = "ta-sources";
|
|
326
|
+
TaMessageSource2.PROMPT = [
|
|
327
|
+
"Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
|
|
328
|
+
"One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
|
|
329
|
+
"- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
|
|
330
|
+
"- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
|
|
331
|
+
"- Never quote it as the user's words nor answer it as if they had said it."
|
|
332
|
+
].join(`
|
|
333
|
+
`);
|
|
334
|
+
function marked(message, source) {
|
|
335
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
336
|
+
return message;
|
|
337
|
+
}
|
|
338
|
+
const context = TaMessageContext.read(message);
|
|
339
|
+
return TaMessageContext.wrap(context === undefined ? source : `${context}
|
|
340
|
+
${source}`, TaMessageContext.strip(message));
|
|
341
|
+
}
|
|
342
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
343
|
+
var TaImageNote;
|
|
344
|
+
(function(TaImageNote2) {
|
|
345
|
+
const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
|
|
346
|
+
function strip(text) {
|
|
347
|
+
const lines = text.split(`
|
|
348
|
+
`);
|
|
349
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
350
|
+
if (kept.length === lines.length) {
|
|
351
|
+
return text;
|
|
352
|
+
}
|
|
353
|
+
return kept.join(`
|
|
354
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
355
|
+
}
|
|
356
|
+
TaImageNote2.strip = strip;
|
|
357
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
358
|
+
var TaImageSize;
|
|
359
|
+
(function(TaImageSize2) {
|
|
360
|
+
const JPEG_BYTES = 256 * 1024;
|
|
361
|
+
function of(base64) {
|
|
362
|
+
var _a, _b, _c;
|
|
363
|
+
let bytes;
|
|
364
|
+
try {
|
|
365
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
366
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
367
|
+
} catch (_d) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
|
|
371
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
372
|
+
}
|
|
373
|
+
TaImageSize2.of = of;
|
|
374
|
+
function u16be(bytes, at) {
|
|
375
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
376
|
+
}
|
|
377
|
+
function u16le(bytes, at) {
|
|
378
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
379
|
+
}
|
|
380
|
+
function u24le(bytes, at) {
|
|
381
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
382
|
+
}
|
|
383
|
+
function u32be(bytes, at) {
|
|
384
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
385
|
+
}
|
|
386
|
+
function text(bytes, at, length) {
|
|
387
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
388
|
+
}
|
|
389
|
+
function png(bytes) {
|
|
390
|
+
return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
391
|
+
}
|
|
392
|
+
function gif(bytes) {
|
|
393
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
394
|
+
}
|
|
395
|
+
function webp(bytes) {
|
|
396
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
switch (text(bytes, 12, 4)) {
|
|
400
|
+
case "VP8 ":
|
|
401
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
402
|
+
case "VP8L": {
|
|
403
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
404
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
405
|
+
}
|
|
406
|
+
case "VP8X":
|
|
407
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
408
|
+
default:
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function jpeg(bytes) {
|
|
413
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
let at = 2;
|
|
417
|
+
while (at + 9 < bytes.length) {
|
|
418
|
+
if (bytes[at] !== 255) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const marker = bytes[at + 1];
|
|
422
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
423
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
424
|
+
}
|
|
425
|
+
at += 2 + u16be(bytes, at + 2);
|
|
426
|
+
}
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
430
|
+
var TaAgentSummary;
|
|
431
|
+
(function(TaAgentSummary2) {
|
|
432
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
433
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
434
|
+
function read(text) {
|
|
435
|
+
if (!START.test(text)) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
439
|
+
}
|
|
440
|
+
TaAgentSummary2.read = read;
|
|
441
|
+
function strip(text) {
|
|
442
|
+
return text.replace(BLOCK, "");
|
|
443
|
+
}
|
|
444
|
+
TaAgentSummary2.strip = strip;
|
|
445
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
446
|
+
var TaSkillUse;
|
|
447
|
+
(function(TaSkillUse2) {
|
|
448
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
449
|
+
function parse(message) {
|
|
450
|
+
var _a;
|
|
451
|
+
const match = BLOCK.exec(message);
|
|
452
|
+
if (!match) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
456
|
+
}
|
|
457
|
+
TaSkillUse2.parse = parse;
|
|
458
|
+
function command(use) {
|
|
459
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
460
|
+
}
|
|
461
|
+
TaSkillUse2.command = command;
|
|
462
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
463
|
+
var TaTaskNote;
|
|
464
|
+
(function(TaTaskNote2) {
|
|
465
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
466
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
467
|
+
function write(note) {
|
|
468
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
469
|
+
if (note.was !== undefined) {
|
|
470
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
471
|
+
}
|
|
472
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
473
|
+
if (note.status !== undefined) {
|
|
474
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
475
|
+
}
|
|
476
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
477
|
+
${note.body}
|
|
478
|
+
</task_${note.kind}>`;
|
|
479
|
+
}
|
|
480
|
+
TaTaskNote2.write = write;
|
|
481
|
+
function parse(text) {
|
|
482
|
+
const match = NOTE.exec(text.trim());
|
|
483
|
+
if (!match) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
const attributes = {};
|
|
487
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
488
|
+
attributes[name] = unquote(value);
|
|
489
|
+
}
|
|
490
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
const { id, title, status, was } = attributes;
|
|
494
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
495
|
+
}
|
|
496
|
+
TaTaskNote2.parse = parse;
|
|
497
|
+
function quote(text) {
|
|
498
|
+
return text.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
499
|
+
}
|
|
500
|
+
function unquote(text) {
|
|
501
|
+
return text.replace(/"/g, '"').replace(/&/g, "&");
|
|
502
|
+
}
|
|
503
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
504
|
+
var TaSecretRef;
|
|
505
|
+
(function(TaSecretRef2) {
|
|
506
|
+
TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
|
|
507
|
+
const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
|
|
508
|
+
const KINDS = [
|
|
509
|
+
[/^PHONE(?:_\d+)?$/, "phone"],
|
|
510
|
+
[/^EMAIL(?:_\d+)?$/, "email"],
|
|
511
|
+
[/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
|
|
512
|
+
[/^BANK_CARD(?:_\d+)?$/, "bankCard"]
|
|
513
|
+
];
|
|
514
|
+
function has(text) {
|
|
515
|
+
return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
|
|
516
|
+
}
|
|
517
|
+
TaSecretRef2.has = has;
|
|
518
|
+
function kind(name) {
|
|
519
|
+
var _a;
|
|
520
|
+
var _b;
|
|
521
|
+
return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
|
|
522
|
+
}
|
|
523
|
+
TaSecretRef2.kind = kind;
|
|
524
|
+
function split(text) {
|
|
525
|
+
if (!has(text)) {
|
|
526
|
+
return [{ text }];
|
|
527
|
+
}
|
|
528
|
+
const parts = [];
|
|
529
|
+
let at = 0;
|
|
530
|
+
for (const match of text.matchAll(REF)) {
|
|
531
|
+
if (match.index > at) {
|
|
532
|
+
parts.push({ text: text.slice(at, match.index) });
|
|
533
|
+
}
|
|
534
|
+
parts.push({ secret: match[1], kind: kind(match[1]) });
|
|
535
|
+
at = match.index + match[0].length;
|
|
536
|
+
}
|
|
537
|
+
if (at < text.length) {
|
|
538
|
+
parts.push({ text: text.slice(at) });
|
|
539
|
+
}
|
|
540
|
+
return parts;
|
|
541
|
+
}
|
|
542
|
+
TaSecretRef2.split = split;
|
|
543
|
+
function plain(text, label) {
|
|
544
|
+
return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
|
|
545
|
+
}
|
|
546
|
+
TaSecretRef2.plain = plain;
|
|
547
|
+
})(TaSecretRef || (TaSecretRef = {}));
|
|
548
|
+
|
|
276
549
|
// web-src/server-texts.ts
|
|
550
|
+
var KINDS = {
|
|
551
|
+
"zh-CN": { phone: "手机号", email: "邮箱", idNumber: "证件号", bankCard: "银行卡号", secret: "密钥" },
|
|
552
|
+
"zh-TW": { phone: "手機號碼", email: "電子郵件", idNumber: "證件號碼", bankCard: "銀行卡號", secret: "金鑰" },
|
|
553
|
+
"en-US": { phone: "phone number", email: "email", idNumber: "ID number", bankCard: "bank card", secret: "secret" },
|
|
554
|
+
"ja-JP": { phone: "電話番号", email: "メール", idNumber: "身分証番号", bankCard: "銀行カード番号", secret: "秘密" }
|
|
555
|
+
};
|
|
277
556
|
var SecretsServerTexts;
|
|
278
557
|
((SecretsServerTexts) => {
|
|
279
558
|
function language(env = process.env) {
|
|
@@ -281,12 +560,13 @@ var SecretsServerTexts;
|
|
|
281
560
|
}
|
|
282
561
|
SecretsServerTexts.language = language;
|
|
283
562
|
function captured(names) {
|
|
284
|
-
const
|
|
563
|
+
const words = TaLanguageUtil.say(KINDS);
|
|
564
|
+
const list = TaLanguageUtil.list(language(), [...new Set(names.map((name) => words[TaSecretRef.kind(name)]))]);
|
|
285
565
|
return TaLanguageUtil.say({
|
|
286
|
-
"zh-CN":
|
|
287
|
-
"zh-TW":
|
|
288
|
-
"en-US": `Kept ${list} in the vault: Ta sees
|
|
289
|
-
"ja-JP":
|
|
566
|
+
"zh-CN": `已把你发的${list}收进保险箱:Ta 看不到内容,用到时才填入`,
|
|
567
|
+
"zh-TW": `已把你發的${list}收進保險箱:Ta 看不到內容,用到時才填入`,
|
|
568
|
+
"en-US": `Kept the ${list} you sent in the vault: Ta never sees it, and fills it in where it is used`,
|
|
569
|
+
"ja-JP": `送信された${list}を金庫に保管しました。Ta には中身が見えず、使う時に入力されます`
|
|
290
570
|
});
|
|
291
571
|
}
|
|
292
572
|
SecretsServerTexts.captured = captured;
|
package/host/index.mjs
CHANGED
|
@@ -961,12 +961,15 @@ class Vault {
|
|
|
961
961
|
scrubbing;
|
|
962
962
|
queue = Promise.resolve();
|
|
963
963
|
placeholderKey = randomBytes3(32);
|
|
964
|
+
unregister;
|
|
964
965
|
constructor(host, vaultStore, proxy) {
|
|
965
966
|
this.host = host;
|
|
966
967
|
this.vaultStore = vaultStore;
|
|
967
968
|
this.proxy = proxy;
|
|
968
969
|
}
|
|
969
970
|
forget() {
|
|
971
|
+
this.unregister?.();
|
|
972
|
+
this.unregister = undefined;
|
|
970
973
|
this.values = undefined;
|
|
971
974
|
this.scrubbing = undefined;
|
|
972
975
|
this.proxy?.dispose();
|
|
@@ -997,14 +1000,15 @@ class Vault {
|
|
|
997
1000
|
const gitUser = input.gitUser?.trim() || before?.gitUser;
|
|
998
1001
|
const entry = {
|
|
999
1002
|
name,
|
|
1000
|
-
kind: input.kind === "personal"
|
|
1003
|
+
kind: input.kind === "personal" || input.kind === "sign-in" ? input.kind : "credential",
|
|
1001
1004
|
...input.note?.trim() ? { note: input.note.trim().slice(0, 200) } : before?.note ? { note: before.note } : {},
|
|
1002
1005
|
source: input.source ?? "typed",
|
|
1003
1006
|
createdAt: Date.now(),
|
|
1004
1007
|
...hosts.length ? { hosts } : {},
|
|
1005
1008
|
...hosts.length && gitUser ? { gitUser: gitUser.slice(0, 100) } : {},
|
|
1006
1009
|
...ssh ? { ssh: true } : {},
|
|
1007
|
-
...input.kind === "personal" && input.hint ? { hint: String(input.hint).slice(0, 60) } : {}
|
|
1010
|
+
...input.kind === "personal" && input.hint ? { hint: String(input.hint).slice(0, 60) } : {},
|
|
1011
|
+
...input.kind === "sign-in" && input.signIn ? { signIn: input.signIn } : {}
|
|
1008
1012
|
};
|
|
1009
1013
|
await this.save([...entries.filter((one) => one.name !== name), entry]);
|
|
1010
1014
|
(await this.loaded()).set(name, entry.ssh && !value.endsWith(`
|
|
@@ -1028,6 +1032,43 @@ class Vault {
|
|
|
1028
1032
|
return true;
|
|
1029
1033
|
});
|
|
1030
1034
|
}
|
|
1035
|
+
keepSignInsFor(credentials) {
|
|
1036
|
+
this.unregister?.();
|
|
1037
|
+
this.unregister = credentials.register({
|
|
1038
|
+
get: (id) => this.signIn(id),
|
|
1039
|
+
set: (id, credential, about) => this.keepSignIn(id, credential, about),
|
|
1040
|
+
remove: (id) => this.forgetSignIn(id)
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
async signIn(id) {
|
|
1044
|
+
const entry = (await this.list()).find((one) => one.kind === "sign-in" && one.signIn?.id === id);
|
|
1045
|
+
const password = entry && (await this.loaded()).get(entry.name);
|
|
1046
|
+
if (!entry?.signIn || password === undefined) {
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
this.record([entry.name], ["sign-in"], `${entry.signIn.feature} ${entry.signIn.name}`);
|
|
1050
|
+
return { password, ...entry.signIn.user !== undefined ? { username: entry.signIn.user } : {} };
|
|
1051
|
+
}
|
|
1052
|
+
async keepSignIn(id, credential, about) {
|
|
1053
|
+
const entries = await this.list();
|
|
1054
|
+
const before = entries.find((one) => one.kind === "sign-in" && one.signIn?.id === id);
|
|
1055
|
+
const name = before?.name ?? SecretNames.free(`${about.feature}_${about.name}`, new Set(entries.map((one) => one.name)));
|
|
1056
|
+
const user = typeof credential.username === "string" ? { user: credential.username.slice(0, 200) } : {};
|
|
1057
|
+
await this.add({
|
|
1058
|
+
name,
|
|
1059
|
+
value: credential.password,
|
|
1060
|
+
kind: "sign-in",
|
|
1061
|
+
source: "asked",
|
|
1062
|
+
hosts: [],
|
|
1063
|
+
signIn: { id, feature: about.feature, name: String(about.name).slice(0, 100), ...user }
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
async forgetSignIn(id) {
|
|
1067
|
+
const entry = (await this.list()).find((one) => one.kind === "sign-in" && one.signIn?.id === id);
|
|
1068
|
+
if (entry) {
|
|
1069
|
+
await this.remove(entry.name);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1031
1072
|
async capturing() {
|
|
1032
1073
|
return await this.host.getExtensionData(NAME, Keys.CAPTURE) !== false;
|
|
1033
1074
|
}
|
|
@@ -1137,6 +1178,10 @@ class Vault {
|
|
|
1137
1178
|
const entries = await this.list();
|
|
1138
1179
|
const values = await this.loaded();
|
|
1139
1180
|
const byName = new Map(entries.map((entry) => [entry.name, entry]));
|
|
1181
|
+
const signIns = named.filter((name) => byName.get(name)?.kind === "sign-in");
|
|
1182
|
+
if (signIns.length) {
|
|
1183
|
+
return { block: `${signIns.map(SecretNames.handle).join(", ")}: a sign-in Ta gives by itself, never to a command. Tell the user.` };
|
|
1184
|
+
}
|
|
1140
1185
|
const missing = named.filter((name) => !values.has(name));
|
|
1141
1186
|
if (missing.length) {
|
|
1142
1187
|
return {
|
|
@@ -1204,12 +1249,12 @@ class Vault {
|
|
|
1204
1249
|
return SecretNames.uses(await this.host.getExtensionData(NAME, Keys.USES));
|
|
1205
1250
|
}
|
|
1206
1251
|
async prompt() {
|
|
1207
|
-
const entries = await this.list();
|
|
1252
|
+
const entries = (await this.list()).filter((entry) => entry.kind !== "sign-in");
|
|
1208
1253
|
const kept = entries.length ? entries.map((entry) => `- ${Vault.described(entry)}`).join(`
|
|
1209
1254
|
`) : "- none yet";
|
|
1210
1255
|
return [
|
|
1211
1256
|
`The user's secrets (tokens, passwords, keys, personal details) are kept in Ta's vault, never in this conversation. Each has a name: in a bash command write it as an environment variable, quoted ("$TA_SECRET_GITHUB_TOKEN"), and Ta gives that command its value. You never see a value: where one would show (output, a file read back) you see its name instead.`,
|
|
1212
|
-
|
|
1257
|
+
'Use a secret only for what the user wants it for: never print it, write it into a file of the project or send it anywhere else. A secret the user sent in a message was taken into the vault and named in its place: read the name as what they sent ($TA_SECRET_PHONE is their phone number), use it as such, and say it as such to them ("your phone number"); never tell them of names or the vault unless they ask.',
|
|
1213
1258
|
"Some are for git or SSH, as listed: git over https to their hosts, and ssh, scp, rsync and git over SSH, get them by themselves, with nothing to name; never put a token into a URL or a remote.",
|
|
1214
1259
|
"Personal details of the user (phone numbers, emails, ID numbers, bank cards) are kept so too, listed with their masked hint: write the name where the detail goes, in a command or in any tool's arguments (a file written, a form, a message), and Ta puts the detail in as the tool runs. Never ask the user to repeat one.",
|
|
1215
1260
|
"A secret bound to hosts reaches only them: a command naming it holds a placeholder, and its HTTPS requests go through Ta's proxy, which puts the value into the headers and the URL for those hosts alone (not into a body). Use it in a header or a query of a request to them, with curl, git or a program that follows HTTPS_PROXY; anything else sees only the placeholder.",
|
|
@@ -1304,7 +1349,8 @@ class VaultService {
|
|
|
1304
1349
|
return this.vault.list();
|
|
1305
1350
|
}
|
|
1306
1351
|
add(input) {
|
|
1307
|
-
|
|
1352
|
+
const { signIn: _signIn, ...rest } = input ?? {};
|
|
1353
|
+
return this.vault.add({ ...rest, kind: rest.kind === "sign-in" ? "credential" : rest.kind });
|
|
1308
1354
|
}
|
|
1309
1355
|
remove(name) {
|
|
1310
1356
|
return this.vault.remove(name);
|
|
@@ -1334,6 +1380,7 @@ function activate(host) {
|
|
|
1334
1380
|
let vault;
|
|
1335
1381
|
const proxy = new VaultProxy({ certs: new ProxyCerts, onUse: (use) => void vault?.recordRequest(use) });
|
|
1336
1382
|
vault = new Vault(host, VaultStores.of(host.agentDir), proxy);
|
|
1383
|
+
vault.keepSignInsFor(host.credentials);
|
|
1337
1384
|
return new VaultService(vault);
|
|
1338
1385
|
}
|
|
1339
1386
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-secrets",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
4
4
|
"description": "A pi package for Ta: a vault of secrets kept in the keychain, which Ta uses in commands by name without the model ever seeing them",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@celljs/ta-protocol": "4.
|
|
31
|
-
"@celljs/ta-web": "4.
|
|
30
|
+
"@celljs/ta-protocol": "4.19.0",
|
|
31
|
+
"@celljs/ta-web": "4.19.0",
|
|
32
32
|
"@types/react": "^19.3.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
package/web/index.js
CHANGED
|
@@ -45,6 +45,7 @@ var EN = {
|
|
|
45
45
|
personalLabel: "Keep personal details I send",
|
|
46
46
|
personalHint: "Phone numbers, emails, ID numbers and bank cards too: Ta sees a name and a masked hint, and fills the detail in where it is used.",
|
|
47
47
|
howTool: "filled in",
|
|
48
|
+
howSignIn: "signed in",
|
|
48
49
|
keptLabel: "Kept",
|
|
49
50
|
keptKeychain: "In the keychain of this computer. Ta uses them in commands without seeing them.",
|
|
50
51
|
keptFile: "In a file of this computer only you can read. Ta uses them in commands without seeing them.",
|
|
@@ -54,6 +55,8 @@ var EN = {
|
|
|
54
55
|
neverUsed: "Not used yet",
|
|
55
56
|
kindCredential: "Credential",
|
|
56
57
|
kindPersonal: "Personal detail",
|
|
58
|
+
kindDesktop: "Remote desktop {name}",
|
|
59
|
+
signInUser: "account {user}",
|
|
57
60
|
remove: "Remove",
|
|
58
61
|
removeTitle: "Remove {name}?",
|
|
59
62
|
removeHint: "Commands that use it will no longer get it.",
|
|
@@ -82,6 +85,7 @@ var ZH = {
|
|
|
82
85
|
personalLabel: "收起我发出的个人信息",
|
|
83
86
|
personalHint: "手机号、邮箱、证件号、银行卡也先收进来:Ta 只看到名字和打码后的样子,用到时再填回去。",
|
|
84
87
|
howTool: "填入",
|
|
88
|
+
howSignIn: "登录",
|
|
85
89
|
keptLabel: "已保存",
|
|
86
90
|
keptKeychain: "存在这台电脑的钥匙串里;Ta 在命令里使用,看不到内容。",
|
|
87
91
|
keptFile: "存在这台电脑上只有你能读的文件里;Ta 在命令里使用,看不到内容。",
|
|
@@ -91,6 +95,8 @@ var ZH = {
|
|
|
91
95
|
neverUsed: "还没用过",
|
|
92
96
|
kindCredential: "凭据",
|
|
93
97
|
kindPersonal: "个人信息",
|
|
98
|
+
kindDesktop: "远程桌面 {name}",
|
|
99
|
+
signInUser: "账号 {user}",
|
|
94
100
|
remove: "删除",
|
|
95
101
|
removeTitle: "删除 {name}?",
|
|
96
102
|
removeHint: "用到它的命令将拿不到它。",
|
|
@@ -119,6 +125,7 @@ var ZH_TW = {
|
|
|
119
125
|
personalLabel: "收起我發出的個人資訊",
|
|
120
126
|
personalHint: "手機號碼、電子郵件、證件號碼、銀行卡也先收進來:Ta 只看到名字和遮蔽後的樣子,用到時再填回去。",
|
|
121
127
|
howTool: "填入",
|
|
128
|
+
howSignIn: "登入",
|
|
122
129
|
keptLabel: "已儲存",
|
|
123
130
|
keptKeychain: "存在這台電腦的鑰匙圈裡;Ta 在命令裡使用,看不到內容。",
|
|
124
131
|
keptFile: "存在這台電腦上只有你能讀的檔案裡;Ta 在命令裡使用,看不到內容。",
|
|
@@ -128,6 +135,8 @@ var ZH_TW = {
|
|
|
128
135
|
neverUsed: "還沒用過",
|
|
129
136
|
kindCredential: "憑據",
|
|
130
137
|
kindPersonal: "個人資訊",
|
|
138
|
+
kindDesktop: "遠端桌面 {name}",
|
|
139
|
+
signInUser: "帳號 {user}",
|
|
131
140
|
remove: "刪除",
|
|
132
141
|
removeTitle: "刪除 {name}?",
|
|
133
142
|
removeHint: "用到它的命令將拿不到它。",
|
|
@@ -156,6 +165,7 @@ var JA = {
|
|
|
156
165
|
personalLabel: "送信した個人情報を保管",
|
|
157
166
|
personalHint: "電話番号、メール、身分証番号、銀行カードも保管します。Ta には名前と伏せ字だけが見え、使う時に元の値が入ります。",
|
|
158
167
|
howTool: "入力",
|
|
168
|
+
howSignIn: "サインイン",
|
|
159
169
|
keptLabel: "保管中",
|
|
160
170
|
keptKeychain: "このコンピュータのキーチェーンに保管。Ta はコマンドで使いますが、中身は見えません。",
|
|
161
171
|
keptFile: "このコンピュータ上の本人だけが読めるファイルに保管。Ta はコマンドで使いますが、中身は見えません。",
|
|
@@ -165,6 +175,8 @@ var JA = {
|
|
|
165
175
|
neverUsed: "未使用",
|
|
166
176
|
kindCredential: "認証情報",
|
|
167
177
|
kindPersonal: "個人情報",
|
|
178
|
+
kindDesktop: "リモートデスクトップ {name}",
|
|
179
|
+
signInUser: "アカウント {user}",
|
|
168
180
|
remove: "削除",
|
|
169
181
|
removeTitle: "{name} を削除しますか?",
|
|
170
182
|
removeHint: "これを使うコマンドは値を受け取れなくなります。",
|
|
@@ -373,7 +385,8 @@ function KeptSetting({ pi }) {
|
|
|
373
385
|
}, entry.name), /* @__PURE__ */ React.createElement("span", {
|
|
374
386
|
className: "ta-secrets-meta"
|
|
375
387
|
}, [
|
|
376
|
-
entry.note || (entry.ssh ? words.sshKey : entry.kind === "personal" ? words.kindPersonal : words.kindCredential),
|
|
388
|
+
entry.signIn ? SecretsWords.format(words.kindDesktop, { name: entry.signIn.name }) : entry.note || (entry.ssh ? words.sshKey : entry.kind === "personal" ? words.kindPersonal : words.kindCredential),
|
|
389
|
+
entry.signIn?.user ? SecretsWords.format(words.signInUser, { user: entry.signIn.user }) : undefined,
|
|
377
390
|
entry.hint,
|
|
378
391
|
entry.ssh && entry.note ? words.sshKey : undefined,
|
|
379
392
|
entry.hosts?.length ? SecretsWords.format(words.hostsLabel, { hosts: entry.hosts.join(", ") }) : undefined,
|
|
@@ -388,7 +401,8 @@ var HOW = {
|
|
|
388
401
|
git: "howGit",
|
|
389
402
|
ssh: "howSsh",
|
|
390
403
|
http: "howHttp",
|
|
391
|
-
tool: "howTool"
|
|
404
|
+
tool: "howTool",
|
|
405
|
+
"sign-in": "howSignIn"
|
|
392
406
|
};
|
|
393
407
|
function ago(language, at, justNow) {
|
|
394
408
|
const seconds = Math.round((at - Date.now()) / 1000);
|