@kelceyp/caw 1.0.41 → 1.0.43
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 +48 -7
- package/dist/caw.js +437 -191
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# CAW
|
|
2
2
|
|
|
3
|
-
CAW helps users build software **sustainably** using AI by providing agents with **C**ontext and **A**gentic **W**orkflows (CAW). CAW is free to download and runs locally as a unified web and MCP server. It provides document management, templates, stories, search and acts as the orchestration layer for your AI development tools.
|
|
3
|
+
CAW helps users build software **sustainably** using AI by providing agents with **C**ontext and **A**gentic **W**orkflows (CAW). CAW is free to download and runs locally as a unified web and MCP server. It provides document management, templates, stories, search and acts as the orchestration layer for your AI development tools. CAW itself reaches out to PostHog for [usage analytics](#usage-analytics), the npm registry, `athenadesign.com.au` for its bundle catalogue and bundles, and Hugging Face to download its embedding model; the agents you run talk to their own vendors.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
@@ -21,6 +21,49 @@ caw start
|
|
|
21
21
|
```
|
|
22
22
|
Then open [http://localhost:2229](http://localhost:2229) in your browser.
|
|
23
23
|
|
|
24
|
+
Requires macOS and Node.js 24 or later. If the install or `caw start` fails, see the [installation guide](https://athenadesign.com.au/caw/installation-guide).
|
|
25
|
+
|
|
26
|
+
## Usage analytics
|
|
27
|
+
|
|
28
|
+
CAW sends timestamped usage events to [PostHog](https://posthog.com) (US) by default. They are keyed to a random install ID. There is no account, and the ID isn't derived from anything about you or your machine.
|
|
29
|
+
|
|
30
|
+
Installing sends no events. On a new install, with no `config.json`, the first event is sent when `caw start` or `caw restart` starts the server, whether or not that start then succeeds, and CAW prints a one-time notice just before it. On an existing install, or with a `config.json` you wrote yourself that doesn't turn analytics off, `caw stop`, `caw upgrade` and `caw caddy setup` can also send an event or start a server that does, and they print no notice.
|
|
31
|
+
|
|
32
|
+
| Event | Sent by | Carries |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `caw cmd` | launcher | `op` (start or stop); on start, also launcher version, OS and architecture |
|
|
35
|
+
| `project op` | server | `op` (created or deleted) |
|
|
36
|
+
| `agent toggled` | server | `agent`, `op` |
|
|
37
|
+
| `infra toggled` | server | `infra`, `op` |
|
|
38
|
+
| `mcp first call` | server | `agent` |
|
|
39
|
+
| `story op` | server | `op`; on completion, the number of states |
|
|
40
|
+
| `job turn completed` | server | start and end times, `agent`, `mechanism`, whether a working directory was set and whether Docker was used, `effort`, `model`, `exit_code`, `error_category` and a hash of the story ID, keyed with a salt that stays on your machine |
|
|
41
|
+
| `analytics opted_out` | server | `via` |
|
|
42
|
+
| `analytics opted_in` | server | `via` |
|
|
43
|
+
|
|
44
|
+
The server also identifies itself with its CAW version, OS and architecture, and its events can carry `channel` (how the action arrived) and `caller_bucket` (which kind of agent made it). PostHog's client library adds its own name and version, and marks each event as sent from a server. Preferences > Analytics lists the events of the server you're running, which may be newer than this page.
|
|
45
|
+
|
|
46
|
+
**Never sent:** document, story, template or prompt content, titles, filesystem paths, search queries, tool arguments or repo URLs.
|
|
47
|
+
|
|
48
|
+
PostHog receives the IP address of each request, as any server does. The CAW PostHog project is set to discard it rather than store it with events, and every event CAW sends asks PostHog not to look up a location from it.
|
|
49
|
+
|
|
50
|
+
### Turning it off
|
|
51
|
+
|
|
52
|
+
- **Preferences > Analytics:** takes effect immediately, and sends one final `analytics opted_out` event.
|
|
53
|
+
- **`"analyticsEnabled": false` in `~/.caw/config.json`:** the launcher stops sending at once. A running server stops at its next start, so run `caw restart`. No final event is sent.
|
|
54
|
+
|
|
55
|
+
The value must be a JSON boolean. `caw start` silently replaces `"false"`, a string, with `true`.
|
|
56
|
+
|
|
57
|
+
### Turning it off before the first start
|
|
58
|
+
|
|
59
|
+
On a machine where CAW has never started, run this before `caw start`. Don't run it on an existing install, because it overwrites `config.json`.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
mkdir -p ~/.caw && echo '{"port":2229,"process_manager":"pid","caddy":{"enabled":false,"domain":"caw.localhost"},"analyticsEnabled":false}' > ~/.caw/config.json && touch ~/.caw/.env
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
CAW then starts with analytics off: it sends no events and prints no notice.
|
|
66
|
+
|
|
24
67
|
## Unlock sustainable development
|
|
25
68
|
Agents are capable coders but struggle to build software sustainably as the codebase and its complexity grow. Code reveals only so much and agents do not inherently know which parts of it to read or what the underlying intent was. Technical debt, technical mess, architectural mismatch and a host of problems creep in over time to grind progress to a halt.
|
|
26
69
|
|
|
@@ -74,16 +117,14 @@ Build your product knowledge base in lock step with your code base.
|
|
|
74
117
|
|
|
75
118
|
Create powerful templates for documents, prompts and saved searches.
|
|
76
119
|
|
|
77
|
-
- Handlebars templating
|
|
120
|
+
- Handlebars templating enabling
|
|
78
121
|
- Substitution
|
|
79
122
|
- Conditionals
|
|
80
123
|
- Enumeration
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
124
|
+
- Comparison
|
|
125
|
+
- Simple arithmetic
|
|
126
|
+
- Splitting, trimming and joining strings
|
|
84
127
|
- Number formatting
|
|
85
|
-
- Word inflection
|
|
86
|
-
- Expressions
|
|
87
128
|
- Type and multivalued enabled
|
|
88
129
|
- Subtypes include document, prompt and saved search, all providing different behaviours
|
|
89
130
|
- Document templates create documents
|
package/dist/caw.js
CHANGED
|
@@ -6622,7 +6622,7 @@ var init_log_symbols = __esm(() => {
|
|
|
6622
6622
|
// node_modules/ansi-regex/index.js
|
|
6623
6623
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
6624
6624
|
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
6625
|
-
const osc = `(?:\\u001B\\][\\
|
|
6625
|
+
const osc = `(?:(?:\\u001B\\]|\\u009D)[^\\u0007\\u001B\\u009C\\u009D]*${ST})`;
|
|
6626
6626
|
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
6627
6627
|
const pattern = `${osc}|${csi}`;
|
|
6628
6628
|
return new RegExp(pattern, onlyFirst ? undefined : "g");
|
|
@@ -6648,7 +6648,7 @@ var ambiguousMinimalCodePoint = 161, ambiguousMaximumCodePoint = 1114109, ambigu
|
|
|
6648
6648
|
var init_lookup_data = __esm(() => {
|
|
6649
6649
|
ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
6650
6650
|
fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
6651
|
-
wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208,
|
|
6651
|
+
wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101594, 101631, 101664, 101760, 101874, 101888, 102801, 102816, 102866, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110888, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110952, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127406, 127406, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128729, 128732, 128735, 128747, 128748, 128756, 128764, 128986, 128986, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129734, 129736, 129736, 129740, 129757, 129759, 129771, 129775, 129786, 131072, 196605, 196608, 262141];
|
|
6652
6652
|
});
|
|
6653
6653
|
|
|
6654
6654
|
// node_modules/get-east-asian-width/utilities.js
|
|
@@ -6691,7 +6691,7 @@ var commonCjkCodePoint = 19968, wideFastPathStart, wideFastPathEnd, isAmbiguous
|
|
|
6691
6691
|
return false;
|
|
6692
6692
|
}
|
|
6693
6693
|
return isInRange(ambiguousRanges, codePoint);
|
|
6694
|
-
},
|
|
6694
|
+
}, isFullwidth = (codePoint) => {
|
|
6695
6695
|
if (codePoint < fullwidthMinimalCodePoint || codePoint > fullwidthMaximumCodePoint) {
|
|
6696
6696
|
return false;
|
|
6697
6697
|
}
|
|
@@ -6718,7 +6718,7 @@ function validate(codePoint) {
|
|
|
6718
6718
|
}
|
|
6719
6719
|
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
6720
6720
|
validate(codePoint);
|
|
6721
|
-
if (
|
|
6721
|
+
if (isFullwidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
6722
6722
|
return 2;
|
|
6723
6723
|
}
|
|
6724
6724
|
return 1;
|
|
@@ -8044,8 +8044,8 @@ var require_semver = __commonJS((exports, module) => {
|
|
|
8044
8044
|
}
|
|
8045
8045
|
} while (++i);
|
|
8046
8046
|
}
|
|
8047
|
-
inc(
|
|
8048
|
-
if (
|
|
8047
|
+
inc(release2, identifier, identifierBase) {
|
|
8048
|
+
if (release2.startsWith("pre")) {
|
|
8049
8049
|
if (!identifier && identifierBase === false) {
|
|
8050
8050
|
throw new Error("invalid increment argument: identifier is empty");
|
|
8051
8051
|
}
|
|
@@ -8056,7 +8056,7 @@ var require_semver = __commonJS((exports, module) => {
|
|
|
8056
8056
|
}
|
|
8057
8057
|
}
|
|
8058
8058
|
}
|
|
8059
|
-
switch (
|
|
8059
|
+
switch (release2) {
|
|
8060
8060
|
case "premajor":
|
|
8061
8061
|
this.prerelease.length = 0;
|
|
8062
8062
|
this.patch = 0;
|
|
@@ -8144,7 +8144,7 @@ var require_semver = __commonJS((exports, module) => {
|
|
|
8144
8144
|
break;
|
|
8145
8145
|
}
|
|
8146
8146
|
default:
|
|
8147
|
-
throw new Error(`invalid increment argument: ${
|
|
8147
|
+
throw new Error(`invalid increment argument: ${release2}`);
|
|
8148
8148
|
}
|
|
8149
8149
|
this.raw = this.format();
|
|
8150
8150
|
if (this.build.length) {
|
|
@@ -8198,14 +8198,14 @@ var require_clean = __commonJS((exports, module) => {
|
|
|
8198
8198
|
// node_modules/semver/functions/inc.js
|
|
8199
8199
|
var require_inc = __commonJS((exports, module) => {
|
|
8200
8200
|
var SemVer = require_semver();
|
|
8201
|
-
var inc = (version,
|
|
8201
|
+
var inc = (version, release2, options, identifier, identifierBase) => {
|
|
8202
8202
|
if (typeof options === "string") {
|
|
8203
8203
|
identifierBase = identifier;
|
|
8204
8204
|
identifier = options;
|
|
8205
8205
|
options = undefined;
|
|
8206
8206
|
}
|
|
8207
8207
|
try {
|
|
8208
|
-
return new SemVer(version instanceof SemVer ? version.version : version, options).inc(
|
|
8208
|
+
return new SemVer(version instanceof SemVer ? version.version : version, options).inc(release2, identifier, identifierBase).version;
|
|
8209
8209
|
} catch (er) {
|
|
8210
8210
|
return null;
|
|
8211
8211
|
}
|
|
@@ -8729,15 +8729,16 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8729
8729
|
};
|
|
8730
8730
|
var replaceTilde = (comp, options) => {
|
|
8731
8731
|
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
8732
|
+
const z = options.includePrerelease ? "-0" : "";
|
|
8732
8733
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
8733
8734
|
debug3("tilde", comp, _, M, m, p, pr);
|
|
8734
8735
|
let ret;
|
|
8735
8736
|
if (isX(M)) {
|
|
8736
8737
|
ret = "";
|
|
8737
8738
|
} else if (isX(m)) {
|
|
8738
|
-
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
8739
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
8739
8740
|
} else if (isX(p)) {
|
|
8740
|
-
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
8741
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
8741
8742
|
} else if (pr) {
|
|
8742
8743
|
debug3("replaceTilde pr", pr);
|
|
8743
8744
|
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
@@ -10878,10 +10879,10 @@ function resolve(overrideBinPath) {
|
|
|
10878
10879
|
}
|
|
10879
10880
|
|
|
10880
10881
|
// src/commands/start.js
|
|
10881
|
-
import
|
|
10882
|
-
import
|
|
10882
|
+
import fs9 from "node:fs";
|
|
10883
|
+
import path10 from "node:path";
|
|
10883
10884
|
import os2 from "node:os";
|
|
10884
|
-
import
|
|
10885
|
+
import crypto3 from "node:crypto";
|
|
10885
10886
|
import { execSync as execSync4 } from "node:child_process";
|
|
10886
10887
|
|
|
10887
10888
|
// src/config.js
|
|
@@ -10904,10 +10905,13 @@ function configPath(envDir) {
|
|
|
10904
10905
|
function pendingPath(envDir) {
|
|
10905
10906
|
return path4.join(envDir, PENDING_FILENAME);
|
|
10906
10907
|
}
|
|
10908
|
+
function serialise(data) {
|
|
10909
|
+
return JSON.stringify(data, null, 2) + `
|
|
10910
|
+
`;
|
|
10911
|
+
}
|
|
10907
10912
|
function atomicWrite(filePath, data) {
|
|
10908
10913
|
const tmpPath = filePath + ".tmp";
|
|
10909
|
-
fs4.writeFileSync(tmpPath,
|
|
10910
|
-
`);
|
|
10914
|
+
fs4.writeFileSync(tmpPath, serialise(data));
|
|
10911
10915
|
fs4.renameSync(tmpPath, filePath);
|
|
10912
10916
|
}
|
|
10913
10917
|
function readJsonFile(filePath) {
|
|
@@ -10931,6 +10935,14 @@ function writeConfig(envDir, data) {
|
|
|
10931
10935
|
function configExists(envDir) {
|
|
10932
10936
|
return fs4.existsSync(configPath(envDir));
|
|
10933
10937
|
}
|
|
10938
|
+
function writeConfigFenced(envDir, data, lock) {
|
|
10939
|
+
const targetPath = configPath(envDir);
|
|
10940
|
+
const tempPath = `${targetPath}.${lock.token}.tmp`;
|
|
10941
|
+
lock.registerCommit({ tempPath, targetPath });
|
|
10942
|
+
const content = serialise(data);
|
|
10943
|
+
fs4.writeFileSync(tempPath, content);
|
|
10944
|
+
return JSON.parse(content);
|
|
10945
|
+
}
|
|
10934
10946
|
function mergeConfig(envDir) {
|
|
10935
10947
|
const active = readConfig(envDir);
|
|
10936
10948
|
const pending = readPendingConfig(envDir);
|
|
@@ -10994,17 +11006,253 @@ function appendInstalledBundle(envDir, entry) {
|
|
|
10994
11006
|
return { persisted: true };
|
|
10995
11007
|
}
|
|
10996
11008
|
|
|
11009
|
+
// src/identity-lock.js
|
|
11010
|
+
import crypto from "node:crypto";
|
|
11011
|
+
import nodeFs from "node:fs";
|
|
11012
|
+
import path5 from "node:path";
|
|
11013
|
+
var LOCK_FILE_NAME = "config.identity.lock";
|
|
11014
|
+
var REAP_INFIX = ".reap-";
|
|
11015
|
+
var RELEASE_INFIX = ".release-";
|
|
11016
|
+
var STALE_MS = 1e4;
|
|
11017
|
+
var WAIT_MS = 50;
|
|
11018
|
+
var BUDGET_MS = 15000;
|
|
11019
|
+
var TOKEN_BYTES = 16;
|
|
11020
|
+
var ERROR_CODES = Object.freeze({
|
|
11021
|
+
TIMEOUT: "IDENTITY_LOCK_TIMEOUT"
|
|
11022
|
+
});
|
|
11023
|
+
var ACQUIRED = "acquired";
|
|
11024
|
+
var RETRY = "retry";
|
|
11025
|
+
var WAIT = "wait";
|
|
11026
|
+
function lockPathFor(envDir) {
|
|
11027
|
+
if (typeof envDir !== "string" || envDir.length === 0) {
|
|
11028
|
+
throw new TypeError(`identity-lock requires envDir, the environment directory, got ${envDir}`);
|
|
11029
|
+
}
|
|
11030
|
+
return path5.join(envDir, LOCK_FILE_NAME);
|
|
11031
|
+
}
|
|
11032
|
+
function sleepSync(ms) {
|
|
11033
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
11034
|
+
}
|
|
11035
|
+
function newToken() {
|
|
11036
|
+
return `${process.pid}:${crypto.randomBytes(TOKEN_BYTES).toString("hex")}`;
|
|
11037
|
+
}
|
|
11038
|
+
function timeoutError(lockPath, budgetMs) {
|
|
11039
|
+
const err = new Error(`Could not take the identity lock ${lockPath} within ${budgetMs} ms. ` + `If no caw command or server is running, remove ${lockPath}, then run caw start again.`);
|
|
11040
|
+
err.code = ERROR_CODES.TIMEOUT;
|
|
11041
|
+
return err;
|
|
11042
|
+
}
|
|
11043
|
+
function isThenable(value) {
|
|
11044
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
11045
|
+
}
|
|
11046
|
+
function putBack(fs5, fromPath, lockPath) {
|
|
11047
|
+
try {
|
|
11048
|
+
fs5.linkSync(fromPath, lockPath);
|
|
11049
|
+
} catch (err) {
|
|
11050
|
+
if (err.code !== "EEXIST")
|
|
11051
|
+
throw err;
|
|
11052
|
+
}
|
|
11053
|
+
}
|
|
11054
|
+
function removeTemp(fs5, tempPath) {
|
|
11055
|
+
try {
|
|
11056
|
+
fs5.unlinkSync(tempPath);
|
|
11057
|
+
} catch (err) {
|
|
11058
|
+
if (err.code !== "ENOENT")
|
|
11059
|
+
throw err;
|
|
11060
|
+
}
|
|
11061
|
+
}
|
|
11062
|
+
function contend(fs5, lockPath, token, now) {
|
|
11063
|
+
let seen;
|
|
11064
|
+
try {
|
|
11065
|
+
seen = fs5.statSync(lockPath);
|
|
11066
|
+
} catch (err) {
|
|
11067
|
+
if (err.code === "ENOENT")
|
|
11068
|
+
return RETRY;
|
|
11069
|
+
throw err;
|
|
11070
|
+
}
|
|
11071
|
+
if (now() - seen.mtimeMs <= STALE_MS)
|
|
11072
|
+
return WAIT;
|
|
11073
|
+
const claimedPath = `${lockPath}${REAP_INFIX}${token}`;
|
|
11074
|
+
try {
|
|
11075
|
+
fs5.renameSync(lockPath, claimedPath);
|
|
11076
|
+
} catch (err) {
|
|
11077
|
+
if (err.code === "ENOENT")
|
|
11078
|
+
return RETRY;
|
|
11079
|
+
throw err;
|
|
11080
|
+
}
|
|
11081
|
+
const claimed = fs5.statSync(claimedPath);
|
|
11082
|
+
if (claimed.ino !== seen.ino || claimed.mtimeMs !== seen.mtimeMs) {
|
|
11083
|
+
putBack(fs5, claimedPath, lockPath);
|
|
11084
|
+
}
|
|
11085
|
+
fs5.unlinkSync(claimedPath);
|
|
11086
|
+
return RETRY;
|
|
11087
|
+
}
|
|
11088
|
+
function tryAcquire(fs5, lockPath, token, now) {
|
|
11089
|
+
let fd;
|
|
11090
|
+
try {
|
|
11091
|
+
fd = fs5.openSync(lockPath, "wx");
|
|
11092
|
+
} catch (err) {
|
|
11093
|
+
if (err.code !== "EEXIST")
|
|
11094
|
+
throw err;
|
|
11095
|
+
return contend(fs5, lockPath, token, now);
|
|
11096
|
+
}
|
|
11097
|
+
try {
|
|
11098
|
+
fs5.writeSync(fd, token);
|
|
11099
|
+
} finally {
|
|
11100
|
+
fs5.closeSync(fd);
|
|
11101
|
+
}
|
|
11102
|
+
return ACQUIRED;
|
|
11103
|
+
}
|
|
11104
|
+
function holds(fs5, lockPath, token) {
|
|
11105
|
+
try {
|
|
11106
|
+
return fs5.readFileSync(lockPath, "utf8") === token;
|
|
11107
|
+
} catch (err) {
|
|
11108
|
+
if (err.code === "ENOENT")
|
|
11109
|
+
return false;
|
|
11110
|
+
throw err;
|
|
11111
|
+
}
|
|
11112
|
+
}
|
|
11113
|
+
function release(fs5, lockPath, token) {
|
|
11114
|
+
const releasedPath = `${lockPath}${RELEASE_INFIX}${token}`;
|
|
11115
|
+
try {
|
|
11116
|
+
fs5.renameSync(lockPath, releasedPath);
|
|
11117
|
+
} catch (err) {
|
|
11118
|
+
if (err.code === "ENOENT")
|
|
11119
|
+
return;
|
|
11120
|
+
throw err;
|
|
11121
|
+
}
|
|
11122
|
+
if (fs5.readFileSync(releasedPath, "utf8") !== token) {
|
|
11123
|
+
putBack(fs5, releasedPath, lockPath);
|
|
11124
|
+
}
|
|
11125
|
+
fs5.unlinkSync(releasedPath);
|
|
11126
|
+
}
|
|
11127
|
+
function runHeld(fs5, lockPath, token, section) {
|
|
11128
|
+
let tempPath = null;
|
|
11129
|
+
let targetPath = null;
|
|
11130
|
+
let decision = null;
|
|
11131
|
+
let active = true;
|
|
11132
|
+
let misuse = null;
|
|
11133
|
+
const refuse = (message) => {
|
|
11134
|
+
const err = new TypeError(`identity-lock: ${message}`);
|
|
11135
|
+
if (misuse === null)
|
|
11136
|
+
misuse = err;
|
|
11137
|
+
return err;
|
|
11138
|
+
};
|
|
11139
|
+
const ctx = Object.freeze({
|
|
11140
|
+
token,
|
|
11141
|
+
registerCommit: (files) => {
|
|
11142
|
+
if (!active)
|
|
11143
|
+
throw refuse("registerCommit was called after the section returned");
|
|
11144
|
+
if (decision !== null)
|
|
11145
|
+
throw refuse("the section may call registerCommit or commitNothing only once");
|
|
11146
|
+
const { tempPath: temp, targetPath: target } = files ?? {};
|
|
11147
|
+
if (typeof temp !== "string" || temp.length === 0 || typeof target !== "string" || target.length === 0) {
|
|
11148
|
+
throw refuse("registerCommit requires { tempPath, targetPath }, two non-empty strings");
|
|
11149
|
+
}
|
|
11150
|
+
if (path5.dirname(path5.resolve(temp)) !== path5.dirname(path5.resolve(target))) {
|
|
11151
|
+
throw refuse(`the temporary file ${temp} and its target ${target} must be in the same directory`);
|
|
11152
|
+
}
|
|
11153
|
+
if (path5.resolve(temp) === path5.resolve(target)) {
|
|
11154
|
+
throw refuse(`the temporary file and its target are the same path, ${target}`);
|
|
11155
|
+
}
|
|
11156
|
+
decision = "commit";
|
|
11157
|
+
tempPath = temp;
|
|
11158
|
+
targetPath = target;
|
|
11159
|
+
},
|
|
11160
|
+
commitNothing: () => {
|
|
11161
|
+
if (!active)
|
|
11162
|
+
throw refuse("commitNothing was called after the section returned");
|
|
11163
|
+
if (decision !== null)
|
|
11164
|
+
throw refuse("the section may call registerCommit or commitNothing only once");
|
|
11165
|
+
decision = "nothing";
|
|
11166
|
+
}
|
|
11167
|
+
});
|
|
11168
|
+
let releaseOnExit = true;
|
|
11169
|
+
let failure = null;
|
|
11170
|
+
try {
|
|
11171
|
+
let value;
|
|
11172
|
+
try {
|
|
11173
|
+
value = section(ctx);
|
|
11174
|
+
} finally {
|
|
11175
|
+
active = false;
|
|
11176
|
+
}
|
|
11177
|
+
if (misuse !== null)
|
|
11178
|
+
throw misuse;
|
|
11179
|
+
if (isThenable(value))
|
|
11180
|
+
throw new TypeError("identity-lock: the section must be synchronous, and it returned a promise");
|
|
11181
|
+
if (decision === null)
|
|
11182
|
+
throw new TypeError("identity-lock: the section returned without calling registerCommit or commitNothing");
|
|
11183
|
+
if (decision === "nothing")
|
|
11184
|
+
return { done: true, value };
|
|
11185
|
+
if (!holds(fs5, lockPath, token)) {
|
|
11186
|
+
releaseOnExit = false;
|
|
11187
|
+
removeTemp(fs5, tempPath);
|
|
11188
|
+
tempPath = null;
|
|
11189
|
+
return { done: false };
|
|
11190
|
+
}
|
|
11191
|
+
fs5.renameSync(tempPath, targetPath);
|
|
11192
|
+
tempPath = null;
|
|
11193
|
+
return { done: true, value };
|
|
11194
|
+
} catch (err) {
|
|
11195
|
+
failure = err;
|
|
11196
|
+
if (tempPath !== null) {
|
|
11197
|
+
try {
|
|
11198
|
+
removeTemp(fs5, tempPath);
|
|
11199
|
+
} catch {}
|
|
11200
|
+
}
|
|
11201
|
+
throw err;
|
|
11202
|
+
} finally {
|
|
11203
|
+
if (releaseOnExit) {
|
|
11204
|
+
if (failure === null) {
|
|
11205
|
+
release(fs5, lockPath, token);
|
|
11206
|
+
} else {
|
|
11207
|
+
try {
|
|
11208
|
+
release(fs5, lockPath, token);
|
|
11209
|
+
} catch {}
|
|
11210
|
+
}
|
|
11211
|
+
}
|
|
11212
|
+
}
|
|
11213
|
+
}
|
|
11214
|
+
function withIdentityLock({ envDir, section, fs: fs5 = nodeFs, budgetMs = BUDGET_MS, now = Date.now, wait = sleepSync }) {
|
|
11215
|
+
const lockPath = lockPathFor(envDir);
|
|
11216
|
+
if (typeof section !== "function")
|
|
11217
|
+
throw new TypeError("identity-lock requires section, a function");
|
|
11218
|
+
if (fs5 === null || typeof fs5 !== "object")
|
|
11219
|
+
throw new TypeError("identity-lock requires fs, the node:fs functions it uses");
|
|
11220
|
+
if (typeof budgetMs !== "number" || !Number.isFinite(budgetMs) || budgetMs <= 0) {
|
|
11221
|
+
throw new TypeError(`identity-lock requires budgetMs, a positive number of milliseconds, got ${budgetMs}`);
|
|
11222
|
+
}
|
|
11223
|
+
if (typeof now !== "function")
|
|
11224
|
+
throw new TypeError("identity-lock requires now, a clock function");
|
|
11225
|
+
if (typeof wait !== "function")
|
|
11226
|
+
throw new TypeError("identity-lock requires wait, a function");
|
|
11227
|
+
const startedAt = now();
|
|
11228
|
+
let token = newToken();
|
|
11229
|
+
for (;; ) {
|
|
11230
|
+
if (now() - startedAt >= budgetMs)
|
|
11231
|
+
throw timeoutError(lockPath, budgetMs);
|
|
11232
|
+
const step = tryAcquire(fs5, lockPath, token, now);
|
|
11233
|
+
if (step === ACQUIRED) {
|
|
11234
|
+
const outcome = runHeld(fs5, lockPath, token, section);
|
|
11235
|
+
if (outcome.done)
|
|
11236
|
+
return outcome.value;
|
|
11237
|
+
token = newToken();
|
|
11238
|
+
} else if (step === WAIT) {
|
|
11239
|
+
wait(WAIT_MS);
|
|
11240
|
+
}
|
|
11241
|
+
}
|
|
11242
|
+
}
|
|
11243
|
+
var identity_lock_default = Object.freeze({ lockPathFor, withIdentityLock });
|
|
11244
|
+
|
|
10997
11245
|
// src/process-manager.js
|
|
10998
11246
|
import fs5 from "node:fs";
|
|
10999
|
-
import
|
|
11247
|
+
import path6 from "node:path";
|
|
11000
11248
|
import { spawn, execSync as execSync3 } from "node:child_process";
|
|
11001
11249
|
var PID_FILENAME = "server.pid";
|
|
11002
11250
|
var LOG_FILENAME = "server.log";
|
|
11003
11251
|
function pidFilePath(envDir) {
|
|
11004
|
-
return
|
|
11252
|
+
return path6.join(envDir, PID_FILENAME);
|
|
11005
11253
|
}
|
|
11006
11254
|
function logFilePath(envDir) {
|
|
11007
|
-
return
|
|
11255
|
+
return path6.join(envDir, LOG_FILENAME);
|
|
11008
11256
|
}
|
|
11009
11257
|
function readPid(envDir) {
|
|
11010
11258
|
const filePath = pidFilePath(envDir);
|
|
@@ -11034,7 +11282,7 @@ function isProcessAlive(pid) {
|
|
|
11034
11282
|
}
|
|
11035
11283
|
}
|
|
11036
11284
|
function getPm2Name(envDir) {
|
|
11037
|
-
const base =
|
|
11285
|
+
const base = path6.basename(envDir).replace(/^\./, "");
|
|
11038
11286
|
if (base === "caw")
|
|
11039
11287
|
return "caw";
|
|
11040
11288
|
return `caw-${base}`;
|
|
@@ -11233,7 +11481,7 @@ async function emitCawCmd({ op, config }) {
|
|
|
11233
11481
|
if (apiKey === null)
|
|
11234
11482
|
return;
|
|
11235
11483
|
const host = process.env.POSTHOG_HOST || DEFAULT_HOST;
|
|
11236
|
-
const properties = { op };
|
|
11484
|
+
const properties = { op, $geoip_disable: true };
|
|
11237
11485
|
if (op === "start") {
|
|
11238
11486
|
properties.$set = {
|
|
11239
11487
|
launcher_version: launcherVersion(),
|
|
@@ -11273,18 +11521,44 @@ async function emitCawCmdStop({ config }) {
|
|
|
11273
11521
|
return emitCawCmd({ op: "stop", config });
|
|
11274
11522
|
}
|
|
11275
11523
|
|
|
11276
|
-
// src/
|
|
11277
|
-
import
|
|
11524
|
+
// src/analytics-notice.js
|
|
11525
|
+
import fs6 from "node:fs";
|
|
11278
11526
|
import path7 from "node:path";
|
|
11279
|
-
|
|
11527
|
+
var MARKER_FILENAME = "analytics-notice-shown";
|
|
11528
|
+
function noticeText(envDir) {
|
|
11529
|
+
return [
|
|
11530
|
+
"CAW sends usage analytics to PostHog. This is on by default.",
|
|
11531
|
+
`To turn it off, use Preferences > Analytics, or set "analyticsEnabled": false in ${path7.join(envDir, "config.json")}.`,
|
|
11532
|
+
"What is sent and what isn't: https://www.npmjs.com/package/@kelceyp/caw"
|
|
11533
|
+
].join(`
|
|
11534
|
+
`);
|
|
11535
|
+
}
|
|
11536
|
+
function showAnalyticsNoticeOnce({ envDir }) {
|
|
11537
|
+
if (readConfig(envDir).analyticsEnabled === false) {
|
|
11538
|
+
return;
|
|
11539
|
+
}
|
|
11540
|
+
const markerPath = path7.join(envDir, MARKER_FILENAME);
|
|
11541
|
+
if (fs6.existsSync(markerPath)) {
|
|
11542
|
+
return;
|
|
11543
|
+
}
|
|
11544
|
+
console.log(noticeText(envDir));
|
|
11545
|
+
try {
|
|
11546
|
+
fs6.closeSync(fs6.openSync(markerPath, "a"));
|
|
11547
|
+
} catch {}
|
|
11548
|
+
}
|
|
11549
|
+
|
|
11550
|
+
// src/first-run-install.js
|
|
11551
|
+
import fs8 from "node:fs";
|
|
11552
|
+
import path9 from "node:path";
|
|
11553
|
+
import crypto2 from "node:crypto";
|
|
11280
11554
|
|
|
11281
11555
|
// src/bundle-install-lock.js
|
|
11282
|
-
import
|
|
11283
|
-
import
|
|
11556
|
+
import fs7 from "node:fs";
|
|
11557
|
+
import path8 from "node:path";
|
|
11284
11558
|
var LOCK_FILENAME = "config.bundle-install.lock";
|
|
11285
11559
|
var STALE_LOCK_MS = 1e4;
|
|
11286
|
-
function
|
|
11287
|
-
return
|
|
11560
|
+
function lockPathFor2(envDir) {
|
|
11561
|
+
return path8.join(envDir, LOCK_FILENAME);
|
|
11288
11562
|
}
|
|
11289
11563
|
function makeReleaser(lockPath) {
|
|
11290
11564
|
let released = false;
|
|
@@ -11293,31 +11567,31 @@ function makeReleaser(lockPath) {
|
|
|
11293
11567
|
return;
|
|
11294
11568
|
released = true;
|
|
11295
11569
|
try {
|
|
11296
|
-
|
|
11570
|
+
fs7.unlinkSync(lockPath);
|
|
11297
11571
|
} catch {}
|
|
11298
11572
|
};
|
|
11299
11573
|
}
|
|
11300
11574
|
var NOOP_RELEASE = () => {};
|
|
11301
11575
|
function acquire({ envDir }) {
|
|
11302
|
-
|
|
11303
|
-
const lockPath =
|
|
11576
|
+
fs7.mkdirSync(envDir, { recursive: true });
|
|
11577
|
+
const lockPath = lockPathFor2(envDir);
|
|
11304
11578
|
try {
|
|
11305
|
-
const fd =
|
|
11306
|
-
|
|
11579
|
+
const fd = fs7.openSync(lockPath, "wx");
|
|
11580
|
+
fs7.closeSync(fd);
|
|
11307
11581
|
return { acquired: true, release: makeReleaser(lockPath) };
|
|
11308
11582
|
} catch (e) {
|
|
11309
11583
|
if (e.code !== "EEXIST")
|
|
11310
11584
|
throw e;
|
|
11311
11585
|
}
|
|
11312
11586
|
try {
|
|
11313
|
-
const st =
|
|
11587
|
+
const st = fs7.statSync(lockPath);
|
|
11314
11588
|
if (Date.now() - st.mtimeMs > STALE_LOCK_MS) {
|
|
11315
11589
|
try {
|
|
11316
|
-
|
|
11590
|
+
fs7.unlinkSync(lockPath);
|
|
11317
11591
|
} catch {}
|
|
11318
11592
|
try {
|
|
11319
|
-
const fd =
|
|
11320
|
-
|
|
11593
|
+
const fd = fs7.openSync(lockPath, "wx");
|
|
11594
|
+
fs7.closeSync(fd);
|
|
11321
11595
|
return { acquired: true, release: makeReleaser(lockPath) };
|
|
11322
11596
|
} catch {}
|
|
11323
11597
|
}
|
|
@@ -11455,10 +11729,10 @@ function resolveFetch(out) {
|
|
|
11455
11729
|
return out && typeof out.fetch === "function" ? out.fetch : fetch;
|
|
11456
11730
|
}
|
|
11457
11731
|
function stagedZipPath(envDir, name) {
|
|
11458
|
-
return
|
|
11732
|
+
return path9.join(envDir, SHARED_EXPORTS_DIR, `${name}.zip`);
|
|
11459
11733
|
}
|
|
11460
11734
|
function sha256File(filePath) {
|
|
11461
|
-
return
|
|
11735
|
+
return crypto2.createHash("sha256").update(fs8.readFileSync(filePath)).digest("hex");
|
|
11462
11736
|
}
|
|
11463
11737
|
async function fetchInfo(port, fetchFn) {
|
|
11464
11738
|
const controller = new AbortController;
|
|
@@ -11485,8 +11759,8 @@ async function downloadTo(url, targetPath, fetchFn) {
|
|
|
11485
11759
|
throw new Error(`download: HTTP ${res.status} for ${url}`);
|
|
11486
11760
|
}
|
|
11487
11761
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
11488
|
-
|
|
11489
|
-
|
|
11762
|
+
fs8.mkdirSync(path9.dirname(targetPath), { recursive: true });
|
|
11763
|
+
fs8.writeFileSync(targetPath, buf);
|
|
11490
11764
|
}
|
|
11491
11765
|
async function postImport(port, filename, fetchFn) {
|
|
11492
11766
|
const url = `http://localhost:${port}/api/shared/bundle/import`;
|
|
@@ -11520,19 +11794,19 @@ async function postImport(port, filename, fetchFn) {
|
|
|
11520
11794
|
function filenameFromCatalogueEntry(entry, name) {
|
|
11521
11795
|
try {
|
|
11522
11796
|
const u = new URL(entry.url);
|
|
11523
|
-
const base =
|
|
11797
|
+
const base = path9.basename(u.pathname);
|
|
11524
11798
|
return base && base.length > 0 ? base : `${name}.zip`;
|
|
11525
11799
|
} catch {
|
|
11526
11800
|
return `${name}.zip`;
|
|
11527
11801
|
}
|
|
11528
11802
|
}
|
|
11529
11803
|
async function ensureLocalBundleFile({ envDir, name, entry, fetchFn }) {
|
|
11530
|
-
const sharedDir =
|
|
11531
|
-
|
|
11804
|
+
const sharedDir = path9.join(envDir, SHARED_EXPORTS_DIR);
|
|
11805
|
+
fs8.mkdirSync(sharedDir, { recursive: true });
|
|
11532
11806
|
if (entry) {
|
|
11533
11807
|
const filename = filenameFromCatalogueEntry(entry, name);
|
|
11534
|
-
const filePath =
|
|
11535
|
-
let needDownload = !
|
|
11808
|
+
const filePath = path9.join(sharedDir, filename);
|
|
11809
|
+
let needDownload = !fs8.existsSync(filePath);
|
|
11536
11810
|
if (!needDownload && entry.sha256) {
|
|
11537
11811
|
try {
|
|
11538
11812
|
if (sha256File(filePath) !== entry.sha256)
|
|
@@ -11555,7 +11829,7 @@ async function ensureLocalBundleFile({ envDir, name, entry, fetchFn }) {
|
|
|
11555
11829
|
return { filename, sourceSha256: entry.sha256 };
|
|
11556
11830
|
}
|
|
11557
11831
|
const stagedPath = stagedZipPath(envDir, name);
|
|
11558
|
-
if (!
|
|
11832
|
+
if (!fs8.existsSync(stagedPath)) {
|
|
11559
11833
|
const err = new Error(`no staged zip at ${stagedPath}`);
|
|
11560
11834
|
err.__outcome = OUTCOME.NOT_FOUND;
|
|
11561
11835
|
throw err;
|
|
@@ -11726,20 +12000,20 @@ var __test__2 = Object.freeze({ OUTCOME, INFO_TIMEOUT_MS, SHARED_EXPORTS_DIR });
|
|
|
11726
12000
|
// src/commands/start.js
|
|
11727
12001
|
function resolveEnvDir(rawEnvDir) {
|
|
11728
12002
|
if (rawEnvDir.startsWith("~")) {
|
|
11729
|
-
rawEnvDir =
|
|
12003
|
+
rawEnvDir = path10.join(os2.homedir(), rawEnvDir.slice(1));
|
|
11730
12004
|
}
|
|
11731
|
-
return
|
|
12005
|
+
return path10.resolve(rawEnvDir);
|
|
11732
12006
|
}
|
|
11733
12007
|
function validateEnvFile(envDir) {
|
|
11734
|
-
const envFilePath =
|
|
11735
|
-
if (!
|
|
12008
|
+
const envFilePath = path10.join(envDir, ".env");
|
|
12009
|
+
if (!fs9.existsSync(envFilePath)) {
|
|
11736
12010
|
return {
|
|
11737
12011
|
ok: false,
|
|
11738
12012
|
message: `Error: Environment file not found: ${envFilePath}
|
|
11739
12013
|
Create it with your configuration variables (e.g., CLAUDE_CODE_OAUTH_TOKEN).`
|
|
11740
12014
|
};
|
|
11741
12015
|
}
|
|
11742
|
-
const content =
|
|
12016
|
+
const content = fs9.readFileSync(envFilePath, "utf8");
|
|
11743
12017
|
const lines = content.split(`
|
|
11744
12018
|
`);
|
|
11745
12019
|
for (let i = 0;i < lines.length; i++) {
|
|
@@ -11761,10 +12035,10 @@ var MAX_LOG_SIZE = 10 * 1024 * 1024;
|
|
|
11761
12035
|
var LOG_RETAIN = 5;
|
|
11762
12036
|
function rotateLogIfNeeded(envDir) {
|
|
11763
12037
|
try {
|
|
11764
|
-
const logPath =
|
|
11765
|
-
if (!
|
|
12038
|
+
const logPath = path10.join(envDir, "server.log");
|
|
12039
|
+
if (!fs9.existsSync(logPath))
|
|
11766
12040
|
return;
|
|
11767
|
-
const stats =
|
|
12041
|
+
const stats = fs9.statSync(logPath);
|
|
11768
12042
|
if (stats.size <= MAX_LOG_SIZE)
|
|
11769
12043
|
return;
|
|
11770
12044
|
const now = new Date;
|
|
@@ -11778,39 +12052,28 @@ function rotateLogIfNeeded(envDir) {
|
|
|
11778
12052
|
pad2(now.getMinutes()),
|
|
11779
12053
|
pad2(now.getSeconds())
|
|
11780
12054
|
].join("-");
|
|
11781
|
-
|
|
12055
|
+
fs9.renameSync(logPath, `${logPath}.${timestamp}`);
|
|
11782
12056
|
console.log(`Rotated server.log (was ${(stats.size / 1024 / 1024).toFixed(1)} MB)`);
|
|
11783
|
-
const rotated =
|
|
12057
|
+
const rotated = fs9.readdirSync(envDir).filter((f) => f.startsWith("server.log.")).map((f) => ({ name: f, mtime: fs9.statSync(path10.join(envDir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
|
|
11784
12058
|
for (const file of rotated.slice(LOG_RETAIN)) {
|
|
11785
|
-
|
|
12059
|
+
fs9.unlinkSync(path10.join(envDir, file.name));
|
|
11786
12060
|
}
|
|
11787
12061
|
} catch (err) {
|
|
11788
12062
|
console.warn(`Warning: log rotation failed: ${err.message}`);
|
|
11789
12063
|
}
|
|
11790
12064
|
}
|
|
11791
12065
|
function buildEnvNodeArgs(envDir) {
|
|
11792
|
-
const envFilePath =
|
|
12066
|
+
const envFilePath = path10.join(envDir, ".env");
|
|
11793
12067
|
return [`--env-file=${envFilePath}`];
|
|
11794
12068
|
}
|
|
11795
12069
|
function buildServerEnvVars(activeConfig, envDir) {
|
|
11796
12070
|
if (typeof envDir !== "string" || envDir.length === 0) {
|
|
11797
12071
|
throw new Error("buildServerEnvVars: envDir is required (server main.js exits when CAW_ENV_DIR is unset)");
|
|
11798
12072
|
}
|
|
11799
|
-
|
|
12073
|
+
return {
|
|
11800
12074
|
CAW_PORT: String(activeConfig.port),
|
|
11801
12075
|
CAW_ENV_DIR: envDir
|
|
11802
12076
|
};
|
|
11803
|
-
if (typeof activeConfig.installId === "string" && activeConfig.installId.length > 0 && typeof activeConfig.installSalt === "string" && activeConfig.installSalt.length > 0) {
|
|
11804
|
-
envVars.CAW_INSTALL_ID = String(activeConfig.installId);
|
|
11805
|
-
envVars.CAW_INSTALL_SALT = String(activeConfig.installSalt);
|
|
11806
|
-
}
|
|
11807
|
-
if (typeof activeConfig.analyticsEnabled === "boolean") {
|
|
11808
|
-
envVars.CAW_ANALYTICS_ENABLED = activeConfig.analyticsEnabled ? "true" : "false";
|
|
11809
|
-
}
|
|
11810
|
-
return envVars;
|
|
11811
|
-
}
|
|
11812
|
-
function sleepSync(ms) {
|
|
11813
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
11814
12077
|
}
|
|
11815
12078
|
function hasFullIdentity(config) {
|
|
11816
12079
|
return typeof config?.installId === "string" && config.installId.length > 0 && typeof config?.installSalt === "string" && config.installSalt.length > 0 && typeof config?.analyticsEnabled === "boolean";
|
|
@@ -11821,63 +12084,36 @@ function ensureInstallIdentity(envDir) {
|
|
|
11821
12084
|
if (hasFullIdentity(existing))
|
|
11822
12085
|
return existing;
|
|
11823
12086
|
}
|
|
11824
|
-
|
|
11825
|
-
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
if (
|
|
11835
|
-
|
|
11836
|
-
|
|
11837
|
-
|
|
11838
|
-
|
|
11839
|
-
|
|
11840
|
-
|
|
11841
|
-
|
|
11842
|
-
}
|
|
11843
|
-
|
|
11844
|
-
}
|
|
11845
|
-
}
|
|
11846
|
-
try {
|
|
11847
|
-
const existing = configExists(envDir) ? readConfig(envDir) : { ...DEFAULTS };
|
|
11848
|
-
const merged = { ...existing };
|
|
11849
|
-
let mutated = false;
|
|
11850
|
-
if (typeof merged.installId !== "string" || merged.installId.length === 0) {
|
|
11851
|
-
merged.installId = crypto2.randomUUID();
|
|
11852
|
-
mutated = true;
|
|
11853
|
-
}
|
|
11854
|
-
if (typeof merged.installSalt !== "string" || merged.installSalt.length === 0) {
|
|
11855
|
-
merged.installSalt = crypto2.randomBytes(32).toString("base64url");
|
|
11856
|
-
mutated = true;
|
|
11857
|
-
}
|
|
11858
|
-
if (typeof merged.analyticsEnabled !== "boolean") {
|
|
11859
|
-
merged.analyticsEnabled = DEFAULTS.analyticsEnabled;
|
|
11860
|
-
mutated = true;
|
|
11861
|
-
}
|
|
11862
|
-
if (mutated) {
|
|
11863
|
-
writeConfig(envDir, merged);
|
|
11864
|
-
}
|
|
11865
|
-
return readConfig(envDir);
|
|
11866
|
-
} finally {
|
|
11867
|
-
if (acquired) {
|
|
11868
|
-
try {
|
|
11869
|
-
fs8.unlinkSync(lockPath);
|
|
11870
|
-
} catch {}
|
|
12087
|
+
fs9.mkdirSync(envDir, { recursive: true });
|
|
12088
|
+
return identity_lock_default.withIdentityLock({
|
|
12089
|
+
envDir,
|
|
12090
|
+
section: (lock) => {
|
|
12091
|
+
const existing = configExists(envDir) ? readConfig(envDir) : { ...DEFAULTS };
|
|
12092
|
+
if (hasFullIdentity(existing)) {
|
|
12093
|
+
lock.commitNothing();
|
|
12094
|
+
return existing;
|
|
12095
|
+
}
|
|
12096
|
+
const merged = { ...existing };
|
|
12097
|
+
if (typeof merged.installId !== "string" || merged.installId.length === 0) {
|
|
12098
|
+
merged.installId = crypto3.randomUUID();
|
|
12099
|
+
}
|
|
12100
|
+
if (typeof merged.installSalt !== "string" || merged.installSalt.length === 0) {
|
|
12101
|
+
merged.installSalt = crypto3.randomBytes(32).toString("base64url");
|
|
12102
|
+
}
|
|
12103
|
+
if (typeof merged.analyticsEnabled !== "boolean") {
|
|
12104
|
+
merged.analyticsEnabled = DEFAULTS.analyticsEnabled;
|
|
12105
|
+
}
|
|
12106
|
+
return writeConfigFenced(envDir, merged, lock);
|
|
11871
12107
|
}
|
|
11872
|
-
}
|
|
12108
|
+
});
|
|
11873
12109
|
}
|
|
11874
12110
|
function bootstrap(envDir) {
|
|
11875
|
-
|
|
11876
|
-
|
|
12111
|
+
fs9.mkdirSync(envDir, { recursive: true });
|
|
12112
|
+
fs9.mkdirSync(path10.join(envDir, "assets"), { recursive: true });
|
|
11877
12113
|
ensureInstallIdentity(envDir);
|
|
11878
|
-
const envFilePath =
|
|
11879
|
-
if (!
|
|
11880
|
-
|
|
12114
|
+
const envFilePath = path10.join(envDir, ".env");
|
|
12115
|
+
if (!fs9.existsSync(envFilePath)) {
|
|
12116
|
+
fs9.writeFileSync(envFilePath, [
|
|
11881
12117
|
"# CAW environment configuration",
|
|
11882
12118
|
"# Uncomment and set values as needed",
|
|
11883
12119
|
"",
|
|
@@ -11996,6 +12232,7 @@ How would you like to proceed?`,
|
|
|
11996
12232
|
await runFirstRunInstall({ envDir, config, port: config.port, out: undefined });
|
|
11997
12233
|
process.exit(0);
|
|
11998
12234
|
}
|
|
12235
|
+
showAnalyticsNoticeOnce({ envDir });
|
|
11999
12236
|
await emitCawCmdStart({ config: readConfig(envDir) });
|
|
12000
12237
|
let activeConfig = config;
|
|
12001
12238
|
if (hasPendingConfig(envDir)) {
|
|
@@ -12041,7 +12278,7 @@ How would you like to proceed?`,
|
|
|
12041
12278
|
const started = await pollHealth(activeConfig.port);
|
|
12042
12279
|
if (!started) {
|
|
12043
12280
|
console.error(`Server did not become healthy within 10 seconds.`);
|
|
12044
|
-
console.error(`Check logs with: caw logs${envDir !==
|
|
12281
|
+
console.error(`Check logs with: caw logs${envDir !== path10.join(os2.homedir(), ".caw") ? ` --env-dir ${envDir}` : ""}`);
|
|
12045
12282
|
process.exit(1);
|
|
12046
12283
|
}
|
|
12047
12284
|
console.log(`Server started successfully on http://localhost:${activeConfig.port}`);
|
|
@@ -12051,14 +12288,14 @@ How would you like to proceed?`,
|
|
|
12051
12288
|
var start_default = Object.freeze({ create: create2 });
|
|
12052
12289
|
|
|
12053
12290
|
// src/commands/stop.js
|
|
12054
|
-
import
|
|
12055
|
-
import
|
|
12291
|
+
import fs10 from "node:fs";
|
|
12292
|
+
import path11 from "node:path";
|
|
12056
12293
|
import os3 from "node:os";
|
|
12057
12294
|
function resolveEnvDir2(rawEnvDir) {
|
|
12058
12295
|
if (rawEnvDir.startsWith("~")) {
|
|
12059
|
-
rawEnvDir =
|
|
12296
|
+
rawEnvDir = path11.join(os3.homedir(), rawEnvDir.slice(1));
|
|
12060
12297
|
}
|
|
12061
|
-
return
|
|
12298
|
+
return path11.resolve(rawEnvDir);
|
|
12062
12299
|
}
|
|
12063
12300
|
async function checkHealth2(port) {
|
|
12064
12301
|
try {
|
|
@@ -12128,7 +12365,7 @@ var create3 = () => {
|
|
|
12128
12365
|
return createCommand("stop").summary("Stop the caw server").param((p) => p.name("env-dir").type("string").flag("env-dir").default("~/.caw/")).param((p) => p.name("force").type("boolean").flag("force").default(false)).run(async (ctx) => {
|
|
12129
12366
|
const envDir = resolveEnvDir2(ctx.params["env-dir"]);
|
|
12130
12367
|
const force = ctx.params.force;
|
|
12131
|
-
if (!
|
|
12368
|
+
if (!fs10.existsSync(envDir) || !configExists(envDir)) {
|
|
12132
12369
|
console.log("Server is not running (no environment directory or config found).");
|
|
12133
12370
|
process.exit(0);
|
|
12134
12371
|
}
|
|
@@ -12149,13 +12386,13 @@ var stop_default = Object.freeze({ create: create3 });
|
|
|
12149
12386
|
|
|
12150
12387
|
// src/commands/status.js
|
|
12151
12388
|
var import_semver = __toESM(require_semver2(), 1);
|
|
12152
|
-
import
|
|
12153
|
-
import
|
|
12389
|
+
import fs12 from "node:fs";
|
|
12390
|
+
import path13 from "node:path";
|
|
12154
12391
|
import os4 from "node:os";
|
|
12155
12392
|
|
|
12156
12393
|
// src/registry.js
|
|
12157
|
-
import
|
|
12158
|
-
import
|
|
12394
|
+
import fs11 from "node:fs";
|
|
12395
|
+
import path12 from "node:path";
|
|
12159
12396
|
var CACHE_FILENAME = "caw-cache.json";
|
|
12160
12397
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
12161
12398
|
var DEFAULT_TTL_MS = 60 * 60 * 1000;
|
|
@@ -12171,18 +12408,18 @@ async function fetchLatestVersion(packageName, { timeoutMs = DEFAULT_TIMEOUT_MS
|
|
|
12171
12408
|
return data["dist-tags"].latest;
|
|
12172
12409
|
}
|
|
12173
12410
|
function readCache(envDir) {
|
|
12174
|
-
const cachePath =
|
|
12411
|
+
const cachePath = path12.join(envDir, CACHE_FILENAME);
|
|
12175
12412
|
try {
|
|
12176
|
-
return JSON.parse(
|
|
12413
|
+
return JSON.parse(fs11.readFileSync(cachePath, "utf8"));
|
|
12177
12414
|
} catch {
|
|
12178
12415
|
return null;
|
|
12179
12416
|
}
|
|
12180
12417
|
}
|
|
12181
12418
|
function writeCache(envDir, cache) {
|
|
12182
|
-
const cachePath =
|
|
12419
|
+
const cachePath = path12.join(envDir, CACHE_FILENAME);
|
|
12183
12420
|
const tmp = cachePath + ".tmp";
|
|
12184
|
-
|
|
12185
|
-
|
|
12421
|
+
fs11.writeFileSync(tmp, JSON.stringify(cache, null, 2));
|
|
12422
|
+
fs11.renameSync(tmp, cachePath);
|
|
12186
12423
|
}
|
|
12187
12424
|
function isCacheStale(cache, ttlMs = DEFAULT_TTL_MS) {
|
|
12188
12425
|
if (!cache)
|
|
@@ -12199,9 +12436,9 @@ function isCacheStale(cache, ttlMs = DEFAULT_TTL_MS) {
|
|
|
12199
12436
|
// src/commands/status.js
|
|
12200
12437
|
function resolveEnvDir3(rawEnvDir) {
|
|
12201
12438
|
if (rawEnvDir.startsWith("~")) {
|
|
12202
|
-
rawEnvDir =
|
|
12439
|
+
rawEnvDir = path13.join(os4.homedir(), rawEnvDir.slice(1));
|
|
12203
12440
|
}
|
|
12204
|
-
return
|
|
12441
|
+
return path13.resolve(rawEnvDir);
|
|
12205
12442
|
}
|
|
12206
12443
|
async function fetchHealth(port) {
|
|
12207
12444
|
try {
|
|
@@ -12244,7 +12481,7 @@ function formatUptime(ms) {
|
|
|
12244
12481
|
function getUptimeFromPidFile(envDir) {
|
|
12245
12482
|
const filePath = pidFilePath(envDir);
|
|
12246
12483
|
try {
|
|
12247
|
-
const stat =
|
|
12484
|
+
const stat = fs12.statSync(filePath);
|
|
12248
12485
|
return Date.now() - stat.mtimeMs;
|
|
12249
12486
|
} catch {
|
|
12250
12487
|
return null;
|
|
@@ -12259,7 +12496,7 @@ function getUptimeFromPm2(runState) {
|
|
|
12259
12496
|
var create4 = () => {
|
|
12260
12497
|
return createCommand("status").summary("Show caw server status").param((p) => p.name("env-dir").type("string").flag("env-dir").default("~/.caw/")).run(async (ctx) => {
|
|
12261
12498
|
const envDir = resolveEnvDir3(ctx.params["env-dir"]);
|
|
12262
|
-
if (!
|
|
12499
|
+
if (!fs12.existsSync(envDir) || !configExists(envDir)) {
|
|
12263
12500
|
console.log("Server: not configured");
|
|
12264
12501
|
console.log(` No environment found at ${envDir}`);
|
|
12265
12502
|
process.exit(0);
|
|
@@ -12324,21 +12561,21 @@ var create4 = () => {
|
|
|
12324
12561
|
var status_default = Object.freeze({ create: create4 });
|
|
12325
12562
|
|
|
12326
12563
|
// src/commands/logs.js
|
|
12327
|
-
import
|
|
12328
|
-
import
|
|
12564
|
+
import fs13 from "node:fs";
|
|
12565
|
+
import path14 from "node:path";
|
|
12329
12566
|
import os5 from "node:os";
|
|
12330
12567
|
import { spawn as spawn2 } from "node:child_process";
|
|
12331
12568
|
function resolveEnvDir4(rawEnvDir) {
|
|
12332
12569
|
if (rawEnvDir.startsWith("~")) {
|
|
12333
|
-
rawEnvDir =
|
|
12570
|
+
rawEnvDir = path14.join(os5.homedir(), rawEnvDir.slice(1));
|
|
12334
12571
|
}
|
|
12335
|
-
return
|
|
12572
|
+
return path14.resolve(rawEnvDir);
|
|
12336
12573
|
}
|
|
12337
12574
|
var create5 = () => {
|
|
12338
12575
|
return createCommand("logs").summary("Tail the caw server logs").param((p) => p.name("env-dir").type("string").flag("env-dir").default("~/.caw/")).run(async (ctx) => {
|
|
12339
12576
|
const envDir = resolveEnvDir4(ctx.params["env-dir"]);
|
|
12340
|
-
const logPath =
|
|
12341
|
-
if (!
|
|
12577
|
+
const logPath = path14.join(envDir, "server.log");
|
|
12578
|
+
if (!fs13.existsSync(logPath)) {
|
|
12342
12579
|
console.log(`No log file found at ${logPath}`);
|
|
12343
12580
|
process.exit(0);
|
|
12344
12581
|
}
|
|
@@ -12360,16 +12597,16 @@ var logs_default = Object.freeze({ create: create5 });
|
|
|
12360
12597
|
|
|
12361
12598
|
// src/commands/upgrade.js
|
|
12362
12599
|
var import_semver2 = __toESM(require_semver2(), 1);
|
|
12363
|
-
import
|
|
12364
|
-
import
|
|
12600
|
+
import fs14 from "node:fs";
|
|
12601
|
+
import path15 from "node:path";
|
|
12365
12602
|
import os6 from "node:os";
|
|
12366
12603
|
import { execSync as execSync5 } from "node:child_process";
|
|
12367
12604
|
var COMPATIBLE_SERVER_RANGE = "^1";
|
|
12368
12605
|
function resolveEnvDir5(rawEnvDir) {
|
|
12369
12606
|
if (rawEnvDir.startsWith("~")) {
|
|
12370
|
-
rawEnvDir =
|
|
12607
|
+
rawEnvDir = path15.join(os6.homedir(), rawEnvDir.slice(1));
|
|
12371
12608
|
}
|
|
12372
|
-
return
|
|
12609
|
+
return path15.resolve(rawEnvDir);
|
|
12373
12610
|
}
|
|
12374
12611
|
async function checkHealth3(port) {
|
|
12375
12612
|
try {
|
|
@@ -12451,7 +12688,7 @@ var create6 = () => {
|
|
|
12451
12688
|
let skipInstall = false;
|
|
12452
12689
|
if (import_semver2.default.gte(installedVersion, latestServerVersion)) {
|
|
12453
12690
|
let needsRestart = false;
|
|
12454
|
-
if (
|
|
12691
|
+
if (fs14.existsSync(envDir) && configExists(envDir)) {
|
|
12455
12692
|
const config = readConfigWithDefaults(envDir);
|
|
12456
12693
|
const pm = createProcessManager(config, envDir);
|
|
12457
12694
|
if (pm.isRunning().running) {
|
|
@@ -12498,8 +12735,15 @@ var create6 = () => {
|
|
|
12498
12735
|
console.log("Rerun `caw upgrade` to complete the server upgrade.");
|
|
12499
12736
|
process.exit(0);
|
|
12500
12737
|
}
|
|
12738
|
+
if (fs14.existsSync(envDir) && configExists(envDir)) {
|
|
12739
|
+
const envCheck = validateEnvFile(envDir);
|
|
12740
|
+
if (!envCheck.ok) {
|
|
12741
|
+
console.error(envCheck.message);
|
|
12742
|
+
process.exit(1);
|
|
12743
|
+
}
|
|
12744
|
+
}
|
|
12501
12745
|
let serverWasStopped = false;
|
|
12502
|
-
if (
|
|
12746
|
+
if (fs14.existsSync(envDir) && configExists(envDir)) {
|
|
12503
12747
|
const config = readConfigWithDefaults(envDir);
|
|
12504
12748
|
const pm = createProcessManager(config, envDir);
|
|
12505
12749
|
const runState = pm.isRunning();
|
|
@@ -12550,7 +12794,7 @@ var create6 = () => {
|
|
|
12550
12794
|
process.exit(1);
|
|
12551
12795
|
}
|
|
12552
12796
|
}
|
|
12553
|
-
if (serverWasStopped ||
|
|
12797
|
+
if (serverWasStopped || fs14.existsSync(envDir) && configExists(envDir)) {
|
|
12554
12798
|
const config = readConfigWithDefaults(envDir);
|
|
12555
12799
|
const pm = createProcessManager(config, envDir);
|
|
12556
12800
|
const newServerInfo = resolve();
|
|
@@ -12558,12 +12802,8 @@ var create6 = () => {
|
|
|
12558
12802
|
console.error(`Error: Server upgraded to ${latestServerVersion} but failed to start. Check logs with 'caw logs'. Start manually with 'caw start'.`);
|
|
12559
12803
|
process.exit(1);
|
|
12560
12804
|
}
|
|
12561
|
-
const envVars = {
|
|
12562
|
-
CAW_PORT: String(config.port),
|
|
12563
|
-
CAW_ENV_DIR: envDir
|
|
12564
|
-
};
|
|
12565
12805
|
console.log("Starting server...");
|
|
12566
|
-
pm.start(newServerInfo.mainJsPath,
|
|
12806
|
+
pm.start(newServerInfo.mainJsPath, buildServerEnvVars(config, envDir), buildEnvNodeArgs(envDir));
|
|
12567
12807
|
const started = await pollHealth2(config.port);
|
|
12568
12808
|
if (!started) {
|
|
12569
12809
|
console.error(`Error: Server upgraded to ${latestServerVersion} but failed to start. Check logs with 'caw logs'. Start manually with 'caw start'.`);
|
|
@@ -12580,15 +12820,15 @@ var create6 = () => {
|
|
|
12580
12820
|
var upgrade_default = Object.freeze({ create: create6 });
|
|
12581
12821
|
|
|
12582
12822
|
// src/commands/restart.js
|
|
12583
|
-
import
|
|
12584
|
-
import
|
|
12823
|
+
import fs15 from "node:fs";
|
|
12824
|
+
import path16 from "node:path";
|
|
12585
12825
|
import os7 from "node:os";
|
|
12586
12826
|
import { execSync as execSync6 } from "node:child_process";
|
|
12587
12827
|
function resolveEnvDir6(rawEnvDir) {
|
|
12588
12828
|
if (rawEnvDir.startsWith("~")) {
|
|
12589
|
-
rawEnvDir =
|
|
12829
|
+
rawEnvDir = path16.join(os7.homedir(), rawEnvDir.slice(1));
|
|
12590
12830
|
}
|
|
12591
|
-
return
|
|
12831
|
+
return path16.resolve(rawEnvDir);
|
|
12592
12832
|
}
|
|
12593
12833
|
function buildChangeSummary2(active, pending) {
|
|
12594
12834
|
const changes = [];
|
|
@@ -12627,9 +12867,11 @@ var create7 = () => {
|
|
|
12627
12867
|
}
|
|
12628
12868
|
const envDir = resolveEnvDir6(ctx.params["env-dir"]);
|
|
12629
12869
|
const force = ctx.params.force;
|
|
12630
|
-
|
|
12870
|
+
const hadConfig = fs15.existsSync(envDir) && configExists(envDir);
|
|
12871
|
+
if (hadConfig) {
|
|
12631
12872
|
const config2 = readConfigWithDefaults(envDir);
|
|
12632
12873
|
const pm3 = createProcessManager(config2, envDir);
|
|
12874
|
+
showAnalyticsNoticeOnce({ envDir });
|
|
12633
12875
|
const result = await executeStop(pm3, config2, force, ctx.prompt, envDir);
|
|
12634
12876
|
if (result.wasRunning && !result.stopped) {
|
|
12635
12877
|
if (result.userDeclined) {
|
|
@@ -12682,6 +12924,9 @@ How would you like to proceed?`,
|
|
|
12682
12924
|
console.log(`Server is already running on port ${config.port}.`);
|
|
12683
12925
|
process.exit(0);
|
|
12684
12926
|
}
|
|
12927
|
+
if (!hadConfig) {
|
|
12928
|
+
showAnalyticsNoticeOnce({ envDir });
|
|
12929
|
+
}
|
|
12685
12930
|
await emitCawCmdStart({ config: readConfig(envDir) });
|
|
12686
12931
|
let activeConfig = config;
|
|
12687
12932
|
if (hasPendingConfig(envDir)) {
|
|
@@ -12727,7 +12972,7 @@ How would you like to proceed?`,
|
|
|
12727
12972
|
const started = await pollHealth(activeConfig.port);
|
|
12728
12973
|
if (!started) {
|
|
12729
12974
|
console.error(`Server did not become healthy within 10 seconds.`);
|
|
12730
|
-
console.error(`Check logs with: caw logs${envDir !==
|
|
12975
|
+
console.error(`Check logs with: caw logs${envDir !== path16.join(os7.homedir(), ".caw") ? ` --env-dir ${envDir}` : ""}`);
|
|
12731
12976
|
process.exit(1);
|
|
12732
12977
|
}
|
|
12733
12978
|
console.log(`Server started successfully on http://localhost:${activeConfig.port}`);
|
|
@@ -12736,12 +12981,12 @@ How would you like to proceed?`,
|
|
|
12736
12981
|
var restart_default = Object.freeze({ create: create7 });
|
|
12737
12982
|
|
|
12738
12983
|
// src/commands/caddy.js
|
|
12739
|
-
import
|
|
12740
|
-
import
|
|
12984
|
+
import fs16 from "node:fs";
|
|
12985
|
+
import path17 from "node:path";
|
|
12741
12986
|
import os8 from "node:os";
|
|
12742
12987
|
import http from "node:http";
|
|
12743
12988
|
import https from "node:https";
|
|
12744
|
-
import
|
|
12989
|
+
import crypto4 from "node:crypto";
|
|
12745
12990
|
import { execFile, spawn as spawn3 } from "node:child_process";
|
|
12746
12991
|
var PRODUCTION_SEAMS = Object.freeze({ execFile, spawn: spawn3, httpRequest: productionHttpRequest });
|
|
12747
12992
|
var DEFAULT_ENV_DIR = "~/.caw/";
|
|
@@ -13073,7 +13318,7 @@ function launchctlLabelForPid(execFileSeam, uid, pid) {
|
|
|
13073
13318
|
async function classifyPhase1({ options, deps }) {
|
|
13074
13319
|
const {
|
|
13075
13320
|
_execFile,
|
|
13076
|
-
fs: fsDep =
|
|
13321
|
+
fs: fsDep = fs16,
|
|
13077
13322
|
hasTty,
|
|
13078
13323
|
uid,
|
|
13079
13324
|
homeDir,
|
|
@@ -13084,10 +13329,10 @@ async function classifyPhase1({ options, deps }) {
|
|
|
13084
13329
|
const sudoPath = paths.sudo ?? DEFAULT_SUDO_PATH;
|
|
13085
13330
|
const usrLocalCaddy = paths.usrLocalCaddy ?? DEFAULT_USR_LOCAL_CADDY;
|
|
13086
13331
|
const homebrewCaddy = paths.homebrewCaddy ?? DEFAULT_HOMEBREW_CADDY;
|
|
13087
|
-
const caddyfilePath = paths.caddyfile ??
|
|
13088
|
-
const plistPath = paths.plist ??
|
|
13089
|
-
const stdoutLogPath = paths.stdoutLog ??
|
|
13090
|
-
const stderrLogPath = paths.stderrLog ??
|
|
13332
|
+
const caddyfilePath = paths.caddyfile ?? path17.join(homeDir, ".caw", "Caddyfile");
|
|
13333
|
+
const plistPath = paths.plist ?? path17.join(homeDir, "Library", "LaunchAgents", `${options.label}.plist`);
|
|
13334
|
+
const stdoutLogPath = paths.stdoutLog ?? path17.join(homeDir, ".caw", "caddy.out.log");
|
|
13335
|
+
const stderrLogPath = paths.stderrLog ?? path17.join(homeDir, ".caw", "caddy.err.log");
|
|
13091
13336
|
let activeConfig;
|
|
13092
13337
|
try {
|
|
13093
13338
|
activeConfig = readConfigDep(options.envDir);
|
|
@@ -13096,7 +13341,7 @@ async function classifyPhase1({ options, deps }) {
|
|
|
13096
13341
|
return {
|
|
13097
13342
|
tag: "envdir-uninitialised",
|
|
13098
13343
|
exitCode: 1,
|
|
13099
|
-
message: `CAW is not configured on this machine ` + `(no config at ${
|
|
13344
|
+
message: `CAW is not configured on this machine ` + `(no config at ${path17.join(options.envDir, "config.json")}). ` + `Run \`caw start\` first, then \`brew install caddy\`, ` + `then re-run \`caw caddy setup\`.`
|
|
13100
13345
|
};
|
|
13101
13346
|
}
|
|
13102
13347
|
return { tag: "envdir-malformed", exitCode: 1, message: e.message };
|
|
@@ -13375,10 +13620,10 @@ function sha256HexOfPem(pem) {
|
|
|
13375
13620
|
} catch {
|
|
13376
13621
|
return null;
|
|
13377
13622
|
}
|
|
13378
|
-
return
|
|
13623
|
+
return crypto4.createHash("sha256").update(der).digest("hex").toUpperCase();
|
|
13379
13624
|
}
|
|
13380
13625
|
function atomicWriteWithBackup({ fs: fsDep, path: filePath, content }) {
|
|
13381
|
-
fsDep.mkdirSync(
|
|
13626
|
+
fsDep.mkdirSync(path17.dirname(filePath), { recursive: true });
|
|
13382
13627
|
let priorContent = null;
|
|
13383
13628
|
let hadPrior = false;
|
|
13384
13629
|
try {
|
|
@@ -13533,7 +13778,7 @@ async function phase2Provision({ classification, options, deps, seams, generator
|
|
|
13533
13778
|
priorCaPem: null,
|
|
13534
13779
|
priorCaFingerprint: null,
|
|
13535
13780
|
writes: { caddyfile: null, plist: null },
|
|
13536
|
-
envDir:
|
|
13781
|
+
envDir: path17.dirname(classification.paths.stderrLog),
|
|
13537
13782
|
stderrLogPath: classification.paths.stderrLog,
|
|
13538
13783
|
uid: deps.uid,
|
|
13539
13784
|
domain: classification.activeConfig.domain,
|
|
@@ -13821,7 +14066,7 @@ async function performRollback({ rollbackCtx, trigger, error, deps, seams }) {
|
|
|
13821
14066
|
}
|
|
13822
14067
|
}
|
|
13823
14068
|
const stamp = nowIso(deps).replace(/[:.]/g, "-");
|
|
13824
|
-
const logPath =
|
|
14069
|
+
const logPath = path17.join(rollbackCtx.envDir, `caw-caddy-setup-${stamp}.log`);
|
|
13825
14070
|
const logBody = renderRollbackLog({ rollbackCtx, trigger, error, events, verifyResult });
|
|
13826
14071
|
try {
|
|
13827
14072
|
deps.fs.writeFileSync(logPath, logBody);
|
|
@@ -13877,9 +14122,9 @@ function resolveEnvDir7(rawEnvDir, homeDir) {
|
|
|
13877
14122
|
if (typeof homeDir !== "string" || homeDir.length === 0) {
|
|
13878
14123
|
throw new TypeError("resolveEnvDir: homeDir is required when rawEnvDir starts with ~");
|
|
13879
14124
|
}
|
|
13880
|
-
return
|
|
14125
|
+
return path17.resolve(path17.join(homeDir, rawEnvDir.slice(1)));
|
|
13881
14126
|
}
|
|
13882
|
-
return
|
|
14127
|
+
return path17.resolve(rawEnvDir);
|
|
13883
14128
|
}
|
|
13884
14129
|
function isPhase4Idempotent({ resolvedEnvDir, resolvedDomain, deps }) {
|
|
13885
14130
|
const readCfg = deps.readConfig ?? readConfig;
|
|
@@ -14147,9 +14392,9 @@ function renderRecoveryLog({ resolvedEnvDir, resolvedDomain, phase4Result, serve
|
|
|
14147
14392
|
}
|
|
14148
14393
|
function writeRecoveryDiagnostic({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath, deps }) {
|
|
14149
14394
|
const stamp = nowIso(deps).replace(/[:.]/g, "-");
|
|
14150
|
-
const logPath =
|
|
14395
|
+
const logPath = path17.join(resolvedEnvDir, `caw-caddy-setup-${stamp}.log`);
|
|
14151
14396
|
const body = renderRecoveryLog({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath });
|
|
14152
|
-
const fsDep = deps.fs ??
|
|
14397
|
+
const fsDep = deps.fs ?? fs16;
|
|
14153
14398
|
try {
|
|
14154
14399
|
fsDep.writeFileSync(logPath, body);
|
|
14155
14400
|
return { logPath, error: null };
|
|
@@ -14192,7 +14437,7 @@ function createSetupHandler(deps = {}) {
|
|
|
14192
14437
|
});
|
|
14193
14438
|
const phase1Deps = {
|
|
14194
14439
|
_execFile,
|
|
14195
|
-
fs: deps.fs ??
|
|
14440
|
+
fs: deps.fs ?? fs16,
|
|
14196
14441
|
hasTty: deps.hasTty ?? Boolean(process.stdin?.isTTY),
|
|
14197
14442
|
uid: deps.uid ?? (process.getuid ? process.getuid() : 0),
|
|
14198
14443
|
homeDir,
|
|
@@ -14221,7 +14466,7 @@ function createSetupHandler(deps = {}) {
|
|
|
14221
14466
|
out(renderContinueSummary({ classification }));
|
|
14222
14467
|
out("→ Phase 2: Provision");
|
|
14223
14468
|
const phase2Deps = {
|
|
14224
|
-
fs: deps.fs ??
|
|
14469
|
+
fs: deps.fs ?? fs16,
|
|
14225
14470
|
stderr: err,
|
|
14226
14471
|
uid: phase1Deps.uid,
|
|
14227
14472
|
adminPollAttempts: deps.adminPollAttempts,
|
|
@@ -14265,7 +14510,7 @@ function createSetupHandler(deps = {}) {
|
|
|
14265
14510
|
const resolvedEnvDir = options.envDir;
|
|
14266
14511
|
const resolvedDomain = classification.activeConfig.domain;
|
|
14267
14512
|
const phase4Deps = {
|
|
14268
|
-
fs: deps.fs ??
|
|
14513
|
+
fs: deps.fs ?? fs16,
|
|
14269
14514
|
now: deps.now,
|
|
14270
14515
|
readConfig: deps.readConfigRaw ?? readConfig,
|
|
14271
14516
|
writeConfig: deps.writeConfig ?? writeConfig,
|
|
@@ -14400,7 +14645,7 @@ async function runPhase4({ preflight, options, classification, seams, keychainPa
|
|
|
14400
14645
|
return returnBase;
|
|
14401
14646
|
case "recovered": {
|
|
14402
14647
|
out(`← Phase 4: Cutover (recovered)`);
|
|
14403
|
-
const serverLogPath =
|
|
14648
|
+
const serverLogPath = path17.join(resolvedEnvDir, "server.log");
|
|
14404
14649
|
const diag = writeRecoveryDiagnostic({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath, deps: phase4Deps });
|
|
14405
14650
|
err(`Phase 4 (Cutover) failed on new config: ${phase4Result.originalError?.message ?? "(no message)"}. ` + `Reverse restart on prior config is /health-green — machine is on the PRIOR config. ` + `Recovery diagnostic: ${diag.logPath}${diag.error ? ` (write warning: ${diag.error.message})` : ""}`);
|
|
14406
14651
|
exit(1);
|
|
@@ -14408,7 +14653,7 @@ async function runPhase4({ preflight, options, classification, seams, keychainPa
|
|
|
14408
14653
|
}
|
|
14409
14654
|
case "recovery-failed": {
|
|
14410
14655
|
out(`← Phase 4: Cutover (recovery-failed)`);
|
|
14411
|
-
const serverLogPath =
|
|
14656
|
+
const serverLogPath = path17.join(resolvedEnvDir, "server.log");
|
|
14412
14657
|
const diag = writeRecoveryDiagnostic({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath, deps: phase4Deps });
|
|
14413
14658
|
err(`Phase 4 (Cutover) failed on new config: ${phase4Result.originalError?.message ?? "(no message)"}
|
|
14414
14659
|
` + `Reverse restart on prior config ALSO failed: ${phase4Result.recoveryError?.message ?? "(no message)"}
|
|
@@ -14436,8 +14681,9 @@ var caddy_default = caddyGroup;
|
|
|
14436
14681
|
// src/main.js
|
|
14437
14682
|
var [major] = process.versions.node.split(".").map(Number);
|
|
14438
14683
|
if (major < 24) {
|
|
14439
|
-
console.error(`caw requires Node.js 24 or later (found
|
|
14684
|
+
console.error(`caw requires Node.js 24 or later (found ${process.version}).`);
|
|
14440
14685
|
console.error("The caw-server package uses Node 24 features that are not available in older versions.");
|
|
14686
|
+
console.error(`See ${INSTALL_GUIDE_URL} for the full walkthrough.`);
|
|
14441
14687
|
process.exit(1);
|
|
14442
14688
|
}
|
|
14443
14689
|
var globalCheck = checkGlobalInstall();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kelceyp/caw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Unified Web/MCP server with React web app. MD document management, handlebars templating, agent orchestration (aka browser based reskinning of claude code, codex and cursor that allows any of these agents to use any other as subagents) and user stories",
|
|
6
6
|
"keywords": [
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"developer-tools",
|
|
15
15
|
"workflow",
|
|
16
16
|
"knowledge-base",
|
|
17
|
-
"local-first",
|
|
18
17
|
"rag",
|
|
19
18
|
"full-text-search",
|
|
20
19
|
"markdown",
|
|
@@ -41,6 +40,6 @@
|
|
|
41
40
|
"license": "Proprietary. All rights reserved. Free for personal and commercial use. Closed source.",
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@kelceyp/clibuilder": "^0.2.2",
|
|
44
|
-
"semver": "^7"
|
|
43
|
+
"semver": "^7.8.5"
|
|
45
44
|
}
|
|
46
45
|
}
|