wherever-dev 0.21.1 → 0.22.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/CHANGELOG.md +20 -0
- package/dist/assistant-channels.d.ts +242 -0
- package/dist/assistant-channels.d.ts.map +1 -0
- package/dist/assistant-channels.js +270 -0
- package/dist/assistant-channels.js.map +1 -0
- package/dist/assistant-controller.d.ts +228 -0
- package/dist/assistant-controller.d.ts.map +1 -0
- package/dist/assistant-controller.js +314 -0
- package/dist/assistant-controller.js.map +1 -0
- package/dist/assistant-cron.d.ts +87 -0
- package/dist/assistant-cron.d.ts.map +1 -0
- package/dist/assistant-cron.js +352 -0
- package/dist/assistant-cron.js.map +1 -0
- package/dist/assistant-folder.d.ts +161 -0
- package/dist/assistant-folder.d.ts.map +1 -0
- package/dist/assistant-folder.js +333 -0
- package/dist/assistant-folder.js.map +1 -0
- package/dist/assistant-schedule.d.ts +236 -0
- package/dist/assistant-schedule.d.ts.map +1 -0
- package/dist/assistant-schedule.js +454 -0
- package/dist/assistant-schedule.js.map +1 -0
- package/dist/assistant-scheduler.d.ts +210 -0
- package/dist/assistant-scheduler.d.ts.map +1 -0
- package/dist/assistant-scheduler.js +472 -0
- package/dist/assistant-scheduler.js.map +1 -0
- package/dist/assistant-tool-text.d.ts +40 -0
- package/dist/assistant-tool-text.d.ts.map +1 -0
- package/dist/assistant-tool-text.js +102 -0
- package/dist/assistant-tool-text.js.map +1 -0
- package/dist/assistant-tools.d.ts +207 -0
- package/dist/assistant-tools.d.ts.map +1 -0
- package/dist/assistant-tools.js +390 -0
- package/dist/assistant-tools.js.map +1 -0
- package/dist/cli-requests.d.ts +90 -0
- package/dist/cli-requests.d.ts.map +1 -0
- package/dist/cli-requests.js +75 -0
- package/dist/cli-requests.js.map +1 -0
- package/dist/index.js +396 -7
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +43 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/reply-routing.d.ts +106 -0
- package/dist/reply-routing.d.ts.map +1 -0
- package/dist/reply-routing.js +174 -0
- package/dist/reply-routing.js.map +1 -0
- package/dist/session-pool.d.ts +232 -4
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +446 -100
- package/dist/session-pool.js.map +1 -1
- package/dist/telegram-channel.d.ts +272 -0
- package/dist/telegram-channel.d.ts.map +1 -0
- package/dist/telegram-channel.js +701 -0
- package/dist/telegram-channel.js.map +1 -0
- package/dist/telegram-files.d.ts +101 -0
- package/dist/telegram-files.d.ts.map +1 -0
- package/dist/telegram-files.js +145 -0
- package/dist/telegram-files.js.map +1 -0
- package/dist/telegram-pairing.d.ts +119 -0
- package/dist/telegram-pairing.d.ts.map +1 -0
- package/dist/telegram-pairing.js +97 -0
- package/dist/telegram-pairing.js.map +1 -0
- package/dist/telegram-replies.d.ts +94 -0
- package/dist/telegram-replies.d.ts.map +1 -0
- package/dist/telegram-replies.js +329 -0
- package/dist/telegram-replies.js.map +1 -0
- package/dist/telegram-token.d.ts +55 -0
- package/dist/telegram-token.d.ts.map +1 -0
- package/dist/telegram-token.js +86 -0
- package/dist/telegram-token.js.map +1 -0
- package/dist/web-push.d.ts +167 -0
- package/dist/web-push.d.ts.map +1 -0
- package/dist/web-push.js +387 -0
- package/dist/web-push.js.map +1 -0
- package/package.json +1 -1
- package/public/_app/immutable/assets/0.BkzT3rFr.css +1 -0
- package/public/_app/immutable/chunks/CExVgK9Z.js +2 -0
- package/public/_app/immutable/chunks/CExVgK9Z.js.map +1 -0
- package/public/_app/immutable/chunks/CkOw6fRa.js +2 -0
- package/public/_app/immutable/chunks/{BQ9B_G4h.js.map → CkOw6fRa.js.map} +1 -1
- package/public/_app/immutable/chunks/DyHllYtq.js +2 -0
- package/public/_app/immutable/chunks/{BUONgvl4.js.map → DyHllYtq.js.map} +1 -1
- package/public/_app/immutable/entry/{app.BZO7Xckk.js → app.D3PEFbtP.js} +3 -3
- package/public/_app/immutable/entry/{app.BZO7Xckk.js.map → app.D3PEFbtP.js.map} +1 -1
- package/public/_app/immutable/entry/start.BR00Qps5.js +2 -0
- package/public/_app/immutable/entry/start.BR00Qps5.js.map +1 -0
- package/public/_app/immutable/nodes/{0.Czz2XmZU.js → 0.DG3L8hMN.js} +3 -3
- package/public/_app/immutable/nodes/{0.Czz2XmZU.js.map → 0.DG3L8hMN.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.DDvrriUW.js → 1.BCpuoZxW.js} +2 -2
- package/public/_app/immutable/nodes/{1.DDvrriUW.js.map → 1.BCpuoZxW.js.map} +1 -1
- package/public/_app/immutable/nodes/2.D2auiZW1.js +122 -0
- package/public/_app/immutable/nodes/2.D2auiZW1.js.map +1 -0
- package/public/_app/version.json +1 -1
- package/public/index.html +11 -11
- package/public/service-worker.js +1 -1
- package/public/_app/immutable/assets/0.BKJ49K71.css +0 -1
- package/public/_app/immutable/chunks/BQ9B_G4h.js +0 -2
- package/public/_app/immutable/chunks/BUONgvl4.js +0 -2
- package/public/_app/immutable/chunks/DauELski.js +0 -2
- package/public/_app/immutable/chunks/DauELski.js.map +0 -1
- package/public/_app/immutable/entry/start.DWD60uNu.js +0 -2
- package/public/_app/immutable/entry/start.DWD60uNu.js.map +0 -1
- package/public/_app/immutable/nodes/2.C7E8EMKX.js +0 -120
- package/public/_app/immutable/nodes/2.C7E8EMKX.js.map +0 -1
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { DEFAULT_GRACE_MS, RunLog, ScheduleStore, UserTimezone, effectiveTimeZone, planJob, } from './assistant-schedule.js';
|
|
4
|
+
export const realClock = {
|
|
5
|
+
now: () => Date.now(),
|
|
6
|
+
setTimeout(fn, ms) {
|
|
7
|
+
const t = setTimeout(fn, ms);
|
|
8
|
+
t.unref?.();
|
|
9
|
+
return () => clearTimeout(t);
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
/** Longest gap between two ticks (each re-reads `schedule.json`, picking up hand edits). */
|
|
13
|
+
export const MAX_TICK_MS = 30_000;
|
|
14
|
+
const MIN_TICK_MS = 500;
|
|
15
|
+
/**
|
|
16
|
+
* A CLI-bridge send that never produced an `agent_start` (an extension command
|
|
17
|
+
* handled it in the terminal, which the server cannot see, ADR 0014) stops
|
|
18
|
+
* blocking inline jobs after this long.
|
|
19
|
+
*/
|
|
20
|
+
export const CLI_START_TIMEOUT_MS = 60_000;
|
|
21
|
+
export class AssistantScheduler {
|
|
22
|
+
store;
|
|
23
|
+
folder;
|
|
24
|
+
stateDir;
|
|
25
|
+
pool;
|
|
26
|
+
controller;
|
|
27
|
+
clock;
|
|
28
|
+
graceMs;
|
|
29
|
+
systemTimezone;
|
|
30
|
+
onTimezoneChange;
|
|
31
|
+
runLog = null;
|
|
32
|
+
timezone = null;
|
|
33
|
+
started = false;
|
|
34
|
+
stopped = false;
|
|
35
|
+
cancelTimer = null;
|
|
36
|
+
unsubscribe = null;
|
|
37
|
+
ticking = Promise.resolve();
|
|
38
|
+
work = new Set();
|
|
39
|
+
lastRead = { valid: [], invalid: [], fileError: null };
|
|
40
|
+
lastInvalidKey = '';
|
|
41
|
+
seen = new Map();
|
|
42
|
+
/** Due inline jobs waiting for the assistant session to settle, oldest first. */
|
|
43
|
+
pendingInline = [];
|
|
44
|
+
/** Isolated jobs being started (their run entry not written yet). */
|
|
45
|
+
startingIsolated = new Set();
|
|
46
|
+
/** Sessions with a run in progress, as seen from events and our own sends. */
|
|
47
|
+
runs = new Map();
|
|
48
|
+
draining = false;
|
|
49
|
+
jobSessions = new Map();
|
|
50
|
+
constructor(opts) {
|
|
51
|
+
this.folder = path.resolve(opts.folder);
|
|
52
|
+
this.stateDir = opts.stateDir;
|
|
53
|
+
this.pool = opts.pool;
|
|
54
|
+
this.controller = opts.controller;
|
|
55
|
+
this.clock = opts.clock ?? realClock;
|
|
56
|
+
this.graceMs = opts.graceMs ?? DEFAULT_GRACE_MS;
|
|
57
|
+
this.systemTimezone = opts.systemTimezone;
|
|
58
|
+
this.onTimezoneChange = opts.onTimezoneChange;
|
|
59
|
+
this.store = new ScheduleStore(this.folder, opts.store);
|
|
60
|
+
}
|
|
61
|
+
/** Load the run log and timezone state, subscribe to the pool, and run the first tick (restart catch-up). */
|
|
62
|
+
start() {
|
|
63
|
+
if (this.started)
|
|
64
|
+
return this.ticking;
|
|
65
|
+
this.started = true;
|
|
66
|
+
this.runLog = new RunLog(this.stateDir);
|
|
67
|
+
this.timezone = new UserTimezone(this.stateDir, this.systemTimezone);
|
|
68
|
+
for (const e of this.runLog.all()) {
|
|
69
|
+
if (e.mode === 'isolated' && e.sessionFile)
|
|
70
|
+
this.jobSessions.set(e.sessionFile, e.jobId);
|
|
71
|
+
}
|
|
72
|
+
this.unsubscribe = this.pool.subscribeEvents((file, event) => this.handleEvent(file, event));
|
|
73
|
+
return this.tick();
|
|
74
|
+
}
|
|
75
|
+
stop() {
|
|
76
|
+
this.stopped = true;
|
|
77
|
+
this.cancelTimer?.();
|
|
78
|
+
this.cancelTimer = null;
|
|
79
|
+
this.unsubscribe?.();
|
|
80
|
+
this.unsubscribe = null;
|
|
81
|
+
}
|
|
82
|
+
/** Resolves once the current tick and every send it started have settled (tests, shutdown). */
|
|
83
|
+
async idle() {
|
|
84
|
+
for (let i = 0; i < 10; i++) {
|
|
85
|
+
await this.ticking;
|
|
86
|
+
if (this.work.size === 0)
|
|
87
|
+
return;
|
|
88
|
+
await Promise.allSettled([...this.work]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The user's current timezone (what a job without `tz` follows). */
|
|
92
|
+
getUserTimezone() {
|
|
93
|
+
return this.requireTimezone().get();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Change the user's timezone (validated IANA name; recorded). Re-plans at
|
|
97
|
+
* once, since every follows-the-user job moves with it. Resolves false when
|
|
98
|
+
* it was already that zone.
|
|
99
|
+
*/
|
|
100
|
+
setUserTimezone(timezone, source) {
|
|
101
|
+
const changed = this.requireTimezone().set(timezone, source);
|
|
102
|
+
if (changed) {
|
|
103
|
+
console.log(`[wherever] assistant: the user's timezone is now ${timezone} (${source})`);
|
|
104
|
+
try {
|
|
105
|
+
this.onTimezoneChange?.(timezone);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
console.error(`[wherever] assistant scheduler: onTimezoneChange failed: ${errMessage(err)}`);
|
|
109
|
+
}
|
|
110
|
+
void this.tick();
|
|
111
|
+
}
|
|
112
|
+
return changed;
|
|
113
|
+
}
|
|
114
|
+
/** Add a job through the store's write queue, then tick (an `at: "now"` job fires at once). */
|
|
115
|
+
async addJob(input) {
|
|
116
|
+
const job = await this.store.addJob(input);
|
|
117
|
+
void this.tick();
|
|
118
|
+
return job;
|
|
119
|
+
}
|
|
120
|
+
async removeJob(id) {
|
|
121
|
+
const removed = await this.store.removeJob(id);
|
|
122
|
+
this.pendingInline = this.pendingInline.filter((p) => p.jobId !== id);
|
|
123
|
+
void this.tick();
|
|
124
|
+
return removed;
|
|
125
|
+
}
|
|
126
|
+
/** The job an isolated job session was started for, or null. */
|
|
127
|
+
jobForSession(sessionFile) {
|
|
128
|
+
return this.jobSessions.get(sessionFile) ?? null;
|
|
129
|
+
}
|
|
130
|
+
/** Every job with its state and last / next run, plus the invalid entries. Re-reads the file. */
|
|
131
|
+
list() {
|
|
132
|
+
const read = this.store.read();
|
|
133
|
+
const now = this.clock.now();
|
|
134
|
+
const userTz = this.getUserTimezone();
|
|
135
|
+
const runLog = this.requireRunLog();
|
|
136
|
+
const jobs = read.valid.map((v) => {
|
|
137
|
+
const tz = effectiveTimeZone(v.job, userTz);
|
|
138
|
+
const runs = runLog.forJob(v.job.id);
|
|
139
|
+
const plan = planJob(v, tz, runs, now, { graceMs: this.graceMs, since: this.sinceFor(v, runs.length > 0, now) });
|
|
140
|
+
const pending = this.pendingInline.some((p) => p.jobId === v.job.id);
|
|
141
|
+
return {
|
|
142
|
+
job: v.job,
|
|
143
|
+
timezone: tz,
|
|
144
|
+
state: pending ? 'pending' : plan.state,
|
|
145
|
+
next: plan.next === null ? null : new Date(plan.next).toISOString(),
|
|
146
|
+
last: runs.at(-1) ?? null,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
return { timezone: userTz, fileError: read.fileError, jobs, invalid: read.invalid };
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* One pass: re-read and validate `schedule.json`, plan every job, record
|
|
153
|
+
* skips, fire what is due, try to deliver pending inline jobs, re-arm the
|
|
154
|
+
* timer. Serialised; safe to call at any time (it is also the test seam).
|
|
155
|
+
*/
|
|
156
|
+
tick() {
|
|
157
|
+
const run = this.ticking.then(() => this.tickNow());
|
|
158
|
+
this.ticking = run.catch((err) => {
|
|
159
|
+
console.error(`[wherever] assistant scheduler: tick failed: ${errMessage(err)}`);
|
|
160
|
+
});
|
|
161
|
+
return this.ticking;
|
|
162
|
+
}
|
|
163
|
+
// -------------------------------------------------------------------------
|
|
164
|
+
tickNow() {
|
|
165
|
+
if (this.stopped || !this.started)
|
|
166
|
+
return;
|
|
167
|
+
const now = this.clock.now();
|
|
168
|
+
const read = this.store.read();
|
|
169
|
+
this.lastRead = read;
|
|
170
|
+
this.reportInvalid(read);
|
|
171
|
+
const userTz = this.getUserTimezone();
|
|
172
|
+
const runLog = this.requireRunLog();
|
|
173
|
+
const ids = new Set();
|
|
174
|
+
let soonest = null;
|
|
175
|
+
for (const v of read.valid) {
|
|
176
|
+
ids.add(v.job.id);
|
|
177
|
+
this.track(v, now);
|
|
178
|
+
if (this.isInFlight(v.job.id))
|
|
179
|
+
continue;
|
|
180
|
+
const runs = runLog.forJob(v.job.id);
|
|
181
|
+
const plan = planJob(v, effectiveTimeZone(v.job, userTz), runs, now, {
|
|
182
|
+
graceMs: this.graceMs,
|
|
183
|
+
since: this.sinceFor(v, runs.length > 0, now),
|
|
184
|
+
});
|
|
185
|
+
if (plan.state === 'waiting') {
|
|
186
|
+
if (soonest === null || plan.next < soonest)
|
|
187
|
+
soonest = plan.next;
|
|
188
|
+
}
|
|
189
|
+
else if (plan.state === 'missed') {
|
|
190
|
+
console.log(`[wherever] assistant scheduler: job "${v.job.id}" missed its run of ${new Date(plan.scheduledFor).toISOString()} (outside the grace window); skipped`);
|
|
191
|
+
this.record(v.job, plan.scheduledFor, 'skipped');
|
|
192
|
+
if (v.cron) {
|
|
193
|
+
// Its next occurrence still needs a timer.
|
|
194
|
+
const after = planJob(v, effectiveTimeZone(v.job, userTz), runLog.forJob(v.job.id), now, {
|
|
195
|
+
graceMs: this.graceMs,
|
|
196
|
+
since: this.sinceFor(v, true, now),
|
|
197
|
+
});
|
|
198
|
+
if (after.state === 'waiting' && (soonest === null || after.next < soonest))
|
|
199
|
+
soonest = after.next;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (plan.state === 'due') {
|
|
203
|
+
this.fire(v, plan.scheduledFor);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (const id of [...this.seen.keys()])
|
|
207
|
+
if (!ids.has(id))
|
|
208
|
+
this.seen.delete(id);
|
|
209
|
+
this.pendingInline = this.pendingInline.filter((p) => ids.has(p.jobId));
|
|
210
|
+
void this.drainInline();
|
|
211
|
+
this.arm(soonest, now);
|
|
212
|
+
}
|
|
213
|
+
isInFlight(jobId) {
|
|
214
|
+
return this.startingIsolated.has(jobId) || this.pendingInline.some((p) => p.jobId === jobId);
|
|
215
|
+
}
|
|
216
|
+
/** Remember when a job was first seen, re-enabled, or had its time spec edited. */
|
|
217
|
+
track(v, now) {
|
|
218
|
+
const fingerprint = JSON.stringify([v.job.cron ?? null, v.job.at ?? null, v.job.tz ?? null]);
|
|
219
|
+
const prev = this.seen.get(v.job.id);
|
|
220
|
+
if (!prev) {
|
|
221
|
+
this.seen.set(v.job.id, { firstSeen: now, enabled: v.job.enabled, fingerprint });
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if ((!prev.enabled && v.job.enabled) || prev.fingerprint !== fingerprint)
|
|
225
|
+
prev.changedAt = now;
|
|
226
|
+
prev.enabled = v.job.enabled;
|
|
227
|
+
prev.fingerprint = fingerprint;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The planner's `since`: occurrences before it are not "missed". A job with
|
|
231
|
+
* no run yet counts from when this process first saw it (so a job added, or
|
|
232
|
+
* hand-written, while the server was down does not catch up on a run from
|
|
233
|
+
* before it existed); a job re-enabled or edited counts from then. A job WITH
|
|
234
|
+
* runs and no change counts from its last run, which is what lets a restart
|
|
235
|
+
* catch up on a run missed while the server was down.
|
|
236
|
+
*/
|
|
237
|
+
sinceFor(v, hasRuns, now) {
|
|
238
|
+
const s = this.seen.get(v.job.id);
|
|
239
|
+
if (s?.changedAt !== undefined)
|
|
240
|
+
return s.changedAt;
|
|
241
|
+
if (hasRuns)
|
|
242
|
+
return undefined;
|
|
243
|
+
return s?.firstSeen ?? now;
|
|
244
|
+
}
|
|
245
|
+
fire(v, scheduledFor) {
|
|
246
|
+
const job = v.job;
|
|
247
|
+
if (job.prompt.trimStart().startsWith('!')) {
|
|
248
|
+
console.warn(`[wherever] assistant scheduler: job "${job.id}" refused: a scheduled prompt cannot run a shell command ("!")`);
|
|
249
|
+
this.record(job, scheduledFor, 'refused', null, 'prompts starting with "!" are refused (no shell commands from the scheduler)');
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (job.mode === 'inline') {
|
|
253
|
+
this.pendingInline.push({ jobId: job.id, scheduledFor });
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
this.startIsolated(job, scheduledFor);
|
|
257
|
+
}
|
|
258
|
+
startIsolated(job, scheduledFor) {
|
|
259
|
+
this.startingIsolated.add(job.id);
|
|
260
|
+
const jobsDir = path.join(this.folder, 'jobs');
|
|
261
|
+
const task = (async () => {
|
|
262
|
+
let sessionFile = null;
|
|
263
|
+
try {
|
|
264
|
+
fs.mkdirSync(jobsDir, { recursive: true });
|
|
265
|
+
const created = await this.pool.createNewSession(jobsDir, undefined, undefined, undefined, undefined, true);
|
|
266
|
+
if (created.error || !created.tracked)
|
|
267
|
+
throw new Error(created.error || 'could not create the job session');
|
|
268
|
+
sessionFile = created.tracked.sessionFile;
|
|
269
|
+
this.jobSessions.set(sessionFile, job.id);
|
|
270
|
+
this.record(job, scheduledFor, 'fired', sessionFile);
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
console.error(`[wherever] assistant scheduler: isolated job "${job.id}" could not start: ${errMessage(err)}`);
|
|
274
|
+
this.record(job, scheduledFor, 'failed', sessionFile, errMessage(err));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
this.startingIsolated.delete(job.id);
|
|
279
|
+
}
|
|
280
|
+
console.log(`[wherever] assistant scheduler: isolated job "${job.id}" started in ${sessionFile}`);
|
|
281
|
+
try {
|
|
282
|
+
await this.pool.sendUserMessage(sessionFile, formatScheduledPrompt(job), undefined, false, scheduleOrigin(job.id));
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
console.error(`[wherever] assistant scheduler: isolated job "${job.id}" failed: ${errMessage(err)}`);
|
|
286
|
+
this.record(job, scheduledFor, 'failed', sessionFile, errMessage(err));
|
|
287
|
+
}
|
|
288
|
+
})();
|
|
289
|
+
this.track_(task);
|
|
290
|
+
}
|
|
291
|
+
/** Deliver the oldest pending inline job if the current assistant session is settled and empty. */
|
|
292
|
+
async drainInline() {
|
|
293
|
+
if (this.draining || this.stopped || this.pendingInline.length === 0)
|
|
294
|
+
return;
|
|
295
|
+
this.draining = true;
|
|
296
|
+
try {
|
|
297
|
+
while (this.pendingInline.length > 0 && !this.stopped) {
|
|
298
|
+
const head = this.pendingInline[0];
|
|
299
|
+
const v = this.lastRead.valid.find((x) => x.job.id === head.jobId);
|
|
300
|
+
if (!v || !v.job.enabled) {
|
|
301
|
+
// Removed or disabled while it waited.
|
|
302
|
+
this.pendingInline.shift();
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const current = this.controller.status().currentSessionFile;
|
|
306
|
+
if (current && !this.isIdle(current))
|
|
307
|
+
return;
|
|
308
|
+
let sessionFile;
|
|
309
|
+
try {
|
|
310
|
+
sessionFile = (await this.controller.ensureCurrent()).sessionFile;
|
|
311
|
+
}
|
|
312
|
+
catch (err) {
|
|
313
|
+
this.pendingInline.shift();
|
|
314
|
+
this.record(v.job, head.scheduledFor, 'failed', null, errMessage(err));
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (!this.isIdle(sessionFile))
|
|
318
|
+
return;
|
|
319
|
+
this.pendingInline.shift();
|
|
320
|
+
this.runs.set(sessionFile, { at: this.clock.now(), started: false });
|
|
321
|
+
this.record(v.job, head.scheduledFor, 'fired', sessionFile);
|
|
322
|
+
console.log(`[wherever] assistant scheduler: inline job "${v.job.id}" sent to ${sessionFile}`);
|
|
323
|
+
const job = v.job;
|
|
324
|
+
const send = this.controller.send(formatScheduledPrompt(job), scheduleOrigin(job.id)).then(() => {
|
|
325
|
+
// A server send resolves when pi is done with it (or an extension
|
|
326
|
+
// command handled it, with no run and so no settle): unblock.
|
|
327
|
+
if (this.pool.getSession(sessionFile)?.type === 'server' && !this.pool.isStreaming(sessionFile)) {
|
|
328
|
+
this.runs.delete(sessionFile);
|
|
329
|
+
void this.drainInline();
|
|
330
|
+
}
|
|
331
|
+
}, (err) => {
|
|
332
|
+
console.error(`[wherever] assistant scheduler: inline job "${job.id}" failed: ${errMessage(err)}`);
|
|
333
|
+
this.record(job, head.scheduledFor, 'failed', sessionFile, errMessage(err));
|
|
334
|
+
this.runs.delete(sessionFile);
|
|
335
|
+
void this.drainInline();
|
|
336
|
+
});
|
|
337
|
+
this.track_(send);
|
|
338
|
+
// One at a time: the next waits for this one's settle.
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
finally {
|
|
343
|
+
this.draining = false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** Settled with nothing queued: no run in progress (pool or ours) and pi's queues empty. */
|
|
347
|
+
isIdle(sessionFile) {
|
|
348
|
+
const session = this.pool.getSession(sessionFile);
|
|
349
|
+
if (!session) {
|
|
350
|
+
// Not resident: nothing can be running there (the send reloads it).
|
|
351
|
+
this.runs.delete(sessionFile);
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
if (this.pool.isStreaming(sessionFile))
|
|
355
|
+
return false;
|
|
356
|
+
const mark = this.runs.get(sessionFile);
|
|
357
|
+
if (mark) {
|
|
358
|
+
const stale = session.type === 'cli' && !mark.started && this.clock.now() - mark.at > CLI_START_TIMEOUT_MS;
|
|
359
|
+
if (!stale)
|
|
360
|
+
return false;
|
|
361
|
+
this.runs.delete(sessionFile);
|
|
362
|
+
}
|
|
363
|
+
return (this.pool.getQueuedMessageCount(sessionFile) ?? 0) === 0;
|
|
364
|
+
}
|
|
365
|
+
handleEvent(sessionFile, event) {
|
|
366
|
+
if (this.stopped || !this.started)
|
|
367
|
+
return;
|
|
368
|
+
if (event.type === 'agent_start') {
|
|
369
|
+
this.runs.set(sessionFile, { at: this.clock.now(), started: true });
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (event.type === 'agent_settled') {
|
|
373
|
+
if (event.aborted === true && sessionFile === this.controller.status().currentSessionFile) {
|
|
374
|
+
// An abort leaves pi's queues populated (ADR 0014): without clearing
|
|
375
|
+
// them, "settled with nothing queued" would never be reached again.
|
|
376
|
+
try {
|
|
377
|
+
this.controller.clearAfterAbort(sessionFile);
|
|
378
|
+
}
|
|
379
|
+
catch (err) {
|
|
380
|
+
console.error(`[wherever] assistant scheduler: clearing after an abort failed: ${errMessage(err)}`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
this.runs.delete(sessionFile);
|
|
384
|
+
void this.drainInline();
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (event.type === 'agent_end') {
|
|
388
|
+
// An older CLI extension never forwards `agent_settled`: settle on agent_end.
|
|
389
|
+
const session = this.pool.getSession(sessionFile);
|
|
390
|
+
if (session?.type !== 'cli')
|
|
391
|
+
return;
|
|
392
|
+
if ((this.pool.getCliCapabilities(sessionFile) ?? []).includes('agent_settled'))
|
|
393
|
+
return;
|
|
394
|
+
this.runs.delete(sessionFile);
|
|
395
|
+
void this.drainInline();
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
record(job, scheduledFor, outcome, sessionFile = null, error) {
|
|
399
|
+
this.requireRunLog().append({
|
|
400
|
+
jobId: job.id,
|
|
401
|
+
time: new Date(this.clock.now()).toISOString(),
|
|
402
|
+
scheduledFor: new Date(scheduledFor).toISOString(),
|
|
403
|
+
mode: job.mode,
|
|
404
|
+
outcome,
|
|
405
|
+
...(sessionFile ? { sessionFile } : {}),
|
|
406
|
+
...(error ? { error } : {}),
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
arm(soonest, now) {
|
|
410
|
+
this.cancelTimer?.();
|
|
411
|
+
this.cancelTimer = null;
|
|
412
|
+
if (this.stopped)
|
|
413
|
+
return;
|
|
414
|
+
const delay = soonest === null ? MAX_TICK_MS : Math.min(MAX_TICK_MS, Math.max(MIN_TICK_MS, soonest - now));
|
|
415
|
+
this.cancelTimer = this.clock.setTimeout(() => {
|
|
416
|
+
this.cancelTimer = null;
|
|
417
|
+
void this.tick();
|
|
418
|
+
}, delay);
|
|
419
|
+
}
|
|
420
|
+
reportInvalid(read) {
|
|
421
|
+
const key = JSON.stringify([read.fileError, read.invalid.map((i) => [i.index, i.errors])]);
|
|
422
|
+
if (key === this.lastInvalidKey)
|
|
423
|
+
return;
|
|
424
|
+
this.lastInvalidKey = key;
|
|
425
|
+
if (read.fileError)
|
|
426
|
+
console.warn(`[wherever] assistant scheduler: ${this.store.filePath} is unreadable, no job runs: ${read.fileError}`);
|
|
427
|
+
for (const i of read.invalid) {
|
|
428
|
+
console.warn(`[wherever] assistant scheduler: ${this.store.filePath} entry #${i.index}${i.id ? ` ("${i.id}")` : ''} is invalid and will not run: ${i.errors.join('; ')}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
track_(p) {
|
|
432
|
+
const tracked = p.catch(() => { });
|
|
433
|
+
this.work.add(tracked);
|
|
434
|
+
void tracked.then(() => this.work.delete(tracked));
|
|
435
|
+
}
|
|
436
|
+
requireRunLog() {
|
|
437
|
+
if (!this.runLog)
|
|
438
|
+
throw new Error('the assistant scheduler is not started');
|
|
439
|
+
return this.runLog;
|
|
440
|
+
}
|
|
441
|
+
requireTimezone() {
|
|
442
|
+
if (!this.timezone)
|
|
443
|
+
throw new Error('the assistant scheduler is not started');
|
|
444
|
+
return this.timezone;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/** The reply-routing origin of a scheduled send (ADR 0014). */
|
|
448
|
+
export function scheduleOrigin(jobId) {
|
|
449
|
+
return `schedule:${jobId}`;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* The text a scheduled job sends: `[schedule:<name>] (from <originCwd>, session
|
|
453
|
+
* <originSessionId>) <prompt>`, so the agent knows it is a job and where it came
|
|
454
|
+
* from. A prompt starting with `/` goes WITHOUT the prefix, so command, skill and
|
|
455
|
+
* prompt-template expansion (start-of-message anchored) still work. Missing
|
|
456
|
+
* origin parts are left out (no parenthesis at all when both are).
|
|
457
|
+
*/
|
|
458
|
+
export function formatScheduledPrompt(job) {
|
|
459
|
+
const trimmed = job.prompt.trimStart();
|
|
460
|
+
if (trimmed.startsWith('/'))
|
|
461
|
+
return trimmed;
|
|
462
|
+
const context = [];
|
|
463
|
+
if (job.originCwd)
|
|
464
|
+
context.push(`from ${job.originCwd}`);
|
|
465
|
+
if (job.originSessionId)
|
|
466
|
+
context.push(`session ${job.originSessionId}`);
|
|
467
|
+
return `[schedule:${job.name}]${context.length > 0 ? ` (${context.join(', ')})` : ''} ${job.prompt}`;
|
|
468
|
+
}
|
|
469
|
+
function errMessage(err) {
|
|
470
|
+
return err instanceof Error ? err.message : String(err);
|
|
471
|
+
}
|
|
472
|
+
//# sourceMappingURL=assistant-scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant-scheduler.js","sourceRoot":"","sources":["../src/assistant-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,gBAAgB,EAChB,MAAM,EACN,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,OAAO,GAQR,MAAM,yBAAyB,CAAC;AA2EjC,MAAM,CAAC,MAAM,SAAS,GAAmB;IACvC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IACrB,UAAU,CAAC,EAAE,EAAE,EAAE;QACf,MAAM,CAAC,GAAG,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7B,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACZ,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;CACF,CAAC;AAEF,4FAA4F;AAC5F,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC;AAClC,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAmD3C,MAAM,OAAO,kBAAkB;IACpB,KAAK,CAAgB;IACb,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,IAAI,CAAoB;IACxB,UAAU,CAA0B;IACpC,KAAK,CAAiB;IACtB,OAAO,CAAS;IAChB,cAAc,CAAU;IACxB,gBAAgB,CAA8B;IAEvD,MAAM,GAAkB,IAAI,CAAC;IAC7B,QAAQ,GAAwB,IAAI,CAAC;IACrC,OAAO,GAAG,KAAK,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,WAAW,GAAwB,IAAI,CAAC;IACxC,WAAW,GAAwB,IAAI,CAAC;IACxC,O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AC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;AACvG,CAAC;AAED,SAAS,UAAU,CAAC,GAAY;IAC9B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SHARED TEXT of the `assistant_*` tools (spec `assistant-session-and-channels`,
|
|
3
|
+
* ADRs 0015 and 0016): each tool's name, label, description, `promptSnippet` and
|
|
4
|
+
* `promptGuidelines`, plus the per-turn timezone line.
|
|
5
|
+
*
|
|
6
|
+
* Owned by `assistant-schedule-tools-server` (which created it with the schedule
|
|
7
|
+
* and timezone tools); `channel-seam-notify-and-web-push` added `assistant_notify`
|
|
8
|
+
* here, and `cli-assistant-tool-twins` copies every entry (and `timezoneLine`) into the
|
|
9
|
+
* extension's `pi.registerTool` twins (extension/src/assistant-tool-twins.ts)
|
|
10
|
+
* under a drift test (server/test/assistant-tool-twins.test.ts, like
|
|
11
|
+
* `say-tool.test.ts`): the extension is a separate published package that
|
|
12
|
+
* cannot import from the server, so its copies must stay identical to these.
|
|
13
|
+
* A change here must be made there too.
|
|
14
|
+
*
|
|
15
|
+
* Text only: no behaviour lives here, so a twin can copy it without dragging
|
|
16
|
+
* server code along.
|
|
17
|
+
*/
|
|
18
|
+
export interface AssistantToolText {
|
|
19
|
+
name: string;
|
|
20
|
+
label: string;
|
|
21
|
+
description: string;
|
|
22
|
+
promptSnippet: string;
|
|
23
|
+
promptGuidelines: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare const ASSISTANT_SCHEDULE_ADD_TEXT: AssistantToolText;
|
|
26
|
+
export declare const ASSISTANT_SCHEDULE_LIST_TEXT: AssistantToolText;
|
|
27
|
+
export declare const ASSISTANT_SCHEDULE_REMOVE_TEXT: AssistantToolText;
|
|
28
|
+
export declare const ASSISTANT_SET_TIMEZONE_TEXT: AssistantToolText;
|
|
29
|
+
export declare const ASSISTANT_NOTIFY_TEXT: AssistantToolText;
|
|
30
|
+
/** The schedule and timezone tools' text (registered in every server session while configured). */
|
|
31
|
+
export declare const ASSISTANT_SCHEDULE_TOOL_TEXTS: readonly AssistantToolText[];
|
|
32
|
+
/**
|
|
33
|
+
* Every assistant tool's text, in registration order (the schedule tools, then
|
|
34
|
+
* `assistant_notify`, which a server session gets only while the assistant is
|
|
35
|
+
* ACTIVE: see assistant-tools.ts).
|
|
36
|
+
*/
|
|
37
|
+
export declare const ASSISTANT_TOOL_TEXTS: readonly AssistantToolText[];
|
|
38
|
+
/** The line appended to the system prompt of every turn in the assistant folder (and `jobs/`). */
|
|
39
|
+
export declare function timezoneLine(timezone: string): string;
|
|
40
|
+
//# sourceMappingURL=assistant-tool-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant-tool-text.d.ts","sourceRoot":"","sources":["../src/assistant-tool-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,eAAO,MAAM,2BAA2B,EAAE,iBAoBzC,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,iBAW1C,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,iBAU5C,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,iBAWzC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,iBAgBnC,CAAC;AAEF,mGAAmG;AACnG,eAAO,MAAM,6BAA6B,EAAE,SAAS,iBAAiB,EAKrE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,iBAAiB,EAA8D,CAAC;AAE5H,kGAAkG;AAClG,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SHARED TEXT of the `assistant_*` tools (spec `assistant-session-and-channels`,
|
|
3
|
+
* ADRs 0015 and 0016): each tool's name, label, description, `promptSnippet` and
|
|
4
|
+
* `promptGuidelines`, plus the per-turn timezone line.
|
|
5
|
+
*
|
|
6
|
+
* Owned by `assistant-schedule-tools-server` (which created it with the schedule
|
|
7
|
+
* and timezone tools); `channel-seam-notify-and-web-push` added `assistant_notify`
|
|
8
|
+
* here, and `cli-assistant-tool-twins` copies every entry (and `timezoneLine`) into the
|
|
9
|
+
* extension's `pi.registerTool` twins (extension/src/assistant-tool-twins.ts)
|
|
10
|
+
* under a drift test (server/test/assistant-tool-twins.test.ts, like
|
|
11
|
+
* `say-tool.test.ts`): the extension is a separate published package that
|
|
12
|
+
* cannot import from the server, so its copies must stay identical to these.
|
|
13
|
+
* A change here must be made there too.
|
|
14
|
+
*
|
|
15
|
+
* Text only: no behaviour lives here, so a twin can copy it without dragging
|
|
16
|
+
* server code along.
|
|
17
|
+
*/
|
|
18
|
+
export const ASSISTANT_SCHEDULE_ADD_TEXT = {
|
|
19
|
+
name: 'assistant_schedule_add',
|
|
20
|
+
label: 'Assistant: Schedule',
|
|
21
|
+
description: "Schedule a job for the wherever assistant. Every job belongs to the assistant and RUNS AS the assistant, " +
|
|
22
|
+
'in its own folder, whichever session schedules it: this session is recorded only as the origin (context ' +
|
|
23
|
+
'the job receives), never as where it runs. Give exactly one of `cron` (5-field, recurring: minute hour ' +
|
|
24
|
+
'day-of-month month day-of-week) or `at` (one-shot: an ISO 8601 date-time, or "now"). Leave `tz` unset so ' +
|
|
25
|
+
"the job follows the user's CURRENT timezone (it moves when they travel); set `tz` (an IANA name) only for " +
|
|
26
|
+
'things pinned to a place, e.g. "6pm her time". An `at` without a UTC offset is read in that timezone. ' +
|
|
27
|
+
'`mode` "inline" delivers the prompt into the current assistant conversation once it is idle; "isolated" ' +
|
|
28
|
+
'runs it at once in a fresh side session (use it for long, slow or possibly urgent work). A scheduled job ' +
|
|
29
|
+
'is silent: it reaches the user only if the job itself notifies them. The prompt must not start with "!".',
|
|
30
|
+
promptSnippet: "Schedule a job (cron or one-shot `at`) that runs as the wherever assistant; jobs follow the user's timezone unless `tz` is set",
|
|
31
|
+
promptGuidelines: [
|
|
32
|
+
'Use assistant_schedule_add for anything time-based: reminders, recurring briefings, "check X in 30 minutes and tell me". The job runs as the assistant, not in this session, so write its prompt so it makes sense on its own.',
|
|
33
|
+
'Leave tz unset on assistant_schedule_add unless the time is pinned to a place; an unset tz follows the user wherever they are.',
|
|
34
|
+
'Use assistant_schedule_add with mode "isolated" (and at "now" to start immediately) for long, slow or possibly urgent work, so it never waits behind a conversation.',
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
export const ASSISTANT_SCHEDULE_LIST_TEXT = {
|
|
38
|
+
name: 'assistant_schedule_list',
|
|
39
|
+
label: 'Assistant: List Schedule',
|
|
40
|
+
description: "List every job in the wherever assistant's schedule (whoever scheduled it), with its id, timing, timezone, " +
|
|
41
|
+
"mode, state and last / next run. Jobs scheduled from THIS session are marked. Done one-shots and invalid " +
|
|
42
|
+
"(malformed, never run) entries are listed too, as is the user's current timezone.",
|
|
43
|
+
promptSnippet: "List the wherever assistant's scheduled jobs, marking the ones this session scheduled",
|
|
44
|
+
promptGuidelines: [
|
|
45
|
+
'Use assistant_schedule_list before changing or cancelling a job, and whenever the user asks what is scheduled.',
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
export const ASSISTANT_SCHEDULE_REMOVE_TEXT = {
|
|
49
|
+
name: 'assistant_schedule_remove',
|
|
50
|
+
label: 'Assistant: Remove Job',
|
|
51
|
+
description: "Remove a job from the wherever assistant's schedule by its id (see assistant_schedule_list). To change a " +
|
|
52
|
+
'job, remove it and add the new version.',
|
|
53
|
+
promptSnippet: "Remove a job from the wherever assistant's schedule by id",
|
|
54
|
+
promptGuidelines: [
|
|
55
|
+
'Use assistant_schedule_remove to cancel a job; get its id from assistant_schedule_list first.',
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
export const ASSISTANT_SET_TIMEZONE_TEXT = {
|
|
59
|
+
name: 'assistant_set_timezone',
|
|
60
|
+
label: 'Assistant: Set Timezone',
|
|
61
|
+
description: "Set the user's CURRENT timezone (an IANA name such as Europe/Paris or America/New_York). Every scheduled " +
|
|
62
|
+
'job without its own `tz` follows it, so changing it moves those jobs to the new local time. Call it when ' +
|
|
63
|
+
'the user says where they are or that they have travelled.',
|
|
64
|
+
promptSnippet: "Set the user's current timezone (IANA name), which every job without its own tz follows",
|
|
65
|
+
promptGuidelines: [
|
|
66
|
+
'Use assistant_set_timezone when the user tells you where they are or that they moved to another timezone.',
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
export const ASSISTANT_NOTIFY_TEXT = {
|
|
70
|
+
name: 'assistant_notify',
|
|
71
|
+
label: 'Assistant: Notify',
|
|
72
|
+
description: "Notify the user NOW through the wherever assistant's channels (a push notification on their subscribed " +
|
|
73
|
+
'devices, and any other configured channel such as Telegram). It is delivered immediately, even while a ' +
|
|
74
|
+
'conversation is running, and is the ONLY way to reach the user with something that is not a reply to ' +
|
|
75
|
+
'their message: a scheduled job, or work in another session, is silent unless it calls this. Give a short ' +
|
|
76
|
+
'`title` and a `body`. Tapping the notification opens `navigateSessionId` when given; otherwise, for a ' +
|
|
77
|
+
'scheduled job (pass `jobId`, or call it from an isolated job session), the session that scheduled the ' +
|
|
78
|
+
'job; otherwise this session. It fails with a clear error when no channel can deliver.',
|
|
79
|
+
promptSnippet: "Notify the user immediately (push / Telegram); the only way to reach them with anything that is not a reply",
|
|
80
|
+
promptGuidelines: [
|
|
81
|
+
'Use assistant_notify only for things the user should know about now (a finished job, a result they asked to be told about, something urgent); never for routine chatter, and not to repeat what you are already replying.',
|
|
82
|
+
'In a scheduled job, call assistant_notify with the result when the user should hear about it: a scheduled turn reaches the user ONLY through assistant_notify.',
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
/** The schedule and timezone tools' text (registered in every server session while configured). */
|
|
86
|
+
export const ASSISTANT_SCHEDULE_TOOL_TEXTS = [
|
|
87
|
+
ASSISTANT_SCHEDULE_ADD_TEXT,
|
|
88
|
+
ASSISTANT_SCHEDULE_LIST_TEXT,
|
|
89
|
+
ASSISTANT_SCHEDULE_REMOVE_TEXT,
|
|
90
|
+
ASSISTANT_SET_TIMEZONE_TEXT,
|
|
91
|
+
];
|
|
92
|
+
/**
|
|
93
|
+
* Every assistant tool's text, in registration order (the schedule tools, then
|
|
94
|
+
* `assistant_notify`, which a server session gets only while the assistant is
|
|
95
|
+
* ACTIVE: see assistant-tools.ts).
|
|
96
|
+
*/
|
|
97
|
+
export const ASSISTANT_TOOL_TEXTS = [...ASSISTANT_SCHEDULE_TOOL_TEXTS, ASSISTANT_NOTIFY_TEXT];
|
|
98
|
+
/** The line appended to the system prompt of every turn in the assistant folder (and `jobs/`). */
|
|
99
|
+
export function timezoneLine(timezone) {
|
|
100
|
+
return `User's current timezone: ${timezone}`;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=assistant-tool-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant-tool-text.js","sourceRoot":"","sources":["../src/assistant-tool-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAUH,MAAM,CAAC,MAAM,2BAA2B,GAAsB;IAC5D,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,qBAAqB;IAC5B,WAAW,EACT,2GAA2G;QAC3G,0GAA0G;QAC1G,yGAAyG;QACzG,2GAA2G;QAC3G,4GAA4G;QAC5G,wGAAwG;QACxG,0GAA0G;QAC1G,2GAA2G;QAC3G,0GAA0G;IAC5G,aA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