@percena/weft 0.4.0-next.1 → 0.4.0-next.3

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/auth.cjs DELETED
@@ -1,241 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/auth.ts
21
- var auth_exports = {};
22
- __export(auth_exports, {
23
- assertCodexAuthConfigured: () => assertCodexAuthConfigured,
24
- claudeAuthMissingMessage: () => claudeAuthMissingMessage,
25
- codexAuthFromResult: () => codexAuthFromResult,
26
- codexAuthMissingMessage: () => codexAuthMissingMessage,
27
- createSanitizedClaudeEnvironment: () => createSanitizedClaudeEnvironment,
28
- readClaudeAuth: () => readClaudeAuth,
29
- readCodexAuth: () => readCodexAuth
30
- });
31
- module.exports = __toCommonJS(auth_exports);
32
-
33
- // ../packages/adaptor/dist/chunk-DMO7RTY3.js
34
- var import_child_process = require("child_process");
35
- var import_child_process2 = require("child_process");
36
- var import_readline = require("readline");
37
- var NESTED_AGENT_ENV_PREFIXES = [
38
- "CLAUDECODE",
39
- "CODEX_HOME",
40
- // All CODEX_* prefix keys
41
- "CODEX_",
42
- "CLAUDE_CODE_ENTRYPOINT"
43
- ];
44
- function shouldStripNestedAgentEnv(key) {
45
- return NESTED_AGENT_ENV_PREFIXES.some(
46
- (prefix) => key === prefix || key.startsWith(prefix + "_") || key.startsWith(prefix)
47
- );
48
- }
49
- var CLAUDE_AGENT_SDK_CLIENT_APP = "weft/agent-bridge";
50
- function createSanitizedClaudeEnvironment(source = process.env) {
51
- const env = {};
52
- for (const [key, value] of Object.entries(source)) {
53
- if (value !== void 0 && !shouldStripNestedAgentEnv(key)) {
54
- env[key] = value;
55
- }
56
- }
57
- env.CLAUDE_AGENT_SDK_CLIENT_APP = CLAUDE_AGENT_SDK_CLIENT_APP;
58
- return env;
59
- }
60
- function resolveClaudeExecutable(env) {
61
- return env.WEFT_CLAUDE_EXECUTABLE || void 0;
62
- }
63
- async function readClaudeAuth(executable, env) {
64
- const resolvedEnv = env ?? createSanitizedClaudeEnvironment();
65
- const claudeBin = executable ?? resolveClaudeExecutable(resolvedEnv) ?? "claude";
66
- try {
67
- const { stdout, exitCode } = await new Promise((resolve) => {
68
- (0, import_child_process.execFile)(claudeBin, ["auth", "status", "--json"], { env: resolvedEnv }, (error, stdout2, stderr) => {
69
- resolve({
70
- stdout: stdout2?.toString() ?? "",
71
- stderr: stderr?.toString() ?? "",
72
- exitCode: error ? error.code ?? 1 : 0
73
- });
74
- });
75
- });
76
- if (exitCode !== 0) {
77
- return {
78
- mode: "provider-owned",
79
- configured: false,
80
- source: `${claudeBin} auth status --json`,
81
- error: `Claude Code CLI returned exit code ${exitCode}. Ensure \`claude\` is on PATH or set WEFT_CLAUDE_EXECUTABLE.`
82
- };
83
- }
84
- const status = JSON.parse(stdout);
85
- return {
86
- mode: "provider-owned",
87
- configured: status.loggedIn === true,
88
- source: `${claudeBin} auth status --json`,
89
- method: status.authMethod,
90
- provider: status.apiProvider,
91
- accountPresent: Boolean(status.account)
92
- };
93
- } catch (err) {
94
- return {
95
- mode: "provider-owned",
96
- configured: false,
97
- source: `${claudeBin} auth status --json`,
98
- error: `Claude Code auth detection failed: ${err.message}. Run \`claude\` and complete login, or set CLAUDE_CONFIG_DIR.`
99
- };
100
- }
101
- }
102
- function claudeAuthMissingMessage() {
103
- return "Claude Code authentication is not configured. Run `claude` and complete login, or set CLAUDE_CONFIG_DIR.";
104
- }
105
- var DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
106
- var nextRpcId = 1;
107
- function makeRequest(method, params) {
108
- return { jsonrpc: "2.0", id: nextRpcId++, method, params };
109
- }
110
- function resolveCodexExecutable(env) {
111
- return env.WEFT_CODEX_EXECUTABLE || void 0;
112
- }
113
- function codexAuthFromResult(result, source) {
114
- const requiresOpenaiAuth = result.requiresOpenaiAuth === true;
115
- const accountPresent = Boolean(result.account);
116
- const configured = !requiresOpenaiAuth || accountPresent;
117
- return {
118
- mode: "provider-owned",
119
- configured,
120
- source,
121
- accountPresent,
122
- requiresOpenaiAuth,
123
- error: configured ? void 0 : codexAuthMissingMessage()
124
- };
125
- }
126
- async function readCodexAuth(executable, env, requestTimeoutMs) {
127
- const resolvedEnv = env ?? Object.fromEntries(
128
- Object.entries(process.env).filter(([, v]) => v !== void 0)
129
- );
130
- const codexBin = executable ?? resolveCodexExecutable(resolvedEnv) ?? "codex";
131
- const timeout = requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
132
- const source = `${codexBin} app-server account/read`;
133
- let proc = null;
134
- try {
135
- proc = (0, import_child_process2.spawn)(codexBin, ["app-server"], {
136
- env: resolvedEnv,
137
- stdio: ["pipe", "pipe", "pipe"]
138
- });
139
- } catch (err) {
140
- return {
141
- mode: "provider-owned",
142
- configured: false,
143
- source,
144
- error: `Codex auth detection failed: ${err.message}. Ensure \`codex\` is on PATH or set WEFT_CODEX_EXECUTABLE.`
145
- };
146
- }
147
- const spawnError = new Promise((_, reject) => {
148
- proc.on("error", (err) => {
149
- reject(new Error(`Codex auth detection failed: ${err.message}. Ensure \`codex\` is on PATH or set WEFT_CODEX_EXECUTABLE.`));
150
- });
151
- });
152
- try {
153
- const rl = (0, import_readline.createInterface)({ input: proc.stdout, crlfDelay: Infinity });
154
- const writeMsg = (msg) => {
155
- proc.stdin.write(JSON.stringify(msg) + "\n");
156
- };
157
- const readResponse = () => {
158
- const linePromise = new Promise((resolve, reject) => {
159
- const deadline = Date.now() + timeout;
160
- const timer = setTimeout(() => {
161
- reject(new Error(`Timeout waiting for Codex app-server response (${timeout}ms)`));
162
- }, Math.max(0, deadline - Date.now()));
163
- rl.once("line", (line) => {
164
- clearTimeout(timer);
165
- const trimmed = line.trim();
166
- if (trimmed) {
167
- try {
168
- resolve(JSON.parse(trimmed));
169
- } catch {
170
- reject(new Error(`Invalid JSON-RPC response: ${trimmed}`));
171
- }
172
- }
173
- });
174
- });
175
- return Promise.race([linePromise, spawnError]);
176
- };
177
- writeMsg(makeRequest("initialize", {
178
- protocolVersion: "2025-03-26",
179
- capabilities: {},
180
- clientInfo: { name: "weft", title: "Weft", version: "0.1.0" }
181
- }));
182
- const initResp = await readResponse();
183
- if (initResp.error) {
184
- rl.close();
185
- proc.kill();
186
- return {
187
- mode: "provider-owned",
188
- configured: false,
189
- source,
190
- error: `Codex initialize failed: ${initResp.error.message}`
191
- };
192
- }
193
- writeMsg({ jsonrpc: "2.0", method: "initialized", params: {} });
194
- await new Promise((resolve) => setTimeout(resolve, 50));
195
- writeMsg(makeRequest("account/read", { refreshToken: false }));
196
- const accountResp = await readResponse();
197
- rl.close();
198
- proc.kill();
199
- if (accountResp.error) {
200
- return {
201
- mode: "provider-owned",
202
- configured: false,
203
- source,
204
- error: `Codex account/read failed: ${accountResp.error.message}`
205
- };
206
- }
207
- return codexAuthFromResult(
208
- accountResp.result,
209
- source
210
- );
211
- } catch (err) {
212
- try {
213
- proc.kill();
214
- } catch {
215
- }
216
- return {
217
- mode: "provider-owned",
218
- configured: false,
219
- source,
220
- error: `Codex auth detection failed: ${err.message}. Ensure \`codex\` is on PATH or set WEFT_CODEX_EXECUTABLE.`
221
- };
222
- }
223
- }
224
- function codexAuthMissingMessage() {
225
- return "Codex authentication is not configured. Run `codex login` or set CODEX_HOME to a directory with valid auth.";
226
- }
227
- function assertCodexAuthConfigured(auth) {
228
- if (!auth.configured) {
229
- throw new Error(auth.error ?? codexAuthMissingMessage());
230
- }
231
- }
232
- // Annotate the CommonJS export names for ESM import in node:
233
- 0 && (module.exports = {
234
- assertCodexAuthConfigured,
235
- claudeAuthMissingMessage,
236
- codexAuthFromResult,
237
- codexAuthMissingMessage,
238
- createSanitizedClaudeEnvironment,
239
- readClaudeAuth,
240
- readCodexAuth
241
- });
package/dist/auth.d.cts DELETED
@@ -1 +0,0 @@
1
- export { ProviderAuthDetection, assertCodexAuthConfigured, claudeAuthMissingMessage, codexAuthFromResult, codexAuthMissingMessage, createSanitizedClaudeEnvironment, readClaudeAuth, readCodexAuth };
package/dist/auth.d.ts DELETED
@@ -1 +0,0 @@
1
- export { ProviderAuthDetection, assertCodexAuthConfigured, claudeAuthMissingMessage, codexAuthFromResult, codexAuthMissingMessage, createSanitizedClaudeEnvironment, readClaudeAuth, readCodexAuth };
package/dist/auth.js DELETED
@@ -1,208 +0,0 @@
1
- // ../packages/adaptor/dist/chunk-DMO7RTY3.js
2
- import { execFile } from "child_process";
3
- import { spawn } from "child_process";
4
- import { createInterface } from "readline";
5
- var NESTED_AGENT_ENV_PREFIXES = [
6
- "CLAUDECODE",
7
- "CODEX_HOME",
8
- // All CODEX_* prefix keys
9
- "CODEX_",
10
- "CLAUDE_CODE_ENTRYPOINT"
11
- ];
12
- function shouldStripNestedAgentEnv(key) {
13
- return NESTED_AGENT_ENV_PREFIXES.some(
14
- (prefix) => key === prefix || key.startsWith(prefix + "_") || key.startsWith(prefix)
15
- );
16
- }
17
- var CLAUDE_AGENT_SDK_CLIENT_APP = "weft/agent-bridge";
18
- function createSanitizedClaudeEnvironment(source = process.env) {
19
- const env = {};
20
- for (const [key, value] of Object.entries(source)) {
21
- if (value !== void 0 && !shouldStripNestedAgentEnv(key)) {
22
- env[key] = value;
23
- }
24
- }
25
- env.CLAUDE_AGENT_SDK_CLIENT_APP = CLAUDE_AGENT_SDK_CLIENT_APP;
26
- return env;
27
- }
28
- function resolveClaudeExecutable(env) {
29
- return env.WEFT_CLAUDE_EXECUTABLE || void 0;
30
- }
31
- async function readClaudeAuth(executable, env) {
32
- const resolvedEnv = env ?? createSanitizedClaudeEnvironment();
33
- const claudeBin = executable ?? resolveClaudeExecutable(resolvedEnv) ?? "claude";
34
- try {
35
- const { stdout, exitCode } = await new Promise((resolve) => {
36
- execFile(claudeBin, ["auth", "status", "--json"], { env: resolvedEnv }, (error, stdout2, stderr) => {
37
- resolve({
38
- stdout: stdout2?.toString() ?? "",
39
- stderr: stderr?.toString() ?? "",
40
- exitCode: error ? error.code ?? 1 : 0
41
- });
42
- });
43
- });
44
- if (exitCode !== 0) {
45
- return {
46
- mode: "provider-owned",
47
- configured: false,
48
- source: `${claudeBin} auth status --json`,
49
- error: `Claude Code CLI returned exit code ${exitCode}. Ensure \`claude\` is on PATH or set WEFT_CLAUDE_EXECUTABLE.`
50
- };
51
- }
52
- const status = JSON.parse(stdout);
53
- return {
54
- mode: "provider-owned",
55
- configured: status.loggedIn === true,
56
- source: `${claudeBin} auth status --json`,
57
- method: status.authMethod,
58
- provider: status.apiProvider,
59
- accountPresent: Boolean(status.account)
60
- };
61
- } catch (err) {
62
- return {
63
- mode: "provider-owned",
64
- configured: false,
65
- source: `${claudeBin} auth status --json`,
66
- error: `Claude Code auth detection failed: ${err.message}. Run \`claude\` and complete login, or set CLAUDE_CONFIG_DIR.`
67
- };
68
- }
69
- }
70
- function claudeAuthMissingMessage() {
71
- return "Claude Code authentication is not configured. Run `claude` and complete login, or set CLAUDE_CONFIG_DIR.";
72
- }
73
- var DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
74
- var nextRpcId = 1;
75
- function makeRequest(method, params) {
76
- return { jsonrpc: "2.0", id: nextRpcId++, method, params };
77
- }
78
- function resolveCodexExecutable(env) {
79
- return env.WEFT_CODEX_EXECUTABLE || void 0;
80
- }
81
- function codexAuthFromResult(result, source) {
82
- const requiresOpenaiAuth = result.requiresOpenaiAuth === true;
83
- const accountPresent = Boolean(result.account);
84
- const configured = !requiresOpenaiAuth || accountPresent;
85
- return {
86
- mode: "provider-owned",
87
- configured,
88
- source,
89
- accountPresent,
90
- requiresOpenaiAuth,
91
- error: configured ? void 0 : codexAuthMissingMessage()
92
- };
93
- }
94
- async function readCodexAuth(executable, env, requestTimeoutMs) {
95
- const resolvedEnv = env ?? Object.fromEntries(
96
- Object.entries(process.env).filter(([, v]) => v !== void 0)
97
- );
98
- const codexBin = executable ?? resolveCodexExecutable(resolvedEnv) ?? "codex";
99
- const timeout = requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
100
- const source = `${codexBin} app-server account/read`;
101
- let proc = null;
102
- try {
103
- proc = spawn(codexBin, ["app-server"], {
104
- env: resolvedEnv,
105
- stdio: ["pipe", "pipe", "pipe"]
106
- });
107
- } catch (err) {
108
- return {
109
- mode: "provider-owned",
110
- configured: false,
111
- source,
112
- error: `Codex auth detection failed: ${err.message}. Ensure \`codex\` is on PATH or set WEFT_CODEX_EXECUTABLE.`
113
- };
114
- }
115
- const spawnError = new Promise((_, reject) => {
116
- proc.on("error", (err) => {
117
- reject(new Error(`Codex auth detection failed: ${err.message}. Ensure \`codex\` is on PATH or set WEFT_CODEX_EXECUTABLE.`));
118
- });
119
- });
120
- try {
121
- const rl = createInterface({ input: proc.stdout, crlfDelay: Infinity });
122
- const writeMsg = (msg) => {
123
- proc.stdin.write(JSON.stringify(msg) + "\n");
124
- };
125
- const readResponse = () => {
126
- const linePromise = new Promise((resolve, reject) => {
127
- const deadline = Date.now() + timeout;
128
- const timer = setTimeout(() => {
129
- reject(new Error(`Timeout waiting for Codex app-server response (${timeout}ms)`));
130
- }, Math.max(0, deadline - Date.now()));
131
- rl.once("line", (line) => {
132
- clearTimeout(timer);
133
- const trimmed = line.trim();
134
- if (trimmed) {
135
- try {
136
- resolve(JSON.parse(trimmed));
137
- } catch {
138
- reject(new Error(`Invalid JSON-RPC response: ${trimmed}`));
139
- }
140
- }
141
- });
142
- });
143
- return Promise.race([linePromise, spawnError]);
144
- };
145
- writeMsg(makeRequest("initialize", {
146
- protocolVersion: "2025-03-26",
147
- capabilities: {},
148
- clientInfo: { name: "weft", title: "Weft", version: "0.1.0" }
149
- }));
150
- const initResp = await readResponse();
151
- if (initResp.error) {
152
- rl.close();
153
- proc.kill();
154
- return {
155
- mode: "provider-owned",
156
- configured: false,
157
- source,
158
- error: `Codex initialize failed: ${initResp.error.message}`
159
- };
160
- }
161
- writeMsg({ jsonrpc: "2.0", method: "initialized", params: {} });
162
- await new Promise((resolve) => setTimeout(resolve, 50));
163
- writeMsg(makeRequest("account/read", { refreshToken: false }));
164
- const accountResp = await readResponse();
165
- rl.close();
166
- proc.kill();
167
- if (accountResp.error) {
168
- return {
169
- mode: "provider-owned",
170
- configured: false,
171
- source,
172
- error: `Codex account/read failed: ${accountResp.error.message}`
173
- };
174
- }
175
- return codexAuthFromResult(
176
- accountResp.result,
177
- source
178
- );
179
- } catch (err) {
180
- try {
181
- proc.kill();
182
- } catch {
183
- }
184
- return {
185
- mode: "provider-owned",
186
- configured: false,
187
- source,
188
- error: `Codex auth detection failed: ${err.message}. Ensure \`codex\` is on PATH or set WEFT_CODEX_EXECUTABLE.`
189
- };
190
- }
191
- }
192
- function codexAuthMissingMessage() {
193
- return "Codex authentication is not configured. Run `codex login` or set CODEX_HOME to a directory with valid auth.";
194
- }
195
- function assertCodexAuthConfigured(auth) {
196
- if (!auth.configured) {
197
- throw new Error(auth.error ?? codexAuthMissingMessage());
198
- }
199
- }
200
- export {
201
- assertCodexAuthConfigured,
202
- claudeAuthMissingMessage,
203
- codexAuthFromResult,
204
- codexAuthMissingMessage,
205
- createSanitizedClaudeEnvironment,
206
- readClaudeAuth,
207
- readCodexAuth
208
- };