@wirecat/cli-core 0.642.0 → 0.643.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 +188 -0
- package/dist/attachments/ocr.js +27 -18
- package/dist/attachments/picture-reading.d.ts +51 -0
- package/dist/attachments/picture-reading.js +207 -0
- package/dist/background/backfill.d.ts +4 -2
- package/dist/background/backfill.js +3 -3
- package/dist/background/schedules.d.ts +23 -1
- package/dist/background/schedules.js +45 -17
- package/dist/background/units.d.ts +2 -0
- package/dist/background/units.js +8 -9
- package/dist/calendar/cli/index.js +10 -2
- package/dist/calendar/feeds.js +2 -2
- package/dist/calendar/server-search.js +2 -2
- package/dist/calendar/source.d.ts +4 -3
- package/dist/calendar/sync.js +12 -10
- package/dist/calendar/testing/source-contract.js +5 -4
- package/dist/calendar/testing/source.js +3 -2
- package/dist/cli/complete-command.d.ts +23 -0
- package/dist/cli/complete-command.js +80 -0
- package/dist/cli/context.js +7 -1
- package/dist/cli/effects.d.ts +2 -0
- package/dist/cli/effects.js +2 -0
- package/dist/cli/envelope.js +6 -1
- package/dist/cli/help/first-screen.js +5 -0
- package/dist/cli/index.d.ts +4 -2
- package/dist/cli/index.js +2 -1
- package/dist/cli/list-query.d.ts +3 -1
- package/dist/cli/list-query.js +5 -3
- package/dist/cli/local-only-command.js +9 -0
- package/dist/cli/messenger/backfill-command.js +1 -1
- package/dist/cli/messenger/chat-queries.js +2 -1
- package/dist/cli/messenger/complete-command.d.ts +4 -7
- package/dist/cli/messenger/complete-command.js +31 -98
- package/dist/cli/messenger/contacts-command.js +4 -0
- package/dist/cli/messenger/guard-commands.js +1 -1
- package/dist/cli/messenger/images-command.js +32 -0
- package/dist/cli/messenger/list-result-queries.d.ts +1 -0
- package/dist/cli/messenger/list-result-queries.js +2 -1
- package/dist/cli/messenger/mentions-command.js +3 -3
- package/dist/cli/messenger/message-items.js +1 -0
- package/dist/cli/messenger/messages-command.js +7 -6
- package/dist/cli/messenger/people-queries.d.ts +2 -2
- package/dist/cli/messenger/people-queries.js +4 -4
- package/dist/cli/messenger/search-answers.js +2 -2
- package/dist/cli/messenger/search-command.js +3 -3
- package/dist/cli/messenger/searches-command.js +1 -1
- package/dist/cli/messenger/store-maintenance-command.js +4 -0
- package/dist/cli/messenger/tasks-analysis-command.js +1 -1
- package/dist/cli/messenger/tasks-command.js +2 -2
- package/dist/cli/model-catalogue-command.js +2 -0
- package/dist/cli/picture-reading-command.d.ts +12 -0
- package/dist/cli/picture-reading-command.js +82 -0
- package/dist/cli/program.d.ts +6 -0
- package/dist/cli/program.js +28 -2
- package/dist/cli/schedule/agent-start.d.ts +23 -0
- package/dist/cli/schedule/agent-start.js +115 -0
- package/dist/cli/schedule/harnesses.d.ts +203 -0
- package/dist/cli/schedule/harnesses.js +278 -0
- package/dist/cli/schedule/schedule-command.d.ts +9 -5
- package/dist/cli/schedule/schedule-command.js +89 -79
- package/dist/cli/shared-command-exports.d.ts +186 -0
- package/dist/cli/shared-command-exports.js +2 -0
- package/dist/cli/untrusted-marks.d.ts +25 -0
- package/dist/cli/untrusted-marks.js +102 -0
- package/dist/crm/cli/index.d.ts +1 -0
- package/dist/crm/cli/index.js +6 -5
- package/dist/crm/cli/store.d.ts +30 -0
- package/dist/crm/cli/store.js +63 -0
- package/dist/crm/source.d.ts +6 -4
- package/dist/crm/sync.js +10 -6
- package/dist/crm/testing/source-contract.js +9 -7
- package/dist/crm/testing/source.js +6 -2
- package/dist/crm/testing/sync-contract.js +4 -4
- package/dist/crm/writes.d.ts +5 -2
- package/dist/crm/writes.js +1 -1
- package/dist/documents.d.ts +1 -0
- package/dist/documents.js +1 -0
- package/dist/domain/addresses.d.ts +2 -0
- package/dist/domain/addresses.js +7 -0
- package/dist/domain/attachments.d.ts +2 -0
- package/dist/domain/attachments.js +2 -1
- package/dist/domain/models.d.ts +2 -0
- package/dist/entities/attachment-results.d.ts +3 -0
- package/dist/entities/attachment-results.js +3 -0
- package/dist/entities/attachment.d.ts +2 -0
- package/dist/entities/attachment.js +8 -1
- package/dist/entities/hit.d.ts +1 -0
- package/dist/entities/index.d.ts +21 -4
- package/dist/entities/index.js +3 -2
- package/dist/entities/list-results.d.ts +33 -5
- package/dist/entities/list-results.js +33 -5
- package/dist/errors/reasons.js +30 -1
- package/dist/mail/cli/index.js +7 -6
- package/dist/mcp/agent.d.ts +2 -1
- package/dist/mcp/agent.js +5 -0
- package/dist/mcp/app-server.js +10 -0
- package/dist/mcp/surface.d.ts +7 -2
- package/dist/mcp/surface.js +49 -10
- package/dist/meetings/cli/index.js +6 -1
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/meetings/mcp/index.js +6 -3
- package/dist/meetings/participant-search.d.ts +2 -2
- package/dist/meetings/project-discovery.d.ts +1 -1
- package/dist/meetings/project-evidence-answer.js +2 -2
- package/dist/meetings/reads.d.ts +2 -2
- package/dist/meetings/reads.js +6 -6
- package/dist/meetings/store.d.ts +2 -1
- package/dist/meetings/testing/contract.js +6 -6
- package/dist/meetings/testing/memory.js +7 -2
- package/dist/models/ai.d.ts +1 -1
- package/dist/models/ai.js +3 -1
- package/dist/models/anthropic.js +15 -9
- package/dist/models/index.js +5 -3
- package/dist/models/openai.js +24 -11
- package/dist/models/types.d.ts +8 -0
- package/dist/models/types.js +11 -1
- package/dist/ports/app.d.ts +17 -1
- package/dist/ports/app.js +63 -3
- package/dist/search/lucene/plain.js +45 -3
- package/dist/search/lucene/registry.d.ts +15 -4
- package/dist/search/lucene/registry.js +70 -12
- package/dist/search/lucene/types.d.ts +2 -0
- package/dist/search/lucene/types.js +12 -0
- package/dist/sends/upload.d.ts +8 -1
- package/dist/sends/upload.js +35 -14
- package/dist/services/account-groups.d.ts +11 -0
- package/dist/services/account-groups.js +29 -0
- package/dist/services/agenda.js +1 -0
- package/dist/services/attachments.d.ts +18 -4
- package/dist/services/attachments.js +66 -15
- package/dist/services/conversations.d.ts +2 -4
- package/dist/services/conversations.js +1 -1
- package/dist/services/deal-context.js +5 -5
- package/dist/services/documents/ingestion.js +3 -3
- package/dist/services/documents/knowledge.d.ts +6 -6
- package/dist/services/documents/knowledge.js +1 -2
- package/dist/services/events-search.d.ts +3 -3
- package/dist/services/events-search.js +7 -7
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/meeting-project-discovery.js +1 -1
- package/dist/services/message-resolution.js +10 -3
- package/dist/services/messages-search.js +6 -4
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.d.ts +3 -3
- package/dist/services/notes-search.js +3 -3
- package/dist/services/organization-context.js +12 -9
- package/dist/services/people.d.ts +2 -0
- package/dist/services/people.js +4 -2
- package/dist/services/pictures.d.ts +9 -0
- package/dist/services/pictures.js +34 -28
- package/dist/services/project-status/index.js +1 -1
- package/dist/services/project-status/signals/payments.js +4 -2
- package/dist/services/project-status/signals/promises.js +5 -2
- package/dist/services/proposals/kinds/action.js +1 -1
- package/dist/services/proposals/kinds/fact.js +1 -1
- package/dist/services/proposals/kinds/findings.d.ts +2 -1
- package/dist/services/proposals/kinds/findings.js +12 -5
- package/dist/services/proposals/kinds/identity-link.js +1 -1
- package/dist/services/proposals/kinds/identity-split.js +1 -1
- package/dist/services/proposals/kinds/key-document.js +1 -1
- package/dist/services/proposals/kinds/mail-findings.d.ts +1 -1
- package/dist/services/proposals/kinds/mail-findings.js +11 -5
- package/dist/services/proposals/kinds/meeting-findings.js +10 -4
- package/dist/services/proposals/kinds/memory.js +1 -1
- package/dist/services/proposals/kinds/organization.js +1 -1
- package/dist/services/proposals/kinds/relationship-update.js +1 -1
- package/dist/services/proposals/kinds/relationship.js +1 -1
- package/dist/services/proposals/kinds/shared.d.ts +3 -2
- package/dist/services/proposals/kinds/shared.js +4 -4
- package/dist/services/proposals/kinds/source-review.js +1 -1
- package/dist/services/proposals/kinds/task-close.js +2 -2
- package/dist/services/proposals/registry.js +1 -1
- package/dist/services/proposals/types.d.ts +2 -1
- package/dist/services/search-all-business.js +3 -4
- package/dist/services/search-all.js +13 -14
- package/dist/services/searches.d.ts +2 -4
- package/dist/services/searches.js +1 -4
- package/dist/services/stored-project-gathering.js +6 -1
- package/dist/services/tags.d.ts +2 -4
- package/dist/services/tags.js +1 -1
- package/dist/services/tasks.d.ts +1 -1
- package/dist/services/tasks.js +4 -3
- package/dist/store/account-store.d.ts +2 -1
- package/dist/store/account-store.js +3 -1
- package/dist/store/accounts.d.ts +2 -0
- package/dist/store/accounts.js +8 -0
- package/dist/store/chats.d.ts +5 -0
- package/dist/store/chats.js +4 -0
- package/dist/store/evidence-findings.d.ts +9 -0
- package/dist/store/exports.d.ts +1 -1
- package/dist/store/exports.js +1 -1
- package/dist/store/identity-links.d.ts +3 -1
- package/dist/store/mail-findings.d.ts +9 -0
- package/dist/store/meeting-findings.d.ts +9 -0
- package/dist/store/searches.d.ts +3 -2
- package/dist/store/sqlite/accounts.js +37 -0
- package/dist/store/sqlite/agent-actions.d.ts +2 -1
- package/dist/store/sqlite/agent-actions.js +10 -4
- package/dist/store/sqlite/business-contracts.d.ts +3 -1
- package/dist/store/sqlite/business-contracts.js +7 -3
- package/dist/store/sqlite/business-search.d.ts +2 -1
- package/dist/store/sqlite/business-search.js +6 -4
- package/dist/store/sqlite/deals.d.ts +6 -4
- package/dist/store/sqlite/deals.js +12 -7
- package/dist/store/sqlite/evidence-findings.js +78 -9
- package/dist/store/sqlite/facts.d.ts +2 -1
- package/dist/store/sqlite/facts.js +6 -2
- package/dist/store/sqlite/finance.d.ts +4 -2
- package/dist/store/sqlite/finance.js +13 -6
- package/dist/store/sqlite/findings-core.d.ts +56 -2
- package/dist/store/sqlite/findings-core.js +109 -22
- package/dist/store/sqlite/identities.d.ts +4 -0
- package/dist/store/sqlite/identities.js +12 -3
- package/dist/store/sqlite/identity-proposals.js +34 -4
- package/dist/store/sqlite/lucene-fields.d.ts +2 -0
- package/dist/store/sqlite/lucene-fields.js +28 -2
- package/dist/store/sqlite/lucene.js +21 -10
- package/dist/store/sqlite/mail-findings.js +60 -22
- package/dist/store/sqlite/meeting-findings.js +53 -7
- package/dist/store/sqlite/meeting-participant-search.js +4 -5
- package/dist/store/sqlite/meetings.js +7 -3
- package/dist/store/sqlite/memories.d.ts +4 -2
- package/dist/store/sqlite/memories.js +13 -6
- package/dist/store/sqlite/money-transactions.d.ts +3 -1
- package/dist/store/sqlite/money-transactions.js +7 -3
- package/dist/store/sqlite/name-traces.d.ts +3 -3
- package/dist/store/sqlite/name-traces.js +29 -2
- package/dist/store/sqlite/orders.d.ts +3 -1
- package/dist/store/sqlite/orders.js +5 -2
- package/dist/store/sqlite/people-list.js +67 -22
- package/dist/store/sqlite/person-match-scan.d.ts +3 -1
- package/dist/store/sqlite/person-match-scan.js +97 -7
- package/dist/store/sqlite/products.d.ts +3 -1
- package/dist/store/sqlite/products.js +5 -2
- package/dist/store/sqlite/proposed-actions.d.ts +2 -1
- package/dist/store/sqlite/proposed-actions.js +7 -3
- package/dist/store/sqlite/query-filter.d.ts +4 -0
- package/dist/store/sqlite/query-filter.js +14 -0
- package/dist/store/sqlite/reads.d.ts +1 -0
- package/dist/store/sqlite/reads.js +14 -0
- package/dist/store/sqlite/records.d.ts +3 -1
- package/dist/store/sqlite/records.js +7 -5
- package/dist/store/sqlite/rows-page.d.ts +3 -0
- package/dist/store/sqlite/rows-page.js +4 -0
- package/dist/store/sqlite/searches.d.ts +2 -1
- package/dist/store/sqlite/searches.js +3 -1
- package/dist/store/sqlite/subscriptions.d.ts +5 -2
- package/dist/store/sqlite/subscriptions.js +13 -6
- package/dist/store/sqlite/task-board.js +27 -0
- package/dist/store/sqlite/task-find.d.ts +15 -0
- package/dist/store/sqlite/task-find.js +1 -0
- package/dist/store/sqlite/wallets.d.ts +3 -1
- package/dist/store/sqlite/wallets.js +7 -3
- package/dist/store/sqlite/work-tasks.d.ts +3 -11
- package/dist/store/sqlite/work-tasks.js +8 -4
- package/package.json +2 -2
- package/parity.json +24 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { findProgram, WORK_FOLDER } from "../../background/schedules.js";
|
|
3
|
+
/**
|
|
4
|
+
* Claude starts without the owner's MCP servers, skills and slash commands: a run reads its instructions through the
|
|
5
|
+
* CLI, and the rest was most of its starting context. `--permission-mode` and `--allowedTools` hold either way.
|
|
6
|
+
*/
|
|
7
|
+
const LEAN_CLAUDE = ["--tools", "Bash", "--strict-mcp-config", "--disable-slash-commands"];
|
|
8
|
+
const modelFlag = (flag, model) => (model ? [flag, model] : []);
|
|
9
|
+
/**
|
|
10
|
+
* Gemini tests a rule's regex against the call's arguments as JSON, after `"command":"`, so a pattern starts at the
|
|
11
|
+
* command's first character and `^` never matches. This one denies a command that chains, pipes, substitutes or runs
|
|
12
|
+
* in the background anywhere in its quoted text, a newline being `\n` there: more than the one CLI command a prefix
|
|
13
|
+
* rule allows. `<` and `>` stay allowed, as queries such as `date>1d` use them.
|
|
14
|
+
*/
|
|
15
|
+
const CHAINED = '(?:[^"\\\\]|\\\\.)*?(?:[;&|`$]|\\\\n)';
|
|
16
|
+
/** A command that starts by setting variables (`MEMO_READ_ONLY=0 memo …`, `env -u …`): never a plain CLI command. */
|
|
17
|
+
const ENV_PREFIX = "\\s*(?:env\\s|[A-Za-z_][A-Za-z0-9_]*=)";
|
|
18
|
+
/** One Gemini policy rule as TOML; every value is a string or a number. */
|
|
19
|
+
const rule = (fields) => [
|
|
20
|
+
"[[rule]]",
|
|
21
|
+
...Object.entries(fields).map(([key, value]) => `${key} = ${typeof value === "number" ? value : JSON.stringify(value)}`),
|
|
22
|
+
"",
|
|
23
|
+
].join("\n");
|
|
24
|
+
/**
|
|
25
|
+
* The coding agents a schedule may start, by the ids WireCat Desktop's Agents page uses. Only agents whose vendor
|
|
26
|
+
* documents a one-shot mode that answers on stdout and exits are here; GLM has no agent CLI of its own, Z.ai runs it
|
|
27
|
+
* inside these agents.
|
|
28
|
+
*/
|
|
29
|
+
const AGENT_HARNESSES = {
|
|
30
|
+
// https://code.claude.com/docs/en/headless
|
|
31
|
+
claude: {
|
|
32
|
+
name: "Claude Code",
|
|
33
|
+
programs: ["claude"],
|
|
34
|
+
// A mid-tier model by default.
|
|
35
|
+
model: "sonnet",
|
|
36
|
+
reportsCost: true,
|
|
37
|
+
// https://code.claude.com/docs/en/iam: dontAsk denies every tool its allow rules do not name.
|
|
38
|
+
restricted: true,
|
|
39
|
+
start: ({ program, prompt, model, clis, leanStart, maxCost }) => ({
|
|
40
|
+
argv: [
|
|
41
|
+
program,
|
|
42
|
+
"-p",
|
|
43
|
+
prompt,
|
|
44
|
+
"--permission-mode",
|
|
45
|
+
"dontAsk",
|
|
46
|
+
"--allowedTools",
|
|
47
|
+
...clis.map((one) => `Bash(${one.command}:*)`),
|
|
48
|
+
"--no-session-persistence",
|
|
49
|
+
// The owner's own settings may allow other commands (python, node); none of them is read, lean or not.
|
|
50
|
+
"--setting-sources",
|
|
51
|
+
"",
|
|
52
|
+
...modelFlag("--model", model),
|
|
53
|
+
...(leanStart ? LEAN_CLAUDE : []),
|
|
54
|
+
...(maxCost ? ["--max-budget-usd", String(maxCost)] : []),
|
|
55
|
+
],
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
// https://learn.chatgpt.com/docs/non-interactive-mode
|
|
59
|
+
codex: {
|
|
60
|
+
name: "Codex",
|
|
61
|
+
programs: ["codex"],
|
|
62
|
+
model: "",
|
|
63
|
+
reportsCost: false,
|
|
64
|
+
restricted: false,
|
|
65
|
+
allowedWithAck: true,
|
|
66
|
+
restrictedReason: "it may run any program, and its rules (https://learn.chatgpt.com/docs/agent-configuration/rules) cannot deny " +
|
|
67
|
+
"every command but the CLIs'. Its sandbox (https://learn.chatgpt.com/docs/sandboxing) blocks the network and " +
|
|
68
|
+
"every write outside its run's folder, the message store's folder and the CLIs' state and cache folders. The " +
|
|
69
|
+
"store must stay writable, as SQLite cannot read it otherwise, so a program such as sqlite3 can change or " +
|
|
70
|
+
"delete the store and the read-only lock does not stop it; it reads every file the owner can",
|
|
71
|
+
// --ignore-user-config and --ignore-rules keep the owner's ~/.codex config and rules from widening the sandbox.
|
|
72
|
+
start: ({ program, prompt, model, folders }) => ({
|
|
73
|
+
argv: [
|
|
74
|
+
program,
|
|
75
|
+
"exec",
|
|
76
|
+
"--skip-git-repo-check",
|
|
77
|
+
"--ephemeral",
|
|
78
|
+
"--ignore-user-config",
|
|
79
|
+
"--ignore-rules",
|
|
80
|
+
"--sandbox",
|
|
81
|
+
"workspace-write",
|
|
82
|
+
"-c",
|
|
83
|
+
"sandbox_workspace_write.network_access=false",
|
|
84
|
+
"--cd",
|
|
85
|
+
WORK_FOLDER,
|
|
86
|
+
...modelFlag("--model", model),
|
|
87
|
+
...folders.flatMap((dir) => ["--add-dir", dir]),
|
|
88
|
+
prompt,
|
|
89
|
+
],
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
// https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/headless.md
|
|
93
|
+
gemini: {
|
|
94
|
+
name: "Gemini CLI",
|
|
95
|
+
programs: ["gemini"],
|
|
96
|
+
model: "",
|
|
97
|
+
reportsCost: false,
|
|
98
|
+
// https://github.com/google-gemini/gemini-cli/blob/main/docs/reference/policy-engine.md: a rule that would ask "is
|
|
99
|
+
// treated as deny" in non-interactive mode. The policy is an admin one, the top tier, so no user setting or rule
|
|
100
|
+
// outranks it; the system settings also drop the owner's allowed tools and MCP servers and turn yolo off.
|
|
101
|
+
restricted: true,
|
|
102
|
+
start: ({ program, prompt, model, clis }) => ({
|
|
103
|
+
argv: [program, "-p", prompt, ...modelFlag("-m", model)],
|
|
104
|
+
environment: { GEMINI_CLI_SYSTEM_SETTINGS_PATH: `${WORK_FOLDER}/gemini/settings.json` },
|
|
105
|
+
files: {
|
|
106
|
+
"gemini/settings.json": JSON.stringify({
|
|
107
|
+
adminPolicyPaths: [`${WORK_FOLDER}/gemini/policy.toml`],
|
|
108
|
+
tools: { allowed: [], core: ["run_shell_command"] },
|
|
109
|
+
mcpServers: {},
|
|
110
|
+
security: { disableYoloMode: true },
|
|
111
|
+
general: { defaultApprovalMode: "default" },
|
|
112
|
+
}),
|
|
113
|
+
"gemini/policy.toml": [
|
|
114
|
+
// The system settings' empty mcpServers is merged into the owner's, so their servers' tools are denied here.
|
|
115
|
+
rule({ toolName: "*", decision: "deny", priority: 1 }),
|
|
116
|
+
rule({ toolName: "run_shell_command", decision: "deny", priority: 10 }),
|
|
117
|
+
...clis.map((one) => rule({ toolName: "run_shell_command", commandPrefix: `${one.command} `, decision: "allow", priority: 100 })),
|
|
118
|
+
// How a prefix rule treats `memo x && rm …` is not documented; a chained or substituted command is refused.
|
|
119
|
+
rule({ toolName: "run_shell_command", commandRegex: CHAINED, decision: "deny", priority: 200 }),
|
|
120
|
+
rule({ toolName: "run_shell_command", commandRegex: ENV_PREFIX, decision: "deny", priority: 200 }),
|
|
121
|
+
...["write_file", "replace", "web_fetch", "google_web_search"].map((toolName) => rule({ toolName, decision: "deny", priority: 200 })),
|
|
122
|
+
].join("\n"),
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
// https://cursor.com/docs/cli/headless
|
|
127
|
+
cursor: {
|
|
128
|
+
name: "Cursor",
|
|
129
|
+
// `cursor` alone starts the editor; the agent's own program was `cursor-agent` and is now `agent`.
|
|
130
|
+
programs: ["cursor-agent", "agent"],
|
|
131
|
+
model: "",
|
|
132
|
+
reportsCost: false,
|
|
133
|
+
restricted: false,
|
|
134
|
+
restrictedReason: "its Shell(<command>) rule matches the first word only, and its docs (https://cursor.com/docs/cli/reference/permissions) " +
|
|
135
|
+
"do not say a chained command such as `memo x; other` is denied",
|
|
136
|
+
start: ({ program, prompt, model }) => ({
|
|
137
|
+
argv: [program, "-p", prompt, "--output-format", "text", ...modelFlag("--model", model)],
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
// https://opencode.ai/docs/cli
|
|
141
|
+
opencode: {
|
|
142
|
+
name: "OpenCode",
|
|
143
|
+
programs: ["opencode"],
|
|
144
|
+
model: "",
|
|
145
|
+
reportsCost: false,
|
|
146
|
+
// https://opencode.ai/docs/permissions/: "configured deny rules always remain enforced", the last matching rule
|
|
147
|
+
// wins, and a rule applies to every part of a chained command. Everything is denied but the CLIs' commands; the
|
|
148
|
+
// older `permission` form is given too, so a version that reads only it is held as well. Never --auto.
|
|
149
|
+
restricted: true,
|
|
150
|
+
start: ({ program, prompt, model, clis }) => ({
|
|
151
|
+
// Its models are `provider/model`.
|
|
152
|
+
argv: [program, "run", ...modelFlag("-m", model), prompt],
|
|
153
|
+
environment: {
|
|
154
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify({
|
|
155
|
+
permissions: [
|
|
156
|
+
{ action: "*", resource: "*", effect: "deny" },
|
|
157
|
+
...clis.map((one) => ({ action: "shell", resource: `${one.command} *`, effect: "allow" })),
|
|
158
|
+
],
|
|
159
|
+
permission: {
|
|
160
|
+
"*": "deny",
|
|
161
|
+
edit: "deny",
|
|
162
|
+
webfetch: "deny",
|
|
163
|
+
bash: { "*": "deny", ...Object.fromEntries(clis.map((one) => [`${one.command} *`, "allow"])) },
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
},
|
|
169
|
+
// https://docs.openclaw.ai/cli/agent
|
|
170
|
+
openclaw: {
|
|
171
|
+
name: "OpenClaw",
|
|
172
|
+
programs: ["openclaw"],
|
|
173
|
+
model: "",
|
|
174
|
+
reportsCost: false,
|
|
175
|
+
restricted: false,
|
|
176
|
+
restrictedReason: "its command allow-list (https://docs.openclaw.ai/tools/exec-approvals.md) lives in its own state database, and " +
|
|
177
|
+
"its docs do not say it holds for a one-shot `agent exec` run",
|
|
178
|
+
start: ({ program, prompt, model }) => ({
|
|
179
|
+
argv: [program, "agent", "exec", prompt, ...modelFlag("--model", model)],
|
|
180
|
+
}),
|
|
181
|
+
},
|
|
182
|
+
// https://hermes-agent.nousresearch.com/docs/reference/cli-commands
|
|
183
|
+
hermes: {
|
|
184
|
+
name: "Hermes",
|
|
185
|
+
programs: ["hermes"],
|
|
186
|
+
model: "",
|
|
187
|
+
reportsCost: false,
|
|
188
|
+
restricted: false,
|
|
189
|
+
restrictedReason: "it checks only commands on its list of dangerous patterns and runs any other " +
|
|
190
|
+
"(https://hermes-agent.nousresearch.com/docs/user-guide/security/); it has no allow-list",
|
|
191
|
+
start: ({ program, prompt, model }) => ({
|
|
192
|
+
argv: [program, "chat", "-q", prompt, "-Q", ...modelFlag("-m", model)],
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
// https://docs.x.ai/build/cli/headless-scripting
|
|
196
|
+
grok: {
|
|
197
|
+
name: "Grok",
|
|
198
|
+
programs: ["grok"],
|
|
199
|
+
model: "",
|
|
200
|
+
reportsCost: false,
|
|
201
|
+
restricted: false,
|
|
202
|
+
restrictedReason: "its dontAsk mode denies what no --allow rule names (https://docs.x.ai/build/features/permissions), but its docs " +
|
|
203
|
+
"do not say a chained command such as `memo x; other` is denied; superagent's grok-cli, also `grok`, has no rules",
|
|
204
|
+
start: ({ program, prompt, model, clis }) => ({
|
|
205
|
+
argv: [
|
|
206
|
+
program,
|
|
207
|
+
"-p",
|
|
208
|
+
prompt,
|
|
209
|
+
"--permission-mode",
|
|
210
|
+
"dontAsk",
|
|
211
|
+
...clis.flatMap((one) => ["--allow", `Bash(${one.command} *)`]),
|
|
212
|
+
...modelFlag("-m", model),
|
|
213
|
+
],
|
|
214
|
+
}),
|
|
215
|
+
},
|
|
216
|
+
// https://moonshotai.github.io/kimi-cli/en/customization/print-mode.html
|
|
217
|
+
kimi: {
|
|
218
|
+
name: "Kimi CLI",
|
|
219
|
+
programs: ["kimi"],
|
|
220
|
+
model: "",
|
|
221
|
+
reportsCost: false,
|
|
222
|
+
restricted: false,
|
|
223
|
+
restrictedReason: "print mode approves every tool call and has no allow-list " +
|
|
224
|
+
"(https://moonshotai.github.io/kimi-cli/en/customization/print-mode.html); its docs do not say a hook runs there",
|
|
225
|
+
start: ({ program, prompt, model }) => ({ argv: [program, "--quiet", "-p", prompt, ...modelFlag("-m", model)] }),
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
/** The variables a harness reads its limits from; a run rebuilds them, so a saved one is never taken from the file. */
|
|
229
|
+
export const HARNESS_VARIABLES = ["GEMINI_CLI_SYSTEM_SETTINGS_PATH", "OPENCODE_CONFIG_CONTENT"];
|
|
230
|
+
/** Every agent a schedule may start, as `schedule agent <harness>` and a digest's agent take it. */
|
|
231
|
+
export const HARNESSES = Object.keys(AGENT_HARNESSES);
|
|
232
|
+
export const AGENT_MODELS = Object.fromEntries(HARNESSES.map((id) => [id, AGENT_HARNESSES[id].model]));
|
|
233
|
+
export const harnessOf = (id) => AGENT_HARNESSES[id];
|
|
234
|
+
export const COSTED = HARNESSES.filter((id) => harnessOf(id).reportsCost).join(", ");
|
|
235
|
+
export const isHarness = (id) => HARNESSES.includes(id);
|
|
236
|
+
/** An agent's name, programs and what holds it, as `schedule agents list` answers them. */
|
|
237
|
+
export const harnessInfo = (harness) => {
|
|
238
|
+
const { name, programs, reportsCost, restricted, restrictedReason, allowedWithAck } = harnessOf(harness);
|
|
239
|
+
return {
|
|
240
|
+
id: harness,
|
|
241
|
+
name,
|
|
242
|
+
programs: [...programs],
|
|
243
|
+
reportsCost,
|
|
244
|
+
restricted,
|
|
245
|
+
restrictedReason: restrictedReason ?? null,
|
|
246
|
+
allowedWithAck: allowedWithAck === true,
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
/** Whether the harness reports what a run cost; the cost caps hold only for one that does. */
|
|
250
|
+
export const reportsCost = (harness) => harnessOf(harness).reportsCost;
|
|
251
|
+
/** The harness's program on PATH, by the first of its names found. */
|
|
252
|
+
export const programOf = (harness, env, platform) => harnessOf(harness)
|
|
253
|
+
.programs.map((name) => findProgram(name, env, platform))
|
|
254
|
+
.find(Boolean);
|
|
255
|
+
/** Which harness an agent schedule's argv starts, by its program's name; null for one no harness here knows. */
|
|
256
|
+
export const harnessOfArgv = (argv) => {
|
|
257
|
+
const name = basename(argv[0] ?? "")
|
|
258
|
+
.replace(/\.(exe|cmd)$/i, "")
|
|
259
|
+
.toLowerCase();
|
|
260
|
+
return HARNESSES.find((id) => harnessOf(id).programs.includes(name)) ?? null;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Why no schedule may start the harness, or nothing: one held to the CLIs' commands may run, and one the owner
|
|
264
|
+
* accepted with `--allow-dangerous` where its sandbox allows that.
|
|
265
|
+
*/
|
|
266
|
+
export const harnessRefusal = (harness, accepted) => {
|
|
267
|
+
const kind = harnessOf(harness);
|
|
268
|
+
if (kind.restricted)
|
|
269
|
+
return undefined;
|
|
270
|
+
if (kind.allowedWithAck === true)
|
|
271
|
+
return accepted ? undefined : `${kind.name} runs only with --allow-dangerous, as ${kind.restrictedReason}`;
|
|
272
|
+
return `${kind.name} cannot run on a schedule: ${kind.restrictedReason}`;
|
|
273
|
+
};
|
|
274
|
+
/** Each harness, with its program when it is on PATH: what `schedule agents list` answers. */
|
|
275
|
+
export const harnessesOn = (env, platform) => HARNESSES.map((id) => {
|
|
276
|
+
const path = programOf(id, env, platform) ?? null;
|
|
277
|
+
return { ...harnessInfo(id), installed: path !== null, path };
|
|
278
|
+
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import { type AgentCli, type AgentInput, type LastRun, type Notify, type Schedule, type SkipReason, type Slot, type When } from "../../background/schedules.js";
|
|
2
|
+
import { type AgentCli, type AgentInput, type AgentSpec, type LastRun, type Notify, type Schedule, type SkipReason, type Slot, type When } from "../../background/schedules.js";
|
|
3
3
|
import { type ServerSystem } from "../../background/system.js";
|
|
4
4
|
import { type MailWaiting } from "../../mail/marks.js";
|
|
5
5
|
import { type AppIdentity } from "../../ports/app.js";
|
|
6
6
|
import { type AnswerOutput } from "../envelope.js";
|
|
7
7
|
import type { DeclaredSetting } from "../setting-defaults.js";
|
|
8
|
-
|
|
9
|
-
export type Harness = (typeof HARNESSES)[number];
|
|
8
|
+
import { type Harness } from "./harnesses.js";
|
|
10
9
|
/** One `--at`: `HH:MM` every day, or weekdays and a time, `mon 09:00` or `mon,fri 09:00`. */
|
|
11
10
|
export declare const slotsOfAt: (at: string) => Slot[];
|
|
12
11
|
export interface ScheduleHost {
|
|
@@ -28,7 +27,7 @@ export interface ScheduleHost {
|
|
|
28
27
|
limits?: (command: Command) => ScheduleLimits;
|
|
29
28
|
/**
|
|
30
29
|
* Other CLIs the scheduled agent may run besides this one, each under its own `<PREFIX>_READ_ONLY`: memo's mail
|
|
31
|
-
* triage runs `mail`. Claude may run them; codex may write their state
|
|
30
|
+
* triage runs `mail`. Claude may run them; codex may write their state and cache folders.
|
|
32
31
|
*/
|
|
33
32
|
agentRuns?: readonly AgentCli[];
|
|
34
33
|
}
|
|
@@ -82,6 +81,8 @@ export interface AgentScheduleSpec {
|
|
|
82
81
|
/** Claude only: a run that costs more is stopped, in US dollars. */
|
|
83
82
|
maxCost?: number;
|
|
84
83
|
maxCostPerDay?: number;
|
|
84
|
+
/** The owner accepts an agent its own limits cannot hold to the CLIs' commands, where its sandbox allows that. */
|
|
85
|
+
allowDangerous?: boolean;
|
|
85
86
|
onNewMail?: string;
|
|
86
87
|
mailWaitMinutes?: number;
|
|
87
88
|
mailBatch?: number;
|
|
@@ -121,6 +122,8 @@ export declare const pauseSchedule: (site: ScheduleSite, name: string, paused: b
|
|
|
121
122
|
maxCostPerDay?: number;
|
|
122
123
|
notify?: Notify;
|
|
123
124
|
to?: string[];
|
|
125
|
+
files?: Record<string, string>;
|
|
126
|
+
agent?: AgentSpec;
|
|
124
127
|
} | {
|
|
125
128
|
name: string;
|
|
126
129
|
kind: "command" | "agent";
|
|
@@ -134,6 +137,8 @@ export declare const pauseSchedule: (site: ScheduleSite, name: string, paused: b
|
|
|
134
137
|
maxCostPerDay?: number;
|
|
135
138
|
notify?: Notify;
|
|
136
139
|
to?: string[];
|
|
140
|
+
files?: Record<string, string>;
|
|
141
|
+
agent?: AgentSpec;
|
|
137
142
|
paused: true;
|
|
138
143
|
};
|
|
139
144
|
}>;
|
|
@@ -158,4 +163,3 @@ export declare const runScheduleNow: (command: Command, site: ScheduleSite, file
|
|
|
158
163
|
* the rest, so what runs and with which variables is the same on all three.
|
|
159
164
|
*/
|
|
160
165
|
export declare const scheduleCommandFor: ({ app, context: contextOf, newMail, agentInput, limits: configured, agentRuns, }: ScheduleHost) => Command;
|
|
161
|
-
export {};
|
|
@@ -7,7 +7,7 @@ import { backfillSchedule } from "../../background/backfill.js";
|
|
|
7
7
|
import { parseRoute, ROUTE_HELP, routeText } from "../../background/deliver.js";
|
|
8
8
|
import { REPORT_CHANNELS } from "../../background/report/render.js";
|
|
9
9
|
import { reportKeysOf } from "../../background/report/stored-templates.js";
|
|
10
|
-
import { calendarOf, describeWhen,
|
|
10
|
+
import { calendarOf, describeWhen, isCalendar, lastRun, listSchedules, NOTIFY_WHEN, notifyOf, readSchedule, recordSkip, runSchedule, SCHEDULE_DEFAULTS, SKIP_REASONS, scheduleFile, scheduleName, slotsOf, spentToday, timerFor, WEEKDAYS, } from "../../background/schedules.js";
|
|
11
11
|
import { thisMachine } from "../../background/system.js";
|
|
12
12
|
import { locationVariables } from "../../background/units.js";
|
|
13
13
|
import { parseDuration } from "../../domain/duration.js";
|
|
@@ -20,24 +20,18 @@ import { ownerLanguages, storedTemplateBodies } from "../../store/store.js";
|
|
|
20
20
|
import { environmentOf, setExitCode } from "../context.js";
|
|
21
21
|
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE, REMOTE_WRITE } from "../effects.js";
|
|
22
22
|
import { itemOf, listOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
23
|
-
import { withQuery } from "../list-query.js";
|
|
24
|
-
import { SCHEDULES_QUERY, scheduleFilter } from "../messenger/list-result-queries.js";
|
|
23
|
+
import { listQuery, typedQuery, withQuery } from "../list-query.js";
|
|
24
|
+
import { SCHEDULE_HARNESSES_QUERY, SCHEDULES_QUERY, scheduleFilter } from "../messenger/list-result-queries.js";
|
|
25
25
|
import { lineOf } from "../steps.js";
|
|
26
|
+
import { agentStart, guardSchedule, sealOf } from "./agent-start.js";
|
|
27
|
+
import { AGENT_MODELS, COSTED, HARNESSES, harnessesOn, harnessOf, harnessOfArgv, isHarness, reportsCost, } from "./harnesses.js";
|
|
26
28
|
/** Each run of an agent is a paid model call that reads chats; keeping the store current is `serve`'s job. */
|
|
27
29
|
const AGENT_MINIMUM_MINUTES = 60;
|
|
28
30
|
/** A run gated on new mail costs a store read when nothing came, so it may check as often as mail syncs. */
|
|
29
31
|
const GATED_AGENT_MINIMUM_MINUTES = 5;
|
|
30
32
|
const COMMAND_MINIMUM_MINUTES = 1;
|
|
31
|
-
const HARNESSES = ["claude", "codex"];
|
|
32
|
-
/** A mid-tier model by default; codex has no alias of that tier, so it takes its own default. Empty: the harness's own. */
|
|
33
|
-
const AGENT_MODELS = { claude: "sonnet", codex: "" };
|
|
34
33
|
/** An alias or a model id; a leading dash would read as the harness's next flag. */
|
|
35
34
|
const isModel = (model) => /^([A-Za-z0-9][\w.:/@[\]-]*)?$/.test(model);
|
|
36
|
-
/**
|
|
37
|
-
* Claude starts without the owner's MCP servers, skills, settings and CLAUDE.md: a run reads its instructions
|
|
38
|
-
* through the CLI, and the rest was most of its starting context. Auth, `--permission-mode` and `--allowedTools` hold.
|
|
39
|
-
*/
|
|
40
|
-
const LEAN_CLAUDE = ["--tools", "Bash", "--strict-mcp-config", "--disable-slash-commands", "--setting-sources", ""];
|
|
41
35
|
const CLOCK = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
42
36
|
/** One `--at`: `HH:MM` every day, or weekdays and a time, `mon 09:00` or `mon,fri 09:00`. */
|
|
43
37
|
export const slotsOfAt = (at) => {
|
|
@@ -211,14 +205,19 @@ const reportTemplatesOf = (env, schedule) => async (kind, language) => {
|
|
|
211
205
|
* One past day's run of the agent schedule in `file`, as `backfillSchedule` makes it, with the owner's language and
|
|
212
206
|
* templates as `schedule run` renders them; a stop of the command stops the agent.
|
|
213
207
|
*/
|
|
214
|
-
export const backfillScheduleRun = (command, app, env, file, { at, input, agentRuns = [] }) =>
|
|
215
|
-
|
|
216
|
-
agentRuns,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
export const backfillScheduleRun = (command, app, env, file, { at, input, agentRuns = [] }) => {
|
|
209
|
+
const system = environmentOf(command).system ?? thisMachine();
|
|
210
|
+
const checked = guardSchedule(file, { app, env, platform: system.platform, agentRuns }, { byHand: true });
|
|
211
|
+
return untilChildEnds(command, (signal) => backfillSchedule(app, system, env, file, {
|
|
212
|
+
at,
|
|
213
|
+
...(checked ? { schedule: checked } : {}),
|
|
214
|
+
agentRuns,
|
|
215
|
+
ownerLanguage: ownerLanguageOf,
|
|
216
|
+
reportTemplates: reportTemplatesOf,
|
|
217
|
+
...(input === undefined ? {} : { input }),
|
|
218
|
+
...(signal ? { signal } : {}),
|
|
219
|
+
}));
|
|
220
|
+
};
|
|
222
221
|
/** The tool's state folder, which holds its schedules. */
|
|
223
222
|
export const scheduleState = ({ app, env }) => resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state;
|
|
224
223
|
/** The variables a run gets on top of the timer's: the profile, where the files are, PATH. Never a credential. */
|
|
@@ -247,56 +246,34 @@ export const agentSchedule = (site, spec) => {
|
|
|
247
246
|
}
|
|
248
247
|
if (spec.model !== undefined && !isModel(spec.model))
|
|
249
248
|
throw new CliError("validation_error", `--model takes an alias such as sonnet or a model id, not "${spec.model}"`);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
?
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// The owner's own settings may let every tool run (bypassPermissions); here only the CLI may.
|
|
266
|
-
"--permission-mode",
|
|
267
|
-
"dontAsk",
|
|
268
|
-
"--allowedTools",
|
|
269
|
-
...agentClis.map((one) => `Bash(${one.command}:*)`),
|
|
270
|
-
"--no-session-persistence",
|
|
271
|
-
...modelFlag,
|
|
272
|
-
...((limits.leanStart ?? true) ? LEAN_CLAUDE : []),
|
|
273
|
-
...(spec.maxCost ? ["--max-budget-usd", String(spec.maxCost)] : []),
|
|
274
|
-
]
|
|
275
|
-
: [
|
|
276
|
-
program,
|
|
277
|
-
"exec",
|
|
278
|
-
"--skip-git-repo-check",
|
|
279
|
-
"--ephemeral",
|
|
280
|
-
"--sandbox",
|
|
281
|
-
"workspace-write",
|
|
282
|
-
// The CLIs reach their provider and write the store and their own state, and nothing else.
|
|
283
|
-
"-c",
|
|
284
|
-
"sandbox_workspace_write.network_access=true",
|
|
285
|
-
...modelFlag,
|
|
286
|
-
...[dirname(storePath(env)), ...folders].flatMap((dir) => ["--add-dir", dir]),
|
|
287
|
-
prompt,
|
|
288
|
-
];
|
|
249
|
+
if (!isHarness(harness))
|
|
250
|
+
throw new CliError("validation_error", `the agent is one of ${HARNESSES.join(", ")}; not "${harness}"`, {
|
|
251
|
+
agents: HARNESSES,
|
|
252
|
+
});
|
|
253
|
+
const kind = harnessOf(harness);
|
|
254
|
+
const agent = {
|
|
255
|
+
harness,
|
|
256
|
+
prompt,
|
|
257
|
+
model: spec.model ?? limits.models?.[harness] ?? AGENT_MODELS[harness],
|
|
258
|
+
leanStart: limits.leanStart ?? true,
|
|
259
|
+
...(spec.maxCost && kind.reportsCost ? { maxCost: spec.maxCost } : {}),
|
|
260
|
+
...(spec.allowDangerous ? { allowDangerous: true } : {}),
|
|
261
|
+
};
|
|
262
|
+
const start = agentStart({ app, env, platform: system.platform, agentRuns }, agent);
|
|
263
|
+
const name = scheduleName(spec.name);
|
|
289
264
|
return {
|
|
290
|
-
name
|
|
265
|
+
name,
|
|
291
266
|
kind: "agent",
|
|
292
|
-
argv,
|
|
267
|
+
argv: start.argv,
|
|
268
|
+
agent,
|
|
293
269
|
when: spec.when,
|
|
294
|
-
environment: scheduleEnvironment(site),
|
|
270
|
+
environment: { ...scheduleEnvironment(site), ...start.environment },
|
|
271
|
+
...(start.files ? { files: start.files } : {}),
|
|
295
272
|
createdAt: new Date().toISOString(),
|
|
296
273
|
...(spec.onNewMail ? { onNewMail: spec.onNewMail } : {}),
|
|
297
274
|
...(spec.mailWaitMinutes === undefined ? {} : { mailWaitMinutes: spec.mailWaitMinutes }),
|
|
298
275
|
...(spec.mailBatch === undefined ? {} : { mailBatch: spec.mailBatch }),
|
|
299
|
-
...(spec.maxCostPerDay === undefined ? {} : { maxCostPerDay: spec.maxCostPerDay }),
|
|
276
|
+
...(spec.maxCostPerDay === undefined || !kind.reportsCost ? {} : { maxCostPerDay: spec.maxCostPerDay }),
|
|
300
277
|
...(spec.notify ? { notify: spec.notify } : {}),
|
|
301
278
|
...(spec.to?.length ? { to: spec.to } : {}),
|
|
302
279
|
...(spec.paused ? { paused: true } : {}),
|
|
@@ -316,12 +293,13 @@ export const writeSchedule = async (site, schedule) => {
|
|
|
316
293
|
throw new CliError("validation_error", `schedule ${schedule.name} already runs for profile ${owner}; name this one for ${profile}, e.g. ${schedule.name}-${profile}`);
|
|
317
294
|
}
|
|
318
295
|
}
|
|
319
|
-
|
|
296
|
+
const text = `${JSON.stringify(schedule, null, 2)}\n`;
|
|
297
|
+
writeSecurely(file, text, 0o600);
|
|
320
298
|
const timer = timerFor(app, system, env);
|
|
321
299
|
if (schedule.paused)
|
|
322
300
|
await timer.remove(schedule.name);
|
|
323
301
|
else
|
|
324
|
-
await timer.install(schedule, [...system.entry, "schedule", "exec", file]);
|
|
302
|
+
await timer.install(schedule, [...system.entry, "schedule", "exec", file, sealOf(text)]);
|
|
325
303
|
return { file, timer: timer.where(schedule.name), replaced };
|
|
326
304
|
};
|
|
327
305
|
/** Why an agent schedule may not start today: its runs cost the day's cap. Recorded as the run's skip. */
|
|
@@ -368,13 +346,14 @@ export const removeSchedule = async (site, name) => {
|
|
|
368
346
|
* and sent along `routes` (its own when absent, none when empty). A stop of the command stops the agent.
|
|
369
347
|
*/
|
|
370
348
|
export const runScheduleNow = async (command, site, file, { routes, agentInput } = {}) => {
|
|
371
|
-
const schedule = readSchedule(file);
|
|
349
|
+
const schedule = guardSchedule(file, { app: site.app, env: site.env, platform: site.system.platform, agentRuns: site.agentRuns }, { byHand: true }) ?? readSchedule(file);
|
|
372
350
|
ownRoutes(schedule, routes);
|
|
373
351
|
const maxCostPerDay = schedule.maxCostPerDay ?? site.limits?.maxCostPerDay ?? SCHEDULE_DEFAULTS.maxCostPerDay;
|
|
374
352
|
const capped = dayCapReached(file, schedule, maxCostPerDay);
|
|
375
353
|
if (capped)
|
|
376
354
|
return { skipped: capped };
|
|
377
355
|
return untilChildEnds(command, (signal) => runSchedule(site.app, site.system, site.env, file, {
|
|
356
|
+
schedule,
|
|
378
357
|
timer: timerFor(site.app, site.system, site.env),
|
|
379
358
|
agentRuns: site.agentRuns ?? [],
|
|
380
359
|
ownerLanguage: ownerLanguageOf,
|
|
@@ -431,6 +410,18 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
431
410
|
maxCostPerDay: schedule.maxCostPerDay,
|
|
432
411
|
}),
|
|
433
412
|
});
|
|
413
|
+
/** An agent that reports no cost answers null for what it spent and for its caps: unknown, not $0 and not capped. */
|
|
414
|
+
const agentCostsOf = (self, state, schedule) => {
|
|
415
|
+
const harness = schedule.agent && isHarness(schedule.agent.harness) ? schedule.agent.harness : harnessOfArgv(schedule.argv);
|
|
416
|
+
const costed = harness !== null && reportsCost(harness);
|
|
417
|
+
return {
|
|
418
|
+
harness,
|
|
419
|
+
reportsCost: costed,
|
|
420
|
+
spentTodayUsd: costed ? spentToday(scheduleFile(state, schedule.name)) : null,
|
|
421
|
+
maxCostUsd: costed ? runCapOf(schedule.argv) : null,
|
|
422
|
+
maxCostPerDayUsd: costed ? limitsOf(self, schedule).maxCostPerDay : null,
|
|
423
|
+
};
|
|
424
|
+
};
|
|
434
425
|
const waits = async (self, file, { timed }) => {
|
|
435
426
|
if (!existsSync(file))
|
|
436
427
|
return undefined;
|
|
@@ -486,17 +477,18 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
486
477
|
effects: LOCAL_WRITE,
|
|
487
478
|
examples: [
|
|
488
479
|
`${app.command} personal schedule agent review claude "review what came in overnight and draft replies" --at 08:30`,
|
|
489
|
-
`${app.command} personal schedule agent triage
|
|
480
|
+
`${app.command} personal schedule agent triage gemini "list what needs an answer today" --every 2h`,
|
|
490
481
|
`${app.command} personal schedule agent weekly claude "review the week's open threads" --at 09:00 --model opus`,
|
|
491
482
|
],
|
|
492
483
|
}))
|
|
493
|
-
.description(`start an agent (
|
|
484
|
+
.description(`start an agent (${HARNESSES.join(", ")}) with a prompt on a timer; it runs with ${agentClis.map((one) => `${one.envPrefix}_READ_ONLY=1`).join(" and ")}, so it reads and drafts and cannot send, and its own limits hold it to these CLIs' commands; an agent with no such limit is refused (\`schedule agents list\` says which) — its answer is kept and you are notified`)
|
|
494
485
|
.argument("<name>", "lowercase letters, digits and dashes")
|
|
495
486
|
.addArgument(new Argument("<harness>", "the agent to start").choices(HARNESSES))
|
|
496
487
|
.argument("<prompt>", `what to do, e.g. "${promptExample(app)}"`)
|
|
497
|
-
.option("--model <model>", `the model it runs on: an alias such as sonnet, or a model id; "" for the
|
|
488
|
+
.option("--model <model>", `the model it runs on: an alias such as sonnet, or a model id; "" for the agent's own default (default sonnet for claude, the agent's own for the others, or the config file's)`)
|
|
498
489
|
.addOption(new Option("--max-cost <usd>", "claude only: stop a run that costs more than this, in US dollars").argParser(Number))
|
|
499
|
-
.
|
|
490
|
+
.option("--allow-dangerous", "start an agent its own limits cannot hold to these CLIs' commands, where `schedule agents list` says allowed_with_ack: it may then run any program inside its sandbox")
|
|
491
|
+
.addOption(new Option("--max-cost-per-day <usd>", `${COSTED} only, as the others report no cost: start no run for the rest of the day once its runs cost this much, in US dollars; 0 for no cap (default ${SCHEDULE_DEFAULTS.maxCostPerDay}, or the config file's)`).argParser(Number))).action(async function (name, harness, prompt) {
|
|
500
492
|
const { site, save } = prepare(this);
|
|
501
493
|
const options = this.opts();
|
|
502
494
|
if (options.onNewMail !== undefined && !HOLDER.test(options.onNewMail))
|
|
@@ -505,6 +497,8 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
505
497
|
throw new CliError("validation_error", "--mail-wait and --mail-batch shape a run gated by --on-new-mail");
|
|
506
498
|
if (options.maxCostPerDay !== undefined && !(Number.isFinite(options.maxCostPerDay) && options.maxCostPerDay >= 0))
|
|
507
499
|
throw new CliError("validation_error", "--max-cost-per-day takes US dollars, 0 or more");
|
|
500
|
+
if (!reportsCost(harness) && (options.maxCost || options.maxCostPerDay))
|
|
501
|
+
throw new CliError("validation_error", `${harness} reports no cost, so --max-cost and --max-cost-per-day cannot stop it; leave them out (${COSTED} reports one)`, { reason: "agent.cost-unknown" });
|
|
508
502
|
const mailBatch = options.mailBatch === undefined ? undefined : Number(options.mailBatch);
|
|
509
503
|
if (mailBatch !== undefined && !(Number.isSafeInteger(mailBatch) && mailBatch >= 1))
|
|
510
504
|
throw new CliError("validation_error", "--mail-batch takes a count of emails, 1 or more");
|
|
@@ -517,6 +511,7 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
517
511
|
...(options.model === undefined ? {} : { model: options.model }),
|
|
518
512
|
...(options.maxCost ? { maxCost: options.maxCost } : {}),
|
|
519
513
|
...(options.maxCostPerDay === undefined ? {} : { maxCostPerDay: options.maxCostPerDay }),
|
|
514
|
+
...(options.allowDangerous ? { allowDangerous: true } : {}),
|
|
520
515
|
...(options.onNewMail ? { onNewMail: options.onNewMail } : {}),
|
|
521
516
|
...(mailWaitMinutes === undefined ? {} : { mailWaitMinutes }),
|
|
522
517
|
...(mailBatch === undefined ? {} : { mailBatch }),
|
|
@@ -545,13 +540,7 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
545
540
|
notify: notifyOf(schedule),
|
|
546
541
|
...(schedule.to?.length ? { deliverTo: schedule.to } : {}),
|
|
547
542
|
last: lastRun(scheduleFile(state, schedule.name)) ?? null,
|
|
548
|
-
...(schedule.kind === "agent"
|
|
549
|
-
? {
|
|
550
|
-
spentTodayUsd: spentToday(scheduleFile(state, schedule.name)),
|
|
551
|
-
maxCostUsd: runCapOf(schedule.argv),
|
|
552
|
-
maxCostPerDayUsd: limitsOf(this, schedule).maxCostPerDay,
|
|
553
|
-
}
|
|
554
|
-
: {}),
|
|
543
|
+
...(schedule.kind === "agent" ? agentCostsOf(this, state, schedule) : {}),
|
|
555
544
|
}));
|
|
556
545
|
const answer = listOf("schedule list", {
|
|
557
546
|
items: rows.map((row) => snakeKeys(row)),
|
|
@@ -564,9 +553,9 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
564
553
|
return "";
|
|
565
554
|
}
|
|
566
555
|
return rows
|
|
567
|
-
.map(({ name, kind, when, paused, notify, deliverTo, last, spentTodayUsd, maxCostPerDayUsd }) => [
|
|
556
|
+
.map(({ name, kind, harness, when, paused, notify, deliverTo, last, spentTodayUsd, maxCostPerDayUsd }) => [
|
|
568
557
|
name,
|
|
569
|
-
kind,
|
|
558
|
+
kind === "agent" ? `agent ${harness ?? "unknown"}` : kind,
|
|
570
559
|
paused ? `${when}, paused` : when,
|
|
571
560
|
`notify ${notify}`,
|
|
572
561
|
...(deliverTo ? [`to ${deliverTo.join(", ")}`] : []),
|
|
@@ -590,6 +579,24 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
590
579
|
.join("\n");
|
|
591
580
|
});
|
|
592
581
|
});
|
|
582
|
+
withQuery(annotate(command.command("agents").description("the coding agents an agent schedule may start").command("list"), {
|
|
583
|
+
effects: LOCAL_READ,
|
|
584
|
+
examples: [`${app.command} schedule agents list`, `${app.command} schedule agents list --json`],
|
|
585
|
+
}), SCHEDULE_HARNESSES_QUERY)
|
|
586
|
+
.description("the agents a schedule may start, and which are on PATH here")
|
|
587
|
+
.action(function (words) {
|
|
588
|
+
listQuery(typedQuery(words), SCHEDULE_HARNESSES_QUERY, "schedule agents list");
|
|
589
|
+
const { context, system } = prepare(this, { needsProfile: false });
|
|
590
|
+
const rows = harnessesOn(context.env, system.platform);
|
|
591
|
+
const answer = listOf("schedule agents list", {
|
|
592
|
+
items: rows.map((row) => snakeKeys(row)),
|
|
593
|
+
limit: rows.length,
|
|
594
|
+
has_more: false,
|
|
595
|
+
});
|
|
596
|
+
renderAnswer(this, context, answer, () => rows
|
|
597
|
+
.map(({ id, name, installed, path, reportsCost }) => [id, name, installed ? path : "not on PATH", reportsCost ? "reports cost" : "cost unknown"].join(" "))
|
|
598
|
+
.join("\n"));
|
|
599
|
+
});
|
|
593
600
|
annotate(command.command("run"), {
|
|
594
601
|
effects: REMOTE_WRITE,
|
|
595
602
|
examples: [`${app.command} personal schedule run health`],
|
|
@@ -665,15 +672,18 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
665
672
|
})
|
|
666
673
|
.description("what a timer runs, given the schedule's file; to run one by hand, use run")
|
|
667
674
|
.argument("<file>", "the schedule's schedule.json in the state folder, as the timer passes it")
|
|
668
|
-
.
|
|
675
|
+
.argument("[seal]", "the file's SHA-256 as it was saved, which the timer passes; a file that differs does not run")
|
|
676
|
+
.action(async function (file, seal) {
|
|
669
677
|
// A timer starts it with no profile named; the schedule's own environment carries the profile.
|
|
670
678
|
const { context, system, timer } = prepare(this, { needsProfile: false });
|
|
671
679
|
// A timer left behind by a pause that could not remove it must not run the schedule.
|
|
672
680
|
if (existsSync(file) && readSchedule(file).paused)
|
|
673
681
|
return;
|
|
682
|
+
const checked = guardSchedule(file, { app, env: context.env, platform: system.platform, agentRuns }, { seal });
|
|
674
683
|
if ((await waits(this, file, { timed: true })) !== undefined)
|
|
675
684
|
return;
|
|
676
685
|
const last = await untilChildEnds(this, (signal) => runSchedule(app, system, context.env, file, {
|
|
686
|
+
...(checked ? { schedule: checked } : {}),
|
|
677
687
|
timer: timer(),
|
|
678
688
|
agentRuns,
|
|
679
689
|
ownerLanguage: ownerLanguageOf,
|