wayform 0.1.7 → 0.2.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.
- package/README.md +85 -49
- package/dist/cli.js +17 -5
- package/dist/cli.js.map +1 -1
- package/dist/config.js +6 -6
- package/dist/config.js.map +1 -1
- package/dist/credential-store.js +77 -0
- package/dist/credential-store.js.map +1 -0
- package/dist/doctor.js +30 -22
- package/dist/doctor.js.map +1 -1
- package/dist/hook-clients.js +16 -13
- package/dist/hook-clients.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/init-configs.js +75 -32
- package/dist/init-configs.js.map +1 -1
- package/dist/init-env.js +13 -6
- package/dist/init-env.js.map +1 -1
- package/dist/init-remote.js +159 -95
- package/dist/init-remote.js.map +1 -1
- package/dist/init.js +7 -3
- package/dist/init.js.map +1 -1
- package/dist/keychain.js +31 -0
- package/dist/keychain.js.map +1 -0
- package/dist/oauth-login.js +149 -0
- package/dist/oauth-login.js.map +1 -0
- package/dist/oauth-session.js +122 -0
- package/dist/oauth-session.js.map +1 -0
- package/dist/prompt-hook.js +53 -0
- package/dist/prompt-hook.js.map +1 -0
- package/dist/remote-read.js +29 -9
- package/dist/remote-read.js.map +1 -1
- package/dist/session-prompt.js +13 -10
- package/dist/session-prompt.js.map +1 -1
- package/dist/space-create.js +17 -201
- package/dist/space-create.js.map +1 -1
- package/dist/stop-hook.js +20 -139
- package/dist/stop-hook.js.map +1 -1
- package/package.json +9 -6
package/dist/stop-hook.js
CHANGED
|
@@ -1,162 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Stop-hook entrypoint —
|
|
3
|
+
* Stop-hook entrypoint — formerly write-trigger Path C (model re-engagement).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Per recorded decision da491a7d, Stop re-engagement is removed: visible extra
|
|
6
|
+
* chats and double model cost across Cursor / Claude Code / Codex. This entry
|
|
7
|
+
* always emits the client no-op so existing Stop wiring remains harmless until
|
|
8
|
+
* configs drop it. Write capture leans on tool descriptions, session playbook,
|
|
9
|
+
* /remember, and (Claude) UserPromptSubmit → /hook/prompt.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
* the client sets stop_hook_active=true on the payload. We MUST emit a no-op then, or we
|
|
12
|
-
* create an infinite Stop loop.
|
|
13
|
-
*
|
|
14
|
-
* FAIL-OPEN: on any error (unparseable payload, unknown state) emit the client no-op and
|
|
15
|
-
* exit 0. A hook that traps a turn would itself cause the "can't rely on this" failure
|
|
16
|
-
* this feature exists to prevent.
|
|
17
|
-
*
|
|
18
|
-
* THROTTLE + GATES: each fire re-engages the model with the full conversation as input,
|
|
19
|
-
* so firing every turn roughly doubles a session's model calls. We fire only every
|
|
20
|
-
* FIRE_EVERY-th stop per session (counter in a tmpdir state file keyed by the payload's
|
|
21
|
-
* session_id / conversation_id), and skip turns that cannot produce a useful review:
|
|
22
|
-
* Cursor aborted/errored turns (status), Codex turns with no assistant text
|
|
23
|
-
* (last_assistant_message), and Claude Code turns where write_context was already
|
|
24
|
-
* called (transcript_path — the only tool whose transcript format is stable enough
|
|
25
|
-
* to parse; Codex documents its transcript as unstable).
|
|
11
|
+
* FAIL-OPEN: always exit 0 with a no-op envelope.
|
|
26
12
|
*/
|
|
27
|
-
import
|
|
28
|
-
import * as os from "node:os";
|
|
29
|
-
import * as path from "node:path";
|
|
30
|
-
import { defaultProject } from "./config.js";
|
|
31
|
-
import { reviewInstruction } from "./review-prompt.js";
|
|
32
|
-
import { resolveClient, renderStopReview, renderStopNoop, } from "./hook-clients.js";
|
|
13
|
+
import { resolveClient, renderStopNoop, } from "./hook-clients.js";
|
|
33
14
|
import { isMain } from "./is-main.js";
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* Increment and return this session's stop counter. State lives in tmpdir (one small
|
|
38
|
-
* file per session id; the OS reaps them). Fail-open: if the counter cannot be
|
|
39
|
-
* read/written, return FIRE_EVERY so the review still fires.
|
|
40
|
-
*/
|
|
41
|
-
export function bumpStopCount(sessionId) {
|
|
42
|
-
const file = path.join(os.tmpdir(), `wayform-stop-${sessionId.replace(/[^\w.-]/g, "_")}`);
|
|
43
|
-
try {
|
|
44
|
-
let count = 0;
|
|
45
|
-
try {
|
|
46
|
-
count = parseInt(fs.readFileSync(file, "utf8"), 10) || 0;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
// First stop of the session — no counter file yet.
|
|
50
|
-
}
|
|
51
|
-
count += 1;
|
|
52
|
-
fs.writeFileSync(file, String(count));
|
|
53
|
-
return count;
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return FIRE_EVERY;
|
|
57
|
-
}
|
|
15
|
+
/** Kept for tests / callers that still import the counter helper. */
|
|
16
|
+
export function bumpStopCount(_sessionId) {
|
|
17
|
+
return 0;
|
|
58
18
|
}
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
* would be pure redundant cost. Claude Code transcripts are JSONL; we walk backwards
|
|
62
|
-
* from the end until the last REAL user message (tool_result carriers also arrive as
|
|
63
|
-
* type "user" and don't end the turn). Fail-open: unparseable transcript → false.
|
|
64
|
-
*/
|
|
65
|
-
export function wroteContextThisTurn(transcriptPath) {
|
|
66
|
-
try {
|
|
67
|
-
const lines = fs.readFileSync(transcriptPath, "utf8").trimEnd().split("\n");
|
|
68
|
-
for (let i = lines.length - 1; i >= 0; i--) {
|
|
69
|
-
let entry;
|
|
70
|
-
try {
|
|
71
|
-
entry = JSON.parse(lines[i]);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const content = entry?.message?.content;
|
|
77
|
-
const blocks = Array.isArray(content) ? content : [];
|
|
78
|
-
if (entry?.type === "assistant") {
|
|
79
|
-
if (blocks.some((b) => b?.type === "tool_use" &&
|
|
80
|
-
typeof b?.name === "string" &&
|
|
81
|
-
b.name.includes("write_context"))) {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else if (entry?.type === "user") {
|
|
86
|
-
if (!blocks.some((b) => b?.type === "tool_result"))
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
// Missing/unreadable transcript — no gate.
|
|
93
|
-
}
|
|
19
|
+
/** Kept for tests that still import the transcript gate helper. */
|
|
20
|
+
export function wroteContextThisTurn(_transcriptPath) {
|
|
94
21
|
return false;
|
|
95
22
|
}
|
|
96
23
|
export async function runStopHook() {
|
|
97
|
-
// Resolved here (not at module load) so the dispatcher can set the client from
|
|
98
|
-
// the subcommand arg before calling.
|
|
99
24
|
const client = resolveClient(process.env.MEMORYLAYER_HOOK_CLIENT);
|
|
100
25
|
const emitNoop = () => {
|
|
101
26
|
process.stdout.write(renderStopNoop(client));
|
|
102
27
|
process.exit(0);
|
|
103
28
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return "";
|
|
107
|
-
let data = "";
|
|
29
|
+
// Drain stdin so the client's write never blocks.
|
|
30
|
+
if (!process.stdin.isTTY) {
|
|
108
31
|
try {
|
|
109
|
-
for await (const
|
|
110
|
-
|
|
32
|
+
for await (const _ of process.stdin) {
|
|
33
|
+
// discard
|
|
34
|
+
}
|
|
111
35
|
}
|
|
112
36
|
catch {
|
|
113
|
-
//
|
|
37
|
+
// ignore
|
|
114
38
|
}
|
|
115
|
-
return data;
|
|
116
|
-
};
|
|
117
|
-
const raw = await readStdin();
|
|
118
|
-
// Loop guard: if we cannot confirm we are NOT already in a hook-driven
|
|
119
|
-
// continuation, the safe choice is to let the turn end (never risk a loop).
|
|
120
|
-
// Client-agnostic: Claude Code / Codex set stop_hook_active; Cursor increments
|
|
121
|
-
// loop_count (and enforces loop_limit in config as a hard backstop).
|
|
122
|
-
let payload = {};
|
|
123
|
-
try {
|
|
124
|
-
payload = raw.trim() ? JSON.parse(raw) : {};
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
emitNoop();
|
|
128
|
-
}
|
|
129
|
-
const isContinuation = payload.stop_hook_active === true ||
|
|
130
|
-
(typeof payload.loop_count === "number" && payload.loop_count > 0);
|
|
131
|
-
if (isContinuation)
|
|
132
|
-
emitNoop();
|
|
133
|
-
// Gate: Cursor reports turn outcome; aborted/errored turns settled nothing worth
|
|
134
|
-
// reviewing. Skipped turns don't advance the throttle counter.
|
|
135
|
-
if (typeof payload.status === "string" && payload.status !== "completed") {
|
|
136
|
-
emitNoop();
|
|
137
|
-
}
|
|
138
|
-
// Gate: Codex reports the turn's assistant text; a turn that produced none has
|
|
139
|
-
// nothing to review. Only gates when the field is explicitly present-but-empty.
|
|
140
|
-
if ("last_assistant_message" in payload &&
|
|
141
|
-
!(payload.last_assistant_message ?? "").trim()) {
|
|
142
|
-
emitNoop();
|
|
143
|
-
}
|
|
144
|
-
// Throttle: fire only every FIRE_EVERY-th counted stop. Claude Code / Codex key by
|
|
145
|
-
// session_id, Cursor by conversation_id; a payload with neither (never seen from a
|
|
146
|
-
// real client) fires every turn, preserving pre-throttle behavior.
|
|
147
|
-
const sessionId = payload.session_id || payload.conversation_id;
|
|
148
|
-
if (sessionId && bumpStopCount(sessionId) % FIRE_EVERY !== 0)
|
|
149
|
-
emitNoop();
|
|
150
|
-
// Gate (checked only on firing turns to spare the file read): the model already
|
|
151
|
-
// recorded a decision this turn — a review fire would be redundant cost.
|
|
152
|
-
if (client === "claude-code" &&
|
|
153
|
-
payload.transcript_path &&
|
|
154
|
-
wroteContextThisTurn(payload.transcript_path)) {
|
|
155
|
-
emitNoop();
|
|
156
39
|
}
|
|
157
|
-
|
|
158
|
-
process.stdout.write(renderStopReview(client, reviewInstruction(project)));
|
|
159
|
-
process.exit(0);
|
|
40
|
+
emitNoop();
|
|
160
41
|
}
|
|
161
42
|
if (isMain(import.meta.url)) {
|
|
162
43
|
void runStopHook();
|
package/dist/stop-hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop-hook.js","sourceRoot":"","sources":["../src/stop-hook.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"stop-hook.js","sourceRoot":"","sources":["../src/stop-hook.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG;AACH,OAAO,EACL,aAAa,EACb,cAAc,GAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,qEAAqE;AACrE,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC9C,OAAO,CAAC,CAAC;AACX,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,oBAAoB,CAAC,eAAuB;IAC1D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,MAAM,GAAe,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAE9E,MAAM,QAAQ,GAAG,GAAU,EAAE;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,kDAAkD;IAClD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBACpC,UAAU;YACZ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;IACH,CAAC;IAED,QAAQ,EAAE,CAAC;AACb,CAAC;AAED,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5B,KAAK,WAAW,EAAE,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wayform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vendor-neutral multiplayer planning memory: a git-backed MCP server that shares planning context across Claude, Cursor, and Codex.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
+
"prepare": "git config core.hooksPath .githooks || true",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
13
15
|
"build": "tsc",
|
|
14
16
|
"dev": "tsc --watch",
|
|
15
17
|
"start": "node dist/index.js",
|
|
@@ -25,15 +27,16 @@
|
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
29
|
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
30
|
+
"@napi-rs/keyring": "^1.3.0",
|
|
28
31
|
"simple-git": "^3.27.0",
|
|
29
32
|
"zod": "^3.23.8"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"@eslint/js": "^9.39.
|
|
33
|
-
"@types/node": "^22.
|
|
34
|
-
"eslint": "^9.39.
|
|
35
|
-
"prettier": "^3.9.
|
|
35
|
+
"@eslint/js": "^9.39.5",
|
|
36
|
+
"@types/node": "^22.20.1",
|
|
37
|
+
"eslint": "^9.39.5",
|
|
38
|
+
"prettier": "^3.9.5",
|
|
36
39
|
"typescript": "^5.7.0",
|
|
37
|
-
"typescript-eslint": "^8.
|
|
40
|
+
"typescript-eslint": "^8.65.0"
|
|
38
41
|
}
|
|
39
42
|
}
|