promptlock-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/hook-forwarder.ts
32
+ var hook_forwarder_exports = {};
33
+ __export(hook_forwarder_exports, {
34
+ detectProvider: () => detectProvider,
35
+ providerFor: () => providerFor
36
+ });
37
+ module.exports = __toCommonJS(hook_forwarder_exports);
38
+ var fs = __toESM(require("node:fs"));
39
+ var http = __toESM(require("node:http"));
40
+ var os = __toESM(require("node:os"));
41
+ var path = __toESM(require("node:path"));
42
+ var CONFIG_PATH = path.join(os.homedir(), ".warp-focus", "config.json");
43
+ function envMs(name, fallback) {
44
+ const raw = process.env[name];
45
+ if (!raw) return fallback;
46
+ const n = Number.parseInt(raw, 10);
47
+ return Number.isFinite(n) && n > 0 && n <= 5e3 ? n : fallback;
48
+ }
49
+ var TIMEOUT_MS = envMs("WARP_FORWARDER_TIMEOUT_MS", 250);
50
+ var STDIN_IDLE_MS = envMs("WARP_FORWARDER_STDIN_MS", 250);
51
+ var MAX_BODY_BYTES = 2 * 1024 * 1024;
52
+ function done() {
53
+ process.exit(0);
54
+ }
55
+ function readConfig() {
56
+ try {
57
+ const cfg = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8"));
58
+ return {
59
+ port: typeof cfg.receiverPort === "number" ? cfg.receiverPort : 8787,
60
+ secret: typeof cfg.secret === "string" ? cfg.secret : ""
61
+ };
62
+ } catch {
63
+ return { port: 8787, secret: "" };
64
+ }
65
+ }
66
+ var CURSOR_STEPS = /* @__PURE__ */ new Set([
67
+ "beforeSubmitPrompt",
68
+ "sessionStart",
69
+ "sessionEnd",
70
+ "stop",
71
+ "preCompact",
72
+ "afterAgentResponse",
73
+ "afterAgentThought",
74
+ "subagentStart",
75
+ "subagentStop",
76
+ "preToolUse",
77
+ "postToolUse",
78
+ "postToolUseFailure",
79
+ "beforeShellExecution",
80
+ "afterShellExecution",
81
+ "beforeMCPExecution",
82
+ "afterMCPExecution",
83
+ "beforeReadFile",
84
+ "afterFileEdit",
85
+ "beforeTabFileRead",
86
+ "afterTabFileEdit",
87
+ "workspaceOpen"
88
+ ]);
89
+ var CLAUDE_ONLY_EVENTS = /* @__PURE__ */ new Set([
90
+ "Notification",
91
+ "PermissionDenied",
92
+ "PostToolUseFailure",
93
+ "StopFailure",
94
+ "MessageDisplay",
95
+ "PostToolBatch",
96
+ "Setup",
97
+ "UserPromptExpansion",
98
+ "InstructionsLoaded",
99
+ "ConfigChange",
100
+ "CwdChanged",
101
+ "DirectoryAdded",
102
+ "FileChanged",
103
+ "PreModelSwitch",
104
+ "PostModelSwitch",
105
+ "TaskCreated",
106
+ "TaskCompleted",
107
+ "TeammateIdle",
108
+ "Elicitation",
109
+ "ElicitationResult",
110
+ "WorktreeCreate",
111
+ "WorktreeRemove"
112
+ ]);
113
+ var CODEX_ONLY_EVENTS = /* @__PURE__ */ new Set(["Interrupt"]);
114
+ function firstString(p, key) {
115
+ const v = p[key];
116
+ return typeof v === "string" && v.length > 0 ? v : null;
117
+ }
118
+ function detectProvider(body) {
119
+ let parsed;
120
+ try {
121
+ parsed = JSON.parse(body);
122
+ } catch {
123
+ return null;
124
+ }
125
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
126
+ const p = parsed;
127
+ if (firstString(p, "type") === "agent-turn-complete") return "codex";
128
+ const event = firstString(p, "hook_event_name");
129
+ if (event !== null) {
130
+ if (CURSOR_STEPS.has(event)) return "cursor";
131
+ if (CLAUDE_ONLY_EVENTS.has(event)) return "claude-code";
132
+ if (CODEX_ONLY_EVENTS.has(event)) return "codex";
133
+ if (firstString(p, "prompt_id") !== null) return "claude-code";
134
+ if (firstString(p, "turn_id") !== null) return "codex";
135
+ }
136
+ if (firstString(p, "cursor_version") !== null || Array.isArray(p.workspace_roots) || firstString(p, "generation_id") !== null || firstString(p, "conversation_id") !== null) {
137
+ return "cursor";
138
+ }
139
+ if (firstString(p, "prompt_id") !== null || firstString(p, "notification_type") !== null) {
140
+ return "claude-code";
141
+ }
142
+ if (firstString(p, "turn_id") !== null && firstString(p, "session_id") !== null) return "codex";
143
+ return null;
144
+ }
145
+ function providerFor(body) {
146
+ return detectProvider(body) ?? process.argv[2] ?? "cursor";
147
+ }
148
+ function forward(body) {
149
+ const { port, secret } = readConfig();
150
+ const provider = providerFor(body);
151
+ let settled = false;
152
+ const finish = () => {
153
+ if (settled) return;
154
+ settled = true;
155
+ done();
156
+ };
157
+ const guard = setTimeout(finish, TIMEOUT_MS);
158
+ guard.unref?.();
159
+ try {
160
+ const req = http.request(
161
+ {
162
+ host: "127.0.0.1",
163
+ port,
164
+ path: `/hook/${encodeURIComponent(provider)}`,
165
+ method: "POST",
166
+ timeout: TIMEOUT_MS,
167
+ headers: {
168
+ "content-type": "application/json",
169
+ "content-length": Buffer.byteLength(body),
170
+ "x-warp-secret": secret
171
+ }
172
+ },
173
+ (res) => {
174
+ res.resume();
175
+ res.on("end", finish);
176
+ res.on("error", finish);
177
+ }
178
+ );
179
+ req.on("error", finish);
180
+ req.on("timeout", () => {
181
+ req.destroy();
182
+ finish();
183
+ });
184
+ req.end(body);
185
+ } catch {
186
+ finish();
187
+ }
188
+ }
189
+ function bodyFromArgv() {
190
+ for (const raw of process.argv.slice(3)) {
191
+ if (typeof raw !== "string") continue;
192
+ const trimmed = raw.trim();
193
+ if (!trimmed.startsWith("{")) continue;
194
+ try {
195
+ JSON.parse(trimmed);
196
+ return trimmed;
197
+ } catch {
198
+ }
199
+ }
200
+ return null;
201
+ }
202
+ function main() {
203
+ const fromArgv = bodyFromArgv();
204
+ if (fromArgv !== null) {
205
+ forward(fromArgv);
206
+ return;
207
+ }
208
+ const chunks = [];
209
+ let size = 0;
210
+ let sawData = false;
211
+ process.stdin.on("error", done);
212
+ process.stdin.on("data", (chunk) => {
213
+ sawData = true;
214
+ size += chunk.length;
215
+ if (size <= MAX_BODY_BYTES) chunks.push(chunk);
216
+ });
217
+ process.stdin.on("end", () => {
218
+ const body = Buffer.concat(chunks).toString("utf8").trim();
219
+ if (!body) done();
220
+ forward(body);
221
+ });
222
+ const idle = setTimeout(() => {
223
+ if (!sawData) done();
224
+ }, STDIN_IDLE_MS);
225
+ idle.unref?.();
226
+ const hardStop = setTimeout(done, STDIN_IDLE_MS + TIMEOUT_MS);
227
+ hardStop.unref?.();
228
+ }
229
+ if (require.main === module) main();
230
+ // Annotate the CommonJS export names for ESM import in node:
231
+ 0 && (module.exports = {
232
+ detectProvider,
233
+ providerFor
234
+ });
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "promptlock-cli",
3
+ "version": "1.0.0",
4
+ "description": "PromptLock for the Mac: watches Cursor, Claude Code and Codex, and tells your iPhone when an agent is working so it can unlock your apps only while one is.",
5
+ "license": "MIT",
6
+ "author": "Mark Guggenheim",
7
+ "homepage": "https://github.com/Markgugg/warp-focus#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Markgugg/warp-focus.git",
11
+ "directory": "apps/desktop"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/Markgugg/warp-focus/issues"
15
+ },
16
+ "keywords": [
17
+ "promptlock",
18
+ "focus",
19
+ "screen-time",
20
+ "claude-code",
21
+ "cursor",
22
+ "codex",
23
+ "coding-agent",
24
+ "hooks",
25
+ "cli",
26
+ "macos"
27
+ ],
28
+ "bin": {
29
+ "promptlock": "bundle/cli.js",
30
+ "warpfocus": "bundle/cli.js"
31
+ },
32
+ "files": [
33
+ "bundle/",
34
+ "README.md",
35
+ "LICENSE"
36
+ ],
37
+ "engines": {
38
+ "node": ">=18"
39
+ },
40
+ "os": [
41
+ "darwin"
42
+ ],
43
+ "scripts": {
44
+ "build": "tsc -p tsconfig.json",
45
+ "bundle": "node scripts/bundle.mjs",
46
+ "prepack": "npm run build:core --prefix ../.. && npm run bundle",
47
+ "dev": "tsx src/cli.ts",
48
+ "typecheck": "tsc -p tsconfig.json --noEmit",
49
+ "test": "npm run build && node --test \"dist/*.test.js\""
50
+ },
51
+ "dependencies": {
52
+ "ws": "^8.18.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^22.0.0",
56
+ "@types/ws": "^8.5.12",
57
+ "@warp/core": "*",
58
+ "esbuild": "^0.28.2",
59
+ "tsx": "^4.19.0",
60
+ "typescript": "^5.6.0"
61
+ }
62
+ }