@kelceyp/caw 1.0.30 → 1.0.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kelceyp/caw",
3
- "version": "1.0.30",
3
+ "version": "1.0.33",
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,12 +27,15 @@
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 && bun build scripts/postinstall.js --outfile dist/postinstall.js --target node --format esm",
31
- "test": "bun test --isolate",
32
- "postinstall": "node dist/postinstall.js"
30
+ "clean": "rm -rf dist",
31
+ "build": "bun run clean && bun build src/main.js --outfile dist/caw.js --target node --format esm",
32
+ "test": "bun test --isolate --define __BUILTIN_POSTHOG_KEY__=null",
33
+ "postinstall": "node scripts/postinstall.js"
33
34
  },
34
35
  "files": [
35
36
  "dist/",
37
+ "scripts/postinstall.js",
38
+ "src/guards.js",
36
39
  "README.md"
37
40
  ],
38
41
  "license": "Proprietary. All rights reserved. Free for personal and commercial use. Closed source.",
@@ -0,0 +1,14 @@
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
+ }
package/src/guards.js ADDED
@@ -0,0 +1,181 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { execSync } from 'node:child_process';
4
+
5
+ export const EXIT_PLATFORM = 100;
6
+ export const EXIT_ARCH = 101;
7
+ export const EXIT_NODE = 102;
8
+ export const EXIT_ROOT = 103;
9
+ export const EXIT_WRITABLE = 104;
10
+
11
+ export const INSTALL_GUIDE_URL = 'https://athenadesign.com.au/caw/installation-guide';
12
+
13
+ const GUIDE_TAIL = `See ${INSTALL_GUIDE_URL} for the full walkthrough.`;
14
+
15
+ export function buildPrefixWritableMessage(prefix) {
16
+ return `caw: writable preflight check failed.\n` +
17
+ `The npm global prefix is not writable.\n\n` +
18
+ `sudo npm install -g @kelceyp/caw-server@latest\n` +
19
+ `(and, if the target server needs a newer launcher: sudo npm install -g @kelceyp/caw@latest)\n\n` +
20
+ `${GUIDE_TAIL}\n\n` +
21
+ `Observed prefix: ${prefix}\n` +
22
+ `Note: sudo may resolve a different Node than your login shell — compare \`node --version\` with \`sudo node --version\` before running.`;
23
+ }
24
+
25
+ export function checkNodeVersion() {
26
+ const major = parseInt(process.versions.node.split('.')[0], 10);
27
+ if (major >= 24) {
28
+ return { ok: true, message: null };
29
+ }
30
+ const message =
31
+ `caw: node preflight check failed.\n` +
32
+ `caw requires Node.js 24 or later.\n\n` +
33
+ `Install Node.js 24 or later (nvm is the recommended path to a user-owned Node).\n\n` +
34
+ `${GUIDE_TAIL}\n\n` +
35
+ `Observed Node: ${process.version}`;
36
+ return { ok: false, message };
37
+ }
38
+
39
+ export function checkGlobalInstall() {
40
+ const scriptPath = process.argv[1];
41
+ if (!scriptPath) {
42
+ return { ok: false, message: 'Unable to determine installation path.' };
43
+ }
44
+
45
+ let globalPrefix;
46
+ try {
47
+ globalPrefix = execSync('npm config get prefix', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
48
+ } catch {
49
+ return { ok: true, message: null };
50
+ }
51
+
52
+ let resolvedScript;
53
+ try {
54
+ resolvedScript = fs.realpathSync(scriptPath);
55
+ } catch {
56
+ resolvedScript = path.resolve(scriptPath);
57
+ }
58
+
59
+ let resolvedPrefix;
60
+ try {
61
+ resolvedPrefix = fs.realpathSync(globalPrefix);
62
+ } catch {
63
+ resolvedPrefix = path.resolve(globalPrefix);
64
+ }
65
+
66
+ if (resolvedScript.startsWith(resolvedPrefix)) {
67
+ return { ok: true, message: null };
68
+ }
69
+
70
+ const isNpx = process.argv[1].includes('npx') ||
71
+ process.env.npm_execpath?.includes('npx') ||
72
+ process.env._?.includes('npx');
73
+
74
+ const invocationType = isNpx ? 'npx' : 'local';
75
+
76
+ return {
77
+ ok: false,
78
+ message: `caw must be installed globally (detected ${invocationType} invocation).\n` +
79
+ 'Global install is required to manage the server lifecycle correctly.\n' +
80
+ 'Locally installed or npx-invoked launchers create orphaned server processes.\n\n' +
81
+ 'Install globally with: npm install -g @kelceyp/caw'
82
+ };
83
+ }
84
+
85
+ export function checkPrefixWritable() {
86
+ let prefix;
87
+ try {
88
+ prefix = execSync('npm config get prefix', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
89
+ } catch {
90
+ return { ok: true, message: null };
91
+ }
92
+
93
+ try {
94
+ fs.accessSync(prefix, fs.constants.W_OK);
95
+ return { ok: true, message: null };
96
+ } catch {
97
+ return {
98
+ ok: false,
99
+ message: buildPrefixWritableMessage(prefix)
100
+ };
101
+ }
102
+ }
103
+
104
+ export function checkPlatform() {
105
+ if (process.platform === 'darwin') {
106
+ return { ok: true, message: null };
107
+ }
108
+ const message =
109
+ `caw: platform preflight check failed.\n` +
110
+ `caw supports macOS only.\n\n` +
111
+ `Install caw on a macOS (darwin) host.\n\n` +
112
+ `${GUIDE_TAIL}\n\n` +
113
+ `Observed platform: ${process.platform}`;
114
+ return { ok: false, message };
115
+ }
116
+
117
+ export function checkArch() {
118
+ if (process.arch === 'x64' || process.arch === 'arm64') {
119
+ return { ok: true, message: null };
120
+ }
121
+ const message =
122
+ `caw: arch preflight check failed.\n` +
123
+ `caw supports x64 (Intel) and arm64 (Apple Silicon) only.\n\n` +
124
+ `Install caw on a supported architecture.\n\n` +
125
+ `${GUIDE_TAIL}\n\n` +
126
+ `Observed arch: ${process.arch}`;
127
+ return { ok: false, message };
128
+ }
129
+
130
+ export function checkNotRoot() {
131
+ const uid = process.getuid?.();
132
+ if (uid !== 0) {
133
+ return { ok: true, message: null };
134
+ }
135
+ const message =
136
+ `caw: not-root preflight check failed.\n` +
137
+ `Refusing to run as root — this command must not be invoked under sudo.\n\n` +
138
+ `Re-run the command without sudo.\n\n` +
139
+ `${GUIDE_TAIL}`;
140
+ return { ok: false, message };
141
+ }
142
+
143
+ export function runInstallPreflight({ requireNotRoot }) {
144
+ const platform = checkPlatform();
145
+ if (!platform.ok) {
146
+ return { ok: false, failedGate: 'platform', message: platform.message, exitCode: EXIT_PLATFORM };
147
+ }
148
+
149
+ const arch = checkArch();
150
+ if (!arch.ok) {
151
+ return { ok: false, failedGate: 'arch', message: arch.message, exitCode: EXIT_ARCH };
152
+ }
153
+
154
+ const node = checkNodeVersion();
155
+ if (!node.ok) {
156
+ return { ok: false, failedGate: 'node', message: node.message, exitCode: EXIT_NODE };
157
+ }
158
+
159
+ if (requireNotRoot) {
160
+ const notRoot = checkNotRoot();
161
+ if (!notRoot.ok) {
162
+ return { ok: false, failedGate: 'root', message: notRoot.message, exitCode: EXIT_ROOT };
163
+ }
164
+ }
165
+
166
+ const writable = checkPrefixWritable();
167
+ if (!writable.ok) {
168
+ return { ok: false, failedGate: 'writable', message: writable.message, exitCode: EXIT_WRITABLE };
169
+ }
170
+
171
+ return { ok: true, failedGate: null, message: null };
172
+ }
173
+
174
+ export function emitPreflightFailure(result, { warnOnly = false } = {}) {
175
+ if (warnOnly) {
176
+ console.log(result.message);
177
+ return;
178
+ }
179
+ console.error(result.message);
180
+ process.exit(result.exitCode);
181
+ }
@@ -1,144 +0,0 @@
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
- }