@agimon-ai/po-wake 0.0.1-alpha.16 → 0.0.1-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/extensions/server.cjs +195 -137
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.mjs +196 -138
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/po-runtime-identity.json +1 -1
- package/dist/wakeRecords-CfkvJoto.cjs.map +1 -1
- package/dist/{wakeRecords-DFT4ibo6.d.mts → wakeRecords-Dokgla-S.d.mts} +2 -2
- package/dist/{wakeRecords-DFT4ibo6.d.mts.map → wakeRecords-Dokgla-S.d.mts.map} +1 -1
- package/dist/wakeRecords-mOiBrclj.mjs.map +1 -1
- package/dist/wakeRecords.d.mts +1 -1
- package/llms.txt +1 -1
- package/package.json +6 -6
- package/src/prompts/codemode-how-to-wake/SKILL.md +1 -2
- package/src/prompts/codemode-how-to-wake-admin/SKILL.md +13 -9
- package/src/prompts/help-how-to-wake/SKILL.md +10 -8
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Providers can register standing work through `po/wake-records`:
|
|
|
18
18
|
- A record that is **due** can wake the bot after 15 quiet minutes. It can supply a private `prompt` for its due work instead of a summary line. A new turn withdraws the pending routine. Once fired, it does not wake the bot again until a due record changes its progress, such as a run landing or a window rolling over.
|
|
19
19
|
- A provider that cannot answer makes its coverage unknown. po-wake retries rather than treating unknown coverage as empty.
|
|
20
20
|
|
|
21
|
-
Only sessions marked as bots are woken.
|
|
21
|
+
Only sessions marked as bots are woken. After an uncovered turn, Wake uses a separate model call to decide whether an earlier check-in is useful. It uses the host-wide planner model and reasoning when set (`wakeAdmin.setPlanner` in Help mode), otherwise the current session model. Settling or reopening never sends an immediate check-in; the ordinary reminder stays armed if there is no plan. The bot can still optionally set its own wake with `wake.schedule`, which takes precedence over a model plan.
|
|
22
22
|
|
|
23
23
|
```text
|
|
24
24
|
/wake
|
|
@@ -48,29 +48,36 @@ const key = (owner, slot) => [
|
|
|
48
48
|
];
|
|
49
49
|
const requestId = () => `wake-${crypto.randomUUID()}`;
|
|
50
50
|
async function openWakeDeadlines(db) {
|
|
51
|
-
await db.migrate("po_wake", [
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
await db.migrate("po_wake", [
|
|
52
|
+
{
|
|
53
|
+
version: 1,
|
|
54
|
+
statements: [`CREATE TABLE po_wake_deadlines (
|
|
54
55
|
workspace_id TEXT NOT NULL, session_id TEXT NOT NULL, slot TEXT NOT NULL CHECK (slot IN ('reminder', 'routine')),
|
|
55
56
|
at INTEGER NOT NULL, request_id TEXT NOT NULL, PRIMARY KEY (workspace_id, session_id, slot)
|
|
56
57
|
)`, "CREATE INDEX po_wake_deadlines_at ON po_wake_deadlines (at)"]
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
version: 2,
|
|
61
|
+
statements: [
|
|
62
|
+
`CREATE TABLE po_wake_deadlines_v2 (
|
|
61
63
|
workspace_id TEXT NOT NULL, session_id TEXT NOT NULL,
|
|
62
64
|
slot TEXT NOT NULL CHECK (slot IN ('reminder', 'routine', 'self')),
|
|
63
65
|
at INTEGER NOT NULL, request_id TEXT NOT NULL,
|
|
64
66
|
prompt TEXT, origin TEXT CHECK (origin IN ('agent', 'model')), profile TEXT,
|
|
65
67
|
PRIMARY KEY (workspace_id, session_id, slot)
|
|
66
68
|
)`,
|
|
67
|
-
|
|
69
|
+
`INSERT INTO po_wake_deadlines_v2 (workspace_id, session_id, slot, at, request_id)
|
|
68
70
|
SELECT workspace_id, session_id, slot, at, request_id FROM po_wake_deadlines`,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
"DROP TABLE po_wake_deadlines",
|
|
72
|
+
"ALTER TABLE po_wake_deadlines_v2 RENAME TO po_wake_deadlines",
|
|
73
|
+
"CREATE INDEX po_wake_deadlines_at ON po_wake_deadlines (at)"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
version: 3,
|
|
78
|
+
statements: ["CREATE TABLE po_wake_settings (key TEXT PRIMARY KEY, value TEXT NOT NULL)"]
|
|
79
|
+
}
|
|
80
|
+
]);
|
|
74
81
|
const { database } = db;
|
|
75
82
|
return {
|
|
76
83
|
async schedule(owner, slot, at, preserve = false) {
|
|
@@ -96,7 +103,13 @@ async function openWakeDeadlines(db) {
|
|
|
96
103
|
due: (at) => database.all(`${SELECT} WHERE at <= ? ORDER BY at, slot`, at),
|
|
97
104
|
next: async () => (await database.get(`${SELECT} ORDER BY at LIMIT 1`))?.at,
|
|
98
105
|
current: async (row) => !!await database.get(`${SELECT} WHERE ${KEY} AND request_id = ?`, ...key(row, row.slot), row.requestId),
|
|
99
|
-
complete: (row, at, retry = false) => at === void 0 ? database.run(`DELETE FROM po_wake_deadlines WHERE ${KEY} AND request_id = ?`, ...key(row, row.slot), row.requestId) : database.run(`UPDATE po_wake_deadlines SET at = ?, request_id = ? WHERE ${KEY} AND request_id = ?`, at, retry ? row.requestId : requestId(), ...key(row, row.slot), row.requestId)
|
|
106
|
+
complete: (row, at, retry = false) => at === void 0 ? database.run(`DELETE FROM po_wake_deadlines WHERE ${KEY} AND request_id = ?`, ...key(row, row.slot), row.requestId) : database.run(`UPDATE po_wake_deadlines SET at = ?, request_id = ? WHERE ${KEY} AND request_id = ?`, at, retry ? row.requestId : requestId(), ...key(row, row.slot), row.requestId),
|
|
107
|
+
/** The host-wide planner choice every bot session uses. */
|
|
108
|
+
planner: async () => {
|
|
109
|
+
const row = await database.get("SELECT value FROM po_wake_settings WHERE key = 'planner'");
|
|
110
|
+
return row ? JSON.parse(row.value) : {};
|
|
111
|
+
},
|
|
112
|
+
setPlanner: (settings) => Object.keys(settings).length ? database.run("INSERT INTO po_wake_settings (key, value) VALUES ('planner', ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value", JSON.stringify(settings)) : database.run("DELETE FROM po_wake_settings WHERE key = 'planner'")
|
|
100
113
|
};
|
|
101
114
|
}
|
|
102
115
|
//#endregion
|
|
@@ -232,6 +245,11 @@ function createWakeRootValue(scopes, onError, timer) {
|
|
|
232
245
|
await timer?.store.dropModelPlan(owner);
|
|
233
246
|
await rearm();
|
|
234
247
|
},
|
|
248
|
+
planner: async () => disposed || !timer ? {} : await timer.store.planner(),
|
|
249
|
+
async setPlanner(settings) {
|
|
250
|
+
if (disposed || !timer) throw new Error("Wake host storage is unavailable.");
|
|
251
|
+
await timer.store.setPlanner(settings);
|
|
252
|
+
},
|
|
235
253
|
async start() {
|
|
236
254
|
const unsubscribe = timer?.alarm.onAlarm(drain);
|
|
237
255
|
const stop = () => {
|
|
@@ -306,12 +324,8 @@ var root_server_default$1 = (0, _agimon_ai_po_core_extensionFile.defineRoot)((co
|
|
|
306
324
|
//#region src/constants/wake.ts
|
|
307
325
|
const COMMAND_DESCRIPTION = "List the standing work that decides whether this bot is woken; `describe` shows its next wake and why";
|
|
308
326
|
const WAKE_NUDGE_TYPE = "wake-nudge";
|
|
309
|
-
const WAKE_INTENT_TYPE = "po.wake-intent";
|
|
310
|
-
const WAKE_RESULT_TYPE = "po.wake-result";
|
|
311
327
|
/** Diagnostics only: one entry per delivery or planner result, never the nudge text. */
|
|
312
328
|
const WAKE_OUTCOME_TYPE = "po.wake-outcome";
|
|
313
|
-
const LEGACY_WAKE_INTENT_TYPE = "po.calendar-wake-intent";
|
|
314
|
-
const LEGACY_WAKE_RESULT_TYPE = "po.calendar-wake-result";
|
|
315
329
|
/** Bounds for a planned `self` wake, shared by the scheduler and delivery. */
|
|
316
330
|
const SELF_WAKE_MIN_DELAY_MS = 3e5;
|
|
317
331
|
const SELF_WAKE_MAX_DELAY_MS = 6048e5;
|
|
@@ -434,6 +448,7 @@ async function planWake(input) {
|
|
|
434
448
|
recent
|
|
435
449
|
}),
|
|
436
450
|
maxTokens: 512,
|
|
451
|
+
...input.thinkingLevel ? { thinkingLevel: input.thinkingLevel } : {},
|
|
437
452
|
recordUsage: true,
|
|
438
453
|
signal,
|
|
439
454
|
tools: plannerTools(periodMs)
|
|
@@ -500,7 +515,7 @@ function createWake(options) {
|
|
|
500
515
|
const now = options.now ?? Date.now;
|
|
501
516
|
const inflight = /* @__PURE__ */ new Set();
|
|
502
517
|
let routineAdmission = false;
|
|
503
|
-
/**
|
|
518
|
+
/** A side-model decision is only valid until the next run starts. */
|
|
504
519
|
let planning;
|
|
505
520
|
const fenceOf = (profile) => `${profile?.generation ?? ""}|${JSON.stringify(profile?.settings?.wake ?? null)}`;
|
|
506
521
|
/** The inputs the run consumed, read by the settle record's entry ids; assistant and tool output is ignored. */
|
|
@@ -535,10 +550,6 @@ function createWake(options) {
|
|
|
535
550
|
kind,
|
|
536
551
|
status
|
|
537
552
|
}).catch(() => void 0);
|
|
538
|
-
const snapshot = async (session, canonical, legacy) => {
|
|
539
|
-
const saved = await session.customSnapshot(canonical);
|
|
540
|
-
return saved.available && !saved.entry ? await session.customSnapshot(legacy) : saved;
|
|
541
|
-
};
|
|
542
553
|
const dueRecords = (read) => read.records.filter((entry) => entry.due);
|
|
543
554
|
/** The earliest moment a not-yet-due record becomes due, so a routine can wake for it. */
|
|
544
555
|
const nextDueAt = (read) => {
|
|
@@ -673,17 +684,16 @@ function createWake(options) {
|
|
|
673
684
|
};
|
|
674
685
|
};
|
|
675
686
|
/** Fire and forget: a failure, a newer settle or a profile change leaves only the delayed reminder. */
|
|
676
|
-
const startPlanner = (model, session, read, settledId, live, periodMs) => {
|
|
687
|
+
const startPlanner = ({ model, thinkingLevel }, completion, session, read, settledId, live, periodMs) => {
|
|
677
688
|
planning?.abort();
|
|
678
689
|
const controller = new AbortController();
|
|
679
690
|
planning = controller;
|
|
680
691
|
const stop = AbortSignal.any([controller.signal, signal]);
|
|
681
692
|
const profile = options.profile()?.profileName ?? null;
|
|
682
693
|
const attempt = async () => {
|
|
683
|
-
const completion = options.completion?.();
|
|
684
|
-
if (!completion) return "unavailable";
|
|
685
694
|
const decision = await planWake({
|
|
686
695
|
model,
|
|
696
|
+
thinkingLevel,
|
|
687
697
|
execution: {
|
|
688
698
|
session,
|
|
689
699
|
...completion
|
|
@@ -720,7 +730,6 @@ function createWake(options) {
|
|
|
720
730
|
const settled = await session.customSnapshot(_agimon_ai_po_core_headless.AGENT_SETTLED_ENTRY_TYPE);
|
|
721
731
|
const saved = record(settled.entry?.["data"]);
|
|
722
732
|
const settledId = typeof saved?.["runId"] === "string" ? saved["runId"] : void 0;
|
|
723
|
-
const id = settledId || "calendar-bootstrap";
|
|
724
733
|
const ids = saved?.["entryIds"];
|
|
725
734
|
if (!settled.available) return "unavailable";
|
|
726
735
|
if (runId !== void 0 && (runId !== settledId || !Array.isArray(ids) || !ids.length)) return "no-record";
|
|
@@ -729,17 +738,9 @@ function createWake(options) {
|
|
|
729
738
|
const horizon = horizonOf(bot);
|
|
730
739
|
if (!live()) return "fenced";
|
|
731
740
|
await timer.schedule("reminder", now() + horizon, true);
|
|
732
|
-
if (inflight.has(
|
|
733
|
-
inflight.add(
|
|
741
|
+
if (inflight.has(settledId)) return "duplicate";
|
|
742
|
+
inflight.add(settledId);
|
|
734
743
|
try {
|
|
735
|
-
const result = await snapshot(session, WAKE_RESULT_TYPE, LEGACY_WAKE_RESULT_TYPE);
|
|
736
|
-
if (!result.available) return "unavailable";
|
|
737
|
-
if (record(result.entry?.["data"])?.["runId"] === id) return "duplicate";
|
|
738
|
-
const intent = await snapshot(session, WAKE_INTENT_TYPE, LEGACY_WAKE_INTENT_TYPE);
|
|
739
|
-
if (!intent.available) return "unavailable";
|
|
740
|
-
const pending = record(intent.entry?.["data"]);
|
|
741
|
-
const requestId = pending?.["runId"] === id ? pending["requestId"] : void 0;
|
|
742
|
-
if (pending?.["runId"] === id && (typeof requestId !== "string" || !requestId)) return "unavailable";
|
|
743
744
|
const inputs = await consumed(session, new Set(ids ?? []));
|
|
744
745
|
if (settledId && !inputs.length) return "no-input";
|
|
745
746
|
const nudgeOnly = inputs.length > 0 && inputs.every(isNudge);
|
|
@@ -755,37 +756,23 @@ function createWake(options) {
|
|
|
755
756
|
if (passiveOnly) return "passive-only";
|
|
756
757
|
if (plan) return "planned";
|
|
757
758
|
if (routinesCover || read.records.some((entry) => entry.covers)) return "covered";
|
|
758
|
-
if (runId === void 0
|
|
759
|
+
if (runId === void 0) return "deferred";
|
|
759
760
|
if (!live()) return "fenced";
|
|
760
761
|
const latest = await session.customSnapshot(_agimon_ai_po_core_headless.AGENT_SETTLED_ENTRY_TYPE);
|
|
761
|
-
if (!latest.available || record(latest.entry?.["data"])?.["runId"] !==
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
const key = typeof requestId === "string" ? requestId : `wake-${crypto.randomUUID()}`;
|
|
768
|
-
if (!requestId) await session.appendCustomEntry(WAKE_INTENT_TYPE, {
|
|
769
|
-
runId: id,
|
|
770
|
-
requestId: key,
|
|
771
|
-
createdAt: now()
|
|
772
|
-
});
|
|
762
|
+
if (!latest.available || record(latest.entry?.["data"])?.["runId"] !== runId || !live()) return "fenced";
|
|
763
|
+
const completion = options.completion();
|
|
764
|
+
const current = completion?.model;
|
|
765
|
+
const host = await options.planner?.() ?? {};
|
|
766
|
+
const model = host.model ?? (current && `${current.provider}/${current.id}`);
|
|
767
|
+
if (!completion || !model) return "deferred";
|
|
773
768
|
if (!live()) return "fenced";
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
}, "followUp", key);
|
|
780
|
-
await session.appendCustomEntry(WAKE_RESULT_TYPE, {
|
|
781
|
-
runId: id,
|
|
782
|
-
requestId: key,
|
|
783
|
-
status: receipt ? "admitted" : "untracked"
|
|
784
|
-
});
|
|
785
|
-
await journal(session, "check-in", receipt ? "admitted" : "untracked");
|
|
786
|
-
return receipt ? "nudged" : "untracked";
|
|
769
|
+
startPlanner({
|
|
770
|
+
model,
|
|
771
|
+
thinkingLevel: host.thinkingLevel
|
|
772
|
+
}, completion, session, read, runId, live, horizon);
|
|
773
|
+
return "planning";
|
|
787
774
|
} finally {
|
|
788
|
-
inflight.delete(
|
|
775
|
+
inflight.delete(settledId);
|
|
789
776
|
}
|
|
790
777
|
};
|
|
791
778
|
return {
|
|
@@ -793,6 +780,7 @@ function createWake(options) {
|
|
|
793
780
|
settled: (event) => typeof event.runId === "string" && event.runId && event.aborted !== true ? run(event.runId) : Promise.resolve("no-record"),
|
|
794
781
|
recover: () => run(),
|
|
795
782
|
started: async () => {
|
|
783
|
+
planning?.abort();
|
|
796
784
|
const session = options.session();
|
|
797
785
|
if (signal.aborted || !options.bot() || !session?.customSnapshot || !session.appendCustomEntry) return;
|
|
798
786
|
const last = await session.customSnapshot(WAKE_ROUTINE_TYPE);
|
|
@@ -810,17 +798,25 @@ function createWake(options) {
|
|
|
810
798
|
//#region src/services/wakeAdmin/index.ts
|
|
811
799
|
const HELP_MODE = _agimon_ai_po_core_help.PO_HELP_WHEN.state["mode"];
|
|
812
800
|
const NOTHING_RAN = "Nothing ran.";
|
|
813
|
-
const PATCH_KEYS = /* @__PURE__ */ new Set([
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
"
|
|
817
|
-
|
|
818
|
-
|
|
801
|
+
const PATCH_KEYS = /* @__PURE__ */ new Set(["period", "prompt"]);
|
|
802
|
+
const PLANNER_KEYS = /* @__PURE__ */ new Set(["model", "thinkingLevel"]);
|
|
803
|
+
const THINKING_LEVELS = [
|
|
804
|
+
"off",
|
|
805
|
+
"minimal",
|
|
806
|
+
"low",
|
|
807
|
+
"medium",
|
|
808
|
+
"high",
|
|
809
|
+
"xhigh",
|
|
810
|
+
"max"
|
|
811
|
+
];
|
|
812
|
+
const DECLARATIONS$1 = `/** Help-only, in any session. read() is open to the main agent; setPlanner and setProfileDefaults ask the host owner. */
|
|
819
813
|
declare const wakeAdmin: {
|
|
820
|
-
/** The saved wake block and its revision, the applied settings, the effective period and where it comes from, and the armed deadlines (slot, time, origin; never message text). */
|
|
814
|
+
/** The host-wide planner choice, the saved wake block and its revision, the applied settings, the effective period and where it comes from, and the armed deadlines (slot, time, origin; never message text). */
|
|
821
815
|
read(): Promise<unknown>;
|
|
822
|
-
/** Change the
|
|
823
|
-
|
|
816
|
+
/** Change the wake planner model and reasoning for every bot session on this host, whatever its profile. A key left out keeps its saved value; null removes it, so the planner uses the session model or no reasoning. */
|
|
817
|
+
setPlanner(input: { model?: string | null; thinkingLevel?: 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | null }): Promise<{ model?: string; thinkingLevel?: string }>;
|
|
818
|
+
/** Change the selected profile's check-in period or prompt. A key left out keeps its saved value; null removes prompt. \`active\` is true when this session re-applies the profile after the current tool round. */
|
|
819
|
+
setProfileDefaults(input: { period?: string; prompt?: string | null }): Promise<{ revision: string; active: boolean }>;
|
|
824
820
|
};`;
|
|
825
821
|
const isObj = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
826
822
|
function optionalText(value, what, min, max, nullable) {
|
|
@@ -830,23 +826,37 @@ function optionalText(value, what, min, max, nullable) {
|
|
|
830
826
|
}
|
|
831
827
|
function parsePatch(args) {
|
|
832
828
|
const [input] = args;
|
|
833
|
-
if (args.length !== 1 || !isObj(input) || !Object.keys(input).length || Object.keys(input).some((key) => !PATCH_KEYS.has(key))) throw new Error(`Give one change with any of period
|
|
829
|
+
if (args.length !== 1 || !isObj(input) || !Object.keys(input).length || Object.keys(input).some((key) => !PATCH_KEYS.has(key))) throw new Error(`Give one change with any of period and prompt. ${NOTHING_RAN}`);
|
|
834
830
|
return {
|
|
835
831
|
period: optionalText(input.period, "period", 1, 32, false) ?? void 0,
|
|
836
|
-
prompt: optionalText(input.prompt, "prompt", 1, 4e3, true)
|
|
837
|
-
|
|
832
|
+
prompt: optionalText(input.prompt, "prompt", 1, 4e3, true)
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function parsePlanner(args, saved) {
|
|
836
|
+
const [input] = args;
|
|
837
|
+
if (args.length !== 1 || !isObj(input) || !Object.keys(input).length || Object.keys(input).some((key) => !PLANNER_KEYS.has(key))) throw new Error(`Give one change with any of model and thinkingLevel. ${NOTHING_RAN}`);
|
|
838
|
+
const model = optionalText(input.model, "model", 3, 256, true);
|
|
839
|
+
if (typeof model === "string" && !/^[^/\s]+\/[^/\s]+(?:\/[^/\s]+)*$/u.test(model)) throw new Error(`model must be in provider/model-id form. ${NOTHING_RAN}`);
|
|
840
|
+
const level = input.thinkingLevel;
|
|
841
|
+
if (level !== void 0 && level !== null && !THINKING_LEVELS.includes(level)) throw new Error(`thinkingLevel must be one of ${THINKING_LEVELS.join(", ")}. ${NOTHING_RAN}`);
|
|
842
|
+
const next = {
|
|
843
|
+
model: model === void 0 ? saved.model : model ?? void 0,
|
|
844
|
+
thinkingLevel: level === void 0 ? saved.thinkingLevel : level ?? void 0
|
|
845
|
+
};
|
|
846
|
+
return {
|
|
847
|
+
...next.model ? { model: next.model } : {},
|
|
848
|
+
...next.thinkingLevel ? { thinkingLevel: next.thinkingLevel } : {}
|
|
838
849
|
};
|
|
839
850
|
}
|
|
851
|
+
const sameSettings = (a, b) => a.model === b.model && a.thinkingLevel === b.thinkingLevel;
|
|
840
852
|
/** The writer replaces the whole block, so the change is merged into what is saved before it is reviewed. */
|
|
841
853
|
function merge(saved, patch) {
|
|
842
854
|
const period = patch.period ?? saved?.period;
|
|
843
855
|
if (!period) throw new Error(`This profile has no check-ins yet, so give a period. ${NOTHING_RAN}`);
|
|
844
856
|
const prompt = patch.prompt === void 0 ? saved?.prompt : patch.prompt ?? void 0;
|
|
845
|
-
const fallbackModel = patch.fallbackModel === void 0 ? saved?.fallbackModel : patch.fallbackModel ?? void 0;
|
|
846
857
|
return {
|
|
847
858
|
period,
|
|
848
|
-
...prompt ? { prompt } : {}
|
|
849
|
-
...fallbackModel ? { fallbackModel } : {}
|
|
859
|
+
...prompt ? { prompt } : {}
|
|
850
860
|
};
|
|
851
861
|
}
|
|
852
862
|
/** Help-only wake defaults of the selected profile. Reads run for the main agent; the write asks the host owner. */
|
|
@@ -855,7 +865,6 @@ function createWakeAdminNamespace(options) {
|
|
|
855
865
|
const { agent } = options;
|
|
856
866
|
const assertEnabled = () => {
|
|
857
867
|
agent.assertActive();
|
|
858
|
-
if (!options.isBot()) throw new Error(`wakeAdmin needs a bot session. ${NOTHING_RAN}`);
|
|
859
868
|
if (agent.context.selection.state?.["mode"]?.includes(HELP_MODE) !== true) throw new Error(`wakeAdmin needs Help mode. ${NOTHING_RAN}`);
|
|
860
869
|
};
|
|
861
870
|
const defaults = () => {
|
|
@@ -871,57 +880,87 @@ function createWakeAdminNamespace(options) {
|
|
|
871
880
|
const now = { signal: new AbortController().signal };
|
|
872
881
|
return {
|
|
873
882
|
name: "wakeAdmin",
|
|
874
|
-
summary: "Help only. Read why
|
|
883
|
+
summary: "Help only, in any session. Read why a session wakes when it does, and change the host-wide wake planner model and reasoning, or the selected profile's check-in period and prompt, after host-owner approval.",
|
|
875
884
|
declarations: DECLARATIONS$1,
|
|
876
|
-
approval: {
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
885
|
+
approval: {
|
|
886
|
+
setPlanner: {
|
|
887
|
+
requirement: "human",
|
|
888
|
+
ownerOnly: true,
|
|
889
|
+
resolve: async (args) => {
|
|
890
|
+
assertEnabled();
|
|
891
|
+
const expected = await options.planner.read();
|
|
892
|
+
assertEnabled();
|
|
893
|
+
return [{
|
|
894
|
+
settings: parsePlanner(args, expected),
|
|
895
|
+
expected
|
|
896
|
+
}];
|
|
897
|
+
},
|
|
898
|
+
describe: async (input, context) => {
|
|
899
|
+
const { settings, expected } = (context?.arguments ?? [input])[0];
|
|
900
|
+
assertEnabled();
|
|
901
|
+
const none = t("wake.approval.sessionModel", "Session model");
|
|
902
|
+
const off = t("wake.approval.none", "None");
|
|
903
|
+
const change = (before, after, empty) => `${before ?? empty} → ${after ?? empty}`.slice(0, _agimon_ai_po_core_approval.PO_APPROVAL_TEXT_LIMITS.value);
|
|
904
|
+
return {
|
|
905
|
+
source: t("wake.approval.source", "Wake"),
|
|
906
|
+
title: t("wake.approval.plannerTitle", "Wake planner for every bot").slice(0, _agimon_ai_po_core_approval.PO_APPROVAL_TEXT_LIMITS.title),
|
|
907
|
+
summary: t("wake.approval.plannerSummary", "Use this model and reasoning when Po plans the next wake of any bot on this host, whatever its profile. If the setting changed since it was read, nothing is saved."),
|
|
908
|
+
details: [{
|
|
909
|
+
label: t("wake.approval.plannerModel", "Model"),
|
|
910
|
+
value: change(expected.model, settings.model, none)
|
|
911
|
+
}, {
|
|
912
|
+
label: t("wake.approval.thinking", "Reasoning"),
|
|
913
|
+
value: change(expected.thinkingLevel, settings.thinkingLevel, off)
|
|
914
|
+
}]
|
|
915
|
+
};
|
|
916
|
+
}
|
|
891
917
|
},
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
918
|
+
setProfileDefaults: {
|
|
919
|
+
requirement: "human",
|
|
920
|
+
ownerOnly: true,
|
|
921
|
+
resolve: async (args) => {
|
|
922
|
+
assertEnabled();
|
|
923
|
+
const patch = parsePatch(args);
|
|
924
|
+
const profile = selected();
|
|
925
|
+
const saved = await defaults().read(profile, now);
|
|
926
|
+
assertEnabled();
|
|
927
|
+
if (saved.readOnly || !saved.revision) throw new Error(`This host cannot save the settings of profile "${profile}". ${NOTHING_RAN}`);
|
|
928
|
+
return [{
|
|
929
|
+
profile,
|
|
930
|
+
wake: merge(saved.wake, patch),
|
|
931
|
+
expectedRevision: saved.revision
|
|
932
|
+
}];
|
|
933
|
+
},
|
|
934
|
+
describe: async (input, context) => {
|
|
935
|
+
const { profile, wake } = (context?.arguments ?? [input])[0];
|
|
936
|
+
assertEnabled();
|
|
937
|
+
const { wake: was } = await defaults().read(profile, now);
|
|
938
|
+
assertEnabled();
|
|
939
|
+
const none = t("wake.approval.none", "None");
|
|
940
|
+
const change = (before, after) => `${before ?? none} → ${after ?? none}`.slice(0, _agimon_ai_po_core_approval.PO_APPROVAL_TEXT_LIMITS.value);
|
|
941
|
+
return {
|
|
942
|
+
source: t("wake.approval.source", "Wake"),
|
|
943
|
+
title: t("wake.approval.title", "Check-in defaults: {profile}", { profile }).slice(0, _agimon_ai_po_core_approval.PO_APPROVAL_TEXT_LIMITS.title),
|
|
944
|
+
summary: t("wake.approval.summary", "Save these check-in defaults for this profile. If they changed since they were read, nothing is saved."),
|
|
945
|
+
details: [
|
|
946
|
+
{
|
|
947
|
+
label: t("wake.approval.profile", "Profile"),
|
|
948
|
+
value: profile.slice(0, _agimon_ai_po_core_approval.PO_APPROVAL_TEXT_LIMITS.value)
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
label: t("wake.approval.period", "Period"),
|
|
952
|
+
value: change(was?.period, wake.period)
|
|
953
|
+
},
|
|
954
|
+
...wake.prompt === void 0 ? [{
|
|
955
|
+
label: t("wake.approval.prompt", "Prompt"),
|
|
956
|
+
value: was?.prompt ? t("wake.approval.removed", "Removed") : none
|
|
957
|
+
}] : []
|
|
958
|
+
],
|
|
959
|
+
...wake.prompt === void 0 ? {} : { content: wake.prompt }
|
|
960
|
+
};
|
|
961
|
+
}
|
|
923
962
|
}
|
|
924
|
-
}
|
|
963
|
+
},
|
|
925
964
|
bind(run) {
|
|
926
965
|
if (run.sessionId !== options.sessionId) throw new Error("Wake administration belongs to another session.");
|
|
927
966
|
let disposed = false;
|
|
@@ -943,14 +982,26 @@ function createWakeAdminNamespace(options) {
|
|
|
943
982
|
const bound = options.defaults();
|
|
944
983
|
const saved = name && bound ? await bound.read(name, { signal: run.signal }) : void 0;
|
|
945
984
|
const description = await options.describe();
|
|
985
|
+
const planner = await options.planner.read();
|
|
946
986
|
assertAvailable();
|
|
947
987
|
return detach({
|
|
988
|
+
planner,
|
|
948
989
|
profile: name ?? null,
|
|
949
990
|
saved: saved ?? null,
|
|
950
991
|
applied: profile?.settings?.wake ?? null,
|
|
951
992
|
...description
|
|
952
993
|
});
|
|
953
994
|
},
|
|
995
|
+
setPlanner: async (input) => {
|
|
996
|
+
assertAvailable();
|
|
997
|
+
if (!run.approvedCall) throw new Error(`The wake planner changes only after the owner approves. ${NOTHING_RAN}`);
|
|
998
|
+
const write = input;
|
|
999
|
+
if (!isObj(write) || !isObj(write.settings) || !isObj(write.expected)) throw new Error(`Give the reviewed planner change. ${NOTHING_RAN}`);
|
|
1000
|
+
if (!sameSettings(await options.planner.read(), write.expected)) throw new Error(`The wake planner changed since the review. Read again and propose again. ${NOTHING_RAN}`);
|
|
1001
|
+
assertAvailable();
|
|
1002
|
+
await options.planner.write(write.settings);
|
|
1003
|
+
return detach(write.settings);
|
|
1004
|
+
},
|
|
954
1005
|
setProfileDefaults: async (input) => {
|
|
955
1006
|
assertAvailable();
|
|
956
1007
|
if (!run.approvedCall) throw new Error(`Wake defaults change only after the owner approves. ${NOTHING_RAN}`);
|
|
@@ -1118,6 +1169,7 @@ function createWakeSessionState(agent, root, owner) {
|
|
|
1118
1169
|
session: () => agent?.context.session,
|
|
1119
1170
|
profile: () => profileRuntime?.readSelection(),
|
|
1120
1171
|
completion: () => agent?.context,
|
|
1172
|
+
planner: () => root.planner(),
|
|
1121
1173
|
timeZone: () => timeZone(),
|
|
1122
1174
|
signal: lifetime.signal,
|
|
1123
1175
|
timer: {
|
|
@@ -1133,8 +1185,7 @@ function createWakeSessionState(agent, root, owner) {
|
|
|
1133
1185
|
let failed = false;
|
|
1134
1186
|
try {
|
|
1135
1187
|
await ready();
|
|
1136
|
-
|
|
1137
|
-
failed = outcome === "unavailable" || outcome === "untracked";
|
|
1188
|
+
failed = await operation() === "unavailable";
|
|
1138
1189
|
} catch {
|
|
1139
1190
|
failed = true;
|
|
1140
1191
|
}
|
|
@@ -1215,17 +1266,20 @@ function createWakeSessionState(agent, root, owner) {
|
|
|
1215
1266
|
});
|
|
1216
1267
|
return () => fiber.dispose();
|
|
1217
1268
|
},
|
|
1218
|
-
(context) =>
|
|
1269
|
+
(context) => {
|
|
1219
1270
|
const fiber = context.inject([_agimon_ai_po_core_codemode.PO_CODEMODE_SERVICE, _agimon_ai_po_core_serverPlugin.PO_SERVER_SCOPE_SERVICE], (bound) => {
|
|
1220
1271
|
const codemode = (0, _agimon_ai_po_core_codemode.readPoCodemode)(bound);
|
|
1221
1272
|
if (!codemode || !agent) return void 0;
|
|
1222
1273
|
return registerWakeAdmin({
|
|
1223
1274
|
sessionId: owner.sessionId,
|
|
1224
1275
|
agent,
|
|
1225
|
-
isBot,
|
|
1226
1276
|
profile: () => profileRuntime?.readSelection(),
|
|
1227
1277
|
defaults: () => bound.get(_agimon_ai_po_profile.PROFILE_ADMIN_SERVICE)?.wakeDefaults,
|
|
1228
1278
|
describe,
|
|
1279
|
+
planner: {
|
|
1280
|
+
read: () => root.planner(),
|
|
1281
|
+
write: (settings) => root.setPlanner(settings)
|
|
1282
|
+
},
|
|
1229
1283
|
refresh: () => {
|
|
1230
1284
|
const service = selfImprove;
|
|
1231
1285
|
return service && (() => service.refresh({
|
|
@@ -1237,7 +1291,7 @@ function createWakeSessionState(agent, root, owner) {
|
|
|
1237
1291
|
}, (namespace) => codemode.register(NAMESPACE_SOURCE, namespace));
|
|
1238
1292
|
});
|
|
1239
1293
|
return () => fiber.dispose();
|
|
1240
|
-
}
|
|
1294
|
+
},
|
|
1241
1295
|
(context) => {
|
|
1242
1296
|
const fiber = context.inject([_agimon_ai_po_core_serverPlugin.PO_SERVER_SCOPE_SERVICE], (bound) => {
|
|
1243
1297
|
const scope = (0, _agimon_ai_po_core_serverPlugin.requirePoServerScope)(bound);
|
|
@@ -1268,17 +1322,21 @@ function createWakeSessionState(agent, root, owner) {
|
|
|
1268
1322
|
} })),
|
|
1269
1323
|
() => whileBot(() => {
|
|
1270
1324
|
if (!agent?.registerHook) return void 0;
|
|
1271
|
-
const settled = agent.registerHook({
|
|
1325
|
+
const settled = agent.registerHook((0, _agimon_ai_po_core_extensionFile.defineHook)({
|
|
1326
|
+
name: "wake-check-settled-run",
|
|
1327
|
+
description: "Plan a bot’s next wake with a side model or arm a routine, without nudging at settle.",
|
|
1272
1328
|
event: "agent_settled",
|
|
1273
1329
|
handle: (event) => check(() => wake.settled(event))
|
|
1274
|
-
});
|
|
1275
|
-
const started = agent.registerHook({
|
|
1330
|
+
}));
|
|
1331
|
+
const started = agent.registerHook((0, _agimon_ai_po_core_extensionFile.defineHook)({
|
|
1332
|
+
name: "wake-withdraw-routine-on-start",
|
|
1333
|
+
description: "Withdraw the routine wake when a run starts and warn if withdrawal fails.",
|
|
1276
1334
|
event: "agent_start",
|
|
1277
1335
|
handle: () => wake.started().catch(() => agent.context.client.notify({
|
|
1278
1336
|
body: t("wake.notice.withdrawFailed", "Po could not withdraw the routine wake."),
|
|
1279
1337
|
level: "warning"
|
|
1280
1338
|
}))
|
|
1281
|
-
});
|
|
1339
|
+
}));
|
|
1282
1340
|
const detach = root.attach(owner.sessionId, () => check(() => wake.recover()), async (row, current) => {
|
|
1283
1341
|
await ready();
|
|
1284
1342
|
return wake.due(row, current);
|