@tidegap/core 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/agent-snippet.d.ts +30 -0
- package/dist/agent-snippet.js +120 -0
- package/dist/budget.d.ts +0 -12
- package/dist/budget.js +2 -24
- package/dist/channels/commands.d.ts +137 -0
- package/dist/channels/commands.js +377 -0
- package/dist/channels/delivery-codes.d.ts +9 -0
- package/dist/channels/delivery-codes.js +53 -0
- package/dist/channels/digest.d.ts +102 -0
- package/dist/channels/digest.js +146 -0
- package/dist/channels/format.d.ts +127 -0
- package/dist/channels/format.js +407 -0
- package/dist/channels/index.d.ts +15 -0
- package/dist/channels/index.js +15 -0
- package/dist/channels/kinds/command.d.ts +13 -0
- package/dist/channels/kinds/command.js +65 -0
- package/dist/channels/kinds/discord.d.ts +16 -0
- package/dist/channels/kinds/discord.js +67 -0
- package/dist/channels/kinds/email.d.ts +20 -0
- package/dist/channels/kinds/email.js +162 -0
- package/dist/channels/kinds/index.d.ts +8 -0
- package/dist/channels/kinds/index.js +17 -0
- package/dist/channels/kinds/ntfy.d.ts +25 -0
- package/dist/channels/kinds/ntfy.js +163 -0
- package/dist/channels/kinds/pushover.d.ts +11 -0
- package/dist/channels/kinds/pushover.js +77 -0
- package/dist/channels/kinds/shared.d.ts +25 -0
- package/dist/channels/kinds/shared.js +39 -0
- package/dist/channels/kinds/shortcuts.d.ts +9 -0
- package/dist/channels/kinds/shortcuts.js +45 -0
- package/dist/channels/kinds/slack.d.ts +8 -0
- package/dist/channels/kinds/slack.js +57 -0
- package/dist/channels/kinds/telegram.d.ts +4 -0
- package/dist/channels/kinds/telegram.js +26 -0
- package/dist/channels/kinds/webhook.d.ts +30 -0
- package/dist/channels/kinds/webhook.js +177 -0
- package/dist/channels/payload.d.ts +36 -0
- package/dist/channels/payload.js +61 -0
- package/dist/channels/plan.d.ts +24 -0
- package/dist/channels/plan.js +66 -0
- package/dist/channels/registry.d.ts +191 -0
- package/dist/channels/registry.js +125 -0
- package/dist/channels/telegram.d.ts +110 -0
- package/dist/channels/telegram.js +168 -0
- package/dist/channels/types.d.ts +107 -0
- package/dist/channels/types.js +26 -0
- package/dist/claude-tools.d.ts +29 -0
- package/dist/claude-tools.js +49 -0
- package/dist/data/tables.generated.d.ts +6 -0
- package/dist/data/tables.generated.js +37 -0
- package/dist/energy.d.ts +77 -0
- package/dist/energy.js +131 -0
- package/dist/grid.d.ts +19 -2
- package/dist/grid.js +84 -28
- package/dist/handoff.d.ts +152 -0
- package/dist/handoff.js +430 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +3 -1
- package/dist/index.d.ts +46 -16
- package/dist/index.js +34 -8
- package/dist/job-cadence.d.ts +76 -0
- package/dist/job-cadence.js +240 -0
- package/dist/jobs.d.ts +173 -0
- package/dist/jobs.js +794 -0
- package/dist/notify.d.ts +2 -0
- package/dist/notify.js +2 -1
- package/dist/paths.d.ts +13 -46
- package/dist/paths.js +51 -219
- package/dist/postpone.d.ts +113 -0
- package/dist/postpone.js +185 -0
- package/dist/providers/anthropic.js +7 -3
- package/dist/providers/base.d.ts +113 -1
- package/dist/providers/base.js +15 -0
- package/dist/providers/budget.d.ts +25 -0
- package/dist/providers/budget.js +57 -0
- package/dist/providers/defaults.js +4 -0
- package/dist/providers/defer.d.ts +16 -0
- package/dist/providers/defer.js +31 -0
- package/dist/providers/gemini.d.ts +1 -0
- package/dist/providers/gemini.js +27 -20
- package/dist/providers/index.d.ts +2 -2
- package/dist/providers/index.js +1 -1
- package/dist/providers/ollama.d.ts +1 -0
- package/dist/providers/ollama.js +26 -22
- package/dist/providers/openai.js +5 -5
- package/dist/providers/timeout.d.ts +18 -0
- package/dist/providers/timeout.js +33 -0
- package/dist/quota.d.ts +7 -2
- package/dist/quota.js +13 -29
- package/dist/readiness.d.ts +169 -0
- package/dist/readiness.js +254 -0
- package/dist/redact.d.ts +42 -0
- package/dist/redact.js +110 -0
- package/dist/region-host.d.ts +30 -0
- package/dist/region-host.js +69 -0
- package/dist/region.d.ts +102 -20
- package/dist/region.js +175 -23
- package/dist/run-session.d.ts +36 -0
- package/dist/run-session.js +72 -0
- package/dist/schedule-job.d.ts +95 -0
- package/dist/schedule-job.js +195 -0
- package/dist/scheduler.d.ts +245 -14
- package/dist/scheduler.js +925 -110
- package/dist/sign.d.ts +8 -1
- package/dist/sign.js +49 -3
- package/dist/storage/sqlite.d.ts +157 -5
- package/dist/storage/sqlite.js +661 -20
- package/dist/task-events.d.ts +102 -0
- package/dist/task-events.js +308 -0
- package/dist/tool-surface.d.ts +31 -2
- package/dist/tool-surface.js +359 -65
- package/dist/types.d.ts +246 -3
- package/dist/types.js +8 -1
- package/dist/zone-time.d.ts +22 -0
- package/dist/zone-time.js +76 -0
- package/package.json +11 -6
- package/dist/aggregator.d.ts.map +0 -1
- package/dist/aggregator.js.map +0 -1
- package/dist/budget.d.ts.map +0 -1
- package/dist/budget.js.map +0 -1
- package/dist/data/tables.generated.d.ts.map +0 -1
- package/dist/data/tables.generated.js.map +0 -1
- package/dist/energy.d.ts.map +0 -1
- package/dist/energy.js.map +0 -1
- package/dist/grid.d.ts.map +0 -1
- package/dist/grid.js.map +0 -1
- package/dist/history.d.ts.map +0 -1
- package/dist/history.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/notify.d.ts.map +0 -1
- package/dist/notify.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/base.d.ts.map +0 -1
- package/dist/providers/base.js.map +0 -1
- package/dist/providers/defaults.d.ts.map +0 -1
- package/dist/providers/defaults.js.map +0 -1
- package/dist/providers/gemini.d.ts.map +0 -1
- package/dist/providers/gemini.js.map +0 -1
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/ollama.d.ts.map +0 -1
- package/dist/providers/ollama.js.map +0 -1
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js.map +0 -1
- package/dist/quota.d.ts.map +0 -1
- package/dist/quota.js.map +0 -1
- package/dist/recommend.d.ts.map +0 -1
- package/dist/recommend.js.map +0 -1
- package/dist/redact.d.ts.map +0 -1
- package/dist/redact.js.map +0 -1
- package/dist/region.d.ts.map +0 -1
- package/dist/region.js.map +0 -1
- package/dist/routing.d.ts.map +0 -1
- package/dist/routing.js.map +0 -1
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js.map +0 -1
- package/dist/select-window.d.ts.map +0 -1
- package/dist/select-window.js.map +0 -1
- package/dist/sign.d.ts.map +0 -1
- package/dist/sign.js.map +0 -1
- package/dist/storage/sqlite.d.ts.map +0 -1
- package/dist/storage/sqlite.js.map +0 -1
- package/dist/tool-surface.d.ts.map +0 -1
- package/dist/tool-surface.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<img src="https://www.tidegap.com/icon-192.png" alt="Tidegap" width="48" height="48">
|
|
2
|
+
|
|
1
3
|
# @tidegap/core
|
|
2
4
|
|
|
3
5
|
> Renamed from `@ebb-ai/core` in 0.18.0. See [Renamed from Ebb AI](https://github.com/tidegap/tidegap#renamed-from-ebb-ai).
|
|
@@ -39,7 +41,7 @@ import { defer } from "@tidegap/core";
|
|
|
39
41
|
|
|
40
42
|
const summary = await defer(
|
|
41
43
|
async () => callAnthropic("Summarize today's CHANGELOG"),
|
|
42
|
-
{ deadline:
|
|
44
|
+
{ deadline: new Date(Date.now() + 12 * 3600 * 1000).toISOString(), region: "US-CAL-CISO" },
|
|
43
45
|
);
|
|
44
46
|
```
|
|
45
47
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent block that makes a coding agent schedule recurring work through
|
|
3
|
+
* Tidegap instead of cron, and the per-host files that carry it (jobs U15,
|
|
4
|
+
* R33-R36, KTD15). One source: `tidegap jobs snippet`, `tidegap install` and
|
|
5
|
+
* the site's install box (a static copy, checked by docs-drift) render it.
|
|
6
|
+
*/
|
|
7
|
+
/** The generic `AGENTS.md` block: at most 12 lines (R35), Markdown. */
|
|
8
|
+
export declare const AGENTS_BLOCK = "## Scheduling (Tidegap)\nWhen the user asks to run something on a schedule (\"every day\", \"every night\", \"weekly\",\n\"every N hours\", \"cron\", \"crontab\", \"launchd\", \"systemd timer\", \"\u043A\u0430\u0436\u0434\u044B\u0439 \u0434\u0435\u043D\u044C\"), use Tidegap, not cron:\n1. Propose Tidegap in one line.\n2. Ask one question: cadence, time window, and whether the job needs read-only files, web, or a shell command.\n \"Every night\" with no hours: ask; night is 22:00-08:00.\n3. Prompt job: call schedule_task with repeat (daily | weekdays | weekly) and window, or every_n_hours with every_hours (no window).\n4. Shell command job: show \"tidegap jobs add --command '<cmd>' --summarize '<what to report>' --daily --window 22:00-08:00\"\n for the user to run. Never create it yourself.\nWrite a crontab, launchd plist or systemd timer only when the user says \"cron anyway\", and say so.\n";
|
|
9
|
+
/** The hosts `tidegap jobs snippet --host` knows, in display order. */
|
|
10
|
+
export declare const AGENT_HOSTS: readonly ["generic", "claude", "opencode", "codex", "cursor", "gemini"];
|
|
11
|
+
export type AgentHost = (typeof AGENT_HOSTS)[number];
|
|
12
|
+
export declare function isAgentHost(name: string): name is AgentHost;
|
|
13
|
+
/** One file a host reads, with the text to add to it. */
|
|
14
|
+
export interface AgentSnippetFile {
|
|
15
|
+
/** Where the host reads it, e.g. `~/.codex/AGENTS.md`. */
|
|
16
|
+
path: string;
|
|
17
|
+
format: "markdown" | "json" | "toml";
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentSnippet {
|
|
21
|
+
host: AgentHost;
|
|
22
|
+
/** One or two sentences: what to do with the files. */
|
|
23
|
+
intro: string;
|
|
24
|
+
files: AgentSnippetFile[];
|
|
25
|
+
}
|
|
26
|
+
/** The intro and files for one host. */
|
|
27
|
+
export declare function agentSnippet(host: AgentHost): AgentSnippet;
|
|
28
|
+
/** The text `tidegap jobs snippet --host <host>` prints. */
|
|
29
|
+
export declare function renderAgentSnippet(host: AgentHost): string;
|
|
30
|
+
//# sourceMappingURL=agent-snippet.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent block that makes a coding agent schedule recurring work through
|
|
3
|
+
* Tidegap instead of cron, and the per-host files that carry it (jobs U15,
|
|
4
|
+
* R33-R36, KTD15). One source: `tidegap jobs snippet`, `tidegap install` and
|
|
5
|
+
* the site's install box (a static copy, checked by docs-drift) render it.
|
|
6
|
+
*/
|
|
7
|
+
/** The generic `AGENTS.md` block: at most 12 lines (R35), Markdown. */
|
|
8
|
+
export const AGENTS_BLOCK = `## Scheduling (Tidegap)
|
|
9
|
+
When the user asks to run something on a schedule ("every day", "every night", "weekly",
|
|
10
|
+
"every N hours", "cron", "crontab", "launchd", "systemd timer", "каждый день"), use Tidegap, not cron:
|
|
11
|
+
1. Propose Tidegap in one line.
|
|
12
|
+
2. Ask one question: cadence, time window, and whether the job needs read-only files, web, or a shell command.
|
|
13
|
+
"Every night" with no hours: ask; night is 22:00-08:00.
|
|
14
|
+
3. Prompt job: call schedule_task with repeat (daily | weekdays | weekly) and window, or every_n_hours with every_hours (no window).
|
|
15
|
+
4. Shell command job: show "tidegap jobs add --command '<cmd>' --summarize '<what to report>' --daily --window 22:00-08:00"
|
|
16
|
+
for the user to run. Never create it yourself.
|
|
17
|
+
Write a crontab, launchd plist or systemd timer only when the user says "cron anyway", and say so.
|
|
18
|
+
`;
|
|
19
|
+
/** The hosts `tidegap jobs snippet --host` knows, in display order. */
|
|
20
|
+
export const AGENT_HOSTS = ["generic", "claude", "opencode", "codex", "cursor", "gemini"];
|
|
21
|
+
export function isAgentHost(name) {
|
|
22
|
+
return AGENT_HOSTS.includes(name);
|
|
23
|
+
}
|
|
24
|
+
/** The skill and rule description: the R30 trigger phrases. */
|
|
25
|
+
const DESCRIPTION = 'Schedule recurring work through Tidegap, not cron. Use when the user says "schedule this", "every day", "every night", ' +
|
|
26
|
+
'"every morning", "daily", "weekly", "every N hours", "once a day", "recurring", "cron", "crontab", "launchd", ' +
|
|
27
|
+
'"launchctl", "systemd timer", "set up a job", "каждый день", "каждую ночь", "по расписанию", "крон" or "раз в день".';
|
|
28
|
+
const MCP_ARGS = ["-y", "@tidegap/mcp"];
|
|
29
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
30
|
+
const mcpServers = json({ mcpServers: { tidegap: { command: "npx", args: MCP_ARGS } } });
|
|
31
|
+
const markdown = (path) => ({ path, format: "markdown", content: AGENTS_BLOCK });
|
|
32
|
+
const ASK = "ask";
|
|
33
|
+
/** OpenCode bash rules: last match wins, so the catch-all comes first (opencode.ai/docs/permissions). */
|
|
34
|
+
const OPENCODE_BASH = {
|
|
35
|
+
"*": "allow",
|
|
36
|
+
crontab: ASK,
|
|
37
|
+
"crontab *": ASK,
|
|
38
|
+
"crontab -l": "allow",
|
|
39
|
+
"launchctl load *": ASK,
|
|
40
|
+
"launchctl bootstrap *": ASK,
|
|
41
|
+
"systemctl --user enable *": ASK,
|
|
42
|
+
};
|
|
43
|
+
/** The intro and files for one host. */
|
|
44
|
+
export function agentSnippet(host) {
|
|
45
|
+
switch (host) {
|
|
46
|
+
case "generic":
|
|
47
|
+
return {
|
|
48
|
+
host,
|
|
49
|
+
intro: "Add this block to the instructions file your agent reads (AGENTS.md, CLAUDE.md, GEMINI.md). The MCP server is npx -y @tidegap/mcp.",
|
|
50
|
+
files: [markdown("AGENTS.md")],
|
|
51
|
+
};
|
|
52
|
+
case "claude":
|
|
53
|
+
return {
|
|
54
|
+
host,
|
|
55
|
+
intro: "The Tidegap plugin already does this (skill text, a prompt hint, and a guard that asks before crontab): " +
|
|
56
|
+
"/plugin marketplace add tidegap/tidegap, then /plugin install tidegap. Without the plugin, add the block to CLAUDE.md " +
|
|
57
|
+
"(~/.claude/CLAUDE.md for every project).",
|
|
58
|
+
files: [markdown("CLAUDE.md")],
|
|
59
|
+
};
|
|
60
|
+
case "opencode":
|
|
61
|
+
return {
|
|
62
|
+
host,
|
|
63
|
+
intro: "Create the skill, then merge the MCP entry and the bash rules into opencode.json (keep your own \"*\" rule if you have one).",
|
|
64
|
+
files: [
|
|
65
|
+
{
|
|
66
|
+
path: "~/.config/opencode/skills/tidegap/SKILL.md",
|
|
67
|
+
format: "markdown",
|
|
68
|
+
content: `---\nname: tidegap\ndescription: ${DESCRIPTION}\n---\n\n${AGENTS_BLOCK}`,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
path: "~/.config/opencode/opencode.json",
|
|
72
|
+
format: "json",
|
|
73
|
+
content: json({
|
|
74
|
+
$schema: "https://opencode.ai/config.json",
|
|
75
|
+
mcp: { tidegap: { type: "local", command: ["npx", ...MCP_ARGS], enabled: true } },
|
|
76
|
+
permission: { bash: OPENCODE_BASH },
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
case "codex":
|
|
82
|
+
return {
|
|
83
|
+
host,
|
|
84
|
+
intro: "Add the block to AGENTS.md and the MCP table to config.toml.",
|
|
85
|
+
files: [
|
|
86
|
+
markdown("~/.codex/AGENTS.md"),
|
|
87
|
+
{
|
|
88
|
+
path: "~/.codex/config.toml",
|
|
89
|
+
format: "toml",
|
|
90
|
+
content: `[mcp_servers.tidegap]\ncommand = "npx"\nargs = ${JSON.stringify(MCP_ARGS).replace(/,/g, ", ")}\n`,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
case "cursor":
|
|
95
|
+
return {
|
|
96
|
+
host,
|
|
97
|
+
intro: "Create the rule in your project and add the MCP entry to .cursor/mcp.json.",
|
|
98
|
+
files: [
|
|
99
|
+
{
|
|
100
|
+
path: ".cursor/rules/tidegap.mdc",
|
|
101
|
+
format: "markdown",
|
|
102
|
+
content: `---\ndescription: ${DESCRIPTION}\nalwaysApply: false\n---\n\n${AGENTS_BLOCK}`,
|
|
103
|
+
},
|
|
104
|
+
{ path: ".cursor/mcp.json", format: "json", content: mcpServers },
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
case "gemini":
|
|
108
|
+
return {
|
|
109
|
+
host,
|
|
110
|
+
intro: "Add the block to GEMINI.md and merge the MCP entry into settings.json.",
|
|
111
|
+
files: [markdown("~/.gemini/GEMINI.md"), { path: "~/.gemini/settings.json", format: "json", content: mcpServers }],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** The text `tidegap jobs snippet --host <host>` prints. */
|
|
116
|
+
export function renderAgentSnippet(host) {
|
|
117
|
+
const s = agentSnippet(host);
|
|
118
|
+
return [s.intro, ...s.files.map((f) => `${f.path}:\n\n${f.content.trimEnd()}`)].join("\n\n");
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=agent-snippet.js.map
|
package/dist/budget.d.ts
CHANGED
|
@@ -67,14 +67,6 @@ export interface CarbonBudgetStatus {
|
|
|
67
67
|
export declare function carbonBudgetConfigPath(): string;
|
|
68
68
|
/** Prefix of every config-file key and host variable since 0.18. */
|
|
69
69
|
export declare const KEY_PREFIX = "TIDEGAP_";
|
|
70
|
-
/** The 0.17 prefix, still read as a fallback until 0.19. */
|
|
71
|
-
export declare const LEGACY_KEY_PREFIX = "EBB_";
|
|
72
|
-
/**
|
|
73
|
-
* Fold 0.17 `EBB_*` keys into their `TIDEGAP_*` names: an `EBB_<NAME>` key
|
|
74
|
-
* is kept as `TIDEGAP_<NAME>` only when `TIDEGAP_<NAME>` is absent, so the new
|
|
75
|
-
* name wins per key. Other keys pass through unchanged.
|
|
76
|
-
*/
|
|
77
|
-
export declare function withTidegapKeys<T extends string | undefined>(values: Record<string, T>): Record<string, T>;
|
|
78
70
|
/**
|
|
79
71
|
* The carbon a single receipt contributes to a window: the *actual* grams
|
|
80
72
|
* billed against the observed intensity, falling back to the schedule-time
|
|
@@ -127,10 +119,6 @@ export declare function parseKeyValues(contents: string): Record<string, string>
|
|
|
127
119
|
export interface CarbonBudgetEnv {
|
|
128
120
|
TIDEGAP_CARBON_BUDGET_G?: string;
|
|
129
121
|
TIDEGAP_CARBON_BUDGET_WINDOW?: string;
|
|
130
|
-
/** @deprecated 0.17 name, read when `TIDEGAP_CARBON_BUDGET_G` is unset; removed in 0.19. */
|
|
131
|
-
EBB_CARBON_BUDGET_G?: string;
|
|
132
|
-
/** @deprecated 0.17 name, read when `TIDEGAP_CARBON_BUDGET_WINDOW` is unset; removed in 0.19. */
|
|
133
|
-
EBB_CARBON_BUDGET_WINDOW?: string;
|
|
134
122
|
}
|
|
135
123
|
export interface LoadCarbonBudgetOptions {
|
|
136
124
|
/** Override the config file path (tests). Defaults to `~/.tidegap/config`. */
|
package/dist/budget.js
CHANGED
|
@@ -30,28 +30,6 @@ export function carbonBudgetConfigPath() {
|
|
|
30
30
|
}
|
|
31
31
|
/** Prefix of every config-file key and host variable since 0.18. */
|
|
32
32
|
export const KEY_PREFIX = "TIDEGAP_";
|
|
33
|
-
/** The 0.17 prefix, still read as a fallback until 0.19. */
|
|
34
|
-
export const LEGACY_KEY_PREFIX = "EBB_";
|
|
35
|
-
/**
|
|
36
|
-
* Fold 0.17 `EBB_*` keys into their `TIDEGAP_*` names: an `EBB_<NAME>` key
|
|
37
|
-
* is kept as `TIDEGAP_<NAME>` only when `TIDEGAP_<NAME>` is absent, so the new
|
|
38
|
-
* name wins per key. Other keys pass through unchanged.
|
|
39
|
-
*/
|
|
40
|
-
export function withTidegapKeys(values) {
|
|
41
|
-
const out = {};
|
|
42
|
-
for (const [key, value] of Object.entries(values)) {
|
|
43
|
-
if (!key.startsWith(LEGACY_KEY_PREFIX))
|
|
44
|
-
out[key] = value;
|
|
45
|
-
}
|
|
46
|
-
for (const [key, value] of Object.entries(values)) {
|
|
47
|
-
if (!key.startsWith(LEGACY_KEY_PREFIX) || value === undefined)
|
|
48
|
-
continue;
|
|
49
|
-
const name = KEY_PREFIX + key.slice(LEGACY_KEY_PREFIX.length);
|
|
50
|
-
if (out[name] === undefined)
|
|
51
|
-
out[name] = value;
|
|
52
|
-
}
|
|
53
|
-
return out;
|
|
54
|
-
}
|
|
55
33
|
/**
|
|
56
34
|
* The carbon a single receipt contributes to a window: the *actual* grams
|
|
57
35
|
* billed against the observed intensity, falling back to the schedule-time
|
|
@@ -202,12 +180,12 @@ export function parseKeyValues(contents) {
|
|
|
202
180
|
* `opts.env`; the OpenClaw plugin builds the same shape from plugin config.
|
|
203
181
|
*/
|
|
204
182
|
export function loadCarbonBudgetConfig(opts = {}) {
|
|
205
|
-
const env =
|
|
183
|
+
const env = opts.env ?? {};
|
|
206
184
|
const path = opts.path ?? carbonBudgetConfigPath();
|
|
207
185
|
let fileValues = {};
|
|
208
186
|
if (existsSync(path)) {
|
|
209
187
|
try {
|
|
210
|
-
fileValues =
|
|
188
|
+
fileValues = parseKeyValues(readFileSync(path, "utf8"));
|
|
211
189
|
}
|
|
212
190
|
catch {
|
|
213
191
|
fileValues = {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bot commands and button presses (KTD15, R27): parse text and callback
|
|
3
|
+
* data into typed commands, then run them through the same `Scheduler`
|
|
4
|
+
* methods the page uses. Every write re-reads the task and checks it is
|
|
5
|
+
* still in a state that allows the action; a `/queue` number resolves only
|
|
6
|
+
* against the last listing and expires after {@link LISTING_TTL_MS}.
|
|
7
|
+
* `/jobs` lists recurring jobs and pauses, resumes or runs one through the
|
|
8
|
+
* core job actions; its numbers come from the last `/jobs` only.
|
|
9
|
+
*/
|
|
10
|
+
import { type PostponeOption, type PostponePreset, type PostponeTarget } from "../postpone.js";
|
|
11
|
+
import type { Scheduler } from "../scheduler.js";
|
|
12
|
+
import type { TaskStore } from "../storage/sqlite.js";
|
|
13
|
+
import type { JobRecord, TaskRecord } from "../types.js";
|
|
14
|
+
import { type CallbackActionName, type OutgoingMessage } from "./format.js";
|
|
15
|
+
/** `/queue` numbers expire after this long (R27). */
|
|
16
|
+
export declare const LISTING_TTL_MS: number;
|
|
17
|
+
/** A task named by its `/queue` number or by its id; a job by its `/jobs` number or id. */
|
|
18
|
+
export type TaskRef = {
|
|
19
|
+
n: number;
|
|
20
|
+
} | {
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
/** The `/later` argument (KTD15 Telegram column). `HH:MM` is local time, the next such time after now. */
|
|
24
|
+
export type LaterArg = {
|
|
25
|
+
preset: Exclude<PostponePreset, "after_limit_reset">;
|
|
26
|
+
} | {
|
|
27
|
+
preset: "after_limit_reset";
|
|
28
|
+
resetClock?: string;
|
|
29
|
+
} | {
|
|
30
|
+
clock: string;
|
|
31
|
+
};
|
|
32
|
+
export type ChannelCommand = {
|
|
33
|
+
kind: "help";
|
|
34
|
+
} | {
|
|
35
|
+
kind: "queue";
|
|
36
|
+
}
|
|
37
|
+
/** `/pair <code>` or the deep-link form `/start <code>`. */
|
|
38
|
+
| {
|
|
39
|
+
kind: "pair";
|
|
40
|
+
code?: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "later";
|
|
43
|
+
ref: TaskRef;
|
|
44
|
+
arg: LaterArg;
|
|
45
|
+
} | {
|
|
46
|
+
kind: "cancel";
|
|
47
|
+
ref: TaskRef;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "run";
|
|
50
|
+
ref: TaskRef;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "result";
|
|
53
|
+
ref: TaskRef;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "jobs";
|
|
56
|
+
}
|
|
57
|
+
/** `/jobs <action> <n|id>`. */
|
|
58
|
+
| {
|
|
59
|
+
kind: "job";
|
|
60
|
+
action: JobAction;
|
|
61
|
+
ref: TaskRef;
|
|
62
|
+
}
|
|
63
|
+
/** A known command with bad arguments; `reply` says how to use it. */
|
|
64
|
+
| {
|
|
65
|
+
kind: "invalid";
|
|
66
|
+
reply: string;
|
|
67
|
+
} | {
|
|
68
|
+
kind: "unknown";
|
|
69
|
+
};
|
|
70
|
+
/** What `/jobs` can do to one job. */
|
|
71
|
+
export type JobAction = "pause" | "resume" | "run";
|
|
72
|
+
/** Parse a message text. A text that is not a command is `unknown`. */
|
|
73
|
+
export declare function parseCommand(text: string): ChannelCommand;
|
|
74
|
+
/** A parsed button press. `later` without a preset opens the Later ▾ menu. */
|
|
75
|
+
export interface CallbackAction {
|
|
76
|
+
action: CallbackActionName;
|
|
77
|
+
taskId: string;
|
|
78
|
+
preset?: PostponePreset;
|
|
79
|
+
}
|
|
80
|
+
/** Parse `callback_data` (`<action>:<task_id>[:<preset code>]`); null when malformed. */
|
|
81
|
+
export declare function parseCallback(data: string): CallbackAction | null;
|
|
82
|
+
/** The next local `HH:MM` after `now` (today, else tomorrow). */
|
|
83
|
+
export declare function nextClockTime(clock: string, now: Date): Date;
|
|
84
|
+
/** The core postpone target of a `/later` argument. */
|
|
85
|
+
export declare function laterTarget(arg: LaterArg, now: Date): PostponeTarget;
|
|
86
|
+
/** Which numbered listing of a chat: `/queue` tasks or `/jobs` jobs. */
|
|
87
|
+
export type ListingKind = "tasks" | "jobs";
|
|
88
|
+
/**
|
|
89
|
+
* The last `/queue` and `/jobs` listings of one chat: item n of a kind is
|
|
90
|
+
* `ids[n-1]` of that kind's last listing. In memory only, so a restart drops it.
|
|
91
|
+
*/
|
|
92
|
+
export declare class QueueListing {
|
|
93
|
+
private readonly ttlMs;
|
|
94
|
+
private readonly lists;
|
|
95
|
+
constructor(ttlMs?: number);
|
|
96
|
+
set(ids: readonly string[], now: Date, kind?: ListingKind): void;
|
|
97
|
+
/** The id of item `n`, or null with no valid listing of that kind (none yet, or expired). */
|
|
98
|
+
resolve(n: number, now: Date, kind?: ListingKind): string | null | undefined;
|
|
99
|
+
}
|
|
100
|
+
/** What a command needs from the host: the ledger, the scheduler's task actions and the job actions. */
|
|
101
|
+
export interface CommandContext {
|
|
102
|
+
getTask(id: string): TaskRecord<unknown> | undefined;
|
|
103
|
+
/** Pending tasks, soonest first. */
|
|
104
|
+
pendingTasks(): TaskRecord<unknown>[];
|
|
105
|
+
postpone(id: string, target: PostponeTarget): Promise<unknown>;
|
|
106
|
+
cancel(id: string): unknown;
|
|
107
|
+
runNow(id: string): unknown;
|
|
108
|
+
laterOptions(record: TaskRecord<unknown>, now: Date): Promise<PostponeOption[]>;
|
|
109
|
+
/** Active and paused jobs, oldest first. */
|
|
110
|
+
listJobs(): JobRecord[];
|
|
111
|
+
/** A job that is not removed. */
|
|
112
|
+
getJob(id: string): JobRecord | undefined;
|
|
113
|
+
pauseJob(id: string): Promise<unknown>;
|
|
114
|
+
resumeJob(id: string): Promise<unknown>;
|
|
115
|
+
runJobNow(id: string): Promise<unknown>;
|
|
116
|
+
now(): Date;
|
|
117
|
+
}
|
|
118
|
+
/** A {@link CommandContext} over a core `Scheduler` and its `TaskStore`. */
|
|
119
|
+
export declare function commandContextFor(scheduler: Scheduler, store: TaskStore): CommandContext;
|
|
120
|
+
/** Run a parsed command for the paired chat. `pair` and `unknown` answer with help; the caller handles pairing. */
|
|
121
|
+
export declare function runCommand(cmd: ChannelCommand, ctx: CommandContext, listing: QueueListing): Promise<OutgoingMessage[]>;
|
|
122
|
+
/** What a host does for a button press: answer the query, maybe remove the pressed message's buttons, send messages. */
|
|
123
|
+
export interface CallbackOutcome {
|
|
124
|
+
answer: {
|
|
125
|
+
text?: string;
|
|
126
|
+
showAlert?: boolean;
|
|
127
|
+
};
|
|
128
|
+
removeButtons: boolean;
|
|
129
|
+
messages: OutgoingMessage[];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Run a button press. A press on a task whose state no longer allows the
|
|
133
|
+
* action answers with an alert naming the state, removes the buttons and
|
|
134
|
+
* writes nothing.
|
|
135
|
+
*/
|
|
136
|
+
export declare function runCallback(data: string, ctx: CommandContext): Promise<CallbackOutcome>;
|
|
137
|
+
//# sourceMappingURL=commands.d.ts.map
|