@tpsdev-ai/cli 0.1.0 → 0.3.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 +46 -60
- package/bin/tps.cjs +22 -0
- package/bin/tps.ts +435 -0
- package/nono-profiles/tps-backup.toml +18 -0
- package/nono-profiles/tps-bootstrap.toml +20 -0
- package/nono-profiles/tps-office-manager.toml +21 -0
- package/nono-profiles/tps-restore.toml +18 -0
- package/nono-profiles/tps-status.toml +19 -0
- package/package.json +19 -15
- package/LICENSE +0 -201
- package/dist/bin/tps.d.ts +0 -3
- package/dist/bin/tps.d.ts.map +0 -1
- package/dist/bin/tps.js +0 -267
- package/dist/bin/tps.js.map +0 -1
- package/dist/src/cli/hire.d.ts +0 -16
- package/dist/src/cli/hire.d.ts.map +0 -1
- package/dist/src/cli/hire.js +0 -176
- package/dist/src/cli/hire.js.map +0 -1
- package/dist/src/cli/office.d.ts +0 -7
- package/dist/src/cli/office.d.ts.map +0 -1
- package/dist/src/cli/office.js +0 -51
- package/dist/src/cli/office.js.map +0 -1
- package/dist/src/cli/review.d.ts +0 -9
- package/dist/src/cli/review.d.ts.map +0 -1
- package/dist/src/cli/review.js +0 -109
- package/dist/src/cli/review.js.map +0 -1
- package/dist/src/cli/roster.d.ts +0 -6
- package/dist/src/cli/roster.d.ts.map +0 -1
- package/dist/src/cli/roster.js +0 -60
- package/dist/src/cli/roster.js.map +0 -1
- package/dist/src/commands/branch.d.ts +0 -14
- package/dist/src/commands/branch.d.ts.map +0 -1
- package/dist/src/commands/branch.js +0 -395
- package/dist/src/commands/branch.js.map +0 -1
- package/dist/src/commands/context.d.ts +0 -9
- package/dist/src/commands/context.d.ts.map +0 -1
- package/dist/src/commands/context.js +0 -57
- package/dist/src/commands/context.js.map +0 -1
- package/dist/src/commands/identity.d.ts +0 -13
- package/dist/src/commands/identity.d.ts.map +0 -1
- package/dist/src/commands/identity.js +0 -231
- package/dist/src/commands/identity.js.map +0 -1
- package/dist/src/commands/mail.d.ts +0 -12
- package/dist/src/commands/mail.d.ts.map +0 -1
- package/dist/src/commands/mail.js +0 -225
- package/dist/src/commands/mail.js.map +0 -1
- package/dist/src/commands/office.d.ts +0 -19
- package/dist/src/commands/office.d.ts.map +0 -1
- package/dist/src/commands/office.js +0 -598
- package/dist/src/commands/office.js.map +0 -1
- package/dist/src/commands/roster.d.ts +0 -10
- package/dist/src/commands/roster.d.ts.map +0 -1
- package/dist/src/commands/roster.js +0 -143
- package/dist/src/commands/roster.js.map +0 -1
- package/dist/src/generators/claude-code.d.ts +0 -17
- package/dist/src/generators/claude-code.d.ts.map +0 -1
- package/dist/src/generators/claude-code.js +0 -80
- package/dist/src/generators/claude-code.js.map +0 -1
- package/dist/src/generators/codex.d.ts +0 -22
- package/dist/src/generators/codex.d.ts.map +0 -1
- package/dist/src/generators/codex.js +0 -78
- package/dist/src/generators/codex.js.map +0 -1
- package/dist/src/generators/ollama.d.ts +0 -18
- package/dist/src/generators/ollama.d.ts.map +0 -1
- package/dist/src/generators/ollama.js +0 -97
- package/dist/src/generators/ollama.js.map +0 -1
- package/dist/src/generators/openclaw.d.ts +0 -15
- package/dist/src/generators/openclaw.d.ts.map +0 -1
- package/dist/src/generators/openclaw.js +0 -103
- package/dist/src/generators/openclaw.js.map +0 -1
- package/dist/src/generators/registry.d.ts +0 -36
- package/dist/src/generators/registry.d.ts.map +0 -1
- package/dist/src/generators/registry.js +0 -99
- package/dist/src/generators/registry.js.map +0 -1
- package/dist/src/schema/manifest.d.ts +0 -140
- package/dist/src/schema/manifest.d.ts.map +0 -1
- package/dist/src/schema/manifest.js +0 -62
- package/dist/src/schema/manifest.js.map +0 -1
- package/dist/src/schema/report.d.ts +0 -166
- package/dist/src/schema/report.d.ts.map +0 -1
- package/dist/src/schema/report.js +0 -90
- package/dist/src/schema/report.js.map +0 -1
- package/dist/src/schema/sanitizer.d.ts +0 -30
- package/dist/src/schema/sanitizer.d.ts.map +0 -1
- package/dist/src/schema/sanitizer.js +0 -97
- package/dist/src/schema/sanitizer.js.map +0 -1
- package/dist/src/soundstage/mock-llm.d.ts +0 -3
- package/dist/src/soundstage/mock-llm.d.ts.map +0 -1
- package/dist/src/soundstage/mock-llm.js +0 -68
- package/dist/src/soundstage/mock-llm.js.map +0 -1
- package/dist/src/utils/agent-info.d.ts +0 -28
- package/dist/src/utils/agent-info.d.ts.map +0 -1
- package/dist/src/utils/agent-info.js +0 -102
- package/dist/src/utils/agent-info.js.map +0 -1
- package/dist/src/utils/archive.d.ts +0 -27
- package/dist/src/utils/archive.d.ts.map +0 -1
- package/dist/src/utils/archive.js +0 -80
- package/dist/src/utils/archive.js.map +0 -1
- package/dist/src/utils/config-inject.d.ts +0 -27
- package/dist/src/utils/config-inject.d.ts.map +0 -1
- package/dist/src/utils/config-inject.js +0 -83
- package/dist/src/utils/config-inject.js.map +0 -1
- package/dist/src/utils/config.d.ts +0 -30
- package/dist/src/utils/config.d.ts.map +0 -1
- package/dist/src/utils/config.js +0 -55
- package/dist/src/utils/config.js.map +0 -1
- package/dist/src/utils/connection-state.d.ts +0 -27
- package/dist/src/utils/connection-state.d.ts.map +0 -1
- package/dist/src/utils/connection-state.js +0 -81
- package/dist/src/utils/connection-state.js.map +0 -1
- package/dist/src/utils/context.d.ts +0 -14
- package/dist/src/utils/context.d.ts.map +0 -1
- package/dist/src/utils/context.js +0 -68
- package/dist/src/utils/context.js.map +0 -1
- package/dist/src/utils/github-webhook.d.ts +0 -3
- package/dist/src/utils/github-webhook.d.ts.map +0 -1
- package/dist/src/utils/github-webhook.js +0 -105
- package/dist/src/utils/github-webhook.js.map +0 -1
- package/dist/src/utils/identity.d.ts +0 -114
- package/dist/src/utils/identity.d.ts.map +0 -1
- package/dist/src/utils/identity.js +0 -341
- package/dist/src/utils/identity.js.map +0 -1
- package/dist/src/utils/internal-mail.d.ts +0 -18
- package/dist/src/utils/internal-mail.d.ts.map +0 -1
- package/dist/src/utils/internal-mail.js +0 -75
- package/dist/src/utils/internal-mail.js.map +0 -1
- package/dist/src/utils/loop-detector.d.ts +0 -27
- package/dist/src/utils/loop-detector.d.ts.map +0 -1
- package/dist/src/utils/loop-detector.js +0 -42
- package/dist/src/utils/loop-detector.js.map +0 -1
- package/dist/src/utils/mail-handler.d.ts +0 -19
- package/dist/src/utils/mail-handler.d.ts.map +0 -1
- package/dist/src/utils/mail-handler.js +0 -94
- package/dist/src/utils/mail-handler.js.map +0 -1
- package/dist/src/utils/mail.d.ts +0 -22
- package/dist/src/utils/mail.d.ts.map +0 -1
- package/dist/src/utils/mail.js +0 -111
- package/dist/src/utils/mail.js.map +0 -1
- package/dist/src/utils/manifest.d.ts +0 -36
- package/dist/src/utils/manifest.d.ts.map +0 -1
- package/dist/src/utils/manifest.js +0 -91
- package/dist/src/utils/manifest.js.map +0 -1
- package/dist/src/utils/noise-ik-transport.d.ts +0 -18
- package/dist/src/utils/noise-ik-transport.d.ts.map +0 -1
- package/dist/src/utils/noise-ik-transport.js +0 -357
- package/dist/src/utils/noise-ik-transport.js.map +0 -1
- package/dist/src/utils/nono.d.ts +0 -72
- package/dist/src/utils/nono.d.ts.map +0 -1
- package/dist/src/utils/nono.js +0 -166
- package/dist/src/utils/nono.js.map +0 -1
- package/dist/src/utils/outbox.d.ts +0 -10
- package/dist/src/utils/outbox.d.ts.map +0 -1
- package/dist/src/utils/outbox.js +0 -29
- package/dist/src/utils/outbox.js.map +0 -1
- package/dist/src/utils/output.d.ts +0 -17
- package/dist/src/utils/output.d.ts.map +0 -1
- package/dist/src/utils/output.js +0 -83
- package/dist/src/utils/output.js.map +0 -1
- package/dist/src/utils/plain-tcp-transport.d.ts +0 -10
- package/dist/src/utils/plain-tcp-transport.d.ts.map +0 -1
- package/dist/src/utils/plain-tcp-transport.js +0 -209
- package/dist/src/utils/plain-tcp-transport.js.map +0 -1
- package/dist/src/utils/provision.d.ts +0 -2
- package/dist/src/utils/provision.d.ts.map +0 -1
- package/dist/src/utils/provision.js +0 -186
- package/dist/src/utils/provision.js.map +0 -1
- package/dist/src/utils/relay.d.ts +0 -30
- package/dist/src/utils/relay.d.ts.map +0 -1
- package/dist/src/utils/relay.js +0 -539
- package/dist/src/utils/relay.js.map +0 -1
- package/dist/src/utils/sandbox.d.ts +0 -37
- package/dist/src/utils/sandbox.d.ts.map +0 -1
- package/dist/src/utils/sandbox.js +0 -126
- package/dist/src/utils/sandbox.js.map +0 -1
- package/dist/src/utils/transport.d.ts +0 -62
- package/dist/src/utils/transport.d.ts.map +0 -1
- package/dist/src/utils/transport.js +0 -75
- package/dist/src/utils/transport.js.map +0 -1
- package/dist/src/utils/wall.d.ts +0 -5
- package/dist/src/utils/wall.d.ts.map +0 -1
- package/dist/src/utils/wall.js +0 -51
- package/dist/src/utils/wall.js.map +0 -1
- package/dist/src/utils/wire-delivery.d.ts +0 -10
- package/dist/src/utils/wire-delivery.d.ts.map +0 -1
- package/dist/src/utils/wire-delivery.js +0 -57
- package/dist/src/utils/wire-delivery.js.map +0 -1
- package/dist/src/utils/wire-frame.d.ts +0 -10
- package/dist/src/utils/wire-frame.d.ts.map +0 -1
- package/dist/src/utils/wire-frame.js +0 -66
- package/dist/src/utils/wire-frame.js.map +0 -1
- package/dist/src/utils/wire-mail.d.ts +0 -54
- package/dist/src/utils/wire-mail.d.ts.map +0 -1
- package/dist/src/utils/wire-mail.js +0 -24
- package/dist/src/utils/wire-mail.js.map +0 -1
- package/dist/src/utils/ws-noise-transport.d.ts +0 -18
- package/dist/src/utils/ws-noise-transport.d.ts.map +0 -1
- package/dist/src/utils/ws-noise-transport.js +0 -356
- package/dist/src/utils/ws-noise-transport.js.map +0 -1
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Noise_IK encrypted transport — mutual authentication + encrypted channel.
|
|
3
|
-
* Uses X25519 static keys from TPS identity for IK pattern.
|
|
4
|
-
*/
|
|
5
|
-
import net from "node:net";
|
|
6
|
-
import { EventEmitter } from "node:events";
|
|
7
|
-
import Noise from "noise-handshake/noise.js";
|
|
8
|
-
import Cipher from "noise-handshake/cipher.js";
|
|
9
|
-
import { decodeWireMessage, encodeWireMessage } from "./wire-frame.js";
|
|
10
|
-
import { fingerprint, loadHostIdentity, lookupBranch } from "./identity.js";
|
|
11
|
-
import { JoinCompleteBodySchema, MSG_JOIN_COMPLETE } from "./wire-mail.js";
|
|
12
|
-
const PROLOGUE = Buffer.from("tps-v1");
|
|
13
|
-
const MAX_HANDSHAKE_BYTES = 512;
|
|
14
|
-
const HANDSHAKE_TIMEOUT_MS = 10_000;
|
|
15
|
-
const MAX_ENCRYPTED_FRAME = 1024 * 1024 + 64;
|
|
16
|
-
function withTimeout(p, ms, onTimeout) {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
const t = setTimeout(() => {
|
|
19
|
-
try {
|
|
20
|
-
onTimeout();
|
|
21
|
-
}
|
|
22
|
-
catch { }
|
|
23
|
-
reject(new Error(`Handshake timeout after ${ms}ms`));
|
|
24
|
-
}, ms);
|
|
25
|
-
p.then((v) => {
|
|
26
|
-
clearTimeout(t);
|
|
27
|
-
resolve(v);
|
|
28
|
-
}).catch((e) => {
|
|
29
|
-
clearTimeout(t);
|
|
30
|
-
reject(e);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
// 2-byte BE length prefix + payload
|
|
35
|
-
async function writeFrame(socket, data) {
|
|
36
|
-
if (data.length > 0xffff) {
|
|
37
|
-
throw new Error(`Frame too large for 2-byte length prefix: ${data.length}`);
|
|
38
|
-
}
|
|
39
|
-
const header = Buffer.alloc(2);
|
|
40
|
-
header.writeUInt16BE(data.length, 0);
|
|
41
|
-
await new Promise((resolve, reject) => {
|
|
42
|
-
socket.write(Buffer.concat([header, data]), (err) => (err ? reject(err) : resolve()));
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async function readFrame(socket, maxBytes = MAX_HANDSHAKE_BYTES) {
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
let buf = Buffer.alloc(0);
|
|
48
|
-
const cleanup = () => {
|
|
49
|
-
socket.off("data", onData);
|
|
50
|
-
socket.off("error", onErr);
|
|
51
|
-
socket.off("close", onClose);
|
|
52
|
-
socket.off("end", onClose);
|
|
53
|
-
};
|
|
54
|
-
const onErr = (err) => {
|
|
55
|
-
cleanup();
|
|
56
|
-
reject(err);
|
|
57
|
-
};
|
|
58
|
-
const onClose = () => {
|
|
59
|
-
cleanup();
|
|
60
|
-
reject(new Error("Socket closed before complete frame"));
|
|
61
|
-
};
|
|
62
|
-
const onData = (chunk) => {
|
|
63
|
-
buf = Buffer.concat([buf, chunk]);
|
|
64
|
-
if (buf.length >= 2) {
|
|
65
|
-
const len = buf.readUInt16BE(0);
|
|
66
|
-
if (len > maxBytes) {
|
|
67
|
-
cleanup();
|
|
68
|
-
socket.destroy();
|
|
69
|
-
reject(new Error(`Frame too large: ${len} > ${maxBytes}`));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (buf.length >= 2 + len) {
|
|
73
|
-
const frame = buf.subarray(2, 2 + len);
|
|
74
|
-
cleanup();
|
|
75
|
-
resolve(frame);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
socket.on("data", onData);
|
|
80
|
-
socket.once("error", onErr);
|
|
81
|
-
socket.once("close", onClose);
|
|
82
|
-
socket.once("end", onClose);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
class NoiseIkChannel {
|
|
86
|
-
socket;
|
|
87
|
-
sendCipher;
|
|
88
|
-
recvCipher;
|
|
89
|
-
peerFp;
|
|
90
|
-
alive = true;
|
|
91
|
-
emitter = new EventEmitter();
|
|
92
|
-
rxBuffer = Buffer.alloc(0);
|
|
93
|
-
constructor(socket, sendCipher, recvCipher, peerFp) {
|
|
94
|
-
this.socket = socket;
|
|
95
|
-
this.sendCipher = sendCipher;
|
|
96
|
-
this.recvCipher = recvCipher;
|
|
97
|
-
this.peerFp = peerFp;
|
|
98
|
-
this.socket.on("close", () => {
|
|
99
|
-
this.alive = false;
|
|
100
|
-
});
|
|
101
|
-
this.socket.on("data", (chunk) => {
|
|
102
|
-
try {
|
|
103
|
-
this.rxBuffer = Buffer.concat([this.rxBuffer, chunk]);
|
|
104
|
-
if (this.rxBuffer.length > MAX_ENCRYPTED_FRAME) {
|
|
105
|
-
this.socket.destroy();
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
let offset = 0;
|
|
109
|
-
while (offset + 2 <= this.rxBuffer.length) {
|
|
110
|
-
const len = this.rxBuffer.readUInt16BE(offset);
|
|
111
|
-
if (len > MAX_ENCRYPTED_FRAME) {
|
|
112
|
-
this.socket.destroy();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (offset + 2 + len > this.rxBuffer.length)
|
|
116
|
-
break;
|
|
117
|
-
const encrypted = this.rxBuffer.subarray(offset + 2, offset + 2 + len);
|
|
118
|
-
const decrypted = Buffer.from(this.recvCipher.decrypt(encrypted));
|
|
119
|
-
const msg = decodeWireMessage(decrypted);
|
|
120
|
-
this.emitter.emit("message", msg);
|
|
121
|
-
offset += 2 + len;
|
|
122
|
-
}
|
|
123
|
-
this.rxBuffer = this.rxBuffer.subarray(offset);
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
this.socket.destroy();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async send(msg) {
|
|
131
|
-
const wireFrame = encodeWireMessage(msg);
|
|
132
|
-
const encrypted = Buffer.from(this.sendCipher.encrypt(wireFrame));
|
|
133
|
-
await writeFrame(this.socket, encrypted);
|
|
134
|
-
}
|
|
135
|
-
onMessage(handler) {
|
|
136
|
-
this.emitter.on("message", handler);
|
|
137
|
-
}
|
|
138
|
-
offMessage(handler) {
|
|
139
|
-
this.emitter.off("message", handler);
|
|
140
|
-
}
|
|
141
|
-
async close() {
|
|
142
|
-
this.socket.end();
|
|
143
|
-
this.alive = false;
|
|
144
|
-
}
|
|
145
|
-
isAlive() {
|
|
146
|
-
return this.alive && !this.socket.destroyed;
|
|
147
|
-
}
|
|
148
|
-
peerFingerprint() {
|
|
149
|
-
return this.peerFp;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
class NoiseIkServer {
|
|
153
|
-
server;
|
|
154
|
-
onConn = null;
|
|
155
|
-
constructor(server) {
|
|
156
|
-
this.server = server;
|
|
157
|
-
}
|
|
158
|
-
port() {
|
|
159
|
-
const addr = this.server.address();
|
|
160
|
-
if (!addr || typeof addr === "string")
|
|
161
|
-
return 0;
|
|
162
|
-
return addr.port;
|
|
163
|
-
}
|
|
164
|
-
onConnection(handler) {
|
|
165
|
-
this.onConn = handler;
|
|
166
|
-
}
|
|
167
|
-
dispatch(channel) {
|
|
168
|
-
this.onConn?.(channel);
|
|
169
|
-
}
|
|
170
|
-
async close() {
|
|
171
|
-
await new Promise((resolve, reject) => {
|
|
172
|
-
this.server.close((err) => (err ? reject(err) : resolve()));
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
export async function listenForJoin(branchKeyPair, port, timeoutMs = 120_000) {
|
|
177
|
-
const server = net.createServer();
|
|
178
|
-
const wrapper = new NoiseIkServer(server);
|
|
179
|
-
const branchStatic = {
|
|
180
|
-
publicKey: Buffer.from(branchKeyPair.encryption.publicKey),
|
|
181
|
-
secretKey: Buffer.from(branchKeyPair.encryption.privateKey),
|
|
182
|
-
};
|
|
183
|
-
const joined = new Promise((resolve, reject) => {
|
|
184
|
-
server.on("connection", async (socket) => {
|
|
185
|
-
try {
|
|
186
|
-
const responder = new Noise("IK", false, branchStatic);
|
|
187
|
-
responder.initialise(PROLOGUE);
|
|
188
|
-
const msg1 = await withTimeout(readFrame(socket), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
189
|
-
responder.recv(msg1);
|
|
190
|
-
const msg2 = Buffer.from(responder.send());
|
|
191
|
-
await withTimeout(writeFrame(socket, msg2), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
192
|
-
const channel = new NoiseIkChannel(socket, new Cipher(responder.tx), new Cipher(responder.rx), fingerprint(Buffer.from(responder.rs)));
|
|
193
|
-
const timer = timeoutMs > 0
|
|
194
|
-
? setTimeout(() => {
|
|
195
|
-
socket.destroy();
|
|
196
|
-
reject(new Error("JOIN_COMPLETE timeout"));
|
|
197
|
-
}, timeoutMs)
|
|
198
|
-
: null;
|
|
199
|
-
const handler = (msg) => {
|
|
200
|
-
if (msg.type !== MSG_JOIN_COMPLETE)
|
|
201
|
-
return;
|
|
202
|
-
const parsed = JoinCompleteBodySchema.safeParse(msg.body);
|
|
203
|
-
if (!parsed.success)
|
|
204
|
-
return;
|
|
205
|
-
const hostPub = new Uint8Array(Buffer.from(parsed.data.hostPubkey, "base64url"));
|
|
206
|
-
const fp = fingerprint(hostPub);
|
|
207
|
-
const claimed = parsed.data.hostFingerprint.replace(/^sha256:/, "");
|
|
208
|
-
if (fp !== claimed) {
|
|
209
|
-
if (timer)
|
|
210
|
-
clearTimeout(timer);
|
|
211
|
-
channel.offMessage(handler);
|
|
212
|
-
socket.destroy();
|
|
213
|
-
reject(new Error("Host fingerprint mismatch in JOIN_COMPLETE"));
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (timer)
|
|
217
|
-
clearTimeout(timer);
|
|
218
|
-
channel.offMessage(handler);
|
|
219
|
-
resolve({
|
|
220
|
-
channel,
|
|
221
|
-
hostPubkey: hostPub,
|
|
222
|
-
hostFingerprint: fp,
|
|
223
|
-
hostId: parsed.data.hostId,
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
channel.onMessage(handler);
|
|
227
|
-
}
|
|
228
|
-
catch (e) {
|
|
229
|
-
socket.destroy();
|
|
230
|
-
reject(e);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
await new Promise((resolve, reject) => {
|
|
235
|
-
server.listen(port, "0.0.0.0", () => resolve());
|
|
236
|
-
server.once("error", reject);
|
|
237
|
-
});
|
|
238
|
-
const timeoutP = timeoutMs > 0
|
|
239
|
-
? new Promise((_, reject) => {
|
|
240
|
-
setTimeout(() => {
|
|
241
|
-
try {
|
|
242
|
-
server.close();
|
|
243
|
-
}
|
|
244
|
-
catch { }
|
|
245
|
-
reject(new Error("Join listener timeout"));
|
|
246
|
-
}, timeoutMs);
|
|
247
|
-
})
|
|
248
|
-
: null;
|
|
249
|
-
const result = timeoutP ? await Promise.race([joined, timeoutP]) : await joined;
|
|
250
|
-
wrapper.dispatch(result.channel);
|
|
251
|
-
return { ...result, server: wrapper };
|
|
252
|
-
}
|
|
253
|
-
export async function listenForHost(branchKeyPair, expectedHostPubkey, port, onMessage) {
|
|
254
|
-
const server = net.createServer();
|
|
255
|
-
const wrapper = new NoiseIkServer(server);
|
|
256
|
-
const branchStatic = {
|
|
257
|
-
publicKey: Buffer.from(branchKeyPair.encryption.publicKey),
|
|
258
|
-
secretKey: Buffer.from(branchKeyPair.encryption.privateKey),
|
|
259
|
-
};
|
|
260
|
-
server.on("connection", async (socket) => {
|
|
261
|
-
try {
|
|
262
|
-
const responder = new Noise("IK", false, branchStatic);
|
|
263
|
-
responder.initialise(PROLOGUE);
|
|
264
|
-
const msg1 = await withTimeout(readFrame(socket), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
265
|
-
responder.recv(msg1);
|
|
266
|
-
const got = Buffer.from(responder.rs);
|
|
267
|
-
const expected = Buffer.from(expectedHostPubkey);
|
|
268
|
-
if (!got.equals(expected)) {
|
|
269
|
-
socket.destroy();
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
const msg2 = Buffer.from(responder.send());
|
|
273
|
-
await withTimeout(writeFrame(socket, msg2), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
274
|
-
const channel = new NoiseIkChannel(socket, new Cipher(responder.tx), new Cipher(responder.rx), fingerprint(got));
|
|
275
|
-
channel.onMessage((msg) => onMessage(msg, channel));
|
|
276
|
-
wrapper.dispatch(channel);
|
|
277
|
-
}
|
|
278
|
-
catch {
|
|
279
|
-
socket.destroy();
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
await new Promise((resolve, reject) => {
|
|
283
|
-
server.listen(port, "0.0.0.0", () => resolve());
|
|
284
|
-
server.once("error", reject);
|
|
285
|
-
});
|
|
286
|
-
return wrapper;
|
|
287
|
-
}
|
|
288
|
-
export class NoiseIkTransport {
|
|
289
|
-
branchKeyPair;
|
|
290
|
-
hostKeyPair;
|
|
291
|
-
constructor(branchKeyPair, hostKeyPair) {
|
|
292
|
-
this.branchKeyPair = branchKeyPair;
|
|
293
|
-
this.hostKeyPair = hostKeyPair;
|
|
294
|
-
}
|
|
295
|
-
async listen(port) {
|
|
296
|
-
const host = this.hostKeyPair ?? loadHostIdentity();
|
|
297
|
-
const server = net.createServer();
|
|
298
|
-
const wrapper = new NoiseIkServer(server);
|
|
299
|
-
const hostStatic = {
|
|
300
|
-
publicKey: Buffer.from(host.encryption.publicKey),
|
|
301
|
-
secretKey: Buffer.from(host.encryption.privateKey),
|
|
302
|
-
};
|
|
303
|
-
server.on("connection", async (socket) => {
|
|
304
|
-
try {
|
|
305
|
-
const responder = new Noise("IK", false, hostStatic);
|
|
306
|
-
responder.initialise(PROLOGUE);
|
|
307
|
-
const msg1 = await withTimeout(readFrame(socket), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
308
|
-
const payload = Buffer.from(responder.recv(msg1));
|
|
309
|
-
const branchId = payload.toString("utf-8");
|
|
310
|
-
const known = lookupBranch(branchId);
|
|
311
|
-
const expected = known?.encryptionKey ? Buffer.from(known.encryptionKey) : null;
|
|
312
|
-
const got = Buffer.from(responder.rs);
|
|
313
|
-
if (!expected || !got.equals(expected)) {
|
|
314
|
-
socket.destroy();
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const msg2 = Buffer.from(responder.send());
|
|
318
|
-
await withTimeout(writeFrame(socket, msg2), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
319
|
-
const channel = new NoiseIkChannel(socket, new Cipher(responder.tx), new Cipher(responder.rx), fingerprint(got));
|
|
320
|
-
wrapper.dispatch(channel);
|
|
321
|
-
}
|
|
322
|
-
catch {
|
|
323
|
-
socket.destroy();
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
await new Promise((resolve, reject) => {
|
|
327
|
-
server.listen(port, "0.0.0.0", () => resolve());
|
|
328
|
-
server.once("error", reject);
|
|
329
|
-
});
|
|
330
|
-
return wrapper;
|
|
331
|
-
}
|
|
332
|
-
async connect(target) {
|
|
333
|
-
const socket = net.createConnection({ host: target.host, port: target.port });
|
|
334
|
-
await new Promise((resolve, reject) => {
|
|
335
|
-
socket.once("connect", () => resolve());
|
|
336
|
-
socket.once("error", reject);
|
|
337
|
-
});
|
|
338
|
-
const branchStatic = {
|
|
339
|
-
publicKey: Buffer.from(this.branchKeyPair.encryption.publicKey),
|
|
340
|
-
secretKey: Buffer.from(this.branchKeyPair.encryption.privateKey),
|
|
341
|
-
};
|
|
342
|
-
const initiator = new Noise("IK", true, branchStatic);
|
|
343
|
-
initiator.initialise(PROLOGUE, Buffer.from(target.hostPublicKey));
|
|
344
|
-
const msg1 = Buffer.from(initiator.send(Buffer.from(target.branchId)));
|
|
345
|
-
await withTimeout(writeFrame(socket, msg1), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
346
|
-
const msg2 = await withTimeout(readFrame(socket), HANDSHAKE_TIMEOUT_MS, () => socket.destroy());
|
|
347
|
-
initiator.recv(msg2);
|
|
348
|
-
const gotHost = Buffer.from(initiator.rs);
|
|
349
|
-
const expectedHost = Buffer.from(target.hostPublicKey);
|
|
350
|
-
if (!gotHost.equals(expectedHost)) {
|
|
351
|
-
socket.destroy();
|
|
352
|
-
throw new Error("Host key mismatch after Noise_IK handshake");
|
|
353
|
-
}
|
|
354
|
-
return new NoiseIkChannel(socket, new Cipher(initiator.tx), new Cipher(initiator.rx), fingerprint(gotHost));
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
//# sourceMappingURL=noise-ik-transport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"noise-ik-transport.js","sourceRoot":"","sources":["../../../src/utils/noise-ik-transport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,GAAiC,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,MAAM,0BAA0B,CAAC;AAC7C,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAQ/C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAmB,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE3E,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACvC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,mBAAmB,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;AAE7C,SAAS,WAAW,CAAI,CAAa,EAAE,EAAU,EAAE,SAAqB;IACtE,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,IAAI,CAAC;gBACH,SAAS,EAAE,CAAC;YACd,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACV,MAAM,CAAC,IAAI,KAAK,CAAC,2BAA2B,EAAE,IAAI,CAAC,CAAC,CAAC;QACvD,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACX,YAAY,CAAC,CAAC,CAAC,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I,cAAc,CACvB,MAAM,EACN,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,EACxB,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,EACxB,WAAW,CAAC,OAAO,CAAC,CACrB,CAAC;IACJ,CAAC;CACF"}
|
package/dist/src/utils/nono.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* nono integration — wraps TPS CLI commands in nono process isolation.
|
|
3
|
-
*
|
|
4
|
-
* When nono is available on PATH, TPS commands run with kernel-level
|
|
5
|
-
* filesystem and network restrictions defined by per-command TOML profiles.
|
|
6
|
-
*
|
|
7
|
-
* If nono is not installed:
|
|
8
|
-
* - Default (warn) mode: logs a warning and runs unprotected
|
|
9
|
-
* - Strict mode (TPS_NONO_STRICT=1): exits non-zero immediately
|
|
10
|
-
*
|
|
11
|
-
* Profile locations (searched in order):
|
|
12
|
-
* 1. ~/.config/nono/profiles/<name>.toml
|
|
13
|
-
* 2. <tps-install-dir>/nono-profiles/<name>.toml
|
|
14
|
-
*
|
|
15
|
-
* Usage:
|
|
16
|
-
* import { withNono } from "./nono.js";
|
|
17
|
-
* await withNono("tps-hire", { workdir: targetWorkspace }, async () => {
|
|
18
|
-
* // ... perform hire logic ...
|
|
19
|
-
* });
|
|
20
|
-
*/
|
|
21
|
-
export type NonoProfile = "tps-hire" | "tps-roster" | "tps-review-local" | "tps-review-deep";
|
|
22
|
-
export interface NonoOptions {
|
|
23
|
-
/** Override workdir for the nono sandbox (--workdir flag) */
|
|
24
|
-
workdir?: string;
|
|
25
|
-
/** Extra read-only paths to allow */
|
|
26
|
-
read?: string[];
|
|
27
|
-
/** Extra read-write paths to allow */
|
|
28
|
-
allow?: string[];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Find the nono binary on PATH. Returns the resolved path or null.
|
|
32
|
-
*/
|
|
33
|
-
export declare function findNono(): string | null;
|
|
34
|
-
/**
|
|
35
|
-
* Check if strict mode is enabled (TPS_NONO_STRICT=1).
|
|
36
|
-
* In strict mode, TPS exits if nono is not available.
|
|
37
|
-
*/
|
|
38
|
-
export declare function isNonoStrict(): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Build the nono command args for a given profile and subcommand.
|
|
41
|
-
*
|
|
42
|
-
* Returns: ["nono", "run", "--profile", name, ...options, "--", ...cmd]
|
|
43
|
-
*/
|
|
44
|
-
export declare function buildNonoArgs(profile: NonoProfile, options: NonoOptions, cmd: string[]): string[];
|
|
45
|
-
/**
|
|
46
|
-
* Run a function wrapped in nono isolation.
|
|
47
|
-
*
|
|
48
|
-
* If nono is unavailable:
|
|
49
|
-
* - strict mode → throws (exits non-zero)
|
|
50
|
-
* - warn mode (default) → logs warning and runs fn directly
|
|
51
|
-
*
|
|
52
|
-
* The callback receives the nono binary path (or null if unavailable).
|
|
53
|
-
* In most cases you won't need it — this wrapper handles invocation.
|
|
54
|
-
*
|
|
55
|
-
* Note: This wrapper is for use when TPS itself is the process being
|
|
56
|
-
* sandboxed. The more common case is calling `runUnderNono()` to spawn
|
|
57
|
-
* a subprocess under nono.
|
|
58
|
-
*/
|
|
59
|
-
export declare function withNono(profile: NonoProfile, options: NonoOptions, fn: () => Promise<void>): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Spawn an external command under nono isolation.
|
|
62
|
-
*
|
|
63
|
-
* Returns the exit code of the wrapped command.
|
|
64
|
-
* Throws if nono is unavailable and strict mode is on.
|
|
65
|
-
*/
|
|
66
|
-
export declare function runCommandUnderNono(profile: NonoProfile, options: NonoOptions, cmd: string[]): number;
|
|
67
|
-
/**
|
|
68
|
-
* Install nono profiles to ~/.config/nono/profiles/.
|
|
69
|
-
* Called during `tps install` or first-run setup.
|
|
70
|
-
*/
|
|
71
|
-
export declare function installNonoProfiles(targetDir?: string, silent?: boolean): void;
|
|
72
|
-
//# sourceMappingURL=nono.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nono.d.ts","sourceRoot":"","sources":["../../../src/utils/nono.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAUH,MAAM,MAAM,WAAW,GACnB,UAAU,GACV,YAAY,GACZ,kBAAkB,GAClB,iBAAiB,CAAC;AAEtB,MAAM,WAAW,WAAW;IAC1B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAUxC;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,WAAW,EACpB,GAAG,EAAE,MAAM,EAAE,GACZ,MAAM,EAAE,CAiBV;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,WAAW,EACpB,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACtB,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,WAAW,EACpB,GAAG,EAAE,MAAM,EAAE,GACZ,MAAM,CA4BR;AAaD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAwB9E"}
|
package/dist/src/utils/nono.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* nono integration — wraps TPS CLI commands in nono process isolation.
|
|
3
|
-
*
|
|
4
|
-
* When nono is available on PATH, TPS commands run with kernel-level
|
|
5
|
-
* filesystem and network restrictions defined by per-command TOML profiles.
|
|
6
|
-
*
|
|
7
|
-
* If nono is not installed:
|
|
8
|
-
* - Default (warn) mode: logs a warning and runs unprotected
|
|
9
|
-
* - Strict mode (TPS_NONO_STRICT=1): exits non-zero immediately
|
|
10
|
-
*
|
|
11
|
-
* Profile locations (searched in order):
|
|
12
|
-
* 1. ~/.config/nono/profiles/<name>.toml
|
|
13
|
-
* 2. <tps-install-dir>/nono-profiles/<name>.toml
|
|
14
|
-
*
|
|
15
|
-
* Usage:
|
|
16
|
-
* import { withNono } from "./nono.js";
|
|
17
|
-
* await withNono("tps-hire", { workdir: targetWorkspace }, async () => {
|
|
18
|
-
* // ... perform hire logic ...
|
|
19
|
-
* });
|
|
20
|
-
*/
|
|
21
|
-
import { spawnSync } from "node:child_process";
|
|
22
|
-
import { existsSync, mkdirSync, copyFileSync, readdirSync } from "node:fs";
|
|
23
|
-
import { join, dirname } from "node:path";
|
|
24
|
-
import { fileURLToPath } from "node:url";
|
|
25
|
-
import { homedir } from "node:os";
|
|
26
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
27
|
-
/**
|
|
28
|
-
* Find the nono binary on PATH. Returns the resolved path or null.
|
|
29
|
-
*/
|
|
30
|
-
export function findNono() {
|
|
31
|
-
if (process.env.TPS_FORCE_NO_NONO === "1")
|
|
32
|
-
return null;
|
|
33
|
-
const result = spawnSync("which", ["nono"], {
|
|
34
|
-
encoding: "utf-8",
|
|
35
|
-
env: process.env, // explicitly pass so PATH mutations in tests are respected
|
|
36
|
-
});
|
|
37
|
-
if (result.status === 0 && result.stdout.trim()) {
|
|
38
|
-
return result.stdout.trim();
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Check if strict mode is enabled (TPS_NONO_STRICT=1).
|
|
44
|
-
* In strict mode, TPS exits if nono is not available.
|
|
45
|
-
*/
|
|
46
|
-
export function isNonoStrict() {
|
|
47
|
-
return process.env.TPS_NONO_STRICT === "1";
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Build the nono command args for a given profile and subcommand.
|
|
51
|
-
*
|
|
52
|
-
* Returns: ["nono", "run", "--profile", name, ...options, "--", ...cmd]
|
|
53
|
-
*/
|
|
54
|
-
export function buildNonoArgs(profile, options, cmd) {
|
|
55
|
-
const args = ["run", "--profile", profile, "--allow-cwd"];
|
|
56
|
-
if (options.workdir) {
|
|
57
|
-
args.push("--workdir", options.workdir);
|
|
58
|
-
}
|
|
59
|
-
for (const p of options.read ?? []) {
|
|
60
|
-
args.push("--read", p);
|
|
61
|
-
}
|
|
62
|
-
for (const p of options.allow ?? []) {
|
|
63
|
-
args.push("--allow", p);
|
|
64
|
-
}
|
|
65
|
-
args.push("--", ...cmd);
|
|
66
|
-
return args;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Run a function wrapped in nono isolation.
|
|
70
|
-
*
|
|
71
|
-
* If nono is unavailable:
|
|
72
|
-
* - strict mode → throws (exits non-zero)
|
|
73
|
-
* - warn mode (default) → logs warning and runs fn directly
|
|
74
|
-
*
|
|
75
|
-
* The callback receives the nono binary path (or null if unavailable).
|
|
76
|
-
* In most cases you won't need it — this wrapper handles invocation.
|
|
77
|
-
*
|
|
78
|
-
* Note: This wrapper is for use when TPS itself is the process being
|
|
79
|
-
* sandboxed. The more common case is calling `runUnderNono()` to spawn
|
|
80
|
-
* a subprocess under nono.
|
|
81
|
-
*/
|
|
82
|
-
export async function withNono(profile, options, fn) {
|
|
83
|
-
const nono = findNono();
|
|
84
|
-
if (!nono) {
|
|
85
|
-
if (isNonoStrict()) {
|
|
86
|
-
console.error(`❌ nono is not installed but TPS_NONO_STRICT=1. Install nono from https://nono.sh`);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
console.warn(`⚠️ nono not found — running ${profile} WITHOUT isolation. Install nono for security: https://nono.sh`);
|
|
91
|
-
return fn();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// nono is available — run the callback directly (the current process IS already
|
|
95
|
-
// being run via nono by the calling shell, or we re-exec under nono).
|
|
96
|
-
// For TPS's architecture, we use runCommandUnderNono() for subprocess isolation.
|
|
97
|
-
return fn();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Spawn an external command under nono isolation.
|
|
101
|
-
*
|
|
102
|
-
* Returns the exit code of the wrapped command.
|
|
103
|
-
* Throws if nono is unavailable and strict mode is on.
|
|
104
|
-
*/
|
|
105
|
-
export function runCommandUnderNono(profile, options, cmd) {
|
|
106
|
-
const nono = findNono();
|
|
107
|
-
if (!nono) {
|
|
108
|
-
if (isNonoStrict()) {
|
|
109
|
-
console.error(`❌ nono is not installed but TPS_NONO_STRICT=1. Install nono from https://nono.sh`);
|
|
110
|
-
return 1;
|
|
111
|
-
}
|
|
112
|
-
console.warn(`⚠️ nono not found — running WITHOUT isolation: ${cmd.join(" ")}`);
|
|
113
|
-
const result = spawnSync(cmd[0], cmd.slice(1), {
|
|
114
|
-
stdio: "inherit",
|
|
115
|
-
encoding: "utf-8",
|
|
116
|
-
env: process.env,
|
|
117
|
-
});
|
|
118
|
-
return result.status ?? 1;
|
|
119
|
-
}
|
|
120
|
-
const args = buildNonoArgs(profile, options, cmd);
|
|
121
|
-
const result = spawnSync(nono, args, {
|
|
122
|
-
stdio: "inherit",
|
|
123
|
-
encoding: "utf-8",
|
|
124
|
-
env: process.env,
|
|
125
|
-
});
|
|
126
|
-
return result.status ?? 1;
|
|
127
|
-
}
|
|
128
|
-
function findBundledProfilesDir() {
|
|
129
|
-
const candidates = [
|
|
130
|
-
join(__dirname, "..", "..", "nono-profiles"), // dist/src/utils -> nono-profiles
|
|
131
|
-
join(__dirname, "..", "..", "..", "nono-profiles"), // deeper nesting
|
|
132
|
-
];
|
|
133
|
-
for (const c of candidates) {
|
|
134
|
-
if (existsSync(c))
|
|
135
|
-
return c;
|
|
136
|
-
}
|
|
137
|
-
return join(__dirname, "..", "..", "nono-profiles"); // fallback
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Install nono profiles to ~/.config/nono/profiles/.
|
|
141
|
-
* Called during `tps install` or first-run setup.
|
|
142
|
-
*/
|
|
143
|
-
export function installNonoProfiles(targetDir, silent) {
|
|
144
|
-
const home = process.env.HOME || homedir() || "/tmp";
|
|
145
|
-
const profilesDir = targetDir ?? join(home, ".config", "nono", "profiles");
|
|
146
|
-
// Source: bundled profiles shipped with TPS
|
|
147
|
-
const bundledDir = findBundledProfilesDir();
|
|
148
|
-
if (!existsSync(bundledDir)) {
|
|
149
|
-
if (!silent)
|
|
150
|
-
console.warn(`⚠️ No bundled nono profiles found at ${bundledDir}`);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
mkdirSync(profilesDir, { recursive: true });
|
|
154
|
-
for (const file of readdirSync(bundledDir)) {
|
|
155
|
-
if (file.endsWith(".toml")) {
|
|
156
|
-
const src = join(bundledDir, file);
|
|
157
|
-
const dst = join(profilesDir, file);
|
|
158
|
-
if (!existsSync(dst)) {
|
|
159
|
-
copyFileSync(src, dst);
|
|
160
|
-
if (!silent)
|
|
161
|
-
console.log(` ✓ Installed nono profile: ${file}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=nono.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nono.js","sourceRoot":"","sources":["../../../src/utils/nono.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,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CAAC,EAAE,CAAC;QAC5B,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,IAAI,CAAC,yCAAyC,UAAU,EAAE,CAAC,CAAC;QACjF,OAAO;IACT,CAAC;IAED,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5C,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3C,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YACnC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YACpC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrB,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;gBACvB,IAAI,CAAC,MAAM;oBAAE,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface OutboxMessage {
|
|
2
|
-
id: string;
|
|
3
|
-
to: string;
|
|
4
|
-
from: string;
|
|
5
|
-
body: string;
|
|
6
|
-
timestamp: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function queueOutboxMessage(to: string, body: string, from: string): void;
|
|
9
|
-
export declare function drainOutbox(): OutboxMessage[];
|
|
10
|
-
//# sourceMappingURL=outbox.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../../src/utils/outbox.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAO/E;AAED,wBAAgB,WAAW,IAAI,aAAa,EAAE,CAa7C"}
|