@tidegap/cli 0.0.0-stage → 0.18.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.
Files changed (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +125 -2
  3. package/dist/commands/env-file.d.ts +53 -0
  4. package/dist/commands/env-file.d.ts.map +1 -0
  5. package/dist/commands/env-file.js +127 -0
  6. package/dist/commands/env-file.js.map +1 -0
  7. package/dist/commands/install.d.ts +84 -0
  8. package/dist/commands/install.d.ts.map +1 -0
  9. package/dist/commands/install.js +299 -0
  10. package/dist/commands/install.js.map +1 -0
  11. package/dist/commands/queue.d.ts +139 -0
  12. package/dist/commands/queue.d.ts.map +1 -0
  13. package/dist/commands/queue.js +491 -0
  14. package/dist/commands/queue.js.map +1 -0
  15. package/dist/commands/receipts.d.ts +15 -0
  16. package/dist/commands/receipts.d.ts.map +1 -0
  17. package/dist/commands/receipts.js +70 -0
  18. package/dist/commands/receipts.js.map +1 -0
  19. package/dist/commands/register-wake.d.ts +21 -0
  20. package/dist/commands/register-wake.d.ts.map +1 -0
  21. package/dist/commands/register-wake.js +76 -0
  22. package/dist/commands/register-wake.js.map +1 -0
  23. package/dist/commands/stats.d.ts +31 -0
  24. package/dist/commands/stats.d.ts.map +1 -0
  25. package/dist/commands/stats.js +165 -0
  26. package/dist/commands/stats.js.map +1 -0
  27. package/dist/commands/tick.d.ts +73 -0
  28. package/dist/commands/tick.d.ts.map +1 -0
  29. package/dist/commands/tick.js +294 -0
  30. package/dist/commands/tick.js.map +1 -0
  31. package/dist/commands/ui.d.ts +25 -0
  32. package/dist/commands/ui.d.ts.map +1 -0
  33. package/dist/commands/ui.js +83 -0
  34. package/dist/commands/ui.js.map +1 -0
  35. package/dist/commands/verify.d.ts +32 -0
  36. package/dist/commands/verify.d.ts.map +1 -0
  37. package/dist/commands/verify.js +135 -0
  38. package/dist/commands/verify.js.map +1 -0
  39. package/dist/env.d.ts +55 -0
  40. package/dist/env.d.ts.map +1 -0
  41. package/dist/env.js +90 -0
  42. package/dist/env.js.map +1 -0
  43. package/dist/index.d.ts +31 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +351 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/platform/index.d.ts +30 -0
  48. package/dist/platform/index.d.ts.map +1 -0
  49. package/dist/platform/index.js +66 -0
  50. package/dist/platform/index.js.map +1 -0
  51. package/dist/platform/linux.d.ts +81 -0
  52. package/dist/platform/linux.d.ts.map +1 -0
  53. package/dist/platform/linux.js +158 -0
  54. package/dist/platform/linux.js.map +1 -0
  55. package/dist/platform/macos.d.ts +69 -0
  56. package/dist/platform/macos.d.ts.map +1 -0
  57. package/dist/platform/macos.js +151 -0
  58. package/dist/platform/macos.js.map +1 -0
  59. package/dist/platform/windows.d.ts +31 -0
  60. package/dist/platform/windows.d.ts.map +1 -0
  61. package/dist/platform/windows.js +58 -0
  62. package/dist/platform/windows.js.map +1 -0
  63. package/dist/ui/api.d.ts +59 -0
  64. package/dist/ui/api.d.ts.map +1 -0
  65. package/dist/ui/api.js +459 -0
  66. package/dist/ui/api.js.map +1 -0
  67. package/dist/ui/dispatcher.d.ts +84 -0
  68. package/dist/ui/dispatcher.d.ts.map +1 -0
  69. package/dist/ui/dispatcher.js +150 -0
  70. package/dist/ui/dispatcher.js.map +1 -0
  71. package/dist/ui/events.d.ts +27 -0
  72. package/dist/ui/events.d.ts.map +1 -0
  73. package/dist/ui/events.js +85 -0
  74. package/dist/ui/events.js.map +1 -0
  75. package/dist/ui/server.d.ts +69 -0
  76. package/dist/ui/server.d.ts.map +1 -0
  77. package/dist/ui/server.js +258 -0
  78. package/dist/ui/server.js.map +1 -0
  79. package/package.json +54 -3
  80. package/ui/agenda.js +256 -0
  81. package/ui/api.js +111 -0
  82. package/ui/app.css +707 -0
  83. package/ui/app.js +597 -0
  84. package/ui/detail.js +431 -0
  85. package/ui/dialog.js +279 -0
  86. package/ui/dnd.js +131 -0
  87. package/ui/dom.js +255 -0
  88. package/ui/index.html +37 -0
  89. package/ui/journal.js +207 -0
  90. package/ui/keys.js +92 -0
  91. package/ui/row.js +153 -0
  92. package/ui/state.js +412 -0
  93. package/ui/timeline.js +202 -0
  94. package/ui/toast.js +69 -0
  95. package/ui/tokens.css +106 -0
  96. package/ui/views.js +31 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend, and
172
+ hold each Contributor harmless for any liability incurred by, or
173
+ claims asserted against, such Contributor by reason of your accepting
174
+ any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Vitalii Borovyk
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing
201
+ permissions and limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,126 @@
1
- # Temporary Holding Version
1
+ # @tidegap/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Renamed from `@ebb-ai/cli` in 0.18.0. The `ebb` command still works in 0.18 and prints one deprecation line; it is removed in 0.19. If npm reports `EEXIST` on install, run `npm uninstall -g @ebb-ai/cli` first. See [Renamed from Ebb AI](https://github.com/tidegap/tidegap#renamed-from-ebb-ai).
4
+
5
+ **The `tidegap` command: runs your queued Tidegap tasks when their cleanest grid hour arrives.**
6
+
7
+ `tidegap` drains the Tidegap task queue on a timer. A task that your agent deferred runs at the lowest-carbon hour before its deadline, also when no agent session is open.
8
+
9
+ - `tidegap tick` dispatches every task that is due. `tidegap install` wires it to launchd on macOS.
10
+ - `tidegap queue list` and `tidegap receipts list` show queued tasks and their carbon receipts.
11
+ - `tidegap verify <task-id>` checks a receipt's Ed25519 signature offline.
12
+
13
+ ```bash
14
+ npm install -g @tidegap/cli
15
+ ```
16
+
17
+ ```bash
18
+ tidegap install --laptop # run `tidegap tick` on a schedule; register wake events across sleep
19
+ tidegap queue list # what is waiting, and for which hour
20
+ tidegap tick --region GB # dispatch what is due now
21
+ tidegap receipts list # one carbon receipt per completed task
22
+ tidegap verify <task-id> # check the receipt signature
23
+ ```
24
+
25
+ Proof: one real GB run, 2026-09-30 (`tidegap tick` + `tidegap verify`). Forecast peak 183 gCO2/kWh vs recommended window 88 gCO2/kWh, about 52 % lower for this run only (forecast, projected). The task had a 5-minute deadline and ran at once; its receipt records 158 gCO2/kWh (measured). Raw output: https://github.com/tidegap/tidegap/tree/main/docs/examples/2026-09-30-GB-tick
26
+
27
+ ## Commands
28
+
29
+ ```text
30
+ tidegap tick — drain due tasks via provider adapters; one OS notification per finished task (--no-notify, or TIDEGAP_NO_NOTIFY=1)
31
+ tidegap install — wire up launchd (macOS) or print systemd / schtasks templates
32
+ tidegap queue list — print tasks (--unread, --kind absolute|quota_reset, --json, --hook)
33
+ tidegap queue show — print one task's prompt, result and receipt; marks it read
34
+ tidegap queue unread — mark a task unread again
35
+ tidegap queue cancel — cancel a pending task (--series ends a repeating series)
36
+ tidegap queue reschedule — move a task: --by <2h|ISO>, --at <ISO>, or --day <yyyy-mm-dd>
37
+ tidegap queue run-now — mark a task due; the next tick runs it
38
+ tidegap queue reply — continue a completed task as a new task (--by, default 1h)
39
+ tidegap receipts list — print carbon receipts for completed tasks
40
+ tidegap stats — local-only personal-impact stats from the queue ledger
41
+ tidegap verify — verify the Ed25519 signature on a carbon receipt
42
+ tidegap register-wake — schedule a macOS wake event 30s before a task
43
+ tidegap ui — local task page: agenda, journal, timeline, task detail and actions (127.0.0.1 only)
44
+ ```
45
+
46
+ Run `tidegap <command> --help` for flags.
47
+
48
+ The write commands and `tidegap ui` change the ledger only; `tidegap tick` (or the
49
+ OpenClaw loop) runs the task, and each command prints when the last tick ran.
50
+ `--day` and a repeating task's next occurrence can lie beyond the 72-hour
51
+ forecast. Such a task waits at a fallback hour (its current time of day, in
52
+ the new day) until a tick re-plans it once the forecast covers the day. If no
53
+ tick runs in that time, it runs at the fallback hour without a carbon choice.
54
+
55
+ ## Quickstart — keep tasks alive across laptop sleep
56
+
57
+ ```bash
58
+ tidegap install --laptop
59
+ # follow the printed launchctl load / systemctl commands
60
+ ```
61
+
62
+ `tidegap install` resolves the daemon's invocation at install time to the exact
63
+ node interpreter plus the real `tidegap` entry (`[process.execPath,
64
+ realpath(argv[1])]`), so the launchd job / systemd unit does not depend on a
65
+ bare `PATH` or a `#!/usr/bin/env node` shebang. Set `TIDEGAP_BINARY` to override
66
+ with a single wrapper executable.
67
+
68
+ ## Secrets
69
+
70
+ > **Scope:** the environment variables below configure **this CLI** (and the
71
+ > `@tidegap/mcp` server, which reads the same set). The CLI reads them at its own
72
+ > entry point and injects them into `@tidegap/core`, which is environment-pure.
73
+ > The `@vitalini/tidegap` **OpenClaw plugin reads no environment variables at all** —
74
+ > configure it under `plugins.entries.tidegap.config` in your gateway config
75
+ > (`anthropicApiKey`, `openaiApiKey`, `geminiApiKey`/`googleApiKey`,
76
+ > `ollamaHost`, `ollamaModels`, `eiaApiKey`, `electricityMapsApiKey`,
77
+ > `entsoeSecurityToken`, `wattTimeUsername`/`wattTimePassword`, `carbonBudgetG`,
78
+ > `carbonBudgetWindow`). OpenClaw resolves the `"${ENV_VAR}"` shorthand in those
79
+ > fields, so you can keep exporting the same variables and let the gateway read
80
+ > them on the plugin's behalf.
81
+
82
+ Provider (and grid-feed) API keys live in `~/.config/tidegap/env` — `KEY=VALUE`
83
+ lines, created `0600` with a commented template on first `tidegap install`. Both
84
+ `tidegap tick` (loads it at startup) and the systemd unit (`EnvironmentFile=`)
85
+ read it, so launchd, systemd, and manual cron all pick up keys the same way:
86
+
87
+ ```
88
+ ANTHROPIC_API_KEY=sk-...
89
+ OPENAI_API_KEY=sk-...
90
+ GEMINI_API_KEY=... # or GOOGLE_API_KEY — Gemini (generativelanguage.googleapis.com)
91
+ OLLAMA_HOST=http://localhost:11434 # local Ollama; presence opts the ollama provider in
92
+ ```
93
+
94
+ Providers: `anthropic` and `openai` are batch-capable (their tasks can
95
+ auto-route through a 50%-cheaper Batch API — projected, provider list
96
+ price); `gemini` and `ollama` are
97
+ sync-only. Gemini reads `GEMINI_API_KEY`, falling back to `GOOGLE_API_KEY`.
98
+ Ollama is local and keyless — set `OLLAMA_HOST` (default `http://localhost:11434`)
99
+ to enable it; optionally list local model ids in `OLLAMA_MODELS` (comma-separated)
100
+ so `schedule_task` can infer the `ollama` provider from a bare model name.
101
+
102
+ `tidegap tick` prints a loud warning when pending tasks need a provider key that
103
+ is not set. (Ollama is keyless, so a pending Ollama task is never flagged.)
104
+
105
+ ## Platform support
106
+
107
+ | Platform | Daemon install | Wake-from-sleep |
108
+ | --- | --- | --- |
109
+ | macOS | launchd plist (`tidegap install`) | `pmset schedule wake` via `tidegap register-wake` / the `--laptop` helper |
110
+ | Linux | systemd user `.service` + `.timer` (`tidegap install`) | `rtcwake` via `tidegap register-wake` / the `--laptop` helper |
111
+ | Windows | not auto-installed — `tidegap install` prints a ready-to-paste `schtasks` command; run `tidegap tick` under Task Scheduler or nssm yourself | not supported (use Task Scheduler's "wake the computer" option) |
112
+
113
+ Wake events (`pmset` / `rtcwake`) need root. When not running as root,
114
+ `tidegap register-wake` prints the exact `sudoers` line to pre-authorize the
115
+ command without a password prompt.
116
+
117
+ ## Develop
118
+
119
+ From the root of a clone of https://github.com/tidegap/tidegap:
120
+
121
+ ```bash
122
+ pnpm install
123
+ pnpm --filter @tidegap/core build
124
+ pnpm --filter @tidegap/cli build
125
+ node packages/cli/dist/index.js --help
126
+ ```
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Shared secrets file: `~/.config/tidegap/env`.
3
+ *
4
+ * 0.17 kept it at `~/.config/ebb/env`. That file is read, never moved: a
5
+ * 0.17 systemd unit still names it in `EnvironmentFile=`. `tidegap tick`
6
+ * reads the new file, else the old one; `tidegap install` creates the new
7
+ * file as a copy of the old one when only the old one exists.
8
+ *
9
+ * A single standardized location for provider API keys that works
10
+ * uniformly across launchd, systemd, and manual cron:
11
+ *
12
+ * - `tidegap install` creates it (0600) with a commented template if it
13
+ * does not already exist, so the user has one obvious place to drop
14
+ * `ANTHROPIC_API_KEY=…`.
15
+ * - `tidegap tick` loads it at startup into `process.env` for any key not
16
+ * already present — this covers launchd (which passes a bare
17
+ * environment) AND systemd (belt-and-braces with `EnvironmentFile=`)
18
+ * AND a hand-rolled crontab entry.
19
+ *
20
+ * The parser is intentionally tiny (no dotenv dependency): `KEY=VALUE`
21
+ * lines, `#` comments, blank lines, optional surrounding quotes.
22
+ */
23
+ /** Absolute path to the standardized secrets file. */
24
+ export declare function envFilePath(home?: string): string;
25
+ /** The 0.17 secrets file, read when the new one is absent (until 0.19). */
26
+ export declare function legacyEnvFilePath(home?: string): string;
27
+ /** The secrets file to load: the new one, else the 0.17 one if present. */
28
+ export declare function resolveEnvFilePath(home?: string): string;
29
+ /** The commented template written when the file is first created. */
30
+ export declare function envFileTemplate(): string;
31
+ /**
32
+ * Parse `KEY=VALUE` lines. Ignores blank lines and `#` comments.
33
+ * Strips one layer of surrounding single/double quotes from the value.
34
+ */
35
+ export declare function parseEnvFile(contents: string): Record<string, string>;
36
+ /**
37
+ * Load the env file into `process.env` for any key not already set.
38
+ * Returns the keys that were applied. Missing file is a silent no-op.
39
+ */
40
+ export declare function loadEnvFileIntoProcess(path?: string): string[];
41
+ export interface EnsureEnvFileResult {
42
+ path: string;
43
+ created: boolean;
44
+ /** The 0.17 file the new one was copied from, when it was. */
45
+ copiedFrom?: string;
46
+ }
47
+ /**
48
+ * Create the secrets file (0600) if it does not already exist: a copy of the
49
+ * 0.17 file `legacy` when that exists, else the commented template.
50
+ * Idempotent: never overwrites an existing file, never touches `legacy`.
51
+ */
52
+ export declare function ensureEnvFile(path?: string, legacy?: string): EnsureEnvFileResult;
53
+ //# sourceMappingURL=env-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../../src/commands/env-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAAkB,GAAG,MAAM,CAE5D;AAED,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,MAAkB,GAAG,MAAM,CAElE;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,MAAkB,GAAG,MAAM,CAInE;AAED,qEAAqE;AACrE,wBAAgB,eAAe,IAAI,MAAM,CAmBxC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBrE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,GAAE,MAA6B,GAAG,MAAM,EAAE,CAgBpF;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,GAAE,MAAsB,EAC5B,MAAM,GAAE,MAA4B,GACnC,mBAAmB,CAUrB"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Shared secrets file: `~/.config/tidegap/env`.
3
+ *
4
+ * 0.17 kept it at `~/.config/ebb/env`. That file is read, never moved: a
5
+ * 0.17 systemd unit still names it in `EnvironmentFile=`. `tidegap tick`
6
+ * reads the new file, else the old one; `tidegap install` creates the new
7
+ * file as a copy of the old one when only the old one exists.
8
+ *
9
+ * A single standardized location for provider API keys that works
10
+ * uniformly across launchd, systemd, and manual cron:
11
+ *
12
+ * - `tidegap install` creates it (0600) with a commented template if it
13
+ * does not already exist, so the user has one obvious place to drop
14
+ * `ANTHROPIC_API_KEY=…`.
15
+ * - `tidegap tick` loads it at startup into `process.env` for any key not
16
+ * already present — this covers launchd (which passes a bare
17
+ * environment) AND systemd (belt-and-braces with `EnvironmentFile=`)
18
+ * AND a hand-rolled crontab entry.
19
+ *
20
+ * The parser is intentionally tiny (no dotenv dependency): `KEY=VALUE`
21
+ * lines, `#` comments, blank lines, optional surrounding quotes.
22
+ */
23
+ import { copyFileSync, chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
24
+ import { homedir } from "node:os";
25
+ import { dirname, join } from "node:path";
26
+ /** Absolute path to the standardized secrets file. */
27
+ export function envFilePath(home = homedir()) {
28
+ return join(home, ".config", "tidegap", "env");
29
+ }
30
+ /** The 0.17 secrets file, read when the new one is absent (until 0.19). */
31
+ export function legacyEnvFilePath(home = homedir()) {
32
+ return join(home, ".config", "ebb", "env");
33
+ }
34
+ /** The secrets file to load: the new one, else the 0.17 one if present. */
35
+ export function resolveEnvFilePath(home = homedir()) {
36
+ const current = envFilePath(home);
37
+ const legacy = legacyEnvFilePath(home);
38
+ return !existsSync(current) && existsSync(legacy) ? legacy : current;
39
+ }
40
+ /** The commented template written when the file is first created. */
41
+ export function envFileTemplate() {
42
+ return `# Tidegap secrets — KEY=VALUE per line. Loaded by \`tidegap tick\` at startup
43
+ # (and referenced by the systemd unit's EnvironmentFile=). This file is
44
+ # created 0600; keep it that way. Uncomment and fill the keys you use.
45
+ #
46
+ # Direct provider keys:
47
+ #ANTHROPIC_API_KEY=
48
+ #OPENAI_API_KEY=
49
+ #
50
+ # Per-region grid-data feed keys (only for the regions you schedule into):
51
+ #TIDEGAP_ELECTRICITY_MAPS_API_KEY=
52
+ #TIDEGAP_EIA_API_KEY=
53
+ #TIDEGAP_ENTSOE_SECURITY_TOKEN=
54
+ # WattTime marginal-emissions (US ISOs) — HTTP Basic login, takes
55
+ # precedence over EIA for the zones it covers. Username + password, not
56
+ # a single key:
57
+ #WATTTIME_USERNAME=
58
+ #WATTTIME_PASSWORD=
59
+ `;
60
+ }
61
+ /**
62
+ * Parse `KEY=VALUE` lines. Ignores blank lines and `#` comments.
63
+ * Strips one layer of surrounding single/double quotes from the value.
64
+ */
65
+ export function parseEnvFile(contents) {
66
+ const out = {};
67
+ for (const rawLine of contents.split(/\r?\n/)) {
68
+ const line = rawLine.trim();
69
+ if (!line || line.startsWith("#"))
70
+ continue;
71
+ const eq = line.indexOf("=");
72
+ if (eq <= 0)
73
+ continue;
74
+ const key = line.slice(0, eq).trim();
75
+ if (!key)
76
+ continue;
77
+ let value = line.slice(eq + 1).trim();
78
+ if (value.length >= 2 &&
79
+ ((value.startsWith('"') && value.endsWith('"')) ||
80
+ (value.startsWith("'") && value.endsWith("'")))) {
81
+ value = value.slice(1, -1);
82
+ }
83
+ out[key] = value;
84
+ }
85
+ return out;
86
+ }
87
+ /**
88
+ * Load the env file into `process.env` for any key not already set.
89
+ * Returns the keys that were applied. Missing file is a silent no-op.
90
+ */
91
+ export function loadEnvFileIntoProcess(path = resolveEnvFilePath()) {
92
+ if (!existsSync(path))
93
+ return [];
94
+ let parsed;
95
+ try {
96
+ parsed = parseEnvFile(readFileSync(path, "utf8"));
97
+ }
98
+ catch {
99
+ return [];
100
+ }
101
+ const applied = [];
102
+ for (const [k, v] of Object.entries(parsed)) {
103
+ if (process.env[k] === undefined) {
104
+ process.env[k] = v;
105
+ applied.push(k);
106
+ }
107
+ }
108
+ return applied;
109
+ }
110
+ /**
111
+ * Create the secrets file (0600) if it does not already exist: a copy of the
112
+ * 0.17 file `legacy` when that exists, else the commented template.
113
+ * Idempotent: never overwrites an existing file, never touches `legacy`.
114
+ */
115
+ export function ensureEnvFile(path = envFilePath(), legacy = legacyEnvFilePath()) {
116
+ if (existsSync(path))
117
+ return { path, created: false };
118
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
119
+ if (existsSync(legacy)) {
120
+ copyFileSync(legacy, path);
121
+ chmodSync(path, 0o600);
122
+ return { path, created: true, copiedFrom: legacy };
123
+ }
124
+ writeFileSync(path, envFileTemplate(), { encoding: "utf8", mode: 0o600 });
125
+ return { path, created: true };
126
+ }
127
+ //# sourceMappingURL=env-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-file.js","sourceRoot":"","sources":["../../src/commands/env-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtG,OAAO,EAAE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C,GAAG,CAAC,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AASD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAe,WAAW,EAAE,EAC5B,SAAiB,iBAAiB,EAAE;IAEpC,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACtD,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3B,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACvB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IACrD,CAAC;IACD,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * `tidegap install` — write a launchd plist (macOS) or systemd user units
3
+ * (Linux). Windows is not auto-installed: it prints a ready-to-paste
4
+ * `schtasks` command instead.
5
+ *
6
+ * The daemon's invocation is resolved at install time to
7
+ * `[process.execPath, realpathSync(process.argv[1])]` — the exact node
8
+ * interpreter plus the real dist entry. This is immune to launchd's bare
9
+ * PATH and to `#!/usr/bin/env node` shebangs (the historical bug: a
10
+ * hardcoded `/usr/local/bin/ebb` (0.17 name) that does not exist on Apple Silicon /
11
+ * homebrew / nvm). `TIDEGAP_BINARY` remains as a documented override
12
+ * (0.17 name `EBB_BINARY` still read).
13
+ *
14
+ * A 0.17 unit (`com.ebb-ai.tick`, `ebb-tick.timer`) is detected, never
15
+ * removed: the next steps print the commands that unload and remove it.
16
+ *
17
+ * In --laptop mode we additionally drop a tiny helper script and print
18
+ * the wake-event story (which needs a sudoers entry); --server skips it.
19
+ */
20
+ import { type PlatformName } from "../platform/index.js";
21
+ export type InstallMode = "laptop" | "server";
22
+ export interface InstallOptions {
23
+ mode: InstallMode;
24
+ /** Override platform detection (tests). */
25
+ platform?: PlatformName;
26
+ /**
27
+ * Override the resolved launcher argv (tests). When set, this is used
28
+ * verbatim as the leading `ProgramArguments` / `ExecStart` tokens
29
+ * instead of resolving `process.execPath` + the real script path.
30
+ */
31
+ launcher?: string[];
32
+ /** Override the SQLite path (tests). */
33
+ dbPath?: string;
34
+ /** Override the tick interval. Defaults to 300s. */
35
+ tickIntervalSec?: number;
36
+ /** If true, do not write any files; only return the rendered strings. */
37
+ dryRun?: boolean;
38
+ /** Override the home directory (tests). */
39
+ home?: string;
40
+ }
41
+ export interface InstallArtifacts {
42
+ platform: PlatformName;
43
+ /** Resolved launcher argv used for the daemon invocation. */
44
+ launcher: string[];
45
+ /** Warnings surfaced during resolution (e.g. a launcher path that does not exist). */
46
+ warnings: string[];
47
+ /** Path to the standardized secrets file (~/.config/tidegap/env). */
48
+ envFilePath: string;
49
+ /** True when this run created the secrets file. */
50
+ envFileCreated: boolean;
51
+ /** Where the daemon writes its log (`~/.tidegap/logs/tick.log`). */
52
+ logPath: string;
53
+ /** Path that would be written, or "" for non-macOS. */
54
+ plistPath: string;
55
+ /** The rendered plist XML, or "" for non-macOS. */
56
+ plistContent: string;
57
+ /** Path for the systemd `.service` unit, or "" for non-linux. */
58
+ servicePath: string;
59
+ /** The rendered `.service` unit content, or "" for non-linux. */
60
+ serviceContent: string;
61
+ /** Path for the systemd `.timer` unit, or "" for non-linux. */
62
+ timerPath: string;
63
+ /** The rendered `.timer` unit content, or "" for non-linux. */
64
+ timerContent: string;
65
+ /** Path for the laptop-wake helper script, or "" if --server or unsupported. */
66
+ helperPath: string;
67
+ /** Rendered helper script content, or "" if --server or unsupported. */
68
+ helperContent: string;
69
+ /** Human-facing next-steps message. */
70
+ nextSteps: string;
71
+ }
72
+ /**
73
+ * Resolve the daemon invocation. Preference order:
74
+ * 1. explicit `override` (tests),
75
+ * 2. `TIDEGAP_BINARY` env (0.17: `EBB_BINARY`) — a single documented override binary,
76
+ * 3. `[process.execPath, realpathSync(process.argv[1])]` — pin the
77
+ * exact node + the real dist entry.
78
+ *
79
+ * Pushes a loud warning onto `warnings` if a resolved path does not
80
+ * exist on disk.
81
+ */
82
+ export declare function resolveLauncher(override: string[] | undefined, warnings: string[]): string[];
83
+ export declare function runInstall(opts: InstallOptions): Promise<InstallArtifacts>;
84
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAYH,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAO9B,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE9C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,YAAY,CAAC;IACvB,6DAA6D;IAC7D,QAA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