shipmates 0.0.0 → 0.2.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/LICENSE +661 -0
- package/dist/cli-run.d.ts +9 -0
- package/dist/cli-run.d.ts.map +1 -0
- package/dist/cli-run.js +237 -0
- package/dist/cli-run.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +11 -0
- package/dist/cli.js.map +1 -0
- package/dist/delivery.d.ts +37 -0
- package/dist/delivery.d.ts.map +1 -0
- package/dist/delivery.js +13 -0
- package/dist/delivery.js.map +1 -0
- package/dist/host.d.ts +132 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +66 -0
- package/dist/host.js.map +1 -0
- package/dist/ids.d.ts +3 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +6 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/liveness.d.ts +25 -0
- package/dist/liveness.d.ts.map +1 -0
- package/dist/liveness.js +75 -0
- package/dist/liveness.js.map +1 -0
- package/dist/quiet.d.ts +7 -0
- package/dist/quiet.d.ts.map +1 -0
- package/dist/quiet.js +19 -0
- package/dist/quiet.js.map +1 -0
- package/dist/shipmates.d.ts +401 -0
- package/dist/shipmates.d.ts.map +1 -0
- package/dist/shipmates.js +1112 -0
- package/dist/shipmates.js.map +1 -0
- package/dist/store.d.ts +19 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +236 -0
- package/dist/store.js.map +1 -0
- package/dist/tail.d.ts +27 -0
- package/dist/tail.d.ts.map +1 -0
- package/dist/tail.js +127 -0
- package/dist/tail.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/watch.d.ts +13 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +30 -0
- package/dist/watch.js.map +1 -0
- package/package.json +50 -13
- package/src/cli-run.ts +263 -0
- package/src/cli.ts +11 -0
- package/src/delivery.ts +49 -0
- package/src/host.ts +161 -0
- package/src/ids.ts +6 -0
- package/src/index.ts +44 -0
- package/src/liveness.ts +86 -0
- package/src/quiet.ts +22 -0
- package/src/shipmates.ts +1634 -0
- package/src/store.ts +252 -0
- package/src/tail.ts +143 -0
- package/src/types.ts +138 -0
- package/src/watch.ts +32 -0
- package/.npm-publish.log +0 -0
- package/README.md +0 -5
package/dist/cli-run.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Shipmates } from './shipmates.js';
|
|
2
|
+
import { readTail } from './tail.js';
|
|
3
|
+
import { ShipmatesError } from './types.js';
|
|
4
|
+
const USAGE = `shipmates: sessions that know about each other
|
|
5
|
+
|
|
6
|
+
shipmates list [--cwd DIR] [--role ROLE] [--json] live sessions
|
|
7
|
+
shipmates read TARGET presence, open questions, recent transcript
|
|
8
|
+
shipmates tell TARGET TEXT... [--urgent] send a message
|
|
9
|
+
shipmates ask TARGET QUESTION... ask a question
|
|
10
|
+
shipmates inbox [--json] the human's open attention items
|
|
11
|
+
shipmates answer ID TEXT... answer an inbox item (h_...) or a question (q_...)
|
|
12
|
+
shipmates owned TARGET [--json] the sessions TARGET spawned (live or not), and its owner
|
|
13
|
+
shipmates stop TARGET stop the current turn of a session (the human only)
|
|
14
|
+
|
|
15
|
+
TARGET is a role (template-tree/push), a session file (.jsonl) or a session-id prefix.
|
|
16
|
+
Run by a human at a terminal, tell, ask and answer are origin "human". Run from an
|
|
17
|
+
agent's bash (PI_SESSION_FILE is set) they come from that session, origin "agent",
|
|
18
|
+
and answer and stop are refused: only the human answers the human's inbox, and
|
|
19
|
+
an agent stops only the sessions it owns, with its session_stop tool.
|
|
20
|
+
State: $SHIPMATES_STATE_DIR, else $XDG_STATE_HOME/shipmates.
|
|
21
|
+
`;
|
|
22
|
+
function flags(args) {
|
|
23
|
+
const rest = [];
|
|
24
|
+
const opts = {};
|
|
25
|
+
for (let i = 0; i < args.length; i++) {
|
|
26
|
+
const a = args[i];
|
|
27
|
+
if (a.startsWith('--')) {
|
|
28
|
+
const key = a.slice(2);
|
|
29
|
+
if (['cwd', 'role'].includes(key))
|
|
30
|
+
opts[key] = args[++i] ?? '';
|
|
31
|
+
else
|
|
32
|
+
opts[key] = true;
|
|
33
|
+
}
|
|
34
|
+
else
|
|
35
|
+
rest.push(a);
|
|
36
|
+
}
|
|
37
|
+
return { rest, opts };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Who is speaking (ADR 0003). Inside an agent session the bash tool sets
|
|
41
|
+
* PI_SESSION_FILE, so the CLI speaks as that session; a human is a terminal
|
|
42
|
+
* with no session around it. Neither is proof against a determined agent on the
|
|
43
|
+
* same user, which is the stated limit.
|
|
44
|
+
*/
|
|
45
|
+
function speaker(io) {
|
|
46
|
+
const session = io.env.PI_SESSION_FILE;
|
|
47
|
+
if (session)
|
|
48
|
+
return { kind: 'agent', session };
|
|
49
|
+
if (io.isTTY)
|
|
50
|
+
return { kind: 'human' };
|
|
51
|
+
return { kind: 'script' };
|
|
52
|
+
}
|
|
53
|
+
function presenceLine(p) {
|
|
54
|
+
const bits = [
|
|
55
|
+
p.roles.join(',') || '(no role)',
|
|
56
|
+
p.state,
|
|
57
|
+
p.cwd ?? '?',
|
|
58
|
+
p.branch,
|
|
59
|
+
p.status ? `status: ${p.status}` : null,
|
|
60
|
+
].filter(Boolean);
|
|
61
|
+
return `${p.sessionFile}\n ${bits.join(' · ')}`;
|
|
62
|
+
}
|
|
63
|
+
function itemLine(i) {
|
|
64
|
+
return `${i.id}${i.blocking ? ' BLOCKING' : ''} ${i.question}${i.options?.length ? ` [${i.options.join(' / ')}]` : ''}\n from ${i.session}`;
|
|
65
|
+
}
|
|
66
|
+
export function runCli(argv, io) {
|
|
67
|
+
const [cmd, ...args] = argv;
|
|
68
|
+
if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') {
|
|
69
|
+
io.stdout(USAGE);
|
|
70
|
+
return cmd ? 0 : 2;
|
|
71
|
+
}
|
|
72
|
+
const known = [
|
|
73
|
+
'list',
|
|
74
|
+
'read',
|
|
75
|
+
'tell',
|
|
76
|
+
'ask',
|
|
77
|
+
'inbox',
|
|
78
|
+
'answer',
|
|
79
|
+
'owned',
|
|
80
|
+
'stop',
|
|
81
|
+
];
|
|
82
|
+
if (!known.includes(cmd)) {
|
|
83
|
+
io.stderr(`shipmates: unknown command ${cmd}\n\n${USAGE}`);
|
|
84
|
+
return 2;
|
|
85
|
+
}
|
|
86
|
+
let k;
|
|
87
|
+
try {
|
|
88
|
+
k = new Shipmates({ stateDir: io.env.SHIPMATES_STATE_DIR || undefined });
|
|
89
|
+
const { rest, opts } = flags(args);
|
|
90
|
+
const who = speaker(io);
|
|
91
|
+
const from = who.kind === 'agent' ? who.session : null;
|
|
92
|
+
const origin = who.kind === 'human' ? 'human' : 'agent';
|
|
93
|
+
switch (cmd) {
|
|
94
|
+
case 'list': {
|
|
95
|
+
const list = k.list({
|
|
96
|
+
cwd: opts.cwd,
|
|
97
|
+
role: opts.role,
|
|
98
|
+
});
|
|
99
|
+
if (opts.json)
|
|
100
|
+
io.stdout(JSON.stringify(list, null, 2) + '\n');
|
|
101
|
+
else
|
|
102
|
+
io.stdout(list.length
|
|
103
|
+
? list.map(presenceLine).join('\n') + '\n'
|
|
104
|
+
: 'No live sessions.\n');
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
case 'read': {
|
|
108
|
+
const r = k.resolve(need(rest[0], 'TARGET'));
|
|
109
|
+
if (!r.session) {
|
|
110
|
+
io.stdout(`${r.target}: nobody holds this role right now.\n`);
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
const p = k.presence(r.session);
|
|
114
|
+
const qs = k.openQuestionsTo(r.session);
|
|
115
|
+
const tail = readTail(r.session);
|
|
116
|
+
io.stdout([
|
|
117
|
+
p ? presenceLine(p) + (p.live ? '' : ' (GONE)') : r.session,
|
|
118
|
+
qs.length
|
|
119
|
+
? 'open questions:\n' +
|
|
120
|
+
qs
|
|
121
|
+
.map((q) => ` ${q.id} from ${q.askerLabel}: ${q.text}`)
|
|
122
|
+
.join('\n')
|
|
123
|
+
: null,
|
|
124
|
+
tail.messages.map((m) => `[${m.role}] ${m.text}`).join('\n\n'),
|
|
125
|
+
]
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join('\n\n') + '\n');
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
case 'tell':
|
|
131
|
+
case 'ask': {
|
|
132
|
+
const target = need(rest[0], 'TARGET');
|
|
133
|
+
const text = need(rest.slice(1).join(' '), cmd === 'ask' ? 'QUESTION' : 'TEXT');
|
|
134
|
+
const sent = k.send({
|
|
135
|
+
from,
|
|
136
|
+
fromLabel: who.kind === 'script' ? 'script' : undefined,
|
|
137
|
+
to: target,
|
|
138
|
+
text,
|
|
139
|
+
kind: cmd,
|
|
140
|
+
origin,
|
|
141
|
+
urgent: opts.urgent === true,
|
|
142
|
+
});
|
|
143
|
+
io.stdout(`${cmd === 'ask' ? `asked ${sent.question.id}` : 'sent'} as ${sent.message.id} (origin ${sent.message.origin})\n`);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
case 'inbox': {
|
|
147
|
+
const items = k.inbox();
|
|
148
|
+
if (opts.json)
|
|
149
|
+
io.stdout(JSON.stringify(items, null, 2) + '\n');
|
|
150
|
+
else
|
|
151
|
+
io.stdout(items.length
|
|
152
|
+
? items.map(itemLine).join('\n') + '\n'
|
|
153
|
+
: 'The inbox is empty.\n');
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
case 'owned': {
|
|
157
|
+
const r = k.resolve(need(rest[0], 'TARGET'));
|
|
158
|
+
if (!r.session) {
|
|
159
|
+
io.stdout(`${r.target}: nobody holds this role right now.\n`);
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
const owned = k.ownedBy(r.session, { transitive: true });
|
|
163
|
+
const owner = k.ownerOf(r.session);
|
|
164
|
+
if (opts.json) {
|
|
165
|
+
io.stdout(JSON.stringify({ session: r.session, owner, owned }, null, 2) + '\n');
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
const lines = [
|
|
169
|
+
`${r.session}${owner ? `\n owner: ${owner}` : ''}`,
|
|
170
|
+
...owned.map((o) => {
|
|
171
|
+
const p = k.presence(o.session);
|
|
172
|
+
const bits = [
|
|
173
|
+
o.role ?? '(no role)',
|
|
174
|
+
p?.live ? p.state : 'not live',
|
|
175
|
+
o.folder,
|
|
176
|
+
`via ${o.via}`,
|
|
177
|
+
o.owner === r.session ? null : `owned by ${o.owner}`,
|
|
178
|
+
o.archived ? o.archived.kind : null,
|
|
179
|
+
].filter(Boolean);
|
|
180
|
+
return ` ${o.session}\n ${bits.join(' · ')}`;
|
|
181
|
+
}),
|
|
182
|
+
];
|
|
183
|
+
if (!owned.length)
|
|
184
|
+
lines.push(' owns no sessions');
|
|
185
|
+
io.stdout(lines.join('\n') + '\n');
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
case 'stop': {
|
|
189
|
+
// D31: the human may stop any session's current turn; an agent stops
|
|
190
|
+
// only what it owns, through session_stop, where ownership is checked.
|
|
191
|
+
asHuman(who, 'stop');
|
|
192
|
+
const r = k.resolve(need(rest[0], 'TARGET'));
|
|
193
|
+
if (!r.session || !k.isLive(r.session)) {
|
|
194
|
+
io.stdout(`${r.session ?? r.target} is not running: nothing to stop.\n`);
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
const req = k.requestStop(r.session, { by: null });
|
|
198
|
+
io.stdout(`stop requested (${req.id}): ${r.session} aborts its current turn within a second, if it is running. Sessions it owns are not stopped.\n`);
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
case 'answer': {
|
|
202
|
+
asHuman(who, 'answer');
|
|
203
|
+
const id = need(rest[0], 'ID');
|
|
204
|
+
const text = need(rest.slice(1).join(' '), 'TEXT');
|
|
205
|
+
if (id.startsWith('h_'))
|
|
206
|
+
k.answerItem(id, text, { channel: 'cli' });
|
|
207
|
+
else
|
|
208
|
+
k.answer({ from: null, questionId: id, text, origin: 'human' });
|
|
209
|
+
io.stdout(`answered ${id}\n`);
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return 2;
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
if (e instanceof ShipmatesError) {
|
|
217
|
+
io.stderr(`shipmates: ${e.message}\n`);
|
|
218
|
+
return 1;
|
|
219
|
+
}
|
|
220
|
+
throw e;
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
k?.close();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function asHuman(who, verb) {
|
|
227
|
+
if (who.kind === 'agent')
|
|
228
|
+
throw new ShipmatesError(`${verb} is refused from inside an agent session (PI_SESSION_FILE is set): only the human ${verb === 'stop' ? 'stops any session' : 'answers as the human'}`, 'not-human');
|
|
229
|
+
if (who.kind !== 'human')
|
|
230
|
+
throw new ShipmatesError(`${verb} needs a terminal: only the human, at their terminal, ${verb === 'stop' ? 'stops any session' : 'answers as the human'}`, 'not-human');
|
|
231
|
+
}
|
|
232
|
+
function need(v, what) {
|
|
233
|
+
if (!v || !v.trim())
|
|
234
|
+
throw new ShipmatesError(`missing ${what}`, 'usage');
|
|
235
|
+
return v;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=cli-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-run.js","sourceRoot":"","sources":["../src/cli-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAC;AACnC,OAAO,EAAC,c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CAAC;YAAS,CAAC;QACV,CAAC,EAAE,KAAK,EAAE,CAAC;IACZ,CAAC;AACF,CAAC;AAED,SAAS,OAAO,CAAC,GAA+B,EAAE,IAAY;IAC7D,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;QACvB,MAAM,IAAI,cAAc,CACvB,GAAG,IAAI,qFAAqF,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,sBAAsB,EAAE,EAC5J,WAAW,CACX,CAAC;IACH,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;QACvB,MAAM,IAAI,cAAc,CACvB,GAAG,IAAI,yDAAyD,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,sBAAsB,EAAE,EAChI,WAAW,CACX,CAAC;AACJ,CAAC;AAED,SAAS,IAAI,CAAC,CAAqB,EAAE,IAAY;IAChD,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,cAAc,CAAC,WAAW,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAC1E,OAAO,CAAC,CAAC;AACV,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runCli } from './cli-run.js';
|
|
3
|
+
import { silenceSqliteWarning } from './quiet.js';
|
|
4
|
+
silenceSqliteWarning();
|
|
5
|
+
process.exitCode = runCli(process.argv.slice(2), {
|
|
6
|
+
env: process.env,
|
|
7
|
+
isTTY: !!(process.stdin.isTTY && process.stdout.isTTY),
|
|
8
|
+
stdout: (s) => process.stdout.write(s),
|
|
9
|
+
stderr: (s) => process.stderr.write(s),
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,oBAAoB,EAAC,MAAM,YAAY,CAAC;AAEhD,oBAAoB,EAAE,CAAC;AACvB,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IAChD,GAAG,EAAE,OAAO,CAAC,GAAG;IAChB,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IACtD,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;CACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SessionState } from './types.js';
|
|
2
|
+
/** What a host knows about a session at the moment a message could be delivered. */
|
|
3
|
+
export interface SessionView {
|
|
4
|
+
/** pi's view: a run is in progress, or the session has settled. */
|
|
5
|
+
phase: 'running' | 'settled';
|
|
6
|
+
/** What the session declared (ADR 0006); only `waiting-for-human` changes the plan. */
|
|
7
|
+
declared: SessionState;
|
|
8
|
+
/** A blocking dialog with the human is open (`ui_prompt_start`). */
|
|
9
|
+
uiPrompt: boolean;
|
|
10
|
+
/** The human has text in the editor: they are typing into this session. */
|
|
11
|
+
editorBusy: boolean;
|
|
12
|
+
/** `/shipmates wake off` turns waking off for this session. */
|
|
13
|
+
wake: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* When a message enters a session (ADR 0002). Nothing goes into pi's own
|
|
17
|
+
* queues, so every plan except `wake` keeps the message in shipmates until the
|
|
18
|
+
* boundary, where it can still be superseded or withdrawn:
|
|
19
|
+
* - `at-settle`: returned from `agent_before_settle` with a continuation;
|
|
20
|
+
* - `at-turn-end`: returned from `turn_end` (urgent, or after a dialog);
|
|
21
|
+
* - `wake`: start a turn now (`sendMessage` with `triggerTurn`);
|
|
22
|
+
* - `hold-for-human`: attached to the human's next run by `before_agent_start`.
|
|
23
|
+
*
|
|
24
|
+
* `fromHuman`: a pending message has origin `human` (an inbox answer, the
|
|
25
|
+
* human's `shipmates tell`), which only a human act can produce (ADR 0003). A
|
|
26
|
+
* session that declared `waiting-for-human` is waiting for exactly that, so it
|
|
27
|
+
* wakes for it: holding it for "the human's next turn" meant an answer given
|
|
28
|
+
* from the inbox (or a host such as wherever) sat there until the human also
|
|
29
|
+
* typed into the session, which they had no reason to do. Still held while the
|
|
30
|
+
* human types into the session (it joins that run) or with waking off.
|
|
31
|
+
*/
|
|
32
|
+
export type DeliveryPlan = 'at-settle' | 'at-turn-end' | 'wake' | 'hold-for-human';
|
|
33
|
+
export declare function planDelivery(view: SessionView, message: {
|
|
34
|
+
urgent: boolean;
|
|
35
|
+
fromHuman?: boolean;
|
|
36
|
+
}): DeliveryPlan;
|
|
37
|
+
//# sourceMappingURL=delivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.d.ts","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAE7C,oFAAoF;AACpF,MAAM,WAAW,WAAW;IAC3B,mEAAmE;IACnE,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,uFAAuF;IACvF,QAAQ,EAAE,YAAY,CAAC;IACvB,oEAAoE;IACpE,QAAQ,EAAE,OAAO,CAAC;IAClB,2EAA2E;IAC3E,UAAU,EAAE,OAAO,CAAC;IACpB,+DAA+D;IAC/D,IAAI,EAAE,OAAO,CAAC;CACd;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,YAAY,GACvB,WAAW,GAAG,aAAa,GAAG,MAAM,GAAG,gBAAgB,CAAC;AAEzD,wBAAgB,YAAY,CAC3B,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAC,GAC7C,YAAY,CASd"}
|
package/dist/delivery.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function planDelivery(view, message) {
|
|
2
|
+
if (view.phase === 'running') {
|
|
3
|
+
if (view.uiPrompt)
|
|
4
|
+
return 'at-turn-end';
|
|
5
|
+
return message.urgent ? 'at-turn-end' : 'at-settle';
|
|
6
|
+
}
|
|
7
|
+
if (view.editorBusy || !view.wake)
|
|
8
|
+
return 'hold-for-human';
|
|
9
|
+
if (view.declared === 'waiting-for-human' && !message.fromHuman)
|
|
10
|
+
return 'hold-for-human';
|
|
11
|
+
return 'wake';
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.js","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":"AAoCA,MAAM,UAAU,YAAY,CAC3B,IAAiB,EACjB,OAA+C;IAE/C,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,aAAa,CAAC;QACxC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,gBAAgB,CAAC;IAC3D,IAAI,IAAI,CAAC,QAAQ,KAAK,mBAAmB,IAAI,CAAC,OAAO,CAAC,SAAS;QAC9D,OAAO,gBAAgB,CAAC;IACzB,OAAO,MAAM,CAAC;AACf,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { DeliveryPlan } from './delivery.js';
|
|
2
|
+
import type { AttentionItem, Message } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The event a host emits on a pi session's event bus (`pi.events`) right before
|
|
5
|
+
* it sends a human's text into that session, so shipmates records the turn as a
|
|
6
|
+
* human act (ADR 0003, D22). Only extension code can reach the bus; the model
|
|
7
|
+
* cannot. Emit it for web, Telegram or any authenticated human channel; never
|
|
8
|
+
* for scheduled or agent-originated sends.
|
|
9
|
+
*/
|
|
10
|
+
export declare const HUMAN_INPUT_EVENT = "shipmates:human-input";
|
|
11
|
+
export interface HumanInputMark {
|
|
12
|
+
text: string;
|
|
13
|
+
/** Where the human typed it: `web`, `telegram`, ... */
|
|
14
|
+
channel: string;
|
|
15
|
+
/** Optional: names this mark, so its end event closes exactly this one. */
|
|
16
|
+
id?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The event a host emits once its marked send attempt has SETTLED: the awaited
|
|
20
|
+
* `prompt()` resolved or threw (D35). shipmates then drops the mark if no input
|
|
21
|
+
* consumed it, so a send that never reached the `input` handlers (another
|
|
22
|
+
* extension returned `handled`, pi refused it while compacting) leaves nothing
|
|
23
|
+
* behind, with no window. Give the mark's `id` to close exactly that mark;
|
|
24
|
+
* without one, the oldest open mark with this text and no id is closed (a mark
|
|
25
|
+
* that has an id is closed only by it).
|
|
26
|
+
*
|
|
27
|
+
* Emit it ONLY after awaiting the send. Never after `pi.sendUserMessage()`
|
|
28
|
+
* from an extension: that call is fire-and-forget in pi 1.4 (it returns before
|
|
29
|
+
* the `input` handlers run and reports failures only as `extension_error`), so
|
|
30
|
+
* an end emitted after it can drop a mark that was about to match. Such a host
|
|
31
|
+
* emits no end event and relies on the mark's 5 s expiry. Also wrong, though
|
|
32
|
+
* safe: a `prompt()` called while pi is emitting `agent_settled` is deferred
|
|
33
|
+
* and resolves before its input runs, so the end drops the mark and that send
|
|
34
|
+
* is not recorded as the human's (it fails toward "not human").
|
|
35
|
+
*/
|
|
36
|
+
export declare const HUMAN_INPUT_END_EVENT = "shipmates:human-input-end";
|
|
37
|
+
export interface HumanInputEnd {
|
|
38
|
+
text: string;
|
|
39
|
+
id?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A session asks its host for a new session it will own (D23, D28). shipmates has
|
|
43
|
+
* already recorded the spawn (`spawnId`) and created the worktree, if any.
|
|
44
|
+
*/
|
|
45
|
+
export interface SpawnRequest {
|
|
46
|
+
/** The ownership record shipmates made for this spawn (`sp_...`). */
|
|
47
|
+
spawnId: string;
|
|
48
|
+
/** The owner's session file. One host serves many sessions, so this says whose child it is. */
|
|
49
|
+
owner: string;
|
|
50
|
+
/** Absolute folder the new session runs in (the worktree, when one was asked for). */
|
|
51
|
+
folder: string;
|
|
52
|
+
/**
|
|
53
|
+
* A short label for the new session (the role, else the prompt's first line,
|
|
54
|
+
* at most 80 characters), for a sidebar. The prompt itself is NOT the host's
|
|
55
|
+
* to send: shipmates delivers it as a message from the owner, origin agent, once
|
|
56
|
+
* the session exists (D28). A host must send nothing into the new session and
|
|
57
|
+
* must never emit a human-input mark for it.
|
|
58
|
+
*/
|
|
59
|
+
title: string;
|
|
60
|
+
/** The role shipmates will claim for the new session. */
|
|
61
|
+
role?: string;
|
|
62
|
+
/** Start from this transcript (up to `entryId`, else all of it) instead of an empty one. */
|
|
63
|
+
fork?: {
|
|
64
|
+
sessionFile: string;
|
|
65
|
+
entryId?: string;
|
|
66
|
+
};
|
|
67
|
+
/** Informational: the worktree shipmates created for `folder`. */
|
|
68
|
+
worktree?: {
|
|
69
|
+
repo: string;
|
|
70
|
+
branch: string;
|
|
71
|
+
path: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export interface SpawnResult {
|
|
75
|
+
/** The new session's transcript path, which shipmates binds to the spawn. */
|
|
76
|
+
sessionFile: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* What a host did with a stop. `not-mine`: this host does not run that session;
|
|
80
|
+
* shipmates then asks the session's own extension to stop (D30).
|
|
81
|
+
*/
|
|
82
|
+
export type StopOutcome = 'stopped' | 'not-running' | 'not-mine';
|
|
83
|
+
/**
|
|
84
|
+
* How a host delivers, notifies, spawns and stops (D20). The pi extension is the
|
|
85
|
+
* default host for a terminal pi; wherever implements its own through its
|
|
86
|
+
* session pool. Every member is optional: a host provides what it can.
|
|
87
|
+
*/
|
|
88
|
+
export interface ShipmatesHost {
|
|
89
|
+
/** Deliver messages into a session the host runs. 'held' leaves them pending. */
|
|
90
|
+
deliver?(sessionFile: string, messages: Message[], plan: DeliveryPlan): Promise<'done' | 'held'>;
|
|
91
|
+
/** Tell the human about a new attention item (push, Telegram). */
|
|
92
|
+
notifyHuman?(item: AttentionItem): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a session owned by `req.owner` in `req.folder` and resolve as soon
|
|
95
|
+
* as it exists and is addressable (its transcript path is final and its
|
|
96
|
+
* shipmates extension will start in it), NOT when a first turn ends: the new
|
|
97
|
+
* session starts with no prompt and shipmates wakes it with the owner's message.
|
|
98
|
+
* Reject to refuse; the agent sees the error.
|
|
99
|
+
*/
|
|
100
|
+
spawn?(req: SpawnRequest): Promise<SpawnResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Stop the CURRENT TURN of `sessionFile` (abort its running agent), leaving
|
|
103
|
+
* the session itself alive, and nothing else: stopping never cascades to the
|
|
104
|
+
* sessions it owns. `by` is the session asking (shipmates already checked that
|
|
105
|
+
* it owns the target). Null is reserved for the human; today `shipmates stop`
|
|
106
|
+
* does not call the host, it records a stop request that the session's own
|
|
107
|
+
* extension acts on (D30).
|
|
108
|
+
*/
|
|
109
|
+
stop?(sessionFile: string, opts: {
|
|
110
|
+
by: string | null;
|
|
111
|
+
}): Promise<StopOutcome>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The per-process host registry (D26). It lives on `globalThis` under a
|
|
115
|
+
* `Symbol.for` key, not in this module, so a host that loaded ANOTHER copy of
|
|
116
|
+
* shipmates (wherever's server, the @wherever-dev/pi bridge, a jiti-loaded
|
|
117
|
+
* extension) fills the same registry @shipmates/pi reads. The same pattern as
|
|
118
|
+
* wherever's `Symbol.for('wherever-dev.server-process')` marker; the key string
|
|
119
|
+
* is a contract between packages, so it changes only with a release that says
|
|
120
|
+
* so (once so far: `kenning.host` became `shipmates.host` in the D38 rename).
|
|
121
|
+
* The shape is versioned for the same reason.
|
|
122
|
+
*/
|
|
123
|
+
export declare const HOST_REGISTRY_KEY: unique symbol;
|
|
124
|
+
/**
|
|
125
|
+
* Register this process's host. The most recently registered host wins; the
|
|
126
|
+
* returned function unregisters it and restores the previous one (registering
|
|
127
|
+
* the same object twice gives two entries, each removed by its own call).
|
|
128
|
+
*/
|
|
129
|
+
export declare function registerHost(host: ShipmatesHost): () => void;
|
|
130
|
+
/** The host registered last in this process, or undefined for the terminal default. */
|
|
131
|
+
export declare function currentHost(): ShipmatesHost | undefined;
|
|
132
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAC,aAAa,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,e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AI,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE;QAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;KAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC5E;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,eAA+B,CAAC;AAe9D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,IAAI,CAQ5D;AAED,uFAAuF;AACvF,wBAAgB,WAAW,IAAI,aAAa,GAAG,SAAS,CAGvD"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The event a host emits on a pi session's event bus (`pi.events`) right before
|
|
3
|
+
* it sends a human's text into that session, so shipmates records the turn as a
|
|
4
|
+
* human act (ADR 0003, D22). Only extension code can reach the bus; the model
|
|
5
|
+
* cannot. Emit it for web, Telegram or any authenticated human channel; never
|
|
6
|
+
* for scheduled or agent-originated sends.
|
|
7
|
+
*/
|
|
8
|
+
export const HUMAN_INPUT_EVENT = 'shipmates:human-input';
|
|
9
|
+
/**
|
|
10
|
+
* The event a host emits once its marked send attempt has SETTLED: the awaited
|
|
11
|
+
* `prompt()` resolved or threw (D35). shipmates then drops the mark if no input
|
|
12
|
+
* consumed it, so a send that never reached the `input` handlers (another
|
|
13
|
+
* extension returned `handled`, pi refused it while compacting) leaves nothing
|
|
14
|
+
* behind, with no window. Give the mark's `id` to close exactly that mark;
|
|
15
|
+
* without one, the oldest open mark with this text and no id is closed (a mark
|
|
16
|
+
* that has an id is closed only by it).
|
|
17
|
+
*
|
|
18
|
+
* Emit it ONLY after awaiting the send. Never after `pi.sendUserMessage()`
|
|
19
|
+
* from an extension: that call is fire-and-forget in pi 1.4 (it returns before
|
|
20
|
+
* the `input` handlers run and reports failures only as `extension_error`), so
|
|
21
|
+
* an end emitted after it can drop a mark that was about to match. Such a host
|
|
22
|
+
* emits no end event and relies on the mark's 5 s expiry. Also wrong, though
|
|
23
|
+
* safe: a `prompt()` called while pi is emitting `agent_settled` is deferred
|
|
24
|
+
* and resolves before its input runs, so the end drops the mark and that send
|
|
25
|
+
* is not recorded as the human's (it fails toward "not human").
|
|
26
|
+
*/
|
|
27
|
+
export const HUMAN_INPUT_END_EVENT = 'shipmates:human-input-end';
|
|
28
|
+
/**
|
|
29
|
+
* The per-process host registry (D26). It lives on `globalThis` under a
|
|
30
|
+
* `Symbol.for` key, not in this module, so a host that loaded ANOTHER copy of
|
|
31
|
+
* shipmates (wherever's server, the @wherever-dev/pi bridge, a jiti-loaded
|
|
32
|
+
* extension) fills the same registry @shipmates/pi reads. The same pattern as
|
|
33
|
+
* wherever's `Symbol.for('wherever-dev.server-process')` marker; the key string
|
|
34
|
+
* is a contract between packages, so it changes only with a release that says
|
|
35
|
+
* so (once so far: `kenning.host` became `shipmates.host` in the D38 rename).
|
|
36
|
+
* The shape is versioned for the same reason.
|
|
37
|
+
*/
|
|
38
|
+
export const HOST_REGISTRY_KEY = Symbol.for('shipmates.host');
|
|
39
|
+
function registry() {
|
|
40
|
+
const g = globalThis;
|
|
41
|
+
let r = g[HOST_REGISTRY_KEY];
|
|
42
|
+
if (!r || !Array.isArray(r.entries))
|
|
43
|
+
r = g[HOST_REGISTRY_KEY] = { version: 1, entries: [] };
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register this process's host. The most recently registered host wins; the
|
|
48
|
+
* returned function unregisters it and restores the previous one (registering
|
|
49
|
+
* the same object twice gives two entries, each removed by its own call).
|
|
50
|
+
*/
|
|
51
|
+
export function registerHost(host) {
|
|
52
|
+
const entry = { host };
|
|
53
|
+
registry().entries.push(entry);
|
|
54
|
+
return () => {
|
|
55
|
+
const entries = registry().entries;
|
|
56
|
+
const i = entries.indexOf(entry);
|
|
57
|
+
if (i >= 0)
|
|
58
|
+
entries.splice(i, 1);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The host registered last in this process, or undefined for the terminal default. */
|
|
62
|
+
export function currentHost() {
|
|
63
|
+
const entries = registry().entries;
|
|
64
|
+
return entries[entries.length - 1]?.host;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAUzD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AA8EjE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAO9D,SAAS,QAAQ;IAChB,MAAM,CAAC,GAAG,UAAiE,CAAC;IAC5E,IAAI,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC,CAAC;IAC7B,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAClC,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC,GAAG,EAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAC,CAAC;IACtD,OAAO,CAAC,CAAC;AACV,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAmB;IAC/C,MAAM,KAAK,GAAG,EAAC,IAAI,EAAC,CAAC;IACrB,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,GAAG,EAAE;QACX,MAAM,OAAO,GAAG,QAAQ,EAAE,CAAC,OAAO,CAAC;QACnC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC,CAAC;AACH,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,WAAW;IAC1B,MAAM,OAAO,GAAG,QAAQ,EAAE,CAAC,OAAO,CAAC;IACnC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC;AAC1C,CAAC"}
|
package/dist/ids.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAEA,4GAA4G;AAC5G,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5C"}
|
package/dist/ids.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
/** Short, typed, unguessable ids: `m_` messages, `q_` questions, `h_` attention items, `t_` human turns. */
|
|
3
|
+
export function newId(prefix) {
|
|
4
|
+
return `${prefix}_${randomBytes(6).toString('base64url')}`;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ids.js.map
|
package/dist/ids.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AAExC,4GAA4G;AAC5G,MAAM,UAAU,KAAK,CAAC,MAAc;IACnC,OAAO,GAAG,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AAC5D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { Shipmates, openShipmates, MAX_TEXT_BYTES, ARCHIVE_UNDO_MS, } from './shipmates.js';
|
|
2
|
+
export type { ShipmatesOptions, RegisterInput, PresencePatch, ListFilter, Resolved, SendInput, SendResult, SpawnInput, WaitStatus, } from './shipmates.js';
|
|
3
|
+
export { OsProbe } from './liveness.js';
|
|
4
|
+
export type { ProcessIdentity, ProcessProbe } from './liveness.js';
|
|
5
|
+
export { defaultStateDir } from './store.js';
|
|
6
|
+
export { silenceSqliteWarning } from './quiet.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export { readTail } from './tail.js';
|
|
9
|
+
export type { Tail, TailMessage, TailOptions } from './tail.js';
|
|
10
|
+
export { planDelivery } from './delivery.js';
|
|
11
|
+
export type { SessionView, DeliveryPlan } from './delivery.js';
|
|
12
|
+
export { watchChanges } from './watch.js';
|
|
13
|
+
export { HUMAN_INPUT_EVENT, HUMAN_INPUT_END_EVENT, HOST_REGISTRY_KEY, registerHost, currentHost, } from './host.js';
|
|
14
|
+
export type { HumanInputEnd, HumanInputMark, ShipmatesHost, SpawnRequest, SpawnResult, StopOutcome, } from './host.js';
|
|
15
|
+
export { runCli } from './cli-run.js';
|
|
16
|
+
export type { CliIo } from './cli-run.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,aAAa,EACb,cAAc,EACd,eAAe,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACX,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,EACV,QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,YAAY,EAAC,eAAe,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AACjE,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAC,oBAAoB,EAAC,MAAM,YAAY,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAC;AACnC,YAAY,EAAC,IAAI,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAC,WAAW,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,WAAW,GACX,MAAM,WAAW,CAAC;AACnB,YAAY,EACX,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,WAAW,EACX,WAAW,GACX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,YAAY,EAAC,KAAK,EAAC,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Shipmates, openShipmates, MAX_TEXT_BYTES, ARCHIVE_UNDO_MS, } from './shipmates.js';
|
|
2
|
+
export { OsProbe } from './liveness.js';
|
|
3
|
+
export { defaultStateDir } from './store.js';
|
|
4
|
+
export { silenceSqliteWarning } from './quiet.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export { readTail } from './tail.js';
|
|
7
|
+
export { planDelivery } from './delivery.js';
|
|
8
|
+
export { watchChanges } from './watch.js';
|
|
9
|
+
export { HUMAN_INPUT_EVENT, HUMAN_INPUT_END_EVENT, HOST_REGISTRY_KEY, registerHost, currentHost, } from './host.js';
|
|
10
|
+
export { runCli } from './cli-run.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,aAAa,EACb,cAAc,EACd,eAAe,GACf,MAAM,gBAAgB,CAAC;AAYxB,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAC,oBAAoB,EAAC,MAAM,YAAY,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,WAAW,GACX,MAAM,WAAW,CAAC;AASnB,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Who a process is, precisely enough that a reused pid is not mistaken for it. */
|
|
2
|
+
export interface ProcessIdentity {
|
|
3
|
+
pid: number;
|
|
4
|
+
/** Process start time as the OS reports it; null when it cannot be read. */
|
|
5
|
+
startTime: string | null;
|
|
6
|
+
bootId: string | null;
|
|
7
|
+
host: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ProcessProbe {
|
|
10
|
+
self(): ProcessIdentity;
|
|
11
|
+
isAlive(p: ProcessIdentity): boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The same rule as wherever's assistant lock: a process is alive when its pid
|
|
15
|
+
* runs on this boot with the start time recorded. On another host we cannot
|
|
16
|
+
* know, so it counts as alive (single machine is the stated scope).
|
|
17
|
+
*/
|
|
18
|
+
export declare class OsProbe implements ProcessProbe {
|
|
19
|
+
private readonly host;
|
|
20
|
+
private readonly bootId;
|
|
21
|
+
private me;
|
|
22
|
+
self(): ProcessIdentity;
|
|
23
|
+
isAlive(p: ProcessIdentity): boolean;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=liveness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liveness.d.ts","sourceRoot":"","sources":["../src/liveness.ts"],"names":[],"mappings":"AAIA,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,4EAA4E;IAC5E,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,IAAI,eAAe,CAAC;IACxB,OAAO,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC;CACrC;AAED;;;;GAIG;AACH,qBAAa,OAAQ,YAAW,YAAY;IAC3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,EAAE,CAA8B;IAExC,IAAI,IAAI,eAAe;IAUvB,OAAO,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO;CAapC"}
|