@kelceyp/caw 1.0.27 → 1.0.30
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/dist/caw.js +203 -44
- package/dist/postinstall.js +144 -0
- package/package.json +3 -4
- package/scripts/postinstall.js +0 -14
package/dist/caw.js
CHANGED
|
@@ -7747,8 +7747,8 @@ var require_constants = __commonJS((exports, module) => {
|
|
|
7747
7747
|
|
|
7748
7748
|
// node_modules/semver/internal/debug.js
|
|
7749
7749
|
var require_debug = __commonJS((exports, module) => {
|
|
7750
|
-
var
|
|
7751
|
-
module.exports =
|
|
7750
|
+
var debug2 = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {};
|
|
7751
|
+
module.exports = debug2;
|
|
7752
7752
|
});
|
|
7753
7753
|
|
|
7754
7754
|
// node_modules/semver/internal/re.js
|
|
@@ -7758,7 +7758,7 @@ var require_re = __commonJS((exports, module) => {
|
|
|
7758
7758
|
MAX_SAFE_BUILD_LENGTH,
|
|
7759
7759
|
MAX_LENGTH
|
|
7760
7760
|
} = require_constants();
|
|
7761
|
-
var
|
|
7761
|
+
var debug2 = require_debug();
|
|
7762
7762
|
exports = module.exports = {};
|
|
7763
7763
|
var re = exports.re = [];
|
|
7764
7764
|
var safeRe = exports.safeRe = [];
|
|
@@ -7781,7 +7781,7 @@ var require_re = __commonJS((exports, module) => {
|
|
|
7781
7781
|
var createToken = (name, value, isGlobal) => {
|
|
7782
7782
|
const safe = makeSafeRegex(value);
|
|
7783
7783
|
const index = R++;
|
|
7784
|
-
|
|
7784
|
+
debug2(name, index, value);
|
|
7785
7785
|
t[name] = index;
|
|
7786
7786
|
src[index] = value;
|
|
7787
7787
|
safeSrc[index] = safe;
|
|
@@ -7876,7 +7876,7 @@ var require_identifiers = __commonJS((exports, module) => {
|
|
|
7876
7876
|
|
|
7877
7877
|
// node_modules/semver/classes/semver.js
|
|
7878
7878
|
var require_semver = __commonJS((exports, module) => {
|
|
7879
|
-
var
|
|
7879
|
+
var debug2 = require_debug();
|
|
7880
7880
|
var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
|
|
7881
7881
|
var { safeRe: re, t } = require_re();
|
|
7882
7882
|
var parseOptions = require_parse_options();
|
|
@@ -7909,7 +7909,7 @@ var require_semver = __commonJS((exports, module) => {
|
|
|
7909
7909
|
if (version.length > MAX_LENGTH) {
|
|
7910
7910
|
throw new TypeError(`version is longer than ${MAX_LENGTH} characters`);
|
|
7911
7911
|
}
|
|
7912
|
-
|
|
7912
|
+
debug2("SemVer", version, options);
|
|
7913
7913
|
this.options = options;
|
|
7914
7914
|
this.loose = !!options.loose;
|
|
7915
7915
|
this.includePrerelease = !!options.includePrerelease;
|
|
@@ -7957,7 +7957,7 @@ var require_semver = __commonJS((exports, module) => {
|
|
|
7957
7957
|
return this.version;
|
|
7958
7958
|
}
|
|
7959
7959
|
compare(other) {
|
|
7960
|
-
|
|
7960
|
+
debug2("SemVer.compare", this.version, this.options, other);
|
|
7961
7961
|
if (!(other instanceof SemVer)) {
|
|
7962
7962
|
if (typeof other === "string" && other === this.version) {
|
|
7963
7963
|
return 0;
|
|
@@ -8008,7 +8008,7 @@ var require_semver = __commonJS((exports, module) => {
|
|
|
8008
8008
|
do {
|
|
8009
8009
|
const a = this.prerelease[i];
|
|
8010
8010
|
const b = other.prerelease[i];
|
|
8011
|
-
|
|
8011
|
+
debug2("prerelease compare", i, a, b);
|
|
8012
8012
|
if (a === undefined && b === undefined) {
|
|
8013
8013
|
return 0;
|
|
8014
8014
|
} else if (b === undefined) {
|
|
@@ -8030,7 +8030,7 @@ var require_semver = __commonJS((exports, module) => {
|
|
|
8030
8030
|
do {
|
|
8031
8031
|
const a = this.build[i];
|
|
8032
8032
|
const b = other.build[i];
|
|
8033
|
-
|
|
8033
|
+
debug2("build compare", i, a, b);
|
|
8034
8034
|
if (a === undefined && b === undefined) {
|
|
8035
8035
|
return 0;
|
|
8036
8036
|
} else if (b === undefined) {
|
|
@@ -8615,21 +8615,21 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8615
8615
|
const loose = this.options.loose;
|
|
8616
8616
|
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
|
|
8617
8617
|
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
|
8618
|
-
|
|
8618
|
+
debug2("hyphen replace", range);
|
|
8619
8619
|
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
8620
|
-
|
|
8620
|
+
debug2("comparator trim", range);
|
|
8621
8621
|
range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
|
|
8622
|
-
|
|
8622
|
+
debug2("tilde trim", range);
|
|
8623
8623
|
range = range.replace(re[t.CARETTRIM], caretTrimReplace);
|
|
8624
|
-
|
|
8624
|
+
debug2("caret trim", range);
|
|
8625
8625
|
let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
|
|
8626
8626
|
if (loose) {
|
|
8627
8627
|
rangeList = rangeList.filter((comp) => {
|
|
8628
|
-
|
|
8628
|
+
debug2("loose invalid filter", comp, this.options);
|
|
8629
8629
|
return !!comp.match(re[t.COMPARATORLOOSE]);
|
|
8630
8630
|
});
|
|
8631
8631
|
}
|
|
8632
|
-
|
|
8632
|
+
debug2("range list", rangeList);
|
|
8633
8633
|
const rangeMap = new Map;
|
|
8634
8634
|
const comparators = rangeList.map((comp) => new Comparator(comp, this.options));
|
|
8635
8635
|
for (const comp of comparators) {
|
|
@@ -8683,7 +8683,7 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8683
8683
|
var cache = new LRU;
|
|
8684
8684
|
var parseOptions = require_parse_options();
|
|
8685
8685
|
var Comparator = require_comparator();
|
|
8686
|
-
var
|
|
8686
|
+
var debug2 = require_debug();
|
|
8687
8687
|
var SemVer = require_semver();
|
|
8688
8688
|
var {
|
|
8689
8689
|
safeRe: re,
|
|
@@ -8711,15 +8711,15 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8711
8711
|
};
|
|
8712
8712
|
var parseComparator = (comp, options) => {
|
|
8713
8713
|
comp = comp.replace(re[t.BUILD], "");
|
|
8714
|
-
|
|
8714
|
+
debug2("comp", comp, options);
|
|
8715
8715
|
comp = replaceCarets(comp, options);
|
|
8716
|
-
|
|
8716
|
+
debug2("caret", comp);
|
|
8717
8717
|
comp = replaceTildes(comp, options);
|
|
8718
|
-
|
|
8718
|
+
debug2("tildes", comp);
|
|
8719
8719
|
comp = replaceXRanges(comp, options);
|
|
8720
|
-
|
|
8720
|
+
debug2("xrange", comp);
|
|
8721
8721
|
comp = replaceStars(comp, options);
|
|
8722
|
-
|
|
8722
|
+
debug2("stars", comp);
|
|
8723
8723
|
return comp;
|
|
8724
8724
|
};
|
|
8725
8725
|
var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
|
|
@@ -8730,7 +8730,7 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8730
8730
|
var replaceTilde = (comp, options) => {
|
|
8731
8731
|
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
8732
8732
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
8733
|
-
|
|
8733
|
+
debug2("tilde", comp, _, M, m, p, pr);
|
|
8734
8734
|
let ret;
|
|
8735
8735
|
if (isX(M)) {
|
|
8736
8736
|
ret = "";
|
|
@@ -8739,12 +8739,12 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8739
8739
|
} else if (isX(p)) {
|
|
8740
8740
|
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
8741
8741
|
} else if (pr) {
|
|
8742
|
-
|
|
8742
|
+
debug2("replaceTilde pr", pr);
|
|
8743
8743
|
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
8744
8744
|
} else {
|
|
8745
8745
|
ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
|
|
8746
8746
|
}
|
|
8747
|
-
|
|
8747
|
+
debug2("tilde return", ret);
|
|
8748
8748
|
return ret;
|
|
8749
8749
|
});
|
|
8750
8750
|
};
|
|
@@ -8752,11 +8752,11 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8752
8752
|
return comp.trim().split(/\s+/).map((c) => replaceCaret(c, options)).join(" ");
|
|
8753
8753
|
};
|
|
8754
8754
|
var replaceCaret = (comp, options) => {
|
|
8755
|
-
|
|
8755
|
+
debug2("caret", comp, options);
|
|
8756
8756
|
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
8757
8757
|
const z = options.includePrerelease ? "-0" : "";
|
|
8758
8758
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
8759
|
-
|
|
8759
|
+
debug2("caret", comp, _, M, m, p, pr);
|
|
8760
8760
|
let ret;
|
|
8761
8761
|
if (isX(M)) {
|
|
8762
8762
|
ret = "";
|
|
@@ -8769,7 +8769,7 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8769
8769
|
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
8770
8770
|
}
|
|
8771
8771
|
} else if (pr) {
|
|
8772
|
-
|
|
8772
|
+
debug2("replaceCaret pr", pr);
|
|
8773
8773
|
if (M === "0") {
|
|
8774
8774
|
if (m === "0") {
|
|
8775
8775
|
ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
|
|
@@ -8780,7 +8780,7 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8780
8780
|
ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
|
|
8781
8781
|
}
|
|
8782
8782
|
} else {
|
|
8783
|
-
|
|
8783
|
+
debug2("no pr");
|
|
8784
8784
|
if (M === "0") {
|
|
8785
8785
|
if (m === "0") {
|
|
8786
8786
|
ret = `>=${M}.${m}.${p} <${M}.${m}.${+p + 1}-0`;
|
|
@@ -8791,19 +8791,19 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8791
8791
|
ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
|
8792
8792
|
}
|
|
8793
8793
|
}
|
|
8794
|
-
|
|
8794
|
+
debug2("caret return", ret);
|
|
8795
8795
|
return ret;
|
|
8796
8796
|
});
|
|
8797
8797
|
};
|
|
8798
8798
|
var replaceXRanges = (comp, options) => {
|
|
8799
|
-
|
|
8799
|
+
debug2("replaceXRanges", comp, options);
|
|
8800
8800
|
return comp.split(/\s+/).map((c) => replaceXRange(c, options)).join(" ");
|
|
8801
8801
|
};
|
|
8802
8802
|
var replaceXRange = (comp, options) => {
|
|
8803
8803
|
comp = comp.trim();
|
|
8804
8804
|
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
|
8805
8805
|
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
8806
|
-
|
|
8806
|
+
debug2("xRange", comp, ret, gtlt, M, m, p, pr);
|
|
8807
8807
|
if (invalidXRangeOrder(M, m, p)) {
|
|
8808
8808
|
return comp;
|
|
8809
8809
|
}
|
|
@@ -8853,16 +8853,16 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8853
8853
|
} else if (xp) {
|
|
8854
8854
|
ret = `>=${M}.${m}.0${pr} <${M}.${+m + 1}.0-0`;
|
|
8855
8855
|
}
|
|
8856
|
-
|
|
8856
|
+
debug2("xRange return", ret);
|
|
8857
8857
|
return ret;
|
|
8858
8858
|
});
|
|
8859
8859
|
};
|
|
8860
8860
|
var replaceStars = (comp, options) => {
|
|
8861
|
-
|
|
8861
|
+
debug2("replaceStars", comp, options);
|
|
8862
8862
|
return comp.trim().replace(re[t.STAR], "");
|
|
8863
8863
|
};
|
|
8864
8864
|
var replaceGTE0 = (comp, options) => {
|
|
8865
|
-
|
|
8865
|
+
debug2("replaceGTE0", comp, options);
|
|
8866
8866
|
return comp.trim().replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
|
|
8867
8867
|
};
|
|
8868
8868
|
var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
|
|
@@ -8900,7 +8900,7 @@ var require_range = __commonJS((exports, module) => {
|
|
|
8900
8900
|
}
|
|
8901
8901
|
if (version.prerelease.length && !options.includePrerelease) {
|
|
8902
8902
|
for (let i = 0;i < set.length; i++) {
|
|
8903
|
-
|
|
8903
|
+
debug2(set[i].semver);
|
|
8904
8904
|
if (set[i].semver === Comparator.ANY) {
|
|
8905
8905
|
continue;
|
|
8906
8906
|
}
|
|
@@ -8935,7 +8935,7 @@ var require_comparator = __commonJS((exports, module) => {
|
|
|
8935
8935
|
}
|
|
8936
8936
|
}
|
|
8937
8937
|
comp = comp.trim().split(/\s+/).join(" ");
|
|
8938
|
-
|
|
8938
|
+
debug2("comparator", comp, options);
|
|
8939
8939
|
this.options = options;
|
|
8940
8940
|
this.loose = !!options.loose;
|
|
8941
8941
|
this.parse(comp);
|
|
@@ -8944,7 +8944,7 @@ var require_comparator = __commonJS((exports, module) => {
|
|
|
8944
8944
|
} else {
|
|
8945
8945
|
this.value = this.operator + this.semver.version;
|
|
8946
8946
|
}
|
|
8947
|
-
|
|
8947
|
+
debug2("comp", this);
|
|
8948
8948
|
}
|
|
8949
8949
|
parse(comp) {
|
|
8950
8950
|
const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
|
|
@@ -8966,7 +8966,7 @@ var require_comparator = __commonJS((exports, module) => {
|
|
|
8966
8966
|
return this.value;
|
|
8967
8967
|
}
|
|
8968
8968
|
test(version) {
|
|
8969
|
-
|
|
8969
|
+
debug2("Comparator.test", version, this.options.loose);
|
|
8970
8970
|
if (this.semver === ANY || version === ANY) {
|
|
8971
8971
|
return true;
|
|
8972
8972
|
}
|
|
@@ -9023,7 +9023,7 @@ var require_comparator = __commonJS((exports, module) => {
|
|
|
9023
9023
|
var parseOptions = require_parse_options();
|
|
9024
9024
|
var { safeRe: re, t } = require_re();
|
|
9025
9025
|
var cmp = require_cmp();
|
|
9026
|
-
var
|
|
9026
|
+
var debug2 = require_debug();
|
|
9027
9027
|
var SemVer = require_semver();
|
|
9028
9028
|
var Range = require_range();
|
|
9029
9029
|
});
|
|
@@ -10781,6 +10781,7 @@ function resolve(overrideBinPath) {
|
|
|
10781
10781
|
import fs6 from "node:fs";
|
|
10782
10782
|
import path6 from "node:path";
|
|
10783
10783
|
import os2 from "node:os";
|
|
10784
|
+
import crypto from "node:crypto";
|
|
10784
10785
|
import { execSync as execSync4 } from "node:child_process";
|
|
10785
10786
|
|
|
10786
10787
|
// src/config.js
|
|
@@ -10794,7 +10795,8 @@ var DEFAULTS = Object.freeze({
|
|
|
10794
10795
|
caddy: Object.freeze({
|
|
10795
10796
|
enabled: false,
|
|
10796
10797
|
domain: "caw.localhost"
|
|
10797
|
-
})
|
|
10798
|
+
}),
|
|
10799
|
+
analyticsEnabled: true
|
|
10798
10800
|
});
|
|
10799
10801
|
function configPath(envDir) {
|
|
10800
10802
|
return path4.join(envDir, CONFIG_FILENAME);
|
|
@@ -11042,6 +11044,87 @@ async function waitForExit(pm, intervalMs, maxWaitMs) {
|
|
|
11042
11044
|
return false;
|
|
11043
11045
|
}
|
|
11044
11046
|
|
|
11047
|
+
// src/analytics.js
|
|
11048
|
+
var DEFAULT_HOST = "https://us.i.posthog.com";
|
|
11049
|
+
var TIMEOUT_MS = 3000;
|
|
11050
|
+
var DEBUG_NS = "caw:launcher:analytics";
|
|
11051
|
+
var TIMEOUT_SENTINEL = Symbol("timeout");
|
|
11052
|
+
function debug(fmt, ...args) {
|
|
11053
|
+
const dbg = process.env.DEBUG;
|
|
11054
|
+
if (!dbg)
|
|
11055
|
+
return;
|
|
11056
|
+
const patterns = dbg.split(/[\s,]+/).filter(Boolean);
|
|
11057
|
+
const matches = patterns.some((p) => {
|
|
11058
|
+
const escaped = p.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
11059
|
+
const re = new RegExp("^" + escaped + "$");
|
|
11060
|
+
return re.test(DEBUG_NS) || re.test(DEBUG_NS + ":debug");
|
|
11061
|
+
});
|
|
11062
|
+
if (!matches)
|
|
11063
|
+
return;
|
|
11064
|
+
const msg = fmt.replace(/%s|%d/g, () => String(args.shift()));
|
|
11065
|
+
process.stderr.write(`${DEBUG_NS}:debug ${msg}
|
|
11066
|
+
`);
|
|
11067
|
+
}
|
|
11068
|
+
function resolveApiKey() {
|
|
11069
|
+
return process.env.POSTHOG_API_KEY ?? "phc_kxCKEn8saL3Zg4mexitLRiqFybxHzTK7gNcxurdh2Ycq";
|
|
11070
|
+
}
|
|
11071
|
+
function launcherVersion() {
|
|
11072
|
+
try {
|
|
11073
|
+
return resolvePackageVersion({ importMetaUrl: import.meta.url, packageName: "@kelceyp/caw" }).version;
|
|
11074
|
+
} catch {
|
|
11075
|
+
return null;
|
|
11076
|
+
}
|
|
11077
|
+
}
|
|
11078
|
+
async function emitCawCmd({ op, config }) {
|
|
11079
|
+
if (config?.analyticsEnabled !== true)
|
|
11080
|
+
return;
|
|
11081
|
+
const installId = config.installId;
|
|
11082
|
+
if (typeof installId !== "string" || installId.length === 0)
|
|
11083
|
+
return;
|
|
11084
|
+
const apiKey = resolveApiKey();
|
|
11085
|
+
if (apiKey === null)
|
|
11086
|
+
return;
|
|
11087
|
+
const host = process.env.POSTHOG_HOST || DEFAULT_HOST;
|
|
11088
|
+
const properties = { op };
|
|
11089
|
+
if (op === "start") {
|
|
11090
|
+
properties.$set = {
|
|
11091
|
+
launcher_version: launcherVersion(),
|
|
11092
|
+
os: process.platform,
|
|
11093
|
+
arch: process.arch
|
|
11094
|
+
};
|
|
11095
|
+
}
|
|
11096
|
+
const body = {
|
|
11097
|
+
api_key: apiKey,
|
|
11098
|
+
event: "caw cmd",
|
|
11099
|
+
distinct_id: installId,
|
|
11100
|
+
properties,
|
|
11101
|
+
timestamp: new Date().toISOString()
|
|
11102
|
+
};
|
|
11103
|
+
try {
|
|
11104
|
+
const timer = new Promise((resolve2) => setTimeout(() => resolve2(TIMEOUT_SENTINEL), TIMEOUT_MS));
|
|
11105
|
+
const req = fetch(`${host}/capture/`, {
|
|
11106
|
+
method: "POST",
|
|
11107
|
+
headers: { "Content-Type": "application/json" },
|
|
11108
|
+
body: JSON.stringify(body)
|
|
11109
|
+
});
|
|
11110
|
+
const res = await Promise.race([req, timer]);
|
|
11111
|
+
if (res === TIMEOUT_SENTINEL) {
|
|
11112
|
+
debug("emit timeout op=%s path=/capture/", op);
|
|
11113
|
+
return;
|
|
11114
|
+
}
|
|
11115
|
+
if (!res.ok)
|
|
11116
|
+
debug("emit non-2xx op=%s status=%d path=/capture/", op, res.status);
|
|
11117
|
+
} catch (err) {
|
|
11118
|
+
debug("emit failed op=%s err=%s path=/capture/", op, err?.message ?? err);
|
|
11119
|
+
}
|
|
11120
|
+
}
|
|
11121
|
+
async function emitCawCmdStart({ config }) {
|
|
11122
|
+
return emitCawCmd({ op: "start", config });
|
|
11123
|
+
}
|
|
11124
|
+
async function emitCawCmdStop({ config }) {
|
|
11125
|
+
return emitCawCmd({ op: "stop", config });
|
|
11126
|
+
}
|
|
11127
|
+
|
|
11045
11128
|
// src/commands/start.js
|
|
11046
11129
|
function resolveEnvDir(rawEnvDir) {
|
|
11047
11130
|
if (rawEnvDir.startsWith("~")) {
|
|
@@ -11114,10 +11197,72 @@ function buildEnvNodeArgs(envDir) {
|
|
|
11114
11197
|
const envFilePath = path6.join(envDir, ".env");
|
|
11115
11198
|
return [`--env-file=${envFilePath}`];
|
|
11116
11199
|
}
|
|
11200
|
+
function sleepSync(ms) {
|
|
11201
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
11202
|
+
}
|
|
11203
|
+
function hasFullIdentity(config) {
|
|
11204
|
+
return typeof config?.installId === "string" && config.installId.length > 0 && typeof config?.installSalt === "string" && config.installSalt.length > 0 && typeof config?.analyticsEnabled === "boolean";
|
|
11205
|
+
}
|
|
11206
|
+
function ensureInstallIdentity(envDir) {
|
|
11207
|
+
if (configExists(envDir)) {
|
|
11208
|
+
const existing = readConfig(envDir);
|
|
11209
|
+
if (hasFullIdentity(existing))
|
|
11210
|
+
return existing;
|
|
11211
|
+
}
|
|
11212
|
+
fs6.mkdirSync(envDir, { recursive: true });
|
|
11213
|
+
const lockPath = path6.join(envDir, "config.identity.lock");
|
|
11214
|
+
let acquired = false;
|
|
11215
|
+
for (let attempt = 0;attempt < 100; attempt++) {
|
|
11216
|
+
try {
|
|
11217
|
+
const fd = fs6.openSync(lockPath, "wx");
|
|
11218
|
+
fs6.closeSync(fd);
|
|
11219
|
+
acquired = true;
|
|
11220
|
+
break;
|
|
11221
|
+
} catch (e) {
|
|
11222
|
+
if (e.code !== "EEXIST")
|
|
11223
|
+
throw e;
|
|
11224
|
+
try {
|
|
11225
|
+
const st = fs6.statSync(lockPath);
|
|
11226
|
+
if (Date.now() - st.mtimeMs > 1e4) {
|
|
11227
|
+
fs6.unlinkSync(lockPath);
|
|
11228
|
+
continue;
|
|
11229
|
+
}
|
|
11230
|
+
} catch {}
|
|
11231
|
+
sleepSync(50);
|
|
11232
|
+
}
|
|
11233
|
+
}
|
|
11234
|
+
try {
|
|
11235
|
+
const existing = configExists(envDir) ? readConfig(envDir) : { ...DEFAULTS };
|
|
11236
|
+
const merged = { ...existing };
|
|
11237
|
+
let mutated = false;
|
|
11238
|
+
if (typeof merged.installId !== "string" || merged.installId.length === 0) {
|
|
11239
|
+
merged.installId = crypto.randomUUID();
|
|
11240
|
+
mutated = true;
|
|
11241
|
+
}
|
|
11242
|
+
if (typeof merged.installSalt !== "string" || merged.installSalt.length === 0) {
|
|
11243
|
+
merged.installSalt = crypto.randomBytes(32).toString("base64url");
|
|
11244
|
+
mutated = true;
|
|
11245
|
+
}
|
|
11246
|
+
if (typeof merged.analyticsEnabled !== "boolean") {
|
|
11247
|
+
merged.analyticsEnabled = DEFAULTS.analyticsEnabled;
|
|
11248
|
+
mutated = true;
|
|
11249
|
+
}
|
|
11250
|
+
if (mutated) {
|
|
11251
|
+
writeConfig(envDir, merged);
|
|
11252
|
+
}
|
|
11253
|
+
return readConfig(envDir);
|
|
11254
|
+
} finally {
|
|
11255
|
+
if (acquired) {
|
|
11256
|
+
try {
|
|
11257
|
+
fs6.unlinkSync(lockPath);
|
|
11258
|
+
} catch {}
|
|
11259
|
+
}
|
|
11260
|
+
}
|
|
11261
|
+
}
|
|
11117
11262
|
function bootstrap(envDir) {
|
|
11118
11263
|
fs6.mkdirSync(envDir, { recursive: true });
|
|
11119
11264
|
fs6.mkdirSync(path6.join(envDir, "assets"), { recursive: true });
|
|
11120
|
-
|
|
11265
|
+
ensureInstallIdentity(envDir);
|
|
11121
11266
|
const envFilePath = path6.join(envDir, ".env");
|
|
11122
11267
|
if (!fs6.existsSync(envFilePath)) {
|
|
11123
11268
|
fs6.writeFileSync(envFilePath, [
|
|
@@ -11217,6 +11362,8 @@ How would you like to proceed?`,
|
|
|
11217
11362
|
console.log(`Creating environment directory: ${envDir}`);
|
|
11218
11363
|
bootstrap(envDir);
|
|
11219
11364
|
console.log("Wrote default config.json");
|
|
11365
|
+
} else {
|
|
11366
|
+
ensureInstallIdentity(envDir);
|
|
11220
11367
|
}
|
|
11221
11368
|
const config = readConfigWithDefaults(envDir);
|
|
11222
11369
|
const pm = createProcessManager(config, envDir);
|
|
@@ -11236,6 +11383,7 @@ How would you like to proceed?`,
|
|
|
11236
11383
|
console.log(`Server is already running on port ${config.port}.`);
|
|
11237
11384
|
process.exit(0);
|
|
11238
11385
|
}
|
|
11386
|
+
await emitCawCmdStart({ config: readConfig(envDir) });
|
|
11239
11387
|
let activeConfig = config;
|
|
11240
11388
|
if (hasPendingConfig(envDir)) {
|
|
11241
11389
|
const active = readConfig(envDir);
|
|
@@ -11275,6 +11423,13 @@ How would you like to proceed?`,
|
|
|
11275
11423
|
CAW_PORT: String(activeConfig.port),
|
|
11276
11424
|
CAW_ENV_DIR: envDir
|
|
11277
11425
|
};
|
|
11426
|
+
if (typeof activeConfig.installId === "string" && activeConfig.installId.length > 0 && typeof activeConfig.installSalt === "string" && activeConfig.installSalt.length > 0) {
|
|
11427
|
+
envVars.CAW_INSTALL_ID = String(activeConfig.installId);
|
|
11428
|
+
envVars.CAW_INSTALL_SALT = String(activeConfig.installSalt);
|
|
11429
|
+
}
|
|
11430
|
+
if (typeof activeConfig.analyticsEnabled === "boolean") {
|
|
11431
|
+
envVars.CAW_ANALYTICS_ENABLED = activeConfig.analyticsEnabled ? "true" : "false";
|
|
11432
|
+
}
|
|
11278
11433
|
const nodeArgs = buildEnvNodeArgs(envDir);
|
|
11279
11434
|
const pm2 = createProcessManager(activeConfig, envDir);
|
|
11280
11435
|
const id = pm2.start(serverInfo.mainJsPath, envVars, nodeArgs);
|
|
@@ -11316,9 +11471,10 @@ async function checkHealth2(port) {
|
|
|
11316
11471
|
return { reachable: false, healthy: false, data: null };
|
|
11317
11472
|
}
|
|
11318
11473
|
}
|
|
11319
|
-
async function executeStop(pm, config, force, promptFn) {
|
|
11474
|
+
async function executeStop(pm, config, force, promptFn, envDir) {
|
|
11320
11475
|
const runState = pm.isRunning();
|
|
11321
11476
|
if (!runState.running) {
|
|
11477
|
+
await emitCawCmdStop({ config: envDir ? readConfig(envDir) : config });
|
|
11322
11478
|
return { stopped: false, wasRunning: false };
|
|
11323
11479
|
}
|
|
11324
11480
|
const health = await checkHealth2(config.port);
|
|
@@ -11348,6 +11504,7 @@ async function executeStop(pm, config, force, promptFn) {
|
|
|
11348
11504
|
if (exited) {
|
|
11349
11505
|
pm.cleanup();
|
|
11350
11506
|
console.log("Server stopped.");
|
|
11507
|
+
await emitCawCmdStop({ config: envDir ? readConfig(envDir) : config });
|
|
11351
11508
|
return { stopped: true, wasRunning: true };
|
|
11352
11509
|
}
|
|
11353
11510
|
if (!force) {
|
|
@@ -11360,6 +11517,7 @@ async function executeStop(pm, config, force, promptFn) {
|
|
|
11360
11517
|
pm.cleanup();
|
|
11361
11518
|
if (killed) {
|
|
11362
11519
|
console.log("Server force-killed.");
|
|
11520
|
+
await emitCawCmdStop({ config: envDir ? readConfig(envDir) : config });
|
|
11363
11521
|
return { stopped: true, wasRunning: true };
|
|
11364
11522
|
}
|
|
11365
11523
|
console.error("Server process could not be stopped.");
|
|
@@ -11375,7 +11533,7 @@ var create3 = () => {
|
|
|
11375
11533
|
}
|
|
11376
11534
|
const config = readConfigWithDefaults(envDir);
|
|
11377
11535
|
const pm = createProcessManager(config, envDir);
|
|
11378
|
-
const result = await executeStop(pm, config, force, ctx.prompt);
|
|
11536
|
+
const result = await executeStop(pm, config, force, ctx.prompt, envDir);
|
|
11379
11537
|
if (!result.wasRunning) {
|
|
11380
11538
|
console.log("Server is not running.");
|
|
11381
11539
|
process.exit(0);
|
|
@@ -11880,7 +12038,7 @@ var create7 = () => {
|
|
|
11880
12038
|
if (fs12.existsSync(envDir) && configExists5(envDir)) {
|
|
11881
12039
|
const config2 = readConfigWithDefaults(envDir);
|
|
11882
12040
|
const pm3 = createProcessManager(config2, envDir);
|
|
11883
|
-
const result = await executeStop(pm3, config2, force, ctx.prompt);
|
|
12041
|
+
const result = await executeStop(pm3, config2, force, ctx.prompt, envDir);
|
|
11884
12042
|
if (result.wasRunning && !result.stopped) {
|
|
11885
12043
|
if (result.userDeclined) {
|
|
11886
12044
|
process.exit(0);
|
|
@@ -11932,6 +12090,7 @@ How would you like to proceed?`,
|
|
|
11932
12090
|
console.log(`Server is already running on port ${config.port}.`);
|
|
11933
12091
|
process.exit(0);
|
|
11934
12092
|
}
|
|
12093
|
+
await emitCawCmdStart({ config: readConfig(envDir) });
|
|
11935
12094
|
let activeConfig = config;
|
|
11936
12095
|
if (hasPendingConfig(envDir)) {
|
|
11937
12096
|
const active = readConfig(envDir);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// scripts/postinstall.js
|
|
2
|
+
import { execSync as execSync2 } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
// src/guards.js
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
var EXIT_PLATFORM = 100;
|
|
8
|
+
var EXIT_ARCH = 101;
|
|
9
|
+
var EXIT_NODE = 102;
|
|
10
|
+
var EXIT_ROOT = 103;
|
|
11
|
+
var EXIT_WRITABLE = 104;
|
|
12
|
+
var INSTALL_GUIDE_URL = "https://athenadesign.com.au/caw/installation-guide";
|
|
13
|
+
var GUIDE_TAIL = `See ${INSTALL_GUIDE_URL} for the full walkthrough.`;
|
|
14
|
+
function buildPrefixWritableMessage(prefix) {
|
|
15
|
+
return `caw: writable preflight check failed.
|
|
16
|
+
` + `The npm global prefix is not writable.
|
|
17
|
+
|
|
18
|
+
` + `sudo npm install -g @kelceyp/caw-server@latest
|
|
19
|
+
` + `(and, if the target server needs a newer launcher: sudo npm install -g @kelceyp/caw@latest)
|
|
20
|
+
|
|
21
|
+
` + `${GUIDE_TAIL}
|
|
22
|
+
|
|
23
|
+
` + `Observed prefix: ${prefix}
|
|
24
|
+
` + `Note: sudo may resolve a different Node than your login shell — compare \`node --version\` with \`sudo node --version\` before running.`;
|
|
25
|
+
}
|
|
26
|
+
function checkNodeVersion() {
|
|
27
|
+
const major = parseInt(process.versions.node.split(".")[0], 10);
|
|
28
|
+
if (major >= 24) {
|
|
29
|
+
return { ok: true, message: null };
|
|
30
|
+
}
|
|
31
|
+
const message = `caw: node preflight check failed.
|
|
32
|
+
` + `caw requires Node.js 24 or later.
|
|
33
|
+
|
|
34
|
+
` + `Install Node.js 24 or later (nvm is the recommended path to a user-owned Node).
|
|
35
|
+
|
|
36
|
+
` + `${GUIDE_TAIL}
|
|
37
|
+
|
|
38
|
+
` + `Observed Node: ${process.version}`;
|
|
39
|
+
return { ok: false, message };
|
|
40
|
+
}
|
|
41
|
+
function checkPrefixWritable() {
|
|
42
|
+
let prefix;
|
|
43
|
+
try {
|
|
44
|
+
prefix = execSync("npm config get prefix", { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
45
|
+
} catch {
|
|
46
|
+
return { ok: true, message: null };
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
fs.accessSync(prefix, fs.constants.W_OK);
|
|
50
|
+
return { ok: true, message: null };
|
|
51
|
+
} catch {
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
message: buildPrefixWritableMessage(prefix)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function checkPlatform() {
|
|
59
|
+
if (process.platform === "darwin") {
|
|
60
|
+
return { ok: true, message: null };
|
|
61
|
+
}
|
|
62
|
+
const message = `caw: platform preflight check failed.
|
|
63
|
+
` + `caw supports macOS only.
|
|
64
|
+
|
|
65
|
+
` + `Install caw on a macOS (darwin) host.
|
|
66
|
+
|
|
67
|
+
` + `${GUIDE_TAIL}
|
|
68
|
+
|
|
69
|
+
` + `Observed platform: ${process.platform}`;
|
|
70
|
+
return { ok: false, message };
|
|
71
|
+
}
|
|
72
|
+
function checkArch() {
|
|
73
|
+
if (process.arch === "x64" || process.arch === "arm64") {
|
|
74
|
+
return { ok: true, message: null };
|
|
75
|
+
}
|
|
76
|
+
const message = `caw: arch preflight check failed.
|
|
77
|
+
` + `caw supports x64 (Intel) and arm64 (Apple Silicon) only.
|
|
78
|
+
|
|
79
|
+
` + `Install caw on a supported architecture.
|
|
80
|
+
|
|
81
|
+
` + `${GUIDE_TAIL}
|
|
82
|
+
|
|
83
|
+
` + `Observed arch: ${process.arch}`;
|
|
84
|
+
return { ok: false, message };
|
|
85
|
+
}
|
|
86
|
+
function checkNotRoot() {
|
|
87
|
+
const uid = process.getuid?.();
|
|
88
|
+
if (uid !== 0) {
|
|
89
|
+
return { ok: true, message: null };
|
|
90
|
+
}
|
|
91
|
+
const message = `caw: not-root preflight check failed.
|
|
92
|
+
` + `Refusing to run as root — this command must not be invoked under sudo.
|
|
93
|
+
|
|
94
|
+
` + `Re-run the command without sudo.
|
|
95
|
+
|
|
96
|
+
` + `${GUIDE_TAIL}`;
|
|
97
|
+
return { ok: false, message };
|
|
98
|
+
}
|
|
99
|
+
function runInstallPreflight({ requireNotRoot }) {
|
|
100
|
+
const platform = checkPlatform();
|
|
101
|
+
if (!platform.ok) {
|
|
102
|
+
return { ok: false, failedGate: "platform", message: platform.message, exitCode: EXIT_PLATFORM };
|
|
103
|
+
}
|
|
104
|
+
const arch = checkArch();
|
|
105
|
+
if (!arch.ok) {
|
|
106
|
+
return { ok: false, failedGate: "arch", message: arch.message, exitCode: EXIT_ARCH };
|
|
107
|
+
}
|
|
108
|
+
const node = checkNodeVersion();
|
|
109
|
+
if (!node.ok) {
|
|
110
|
+
return { ok: false, failedGate: "node", message: node.message, exitCode: EXIT_NODE };
|
|
111
|
+
}
|
|
112
|
+
if (requireNotRoot) {
|
|
113
|
+
const notRoot = checkNotRoot();
|
|
114
|
+
if (!notRoot.ok) {
|
|
115
|
+
return { ok: false, failedGate: "root", message: notRoot.message, exitCode: EXIT_ROOT };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const writable = checkPrefixWritable();
|
|
119
|
+
if (!writable.ok) {
|
|
120
|
+
return { ok: false, failedGate: "writable", message: writable.message, exitCode: EXIT_WRITABLE };
|
|
121
|
+
}
|
|
122
|
+
return { ok: true, failedGate: null, message: null };
|
|
123
|
+
}
|
|
124
|
+
function emitPreflightFailure(result, { warnOnly = false } = {}) {
|
|
125
|
+
if (warnOnly) {
|
|
126
|
+
console.log(result.message);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
console.error(result.message);
|
|
130
|
+
process.exit(result.exitCode);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// scripts/postinstall.js
|
|
134
|
+
var preflight = runInstallPreflight({ requireNotRoot: false });
|
|
135
|
+
if (!preflight.ok) {
|
|
136
|
+
emitPreflightFailure(preflight, { warnOnly: true });
|
|
137
|
+
} else {
|
|
138
|
+
try {
|
|
139
|
+
execSync2("npm install -g @kelceyp/caw-server@^1 --loglevel=error", { stdio: "inherit" });
|
|
140
|
+
} catch {
|
|
141
|
+
console.warn("Could not install @kelceyp/caw-server automatically.");
|
|
142
|
+
console.warn('Run "caw start" to retry installation.');
|
|
143
|
+
}
|
|
144
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kelceyp/caw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Unified Web/MCP server with React web app. Provides MD document management, handlebars based templating (documents, prompts and saved searches), user stories including task management and search (rag, fts & metadata with query language). CAW works with any agent that supports MCP but has specific integrations for Claude Code, Codex and Cursor CLI that enable agent orchestration. For humans, think of this as a browser-based reskinning of these tools enabling all prompts and outputs to be captured. For agents, this means that any of these three agents can be used by any other as a \"sub-agent\". And this works recursively to a user configurable depth.",
|
|
6
6
|
"keywords": [
|
|
@@ -27,13 +27,12 @@
|
|
|
27
27
|
"caw": "dist/caw.js"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "bun build src/main.js --outfile dist/caw.js --target node --format esm",
|
|
30
|
+
"build": "bun build src/main.js --outfile dist/caw.js --target node --format esm && bun build scripts/postinstall.js --outfile dist/postinstall.js --target node --format esm",
|
|
31
31
|
"test": "bun test --isolate",
|
|
32
|
-
"postinstall": "node
|
|
32
|
+
"postinstall": "node dist/postinstall.js"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist/",
|
|
36
|
-
"scripts/postinstall.js",
|
|
37
36
|
"README.md"
|
|
38
37
|
],
|
|
39
38
|
"license": "Proprietary. All rights reserved. Free for personal and commercial use. Closed source.",
|
package/scripts/postinstall.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'node:child_process';
|
|
2
|
-
import { runInstallPreflight, emitPreflightFailure } from '../src/guards.js';
|
|
3
|
-
|
|
4
|
-
const preflight = runInstallPreflight({ requireNotRoot: false });
|
|
5
|
-
if (!preflight.ok) {
|
|
6
|
-
emitPreflightFailure(preflight, { warnOnly: true });
|
|
7
|
-
} else {
|
|
8
|
-
try {
|
|
9
|
-
execSync('npm install -g @kelceyp/caw-server@^1 --loglevel=error', { stdio: 'inherit' });
|
|
10
|
-
} catch {
|
|
11
|
-
console.warn('Could not install @kelceyp/caw-server automatically.');
|
|
12
|
-
console.warn('Run "caw start" to retry installation.');
|
|
13
|
-
}
|
|
14
|
-
}
|