@kelceyp/caw 1.0.40 → 1.0.42
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 +15 -7
- package/dist/caw.js +355 -142
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,15 @@ CAW helps users build software **sustainably** using AI by providing agents with
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
+
## Platform support
|
|
8
|
+
|
|
9
|
+
| Platform | Status |
|
|
10
|
+
|---|-----------------|
|
|
11
|
+
| macOS — Apple Silicon | ✅ Supported |
|
|
12
|
+
| macOS — Intel | ✅ Supported |
|
|
13
|
+
| Linux | 🛠️ Coming soon |
|
|
14
|
+
| Windows | 🛠️ Planned |
|
|
15
|
+
|
|
7
16
|
## Quick Start
|
|
8
17
|
|
|
9
18
|
```bash
|
|
@@ -65,16 +74,14 @@ Build your product knowledge base in lock step with your code base.
|
|
|
65
74
|
|
|
66
75
|
Create powerful templates for documents, prompts and saved searches.
|
|
67
76
|
|
|
68
|
-
- Handlebars templating
|
|
77
|
+
- Handlebars templating enabling
|
|
69
78
|
- Substitution
|
|
70
79
|
- Conditionals
|
|
71
80
|
- Enumeration
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
81
|
+
- Comparison
|
|
82
|
+
- Simple arithmetic
|
|
83
|
+
- Splitting, trimming and joining strings
|
|
75
84
|
- Number formatting
|
|
76
|
-
- Word inflection
|
|
77
|
-
- Expressions
|
|
78
85
|
- Type and multivalued enabled
|
|
79
86
|
- Subtypes include document, prompt and saved search, all providing different behaviours
|
|
80
87
|
- Document templates create documents
|
|
@@ -218,6 +225,7 @@ caw stop # Stop the server
|
|
|
218
225
|
caw status # Check if the server is running
|
|
219
226
|
caw logs # Tail the server logs
|
|
220
227
|
caw upgrade # Upgrade to the latest version
|
|
228
|
+
caw caddy setup # Sets up Caddy for use with CAW
|
|
221
229
|
```
|
|
222
230
|
|
|
223
231
|
## Prerequisites
|
|
@@ -226,7 +234,7 @@ caw upgrade # Upgrade to the latest version
|
|
|
226
234
|
|
|
227
235
|
## Optional Integrations
|
|
228
236
|
|
|
229
|
-
All optional integrations are configured via Preferences > Infrastructure in the web UI. These integrations rely on 3rd party tools that require their own installation and setup outside of CAW. For detailed instructions visit [Athena Design](https://athenadesign.com.au/) or
|
|
237
|
+
All optional integrations are configured via Preferences > Infrastructure in the web UI. These integrations rely on 3rd party tools that require their own installation and setup outside of CAW. For detailed instructions visit [Athena Design](https://athenadesign.com.au/caw/) or read the fine manual (RTFM) that ships with CAW. Or even better, have agents RTFM for you and follow the instructions provided.
|
|
230
238
|
|
|
231
239
|
### Caddy
|
|
232
240
|
|
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`;
|
|
@@ -10879,9 +10880,9 @@ function resolve(overrideBinPath) {
|
|
|
10879
10880
|
|
|
10880
10881
|
// src/commands/start.js
|
|
10881
10882
|
import fs8 from "node:fs";
|
|
10882
|
-
import
|
|
10883
|
+
import path9 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}`;
|
|
@@ -11275,16 +11523,16 @@ async function emitCawCmdStop({ config }) {
|
|
|
11275
11523
|
|
|
11276
11524
|
// src/first-run-install.js
|
|
11277
11525
|
import fs7 from "node:fs";
|
|
11278
|
-
import
|
|
11279
|
-
import
|
|
11526
|
+
import path8 from "node:path";
|
|
11527
|
+
import crypto2 from "node:crypto";
|
|
11280
11528
|
|
|
11281
11529
|
// src/bundle-install-lock.js
|
|
11282
11530
|
import fs6 from "node:fs";
|
|
11283
|
-
import
|
|
11531
|
+
import path7 from "node:path";
|
|
11284
11532
|
var LOCK_FILENAME = "config.bundle-install.lock";
|
|
11285
11533
|
var STALE_LOCK_MS = 1e4;
|
|
11286
|
-
function
|
|
11287
|
-
return
|
|
11534
|
+
function lockPathFor2(envDir) {
|
|
11535
|
+
return path7.join(envDir, LOCK_FILENAME);
|
|
11288
11536
|
}
|
|
11289
11537
|
function makeReleaser(lockPath) {
|
|
11290
11538
|
let released = false;
|
|
@@ -11300,7 +11548,7 @@ function makeReleaser(lockPath) {
|
|
|
11300
11548
|
var NOOP_RELEASE = () => {};
|
|
11301
11549
|
function acquire({ envDir }) {
|
|
11302
11550
|
fs6.mkdirSync(envDir, { recursive: true });
|
|
11303
|
-
const lockPath =
|
|
11551
|
+
const lockPath = lockPathFor2(envDir);
|
|
11304
11552
|
try {
|
|
11305
11553
|
const fd = fs6.openSync(lockPath, "wx");
|
|
11306
11554
|
fs6.closeSync(fd);
|
|
@@ -11455,10 +11703,10 @@ function resolveFetch(out) {
|
|
|
11455
11703
|
return out && typeof out.fetch === "function" ? out.fetch : fetch;
|
|
11456
11704
|
}
|
|
11457
11705
|
function stagedZipPath(envDir, name) {
|
|
11458
|
-
return
|
|
11706
|
+
return path8.join(envDir, SHARED_EXPORTS_DIR, `${name}.zip`);
|
|
11459
11707
|
}
|
|
11460
11708
|
function sha256File(filePath) {
|
|
11461
|
-
return
|
|
11709
|
+
return crypto2.createHash("sha256").update(fs7.readFileSync(filePath)).digest("hex");
|
|
11462
11710
|
}
|
|
11463
11711
|
async function fetchInfo(port, fetchFn) {
|
|
11464
11712
|
const controller = new AbortController;
|
|
@@ -11485,7 +11733,7 @@ async function downloadTo(url, targetPath, fetchFn) {
|
|
|
11485
11733
|
throw new Error(`download: HTTP ${res.status} for ${url}`);
|
|
11486
11734
|
}
|
|
11487
11735
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
11488
|
-
fs7.mkdirSync(
|
|
11736
|
+
fs7.mkdirSync(path8.dirname(targetPath), { recursive: true });
|
|
11489
11737
|
fs7.writeFileSync(targetPath, buf);
|
|
11490
11738
|
}
|
|
11491
11739
|
async function postImport(port, filename, fetchFn) {
|
|
@@ -11520,18 +11768,18 @@ async function postImport(port, filename, fetchFn) {
|
|
|
11520
11768
|
function filenameFromCatalogueEntry(entry, name) {
|
|
11521
11769
|
try {
|
|
11522
11770
|
const u = new URL(entry.url);
|
|
11523
|
-
const base =
|
|
11771
|
+
const base = path8.basename(u.pathname);
|
|
11524
11772
|
return base && base.length > 0 ? base : `${name}.zip`;
|
|
11525
11773
|
} catch {
|
|
11526
11774
|
return `${name}.zip`;
|
|
11527
11775
|
}
|
|
11528
11776
|
}
|
|
11529
11777
|
async function ensureLocalBundleFile({ envDir, name, entry, fetchFn }) {
|
|
11530
|
-
const sharedDir =
|
|
11778
|
+
const sharedDir = path8.join(envDir, SHARED_EXPORTS_DIR);
|
|
11531
11779
|
fs7.mkdirSync(sharedDir, { recursive: true });
|
|
11532
11780
|
if (entry) {
|
|
11533
11781
|
const filename = filenameFromCatalogueEntry(entry, name);
|
|
11534
|
-
const filePath =
|
|
11782
|
+
const filePath = path8.join(sharedDir, filename);
|
|
11535
11783
|
let needDownload = !fs7.existsSync(filePath);
|
|
11536
11784
|
if (!needDownload && entry.sha256) {
|
|
11537
11785
|
try {
|
|
@@ -11726,12 +11974,12 @@ var __test__2 = Object.freeze({ OUTCOME, INFO_TIMEOUT_MS, SHARED_EXPORTS_DIR });
|
|
|
11726
11974
|
// src/commands/start.js
|
|
11727
11975
|
function resolveEnvDir(rawEnvDir) {
|
|
11728
11976
|
if (rawEnvDir.startsWith("~")) {
|
|
11729
|
-
rawEnvDir =
|
|
11977
|
+
rawEnvDir = path9.join(os2.homedir(), rawEnvDir.slice(1));
|
|
11730
11978
|
}
|
|
11731
|
-
return
|
|
11979
|
+
return path9.resolve(rawEnvDir);
|
|
11732
11980
|
}
|
|
11733
11981
|
function validateEnvFile(envDir) {
|
|
11734
|
-
const envFilePath =
|
|
11982
|
+
const envFilePath = path9.join(envDir, ".env");
|
|
11735
11983
|
if (!fs8.existsSync(envFilePath)) {
|
|
11736
11984
|
return {
|
|
11737
11985
|
ok: false,
|
|
@@ -11761,7 +12009,7 @@ var MAX_LOG_SIZE = 10 * 1024 * 1024;
|
|
|
11761
12009
|
var LOG_RETAIN = 5;
|
|
11762
12010
|
function rotateLogIfNeeded(envDir) {
|
|
11763
12011
|
try {
|
|
11764
|
-
const logPath =
|
|
12012
|
+
const logPath = path9.join(envDir, "server.log");
|
|
11765
12013
|
if (!fs8.existsSync(logPath))
|
|
11766
12014
|
return;
|
|
11767
12015
|
const stats = fs8.statSync(logPath);
|
|
@@ -11780,37 +12028,26 @@ function rotateLogIfNeeded(envDir) {
|
|
|
11780
12028
|
].join("-");
|
|
11781
12029
|
fs8.renameSync(logPath, `${logPath}.${timestamp}`);
|
|
11782
12030
|
console.log(`Rotated server.log (was ${(stats.size / 1024 / 1024).toFixed(1)} MB)`);
|
|
11783
|
-
const rotated = fs8.readdirSync(envDir).filter((f) => f.startsWith("server.log.")).map((f) => ({ name: f, mtime: fs8.statSync(
|
|
12031
|
+
const rotated = fs8.readdirSync(envDir).filter((f) => f.startsWith("server.log.")).map((f) => ({ name: f, mtime: fs8.statSync(path9.join(envDir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
|
|
11784
12032
|
for (const file of rotated.slice(LOG_RETAIN)) {
|
|
11785
|
-
fs8.unlinkSync(
|
|
12033
|
+
fs8.unlinkSync(path9.join(envDir, file.name));
|
|
11786
12034
|
}
|
|
11787
12035
|
} catch (err) {
|
|
11788
12036
|
console.warn(`Warning: log rotation failed: ${err.message}`);
|
|
11789
12037
|
}
|
|
11790
12038
|
}
|
|
11791
12039
|
function buildEnvNodeArgs(envDir) {
|
|
11792
|
-
const envFilePath =
|
|
12040
|
+
const envFilePath = path9.join(envDir, ".env");
|
|
11793
12041
|
return [`--env-file=${envFilePath}`];
|
|
11794
12042
|
}
|
|
11795
12043
|
function buildServerEnvVars(activeConfig, envDir) {
|
|
11796
12044
|
if (typeof envDir !== "string" || envDir.length === 0) {
|
|
11797
12045
|
throw new Error("buildServerEnvVars: envDir is required (server main.js exits when CAW_ENV_DIR is unset)");
|
|
11798
12046
|
}
|
|
11799
|
-
|
|
12047
|
+
return {
|
|
11800
12048
|
CAW_PORT: String(activeConfig.port),
|
|
11801
12049
|
CAW_ENV_DIR: envDir
|
|
11802
12050
|
};
|
|
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
12051
|
}
|
|
11815
12052
|
function hasFullIdentity(config) {
|
|
11816
12053
|
return typeof config?.installId === "string" && config.installId.length > 0 && typeof config?.installSalt === "string" && config.installSalt.length > 0 && typeof config?.analyticsEnabled === "boolean";
|
|
@@ -11822,60 +12059,33 @@ function ensureInstallIdentity(envDir) {
|
|
|
11822
12059
|
return existing;
|
|
11823
12060
|
}
|
|
11824
12061
|
fs8.mkdirSync(envDir, { recursive: true });
|
|
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 {}
|
|
12062
|
+
return identity_lock_default.withIdentityLock({
|
|
12063
|
+
envDir,
|
|
12064
|
+
section: (lock) => {
|
|
12065
|
+
const existing = configExists(envDir) ? readConfig(envDir) : { ...DEFAULTS };
|
|
12066
|
+
if (hasFullIdentity(existing)) {
|
|
12067
|
+
lock.commitNothing();
|
|
12068
|
+
return existing;
|
|
12069
|
+
}
|
|
12070
|
+
const merged = { ...existing };
|
|
12071
|
+
if (typeof merged.installId !== "string" || merged.installId.length === 0) {
|
|
12072
|
+
merged.installId = crypto3.randomUUID();
|
|
12073
|
+
}
|
|
12074
|
+
if (typeof merged.installSalt !== "string" || merged.installSalt.length === 0) {
|
|
12075
|
+
merged.installSalt = crypto3.randomBytes(32).toString("base64url");
|
|
12076
|
+
}
|
|
12077
|
+
if (typeof merged.analyticsEnabled !== "boolean") {
|
|
12078
|
+
merged.analyticsEnabled = DEFAULTS.analyticsEnabled;
|
|
12079
|
+
}
|
|
12080
|
+
return writeConfigFenced(envDir, merged, lock);
|
|
11871
12081
|
}
|
|
11872
|
-
}
|
|
12082
|
+
});
|
|
11873
12083
|
}
|
|
11874
12084
|
function bootstrap(envDir) {
|
|
11875
12085
|
fs8.mkdirSync(envDir, { recursive: true });
|
|
11876
|
-
fs8.mkdirSync(
|
|
12086
|
+
fs8.mkdirSync(path9.join(envDir, "assets"), { recursive: true });
|
|
11877
12087
|
ensureInstallIdentity(envDir);
|
|
11878
|
-
const envFilePath =
|
|
12088
|
+
const envFilePath = path9.join(envDir, ".env");
|
|
11879
12089
|
if (!fs8.existsSync(envFilePath)) {
|
|
11880
12090
|
fs8.writeFileSync(envFilePath, [
|
|
11881
12091
|
"# CAW environment configuration",
|
|
@@ -12041,7 +12251,7 @@ How would you like to proceed?`,
|
|
|
12041
12251
|
const started = await pollHealth(activeConfig.port);
|
|
12042
12252
|
if (!started) {
|
|
12043
12253
|
console.error(`Server did not become healthy within 10 seconds.`);
|
|
12044
|
-
console.error(`Check logs with: caw logs${envDir !==
|
|
12254
|
+
console.error(`Check logs with: caw logs${envDir !== path9.join(os2.homedir(), ".caw") ? ` --env-dir ${envDir}` : ""}`);
|
|
12045
12255
|
process.exit(1);
|
|
12046
12256
|
}
|
|
12047
12257
|
console.log(`Server started successfully on http://localhost:${activeConfig.port}`);
|
|
@@ -12052,13 +12262,13 @@ var start_default = Object.freeze({ create: create2 });
|
|
|
12052
12262
|
|
|
12053
12263
|
// src/commands/stop.js
|
|
12054
12264
|
import fs9 from "node:fs";
|
|
12055
|
-
import
|
|
12265
|
+
import path10 from "node:path";
|
|
12056
12266
|
import os3 from "node:os";
|
|
12057
12267
|
function resolveEnvDir2(rawEnvDir) {
|
|
12058
12268
|
if (rawEnvDir.startsWith("~")) {
|
|
12059
|
-
rawEnvDir =
|
|
12269
|
+
rawEnvDir = path10.join(os3.homedir(), rawEnvDir.slice(1));
|
|
12060
12270
|
}
|
|
12061
|
-
return
|
|
12271
|
+
return path10.resolve(rawEnvDir);
|
|
12062
12272
|
}
|
|
12063
12273
|
async function checkHealth2(port) {
|
|
12064
12274
|
try {
|
|
@@ -12150,12 +12360,12 @@ var stop_default = Object.freeze({ create: create3 });
|
|
|
12150
12360
|
// src/commands/status.js
|
|
12151
12361
|
var import_semver = __toESM(require_semver2(), 1);
|
|
12152
12362
|
import fs11 from "node:fs";
|
|
12153
|
-
import
|
|
12363
|
+
import path12 from "node:path";
|
|
12154
12364
|
import os4 from "node:os";
|
|
12155
12365
|
|
|
12156
12366
|
// src/registry.js
|
|
12157
12367
|
import fs10 from "node:fs";
|
|
12158
|
-
import
|
|
12368
|
+
import path11 from "node:path";
|
|
12159
12369
|
var CACHE_FILENAME = "caw-cache.json";
|
|
12160
12370
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
12161
12371
|
var DEFAULT_TTL_MS = 60 * 60 * 1000;
|
|
@@ -12171,7 +12381,7 @@ async function fetchLatestVersion(packageName, { timeoutMs = DEFAULT_TIMEOUT_MS
|
|
|
12171
12381
|
return data["dist-tags"].latest;
|
|
12172
12382
|
}
|
|
12173
12383
|
function readCache(envDir) {
|
|
12174
|
-
const cachePath =
|
|
12384
|
+
const cachePath = path11.join(envDir, CACHE_FILENAME);
|
|
12175
12385
|
try {
|
|
12176
12386
|
return JSON.parse(fs10.readFileSync(cachePath, "utf8"));
|
|
12177
12387
|
} catch {
|
|
@@ -12179,7 +12389,7 @@ function readCache(envDir) {
|
|
|
12179
12389
|
}
|
|
12180
12390
|
}
|
|
12181
12391
|
function writeCache(envDir, cache) {
|
|
12182
|
-
const cachePath =
|
|
12392
|
+
const cachePath = path11.join(envDir, CACHE_FILENAME);
|
|
12183
12393
|
const tmp = cachePath + ".tmp";
|
|
12184
12394
|
fs10.writeFileSync(tmp, JSON.stringify(cache, null, 2));
|
|
12185
12395
|
fs10.renameSync(tmp, cachePath);
|
|
@@ -12199,9 +12409,9 @@ function isCacheStale(cache, ttlMs = DEFAULT_TTL_MS) {
|
|
|
12199
12409
|
// src/commands/status.js
|
|
12200
12410
|
function resolveEnvDir3(rawEnvDir) {
|
|
12201
12411
|
if (rawEnvDir.startsWith("~")) {
|
|
12202
|
-
rawEnvDir =
|
|
12412
|
+
rawEnvDir = path12.join(os4.homedir(), rawEnvDir.slice(1));
|
|
12203
12413
|
}
|
|
12204
|
-
return
|
|
12414
|
+
return path12.resolve(rawEnvDir);
|
|
12205
12415
|
}
|
|
12206
12416
|
async function fetchHealth(port) {
|
|
12207
12417
|
try {
|
|
@@ -12325,19 +12535,19 @@ var status_default = Object.freeze({ create: create4 });
|
|
|
12325
12535
|
|
|
12326
12536
|
// src/commands/logs.js
|
|
12327
12537
|
import fs12 from "node:fs";
|
|
12328
|
-
import
|
|
12538
|
+
import path13 from "node:path";
|
|
12329
12539
|
import os5 from "node:os";
|
|
12330
12540
|
import { spawn as spawn2 } from "node:child_process";
|
|
12331
12541
|
function resolveEnvDir4(rawEnvDir) {
|
|
12332
12542
|
if (rawEnvDir.startsWith("~")) {
|
|
12333
|
-
rawEnvDir =
|
|
12543
|
+
rawEnvDir = path13.join(os5.homedir(), rawEnvDir.slice(1));
|
|
12334
12544
|
}
|
|
12335
|
-
return
|
|
12545
|
+
return path13.resolve(rawEnvDir);
|
|
12336
12546
|
}
|
|
12337
12547
|
var create5 = () => {
|
|
12338
12548
|
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
12549
|
const envDir = resolveEnvDir4(ctx.params["env-dir"]);
|
|
12340
|
-
const logPath =
|
|
12550
|
+
const logPath = path13.join(envDir, "server.log");
|
|
12341
12551
|
if (!fs12.existsSync(logPath)) {
|
|
12342
12552
|
console.log(`No log file found at ${logPath}`);
|
|
12343
12553
|
process.exit(0);
|
|
@@ -12361,15 +12571,15 @@ var logs_default = Object.freeze({ create: create5 });
|
|
|
12361
12571
|
// src/commands/upgrade.js
|
|
12362
12572
|
var import_semver2 = __toESM(require_semver2(), 1);
|
|
12363
12573
|
import fs13 from "node:fs";
|
|
12364
|
-
import
|
|
12574
|
+
import path14 from "node:path";
|
|
12365
12575
|
import os6 from "node:os";
|
|
12366
12576
|
import { execSync as execSync5 } from "node:child_process";
|
|
12367
12577
|
var COMPATIBLE_SERVER_RANGE = "^1";
|
|
12368
12578
|
function resolveEnvDir5(rawEnvDir) {
|
|
12369
12579
|
if (rawEnvDir.startsWith("~")) {
|
|
12370
|
-
rawEnvDir =
|
|
12580
|
+
rawEnvDir = path14.join(os6.homedir(), rawEnvDir.slice(1));
|
|
12371
12581
|
}
|
|
12372
|
-
return
|
|
12582
|
+
return path14.resolve(rawEnvDir);
|
|
12373
12583
|
}
|
|
12374
12584
|
async function checkHealth3(port) {
|
|
12375
12585
|
try {
|
|
@@ -12498,6 +12708,13 @@ var create6 = () => {
|
|
|
12498
12708
|
console.log("Rerun `caw upgrade` to complete the server upgrade.");
|
|
12499
12709
|
process.exit(0);
|
|
12500
12710
|
}
|
|
12711
|
+
if (fs13.existsSync(envDir) && configExists(envDir)) {
|
|
12712
|
+
const envCheck = validateEnvFile(envDir);
|
|
12713
|
+
if (!envCheck.ok) {
|
|
12714
|
+
console.error(envCheck.message);
|
|
12715
|
+
process.exit(1);
|
|
12716
|
+
}
|
|
12717
|
+
}
|
|
12501
12718
|
let serverWasStopped = false;
|
|
12502
12719
|
if (fs13.existsSync(envDir) && configExists(envDir)) {
|
|
12503
12720
|
const config = readConfigWithDefaults(envDir);
|
|
@@ -12558,12 +12775,8 @@ var create6 = () => {
|
|
|
12558
12775
|
console.error(`Error: Server upgraded to ${latestServerVersion} but failed to start. Check logs with 'caw logs'. Start manually with 'caw start'.`);
|
|
12559
12776
|
process.exit(1);
|
|
12560
12777
|
}
|
|
12561
|
-
const envVars = {
|
|
12562
|
-
CAW_PORT: String(config.port),
|
|
12563
|
-
CAW_ENV_DIR: envDir
|
|
12564
|
-
};
|
|
12565
12778
|
console.log("Starting server...");
|
|
12566
|
-
pm.start(newServerInfo.mainJsPath,
|
|
12779
|
+
pm.start(newServerInfo.mainJsPath, buildServerEnvVars(config, envDir), buildEnvNodeArgs(envDir));
|
|
12567
12780
|
const started = await pollHealth2(config.port);
|
|
12568
12781
|
if (!started) {
|
|
12569
12782
|
console.error(`Error: Server upgraded to ${latestServerVersion} but failed to start. Check logs with 'caw logs'. Start manually with 'caw start'.`);
|
|
@@ -12581,14 +12794,14 @@ var upgrade_default = Object.freeze({ create: create6 });
|
|
|
12581
12794
|
|
|
12582
12795
|
// src/commands/restart.js
|
|
12583
12796
|
import fs14 from "node:fs";
|
|
12584
|
-
import
|
|
12797
|
+
import path15 from "node:path";
|
|
12585
12798
|
import os7 from "node:os";
|
|
12586
12799
|
import { execSync as execSync6 } from "node:child_process";
|
|
12587
12800
|
function resolveEnvDir6(rawEnvDir) {
|
|
12588
12801
|
if (rawEnvDir.startsWith("~")) {
|
|
12589
|
-
rawEnvDir =
|
|
12802
|
+
rawEnvDir = path15.join(os7.homedir(), rawEnvDir.slice(1));
|
|
12590
12803
|
}
|
|
12591
|
-
return
|
|
12804
|
+
return path15.resolve(rawEnvDir);
|
|
12592
12805
|
}
|
|
12593
12806
|
function buildChangeSummary2(active, pending) {
|
|
12594
12807
|
const changes = [];
|
|
@@ -12727,7 +12940,7 @@ How would you like to proceed?`,
|
|
|
12727
12940
|
const started = await pollHealth(activeConfig.port);
|
|
12728
12941
|
if (!started) {
|
|
12729
12942
|
console.error(`Server did not become healthy within 10 seconds.`);
|
|
12730
|
-
console.error(`Check logs with: caw logs${envDir !==
|
|
12943
|
+
console.error(`Check logs with: caw logs${envDir !== path15.join(os7.homedir(), ".caw") ? ` --env-dir ${envDir}` : ""}`);
|
|
12731
12944
|
process.exit(1);
|
|
12732
12945
|
}
|
|
12733
12946
|
console.log(`Server started successfully on http://localhost:${activeConfig.port}`);
|
|
@@ -12737,11 +12950,11 @@ var restart_default = Object.freeze({ create: create7 });
|
|
|
12737
12950
|
|
|
12738
12951
|
// src/commands/caddy.js
|
|
12739
12952
|
import fs15 from "node:fs";
|
|
12740
|
-
import
|
|
12953
|
+
import path16 from "node:path";
|
|
12741
12954
|
import os8 from "node:os";
|
|
12742
12955
|
import http from "node:http";
|
|
12743
12956
|
import https from "node:https";
|
|
12744
|
-
import
|
|
12957
|
+
import crypto4 from "node:crypto";
|
|
12745
12958
|
import { execFile, spawn as spawn3 } from "node:child_process";
|
|
12746
12959
|
var PRODUCTION_SEAMS = Object.freeze({ execFile, spawn: spawn3, httpRequest: productionHttpRequest });
|
|
12747
12960
|
var DEFAULT_ENV_DIR = "~/.caw/";
|
|
@@ -13084,10 +13297,10 @@ async function classifyPhase1({ options, deps }) {
|
|
|
13084
13297
|
const sudoPath = paths.sudo ?? DEFAULT_SUDO_PATH;
|
|
13085
13298
|
const usrLocalCaddy = paths.usrLocalCaddy ?? DEFAULT_USR_LOCAL_CADDY;
|
|
13086
13299
|
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 ??
|
|
13300
|
+
const caddyfilePath = paths.caddyfile ?? path16.join(homeDir, ".caw", "Caddyfile");
|
|
13301
|
+
const plistPath = paths.plist ?? path16.join(homeDir, "Library", "LaunchAgents", `${options.label}.plist`);
|
|
13302
|
+
const stdoutLogPath = paths.stdoutLog ?? path16.join(homeDir, ".caw", "caddy.out.log");
|
|
13303
|
+
const stderrLogPath = paths.stderrLog ?? path16.join(homeDir, ".caw", "caddy.err.log");
|
|
13091
13304
|
let activeConfig;
|
|
13092
13305
|
try {
|
|
13093
13306
|
activeConfig = readConfigDep(options.envDir);
|
|
@@ -13096,7 +13309,7 @@ async function classifyPhase1({ options, deps }) {
|
|
|
13096
13309
|
return {
|
|
13097
13310
|
tag: "envdir-uninitialised",
|
|
13098
13311
|
exitCode: 1,
|
|
13099
|
-
message: `CAW is not configured on this machine ` + `(no config at ${
|
|
13312
|
+
message: `CAW is not configured on this machine ` + `(no config at ${path16.join(options.envDir, "config.json")}). ` + `Run \`caw start\` first, then \`brew install caddy\`, ` + `then re-run \`caw caddy setup\`.`
|
|
13100
13313
|
};
|
|
13101
13314
|
}
|
|
13102
13315
|
return { tag: "envdir-malformed", exitCode: 1, message: e.message };
|
|
@@ -13375,10 +13588,10 @@ function sha256HexOfPem(pem) {
|
|
|
13375
13588
|
} catch {
|
|
13376
13589
|
return null;
|
|
13377
13590
|
}
|
|
13378
|
-
return
|
|
13591
|
+
return crypto4.createHash("sha256").update(der).digest("hex").toUpperCase();
|
|
13379
13592
|
}
|
|
13380
13593
|
function atomicWriteWithBackup({ fs: fsDep, path: filePath, content }) {
|
|
13381
|
-
fsDep.mkdirSync(
|
|
13594
|
+
fsDep.mkdirSync(path16.dirname(filePath), { recursive: true });
|
|
13382
13595
|
let priorContent = null;
|
|
13383
13596
|
let hadPrior = false;
|
|
13384
13597
|
try {
|
|
@@ -13533,7 +13746,7 @@ async function phase2Provision({ classification, options, deps, seams, generator
|
|
|
13533
13746
|
priorCaPem: null,
|
|
13534
13747
|
priorCaFingerprint: null,
|
|
13535
13748
|
writes: { caddyfile: null, plist: null },
|
|
13536
|
-
envDir:
|
|
13749
|
+
envDir: path16.dirname(classification.paths.stderrLog),
|
|
13537
13750
|
stderrLogPath: classification.paths.stderrLog,
|
|
13538
13751
|
uid: deps.uid,
|
|
13539
13752
|
domain: classification.activeConfig.domain,
|
|
@@ -13821,7 +14034,7 @@ async function performRollback({ rollbackCtx, trigger, error, deps, seams }) {
|
|
|
13821
14034
|
}
|
|
13822
14035
|
}
|
|
13823
14036
|
const stamp = nowIso(deps).replace(/[:.]/g, "-");
|
|
13824
|
-
const logPath =
|
|
14037
|
+
const logPath = path16.join(rollbackCtx.envDir, `caw-caddy-setup-${stamp}.log`);
|
|
13825
14038
|
const logBody = renderRollbackLog({ rollbackCtx, trigger, error, events, verifyResult });
|
|
13826
14039
|
try {
|
|
13827
14040
|
deps.fs.writeFileSync(logPath, logBody);
|
|
@@ -13877,9 +14090,9 @@ function resolveEnvDir7(rawEnvDir, homeDir) {
|
|
|
13877
14090
|
if (typeof homeDir !== "string" || homeDir.length === 0) {
|
|
13878
14091
|
throw new TypeError("resolveEnvDir: homeDir is required when rawEnvDir starts with ~");
|
|
13879
14092
|
}
|
|
13880
|
-
return
|
|
14093
|
+
return path16.resolve(path16.join(homeDir, rawEnvDir.slice(1)));
|
|
13881
14094
|
}
|
|
13882
|
-
return
|
|
14095
|
+
return path16.resolve(rawEnvDir);
|
|
13883
14096
|
}
|
|
13884
14097
|
function isPhase4Idempotent({ resolvedEnvDir, resolvedDomain, deps }) {
|
|
13885
14098
|
const readCfg = deps.readConfig ?? readConfig;
|
|
@@ -14147,7 +14360,7 @@ function renderRecoveryLog({ resolvedEnvDir, resolvedDomain, phase4Result, serve
|
|
|
14147
14360
|
}
|
|
14148
14361
|
function writeRecoveryDiagnostic({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath, deps }) {
|
|
14149
14362
|
const stamp = nowIso(deps).replace(/[:.]/g, "-");
|
|
14150
|
-
const logPath =
|
|
14363
|
+
const logPath = path16.join(resolvedEnvDir, `caw-caddy-setup-${stamp}.log`);
|
|
14151
14364
|
const body = renderRecoveryLog({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath });
|
|
14152
14365
|
const fsDep = deps.fs ?? fs15;
|
|
14153
14366
|
try {
|
|
@@ -14400,7 +14613,7 @@ async function runPhase4({ preflight, options, classification, seams, keychainPa
|
|
|
14400
14613
|
return returnBase;
|
|
14401
14614
|
case "recovered": {
|
|
14402
14615
|
out(`← Phase 4: Cutover (recovered)`);
|
|
14403
|
-
const serverLogPath =
|
|
14616
|
+
const serverLogPath = path16.join(resolvedEnvDir, "server.log");
|
|
14404
14617
|
const diag = writeRecoveryDiagnostic({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath, deps: phase4Deps });
|
|
14405
14618
|
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
14619
|
exit(1);
|
|
@@ -14408,7 +14621,7 @@ async function runPhase4({ preflight, options, classification, seams, keychainPa
|
|
|
14408
14621
|
}
|
|
14409
14622
|
case "recovery-failed": {
|
|
14410
14623
|
out(`← Phase 4: Cutover (recovery-failed)`);
|
|
14411
|
-
const serverLogPath =
|
|
14624
|
+
const serverLogPath = path16.join(resolvedEnvDir, "server.log");
|
|
14412
14625
|
const diag = writeRecoveryDiagnostic({ resolvedEnvDir, resolvedDomain, phase4Result, serverLogPath, deps: phase4Deps });
|
|
14413
14626
|
err(`Phase 4 (Cutover) failed on new config: ${phase4Result.originalError?.message ?? "(no message)"}
|
|
14414
14627
|
` + `Reverse restart on prior config ALSO failed: ${phase4Result.recoveryError?.message ?? "(no message)"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kelceyp/caw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
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": [
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"license": "Proprietary. All rights reserved. Free for personal and commercial use. Closed source.",
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@kelceyp/clibuilder": "^0.2.2",
|
|
44
|
-
"semver": "^7"
|
|
44
|
+
"semver": "^7.8.5"
|
|
45
45
|
}
|
|
46
46
|
}
|