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
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { loadStoredOAuth, saveStoredOAuth, } from "./keychain.js";
|
|
2
|
+
const REFRESH_SKEW_MS = 60_000;
|
|
3
|
+
const LOGIN_REQUIRED = "Wayform login expired — run: wayform login";
|
|
4
|
+
const refreshes = new Map();
|
|
5
|
+
function requireLogin() {
|
|
6
|
+
throw new Error(LOGIN_REQUIRED);
|
|
7
|
+
}
|
|
8
|
+
function isTerminalRefreshFailure(status) {
|
|
9
|
+
return status === 400 || status === 401 || status === 403;
|
|
10
|
+
}
|
|
11
|
+
function concurrentSession(gatewayUrl, stored, store) {
|
|
12
|
+
const latest = loadStoredOAuth(gatewayUrl, store);
|
|
13
|
+
if (latest?.access_token &&
|
|
14
|
+
(latest.access_token !== stored.access_token ||
|
|
15
|
+
latest.refresh_token !== stored.refresh_token)) {
|
|
16
|
+
return latest;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
async function refreshAccessToken(gatewayUrl, stored, options) {
|
|
21
|
+
const now = options.now ?? Date.now;
|
|
22
|
+
if (!stored.refresh_token || !stored.client_id || !stored.token_endpoint) {
|
|
23
|
+
return requireLogin();
|
|
24
|
+
}
|
|
25
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
26
|
+
let response;
|
|
27
|
+
try {
|
|
28
|
+
response = await fetchImpl(stored.token_endpoint, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
31
|
+
body: new URLSearchParams({
|
|
32
|
+
grant_type: "refresh_token",
|
|
33
|
+
refresh_token: stored.refresh_token,
|
|
34
|
+
client_id: stored.client_id,
|
|
35
|
+
resource: stored.resource,
|
|
36
|
+
}).toString(),
|
|
37
|
+
signal: options.signal,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new Error("Wayform could not refresh the OAuth session", {
|
|
42
|
+
cause: error,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
if (isTerminalRefreshFailure(response.status)) {
|
|
47
|
+
const concurrent = concurrentSession(gatewayUrl, stored, options.store);
|
|
48
|
+
if (concurrent)
|
|
49
|
+
return concurrent.access_token;
|
|
50
|
+
return requireLogin();
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Wayform OAuth refresh failed (${response.status})`);
|
|
53
|
+
}
|
|
54
|
+
const body = (await response.json());
|
|
55
|
+
if (typeof body.access_token !== "string" || !body.access_token) {
|
|
56
|
+
const concurrent = concurrentSession(gatewayUrl, stored, options.store);
|
|
57
|
+
if (concurrent)
|
|
58
|
+
return concurrent.access_token;
|
|
59
|
+
return requireLogin();
|
|
60
|
+
}
|
|
61
|
+
const expiresIn = typeof body.expires_in === "number" &&
|
|
62
|
+
Number.isFinite(body.expires_in) &&
|
|
63
|
+
body.expires_in > 0
|
|
64
|
+
? body.expires_in
|
|
65
|
+
: 3600;
|
|
66
|
+
const refreshed = {
|
|
67
|
+
...stored,
|
|
68
|
+
access_token: body.access_token,
|
|
69
|
+
refresh_token: typeof body.refresh_token === "string" && body.refresh_token
|
|
70
|
+
? body.refresh_token
|
|
71
|
+
: stored.refresh_token,
|
|
72
|
+
expires_at: now() + expiresIn * 1000,
|
|
73
|
+
};
|
|
74
|
+
saveStoredOAuth(gatewayUrl, refreshed, options.store);
|
|
75
|
+
return refreshed.access_token;
|
|
76
|
+
}
|
|
77
|
+
export async function getValidAccessToken(gatewayUrl, options = {}) {
|
|
78
|
+
const stored = loadStoredOAuth(gatewayUrl, options.store);
|
|
79
|
+
if (!stored?.access_token) {
|
|
80
|
+
throw new Error("Wayform is not logged in — run: wayform login");
|
|
81
|
+
}
|
|
82
|
+
const now = options.now ?? Date.now;
|
|
83
|
+
if (!options.forceRefresh && stored.expires_at > now() + REFRESH_SKEW_MS) {
|
|
84
|
+
return stored.access_token;
|
|
85
|
+
}
|
|
86
|
+
const active = refreshes.get(gatewayUrl);
|
|
87
|
+
if (active)
|
|
88
|
+
return active;
|
|
89
|
+
const refresh = refreshAccessToken(gatewayUrl, stored, options);
|
|
90
|
+
refreshes.set(gatewayUrl, refresh);
|
|
91
|
+
try {
|
|
92
|
+
return await refresh;
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
if (refreshes.get(gatewayUrl) === refresh)
|
|
96
|
+
refreshes.delete(gatewayUrl);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function withAuthorization(init, accessToken) {
|
|
100
|
+
const headers = new Headers(init?.headers);
|
|
101
|
+
headers.set("authorization", `Bearer ${accessToken}`);
|
|
102
|
+
return { ...init, headers };
|
|
103
|
+
}
|
|
104
|
+
export async function oauthFetch(gatewayUrl, input, init = {}, options = {}) {
|
|
105
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
106
|
+
const sessionOptions = {
|
|
107
|
+
...options,
|
|
108
|
+
signal: options.signal ?? init.signal ?? undefined,
|
|
109
|
+
};
|
|
110
|
+
const accessToken = await getValidAccessToken(gatewayUrl, sessionOptions);
|
|
111
|
+
const firstInput = input instanceof Request ? input.clone() : input;
|
|
112
|
+
const first = await fetchImpl(firstInput, withAuthorization(init, accessToken));
|
|
113
|
+
if (first.status !== 401)
|
|
114
|
+
return first;
|
|
115
|
+
const refreshed = await getValidAccessToken(gatewayUrl, {
|
|
116
|
+
...sessionOptions,
|
|
117
|
+
forceRefresh: true,
|
|
118
|
+
});
|
|
119
|
+
const retryInput = input instanceof Request ? input.clone() : input;
|
|
120
|
+
return fetchImpl(retryInput, withAuthorization(init, refreshed));
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=oauth-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-session.js","sourceRoot":"","sources":["../src/oauth-session.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,eAAe,GAEhB,MAAM,eAAe,CAAC;AAEvB,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,cAAc,GAAG,4CAA4C,CAAC;AAUpE,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;AAErD,SAAS,YAAY;IACnB,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,wBAAwB,CAAC,MAAc;IAC9C,OAAO,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;AAC5D,CA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Submit hook — hidden prompt-context injection via
|
|
4
|
+
* gateway POST /hook/prompt (decision da491a7d). Cursor cannot inject on
|
|
5
|
+
* beforeSubmitPrompt; Cursor stays rules + remote MCP.
|
|
6
|
+
*
|
|
7
|
+
* FAIL-OPEN: any error / empty injection → client empty no-op, exit 0.
|
|
8
|
+
*/
|
|
9
|
+
import { loadConfig, defaultProject } from "./config.js";
|
|
10
|
+
import { remoteHookPrompt } from "./remote-read.js";
|
|
11
|
+
import { resolveClient, renderPromptContext, renderEmpty, } from "./hook-clients.js";
|
|
12
|
+
import { isMain } from "./is-main.js";
|
|
13
|
+
export async function runPromptHook() {
|
|
14
|
+
const client = resolveClient(process.env.MEMORYLAYER_HOOK_CLIENT);
|
|
15
|
+
const emitEmpty = () => {
|
|
16
|
+
process.stdout.write(renderEmpty(client));
|
|
17
|
+
process.exit(0);
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
let raw = "";
|
|
21
|
+
if (!process.stdin.isTTY) {
|
|
22
|
+
for await (const chunk of process.stdin)
|
|
23
|
+
raw += chunk;
|
|
24
|
+
}
|
|
25
|
+
let prompt = "";
|
|
26
|
+
try {
|
|
27
|
+
const payload = raw.trim() ? JSON.parse(raw) : {};
|
|
28
|
+
prompt = typeof payload.prompt === "string" ? payload.prompt.trim() : "";
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
emitEmpty();
|
|
32
|
+
}
|
|
33
|
+
if (!prompt)
|
|
34
|
+
emitEmpty();
|
|
35
|
+
// Only Claude Code supports hidden UserPromptSubmit injection for us.
|
|
36
|
+
if (client !== "claude-code")
|
|
37
|
+
emitEmpty();
|
|
38
|
+
const project = process.env.MEMORYLAYER_PROJECT?.trim() || defaultProject();
|
|
39
|
+
const cfg = loadConfig();
|
|
40
|
+
const text = await remoteHookPrompt(cfg, project, prompt, cfg.readBudgetTokens);
|
|
41
|
+
if (text == null || text === "")
|
|
42
|
+
emitEmpty();
|
|
43
|
+
process.stdout.write(renderPromptContext(client, text));
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
emitEmpty();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (isMain(import.meta.url)) {
|
|
51
|
+
void runPromptHook();
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=prompt-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-hook.js","sourceRoot":"","sources":["../src/prompt-hook.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,WAAW,GAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,MAAM,MAAM,GAAe,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAE9E,MAAM,SAAS,GAAG,GAAU,EAAE;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACzB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK;gBAAE,GAAG,IAAI,KAAK,CAAC;QACxD,CAAC;QACD,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,GAAG,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,CAAC;QAAC,MAAM,CAAC;YACP,SAAS,EAAE,CAAC;QACd,CAAC;QACD,IAAI,CAAC,MAAM;YAAE,SAAS,EAAE,CAAC;QAEzB,sEAAsE;QACtE,IAAI,MAAM,KAAK,aAAa;YAAE,SAAS,EAAE,CAAC;QAE1C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,EAAE,IAAI,cAAc,EAAE,CAAC;QAC5E,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CACjC,GAAG,EACH,OAAO,EACP,MAAM,EACN,GAAG,CAAC,gBAAgB,CACrB,CAAC;QACF,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,KAAK,EAAE;YAAE,SAAS,EAAE,CAAC;QAC7C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAc,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,SAAS,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5B,KAAK,aAAa,EAAE,CAAC;AACvB,CAAC"}
|
package/dist/remote-read.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { oauthFetch } from "./oauth-session.js";
|
|
1
2
|
const REMOTE_TIMEOUT_MS = 4000;
|
|
2
3
|
function configured(cfg) {
|
|
3
|
-
return Boolean(cfg.gatewayUrl
|
|
4
|
+
return Boolean(cfg.gatewayUrl);
|
|
4
5
|
}
|
|
5
|
-
export async function remoteApiRead(cfg, opts, fetchImpl =
|
|
6
|
+
export async function remoteApiRead(cfg, opts, fetchImpl = oauthFetch) {
|
|
6
7
|
if (!configured(cfg))
|
|
7
8
|
return null;
|
|
8
9
|
try {
|
|
9
|
-
const url = new URL(`${cfg.gatewayUrl}/api/read`);
|
|
10
|
+
const url = new URL(`${cfg.gatewayUrl}/mcp/api/read`);
|
|
10
11
|
url.searchParams.set("project", opts.project);
|
|
11
12
|
if (opts.query)
|
|
12
13
|
url.searchParams.set("query", opts.query);
|
|
@@ -16,8 +17,7 @@ export async function remoteApiRead(cfg, opts, fetchImpl = fetch) {
|
|
|
16
17
|
url.searchParams.set("kinds", opts.kinds.join(","));
|
|
17
18
|
if (opts.trigger)
|
|
18
19
|
url.searchParams.set("trigger", opts.trigger);
|
|
19
|
-
const res = await fetchImpl(url.toString(), {
|
|
20
|
-
headers: { authorization: `Bearer ${cfg.gatewayToken}` },
|
|
20
|
+
const res = await fetchImpl(cfg.gatewayUrl, url.toString(), {
|
|
21
21
|
signal: AbortSignal.timeout(REMOTE_TIMEOUT_MS),
|
|
22
22
|
});
|
|
23
23
|
if (!res.ok)
|
|
@@ -35,15 +35,35 @@ export async function remoteApiRead(cfg, opts, fetchImpl = fetch) {
|
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
export async function remoteHookRead(cfg, project, budgetTokens, fetchImpl =
|
|
38
|
+
export async function remoteHookRead(cfg, project, budgetTokens, fetchImpl = oauthFetch) {
|
|
39
39
|
if (!configured(cfg))
|
|
40
40
|
return null;
|
|
41
41
|
try {
|
|
42
|
-
const url = new URL(`${cfg.gatewayUrl}/hook/read`);
|
|
42
|
+
const url = new URL(`${cfg.gatewayUrl}/mcp/hook/read`);
|
|
43
43
|
url.searchParams.set("project", project);
|
|
44
44
|
url.searchParams.set("budget", String(budgetTokens));
|
|
45
|
-
const res = await fetchImpl(url.toString(), {
|
|
46
|
-
|
|
45
|
+
const res = await fetchImpl(cfg.gatewayUrl, url.toString(), {
|
|
46
|
+
signal: AbortSignal.timeout(REMOTE_TIMEOUT_MS),
|
|
47
|
+
});
|
|
48
|
+
if (!res.ok)
|
|
49
|
+
return null;
|
|
50
|
+
return await res.text();
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** POST /mcp/hook/prompt — returns inject text or "" (nothing to inject) or null (gateway unusable). */
|
|
57
|
+
export async function remoteHookPrompt(cfg, project, prompt, budgetTokens, fetchImpl = oauthFetch) {
|
|
58
|
+
if (!configured(cfg))
|
|
59
|
+
return null;
|
|
60
|
+
try {
|
|
61
|
+
const res = await fetchImpl(cfg.gatewayUrl, `${cfg.gatewayUrl}/mcp/hook/prompt`, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: {
|
|
64
|
+
"content-type": "application/json",
|
|
65
|
+
},
|
|
66
|
+
body: JSON.stringify({ project, prompt, budget: budgetTokens }),
|
|
47
67
|
signal: AbortSignal.timeout(REMOTE_TIMEOUT_MS),
|
|
48
68
|
});
|
|
49
69
|
if (!res.ok)
|
package/dist/remote-read.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-read.js","sourceRoot":"","sources":["../src/remote-read.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remote-read.js","sourceRoot":"","sources":["../src/remote-read.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQhD,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAU/B,SAAS,UAAU,CACjB,GAAe;IAEf,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAe,EACf,IAMC,EACD,YAA0B,UAAU;IAEpC,IAAI,CAAC,UAAU,CAAC,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,SAAS,CACzB,GAAG,CAAC,UAAU,EACd,GAAG,GAAG,CAAC,UAAU,kBAAkB,EACnC;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;YAC/D,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,iBAAiB,CAAC;SAC/C,CACF,CAAC;QACF,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACzB,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/session-prompt.js
CHANGED
|
@@ -21,9 +21,10 @@ export function invocationPlaybook(project, opts = {}) {
|
|
|
21
21
|
return [
|
|
22
22
|
`## MemoryLayer — required tool policy (project "${project}")`,
|
|
23
23
|
``,
|
|
24
|
-
`
|
|
25
|
-
`
|
|
26
|
-
`
|
|
24
|
+
`Product plane: remote MCP (hosted gateway) only. The briefing below is a ` +
|
|
25
|
+
`SELECTIVE snapshot, not the full store. Collaborator decisions live in ` +
|
|
26
|
+
`MemoryLayer tools — not in your training data. Prefer these tools over ` +
|
|
27
|
+
`guessing or asking the user to re-explain recorded work.`,
|
|
27
28
|
``,
|
|
28
29
|
`### MUST call`,
|
|
29
30
|
`- \`search_memory(query)\` BEFORE contradicting, reversing, or re-deciding ` +
|
|
@@ -39,9 +40,9 @@ export function invocationPlaybook(project, opts = {}) {
|
|
|
39
40
|
`(after search, or when Open questions / Unresolved conflicts touch the work).`,
|
|
40
41
|
`- \`write_context(project="${project}", type, payload)\` when THIS turn ` +
|
|
41
42
|
`settles "we decided X because Y" or durable background not already stored — ` +
|
|
42
|
-
`including
|
|
43
|
-
`
|
|
44
|
-
`intermediate reasoning.`,
|
|
43
|
+
`including soft asks ("log this for the team", "remember we…", "note that…", ` +
|
|
44
|
+
`"/remember") and durable conclusions YOU produced (condensed). Not for open ` +
|
|
45
|
+
`options or intermediate reasoning.`,
|
|
45
46
|
...(opts.supersedes
|
|
46
47
|
? [
|
|
47
48
|
`- To UPDATE or CORRECT a recorded decision: \`write_context\` the new ` +
|
|
@@ -59,6 +60,7 @@ export function invocationPlaybook(project, opts = {}) {
|
|
|
59
60
|
`treat the briefing as exhaustive.`,
|
|
60
61
|
`- Skip search because the briefing "looks related" — if you would change a ` +
|
|
61
62
|
`settled call, search first.`,
|
|
63
|
+
`- Skip \`write_context\` on soft team-log phrasing — if they want it remembered, write it.`,
|
|
62
64
|
``,
|
|
63
65
|
`### Order`,
|
|
64
66
|
`search_memory (or read_context with query) → then decide/advise → ` +
|
|
@@ -78,15 +80,16 @@ export function composeSessionStartText(project, body, opts = {}) {
|
|
|
78
80
|
*/
|
|
79
81
|
export function mcpInstructions(defaultProject, opts = {}) {
|
|
80
82
|
return (`This server holds shared planning memory (decisions and durable context) ` +
|
|
81
|
-
`for collaborators
|
|
83
|
+
`for collaborators over remote MCP (hosted gateway only). Default project ` +
|
|
84
|
+
`if unsure: "${defaultProject}". ` +
|
|
82
85
|
`MUST: call search_memory before contradicting or re-deciding settled work, ` +
|
|
83
86
|
`before asking the user a clarifying question memory might answer, and ` +
|
|
84
87
|
`before recommending an action that may already be recommended or done; ` +
|
|
85
88
|
`call read_context(project, query=…) for topic depth (if a session-start ` +
|
|
86
89
|
`briefing was already injected, do NOT queryless re-read just to refresh); ` +
|
|
87
|
-
`call write_context
|
|
88
|
-
`background,
|
|
89
|
-
`reasoning step; ` +
|
|
90
|
+
`call write_context for deliberate "we decided X because Y", durable ` +
|
|
91
|
+
`background, soft team-log phrasing ("log this for the team", "remember we…"), ` +
|
|
92
|
+
`or a condensed durable conclusion you produced — not every reasoning step; ` +
|
|
90
93
|
(opts.supersedes
|
|
91
94
|
? `to update or correct a recorded decision, write_context the new ` +
|
|
92
95
|
`version with supersedes:[old fact id from search results] instead of ` +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-prompt.js","sourceRoot":"","sources":["../src/session-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mFAAmF;AACnF,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO,CACL,oEAAoE;QACpE,IAAI,OAAO,iEAAiE;QAC5E,4EAA4E;QAC5E,OAAO,CACR,CAAC;AACJ,CAAC;AAcD,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,OAAqB,EAAE;IAEvB,OAAO;QACL,mDAAmD,OAAO,IAAI;QAC9D,EAAE;QACF
|
|
1
|
+
{"version":3,"file":"session-prompt.js","sourceRoot":"","sources":["../src/session-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mFAAmF;AACnF,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO,CACL,oEAAoE;QACpE,IAAI,OAAO,iEAAiE;QAC5E,4EAA4E;QAC5E,OAAO,CACR,CAAC;AACJ,CAAC;AAcD,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,OAAqB,EAAE;IAEvB,OAAO;QACL,mDAAmD,OAAO,IAAI;QAC9D,EAAE;QACF,2EAA2E;YACzE,yEAAyE;YACzE,yEAAyE;YACzE,0DAA0D;QAC5D,EAAE;QACF,eAAe;QACf,6EAA6E;YAC3E,4EAA4E;YAC5E,qEAAqE;QACvE,4EAA4E;YAC1E,2EAA2E;YAC3E,+CAA+C;QACjD,+EAA+E;YAC7E,uEAAuE;YACvE,0BAA0B;QAC5B,6BAA6B,OAAO,uCAAuC;YACzE,+EAA+E;QACjF,8BAA8B,OAAO,qCAAqC;YACxE,8EAA8E;YAC9E,8EAA8E;YAC9E,8EAA8E;YAC9E,oCAAoC;QACtC,GAAG,CAAC,IAAI,CAAC,UAAU;YACjB,CAAC,CAAC;gBACE,wEAAwE;oBACtE,qEAAqE;oBACrE,yCAAyC;aAC5C;YACH,CAAC,CAAC,EAAE,CAAC;QACP,4EAA4E;YAC1E,+DAA+D;QACjE,EAAE;QACF,cAAc;QACd,iFAAiF;YAC/E,yBAAyB;QAC3B,6EAA6E;YAC3E,mCAAmC;QACrC,6EAA6E;YAC3E,6BAA6B;QAC/B,4FAA4F;QAC5F,EAAE;QACF,WAAW;QACX,oEAAoE;YAClE,0EAA0E;YAC1E,8EAA8E;YAC9E,0BAA0B;KAC7B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,uBAAuB,CACrC,OAAe,EACf,IAAY,EACZ,OAAqB,EAAE;IAEvB,OAAO,CACL,GAAG,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa;QACjD,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CACzC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,cAAsB,EACtB,OAAqB,EAAE;IAEvB,OAAO,CACL,2EAA2E;QAC3E,2EAA2E;QAC3E,eAAe,cAAc,KAAK;QAClC,6EAA6E;QAC7E,wEAAwE;QACxE,yEAAyE;QACzE,0EAA0E;QAC1E,4EAA4E;QAC5E,sEAAsE;QACtE,gFAAgF;QAChF,6EAA6E;QAC7E,CAAC,IAAI,CAAC,UAAU;YACd,CAAC,CAAC,kEAAkE;gBAClE,uEAAuE;gBACvE,oBAAoB;YACtB,CAAC,CAAC,EAAE,CAAC;QACP,0EAA0E;QAC1E,2EAA2E;QAC3E,gCAAgC,CACjC,CAAC;AACJ,CAAC"}
|
package/dist/space-create.js
CHANGED
|
@@ -1,219 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `wayform space create` —
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* credential the manual `curl` flow against POST /admin/members already uses.
|
|
2
|
+
* `wayform space create` — operator helper: print the GitHub App install URL
|
|
3
|
+
* and remind them to allowlist the customer. Does not mint tokens or create
|
|
4
|
+
* their repo.
|
|
6
5
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import readline from "node:readline/promises";
|
|
9
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
10
|
-
import { gitConfigDefault } from "./init-env.js";
|
|
6
|
+
import { DEFAULT_GATEWAY_URL } from "./oauth-login.js";
|
|
11
7
|
const flag = (args, name) => {
|
|
12
8
|
const i = args.indexOf(`--${name}`);
|
|
13
9
|
return i >= 0 && i + 1 < args.length ? args[i + 1] : undefined;
|
|
14
10
|
};
|
|
15
|
-
const has = (args, name) => args.includes(`--${name}`);
|
|
16
11
|
export function parseSpaceCreateArgs(args) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!space || !owner || !repo) {
|
|
21
|
-
throw new Error("wayform space create requires --space <name> --owner <owner> --repo <repo>");
|
|
22
|
-
}
|
|
23
|
-
const appSlug = flag(args, "app-slug") ?? process.env.WAYFORM_GITHUB_APP_SLUG;
|
|
24
|
-
if (!appSlug) {
|
|
25
|
-
throw new Error("wayform space create requires --app-slug <slug> or WAYFORM_GITHUB_APP_SLUG " +
|
|
26
|
-
"(the GitHub App's slug, used to build the install URL)");
|
|
27
|
-
}
|
|
12
|
+
const appSlug = flag(args, "app-slug") ??
|
|
13
|
+
process.env.WAYFORM_GITHUB_APP_SLUG ??
|
|
14
|
+
"memorylayer-gateway";
|
|
28
15
|
return {
|
|
29
|
-
|
|
30
|
-
owner,
|
|
31
|
-
repo,
|
|
32
|
-
isPublic: has(args, "public"),
|
|
16
|
+
owner: flag(args, "owner"),
|
|
33
17
|
appSlug,
|
|
34
|
-
|
|
35
|
-
authorEmail: flag(args, "author-email"),
|
|
18
|
+
gatewayUrl: (flag(args, "gateway") ?? DEFAULT_GATEWAY_URL).replace(/\/+$/, ""),
|
|
36
19
|
};
|
|
37
20
|
}
|
|
38
|
-
export function resolveAdminSecret() {
|
|
39
|
-
const secret = process.env.WAYFORM_ADMIN_SECRET;
|
|
40
|
-
if (!secret) {
|
|
41
|
-
throw new Error("WAYFORM_ADMIN_SECRET is not set. `wayform space create` is an " +
|
|
42
|
-
"operator-only command — export the gateway's ADMIN_SECRET before running it.");
|
|
43
|
-
}
|
|
44
|
-
return secret;
|
|
45
|
-
}
|
|
46
|
-
const defaultRunner = (cmd, args) =>
|
|
47
|
-
// Bounded + non-interactive, same posture as init-remote's registerClaudeCodeMcp:
|
|
48
|
-
// a hanging or prompting child process must never freeze space create.
|
|
49
|
-
void execFileSync(cmd, args, {
|
|
50
|
-
stdio: ["ignore", "ignore", "ignore"],
|
|
51
|
-
timeout: 15000,
|
|
52
|
-
});
|
|
53
|
-
export function ghAuthenticated(run = defaultRunner) {
|
|
54
|
-
try {
|
|
55
|
-
run("gh", ["auth", "status"]);
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export function createRepoWithGh(owner, repo, isPublic, run = defaultRunner) {
|
|
63
|
-
run("gh", [
|
|
64
|
-
"repo",
|
|
65
|
-
"create",
|
|
66
|
-
`${owner}/${repo}`,
|
|
67
|
-
isPublic ? "--public" : "--private",
|
|
68
|
-
]);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Tries the org repo-creation endpoint first, falls back to /user/repos on a
|
|
72
|
-
* 404 (the owner isn't an org this token can create under — the common case
|
|
73
|
-
* when --owner is the token holder's own username).
|
|
74
|
-
*/
|
|
75
|
-
export async function createRepoWithPat(owner, repo, isPublic, pat, fetchImpl = fetch) {
|
|
76
|
-
const body = JSON.stringify({ name: repo, private: !isPublic });
|
|
77
|
-
const headers = {
|
|
78
|
-
authorization: `Bearer ${pat}`,
|
|
79
|
-
accept: "application/vnd.github+json",
|
|
80
|
-
"content-type": "application/json",
|
|
81
|
-
"user-agent": "wayform-cli",
|
|
82
|
-
};
|
|
83
|
-
let res = await fetchImpl(`https://api.github.com/orgs/${owner}/repos`, {
|
|
84
|
-
method: "POST",
|
|
85
|
-
headers,
|
|
86
|
-
body,
|
|
87
|
-
});
|
|
88
|
-
if (res.status === 404) {
|
|
89
|
-
res = await fetchImpl("https://api.github.com/user/repos", {
|
|
90
|
-
method: "POST",
|
|
91
|
-
headers,
|
|
92
|
-
body,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
if (!res.ok) {
|
|
96
|
-
const detail = await res.text();
|
|
97
|
-
throw new Error(`GitHub repo creation failed (${res.status}): ${detail}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const DEFAULT_POLL = { intervalMs: 3000, timeoutMs: 120_000 };
|
|
101
|
-
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
102
|
-
export async function pollInstallation(gatewayUrl, adminSecret, owner, fetchImpl = fetch, opts = DEFAULT_POLL, sleep = defaultSleep) {
|
|
103
|
-
const deadline = Date.now() + opts.timeoutMs;
|
|
104
|
-
const url = `${gatewayUrl}/admin/installations?owner=${encodeURIComponent(owner)}`;
|
|
105
|
-
const manualFallback = `curl -X POST ${gatewayUrl}/admin/members -H "x-admin-secret: <secret>" ` +
|
|
106
|
-
`-H "content-type: application/json" -d '{"space":"...","installationId":<id>,` +
|
|
107
|
-
`"owner":"${owner}","repo":"...","author":"...","authorEmail":"..."}'`;
|
|
108
|
-
while (true) {
|
|
109
|
-
const res = await fetchImpl(url, {
|
|
110
|
-
headers: { "x-admin-secret": adminSecret },
|
|
111
|
-
});
|
|
112
|
-
if (res.status === 200) {
|
|
113
|
-
const body = (await res.json());
|
|
114
|
-
return body.installationId;
|
|
115
|
-
}
|
|
116
|
-
if (res.status === 409) {
|
|
117
|
-
const body = (await res.json());
|
|
118
|
-
throw new Error(`Multiple GitHub App installations found for owner "${owner}" ` +
|
|
119
|
-
`(${body.installationIds.join(", ")}). Resolve manually, then mint the ` +
|
|
120
|
-
`token directly:\n ${manualFallback}`);
|
|
121
|
-
}
|
|
122
|
-
if (Date.now() >= deadline) {
|
|
123
|
-
throw new Error(`Timed out waiting for the GitHub App install on "${owner}". Install it, ` +
|
|
124
|
-
`then mint the token manually:\n ${manualFallback}`);
|
|
125
|
-
}
|
|
126
|
-
await sleep(opts.intervalMs);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
export async function mintMemberToken(gatewayUrl, adminSecret, body, fetchImpl = fetch) {
|
|
130
|
-
const res = await fetchImpl(`${gatewayUrl}/admin/members`, {
|
|
131
|
-
method: "POST",
|
|
132
|
-
headers: {
|
|
133
|
-
"x-admin-secret": adminSecret,
|
|
134
|
-
"content-type": "application/json",
|
|
135
|
-
},
|
|
136
|
-
body: JSON.stringify(body),
|
|
137
|
-
});
|
|
138
|
-
if (!res.ok) {
|
|
139
|
-
const detail = await res.text();
|
|
140
|
-
throw new Error(`token mint failed (${res.status}): ${detail}`);
|
|
141
|
-
}
|
|
142
|
-
return (await res.json());
|
|
143
|
-
}
|
|
144
|
-
export async function createTeamInvite(gatewayUrl, adminSecret, body, fetchImpl = fetch) {
|
|
145
|
-
const res = await fetchImpl(`${gatewayUrl}/admin/invites`, {
|
|
146
|
-
method: "POST",
|
|
147
|
-
headers: {
|
|
148
|
-
"x-admin-secret": adminSecret,
|
|
149
|
-
"content-type": "application/json",
|
|
150
|
-
},
|
|
151
|
-
body: JSON.stringify(body),
|
|
152
|
-
});
|
|
153
|
-
if (!res.ok) {
|
|
154
|
-
const detail = await res.text();
|
|
155
|
-
throw new Error(`invite mint failed (${res.status}): ${detail}`);
|
|
156
|
-
}
|
|
157
|
-
const { invite } = (await res.json());
|
|
158
|
-
return invite;
|
|
159
|
-
}
|
|
160
|
-
export async function promptForPat() {
|
|
161
|
-
const rl = readline.createInterface({ input, output });
|
|
162
|
-
const pat = await rl.question("gh not found or not authenticated. Paste a GitHub PAT with repo-creation scope: ");
|
|
163
|
-
rl.close();
|
|
164
|
-
return pat.trim();
|
|
165
|
-
}
|
|
166
|
-
const defaultDeps = {
|
|
167
|
-
run: defaultRunner,
|
|
168
|
-
fetchImpl: fetch,
|
|
169
|
-
promptForPat,
|
|
170
|
-
sleep: defaultSleep,
|
|
171
|
-
log: (msg) => console.log(msg),
|
|
172
|
-
poll: DEFAULT_POLL,
|
|
173
|
-
};
|
|
174
21
|
export async function runSpaceCreate(args, deps = {}) {
|
|
175
|
-
const
|
|
22
|
+
const log = deps.log ?? ((m) => console.log(m));
|
|
176
23
|
const parsed = parseSpaceCreateArgs(args);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
throw new Error("wayform space create requires --gateway <url>");
|
|
180
|
-
}
|
|
181
|
-
const adminSecret = resolveAdminSecret();
|
|
182
|
-
const author = parsed.author ?? gitConfigDefault("user.name");
|
|
183
|
-
const authorEmail = parsed.authorEmail ?? gitConfigDefault("user.email");
|
|
184
|
-
d.log(`Creating repo ${parsed.owner}/${parsed.repo}...`);
|
|
185
|
-
if (ghAuthenticated(d.run)) {
|
|
186
|
-
createRepoWithGh(parsed.owner, parsed.repo, parsed.isPublic, d.run);
|
|
24
|
+
if (parsed.owner) {
|
|
25
|
+
log(`Allowlist ${parsed.owner} (operator): curl -X POST ${parsed.gatewayUrl}/admin/allowlist -H "x-admin-secret: $ADMIN_SECRET" -H "content-type: application/json" -d '{"add":["${parsed.owner}"]}'`);
|
|
187
26
|
}
|
|
188
27
|
else {
|
|
189
|
-
|
|
190
|
-
await createRepoWithPat(parsed.owner, parsed.repo, parsed.isPublic, pat, d.fetchImpl);
|
|
28
|
+
log("Pass --owner <github-login-or-org> to print the allowlist command.");
|
|
191
29
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const minted = await mintMemberToken(gatewayUrl, adminSecret, {
|
|
197
|
-
space: parsed.space,
|
|
198
|
-
installationId,
|
|
199
|
-
owner: parsed.owner,
|
|
200
|
-
repo: parsed.repo,
|
|
201
|
-
author,
|
|
202
|
-
authorEmail,
|
|
203
|
-
}, d.fetchImpl);
|
|
204
|
-
const invite = await createTeamInvite(gatewayUrl, adminSecret, {
|
|
205
|
-
space: parsed.space,
|
|
206
|
-
installationId,
|
|
207
|
-
owner: parsed.owner,
|
|
208
|
-
repo: parsed.repo,
|
|
209
|
-
}, d.fetchImpl);
|
|
210
|
-
d.log("");
|
|
211
|
-
d.log(`Space "${parsed.space}" created.`);
|
|
212
|
-
d.log(`Your token (shown once): ${minted.token}`);
|
|
213
|
-
d.log("");
|
|
214
|
-
d.log("Hand this ONE line to each teammate — each mints their own token");
|
|
215
|
-
d.log("(invite expires in 14 days / 25 uses; send via email or a Slack");
|
|
216
|
-
d.log("code block, never iMessage — it mangles the dashes):");
|
|
217
|
-
d.log(` wayform init --remote --gateway ${gatewayUrl} --invite ${invite}`);
|
|
30
|
+
log(`GitHub App used by the guided flow: https://github.com/apps/${parsed.appSlug}`);
|
|
31
|
+
log(`In the product repo, run: wayform init --remote --gateway ${parsed.gatewayUrl}`);
|
|
32
|
+
log(`Then Connect the project-scoped Wayform MCP server; OAuth guides App installation and repository selection.`);
|
|
33
|
+
log(`MCP URL (URL-only project config): ${parsed.gatewayUrl}/mcp`);
|
|
218
34
|
}
|
|
219
35
|
//# sourceMappingURL=space-create.js.map
|
package/dist/space-create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space-create.js","sourceRoot":"","sources":["../src/space-create.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"space-create.js","sourceRoot":"","sources":["../src/space-create.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,IAAI,GAAG,CAAC,IAAc,EAAE,IAAY,EAAsB,EAAE;IAChE,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACpC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAA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