@ouro.bot/cli 0.1.0-alpha.6 → 0.1.0-alpha.61
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/AdoptionSpecialist.ouro/agent.json +70 -9
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +5 -2
- package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
- package/README.md +147 -205
- package/assets/ouroboros.png +0 -0
- package/changelog.json +334 -0
- package/dist/heart/active-work.js +178 -0
- package/dist/heart/bridges/manager.js +358 -0
- package/dist/heart/bridges/state-machine.js +135 -0
- package/dist/heart/bridges/store.js +123 -0
- package/dist/heart/config.js +57 -23
- package/dist/heart/core.js +236 -90
- package/dist/heart/cross-chat-delivery.js +146 -0
- package/dist/heart/daemon/agent-discovery.js +81 -0
- package/dist/heart/daemon/auth-flow.js +351 -0
- package/dist/heart/daemon/daemon-cli.js +1175 -232
- package/dist/heart/daemon/daemon-entry.js +55 -6
- package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
- package/dist/heart/daemon/daemon.js +189 -10
- package/dist/heart/daemon/hatch-animation.js +10 -3
- package/dist/heart/daemon/hatch-flow.js +4 -82
- package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
- package/dist/heart/daemon/launchd.js +159 -0
- package/dist/heart/daemon/log-tailer.js +4 -3
- package/dist/heart/daemon/message-router.js +17 -8
- package/dist/heart/daemon/ouro-bot-entry.js +0 -0
- package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
- package/dist/heart/daemon/ouro-entry.js +0 -0
- package/dist/heart/daemon/ouro-path-installer.js +178 -0
- package/dist/heart/daemon/ouro-uti.js +11 -2
- package/dist/heart/daemon/process-manager.js +14 -1
- package/dist/heart/daemon/run-hooks.js +37 -0
- package/dist/heart/daemon/runtime-logging.js +58 -15
- package/dist/heart/daemon/runtime-metadata.js +219 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/sense-manager.js +307 -0
- package/dist/heart/daemon/skill-management-installer.js +73 -0
- package/dist/heart/daemon/socket-client.js +202 -0
- package/dist/heart/daemon/specialist-orchestrator.js +53 -84
- package/dist/heart/daemon/specialist-prompt.js +64 -5
- package/dist/heart/daemon/specialist-tools.js +213 -58
- package/dist/heart/daemon/staged-restart.js +114 -0
- package/dist/heart/daemon/thoughts.js +379 -0
- package/dist/heart/daemon/update-checker.js +111 -0
- package/dist/heart/daemon/update-hooks.js +138 -0
- package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/identity.js +122 -19
- package/dist/heart/kicks.js +1 -19
- package/dist/heart/model-capabilities.js +40 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/providers/anthropic.js +74 -9
- package/dist/heart/providers/azure.js +86 -7
- package/dist/heart/providers/minimax.js +4 -0
- package/dist/heart/providers/openai-codex.js +12 -3
- package/dist/heart/safe-workspace.js +228 -0
- package/dist/heart/sense-truth.js +61 -0
- package/dist/heart/session-activity.js +169 -0
- package/dist/heart/session-recall.js +116 -0
- package/dist/heart/streaming.js +100 -22
- package/dist/heart/target-resolution.js +123 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/mind/associative-recall.js +14 -2
- package/dist/mind/bundle-manifest.js +70 -0
- package/dist/mind/context.js +27 -11
- package/dist/mind/first-impressions.js +16 -2
- package/dist/mind/friends/channel.js +35 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/store-file.js +19 -0
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +8 -0
- package/dist/mind/memory.js +27 -26
- package/dist/mind/pending.js +72 -9
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt.js +299 -77
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/cli-logging.js +15 -2
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/repertoire/ado-client.js +4 -2
- package/dist/repertoire/coding/feedback.js +134 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +62 -4
- package/dist/repertoire/coding/spawner.js +3 -3
- package/dist/repertoire/coding/tools.js +41 -2
- package/dist/repertoire/data/ado-endpoints.json +188 -0
- package/dist/repertoire/skills.js +3 -26
- package/dist/repertoire/tasks/board.js +12 -0
- package/dist/repertoire/tasks/index.js +23 -9
- package/dist/repertoire/tasks/transitions.js +1 -2
- package/dist/repertoire/tools-base.js +629 -251
- package/dist/repertoire/tools-bluebubbles.js +93 -0
- package/dist/repertoire/tools-teams.js +58 -25
- package/dist/repertoire/tools.js +92 -48
- package/dist/senses/bluebubbles-client.js +210 -5
- package/dist/senses/bluebubbles-entry.js +2 -0
- package/dist/senses/bluebubbles-inbound-log.js +109 -0
- package/dist/senses/bluebubbles-media.js +339 -0
- package/dist/senses/bluebubbles-model.js +12 -4
- package/dist/senses/bluebubbles-mutation-log.js +45 -5
- package/dist/senses/bluebubbles-runtime-state.js +109 -0
- package/dist/senses/bluebubbles-session-cleanup.js +72 -0
- package/dist/senses/bluebubbles.js +890 -45
- package/dist/senses/cli-layout.js +87 -0
- package/dist/senses/cli.js +345 -144
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/debug-activity.js +148 -0
- package/dist/senses/inner-dialog-worker.js +47 -18
- package/dist/senses/inner-dialog.js +330 -84
- package/dist/senses/pipeline.js +278 -0
- package/dist/senses/teams.js +570 -129
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +14 -3
- package/subagents/README.md +4 -70
- package/dist/heart/daemon/specialist-session.js +0 -142
- package/dist/heart/daemon/subagent-installer.js +0 -125
- package/dist/inner-worker-entry.js +0 -4
- package/subagents/work-doer.md +0 -233
- package/subagents/work-merger.md +0 -624
- package/subagents/work-planner.md +0 -373
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.listEnabledBundleAgents = listEnabledBundleAgents;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const identity_1 = require("../identity");
|
|
40
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
41
|
+
function listEnabledBundleAgents(options = {}) {
|
|
42
|
+
const bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
43
|
+
const readdirSync = options.readdirSync ?? fs.readdirSync;
|
|
44
|
+
const readFileSync = options.readFileSync ?? fs.readFileSync;
|
|
45
|
+
let entries;
|
|
46
|
+
try {
|
|
47
|
+
entries = readdirSync(bundlesRoot, { withFileTypes: true });
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
(0, runtime_1.emitNervesEvent)({
|
|
51
|
+
level: "warn",
|
|
52
|
+
component: "daemon",
|
|
53
|
+
event: "daemon.agent_discovery_failed",
|
|
54
|
+
message: "failed to read bundle root for daemon agent discovery",
|
|
55
|
+
meta: { bundlesRoot },
|
|
56
|
+
});
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const discovered = [];
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
if (!entry.isDirectory() || !entry.name.endsWith(".ouro"))
|
|
62
|
+
continue;
|
|
63
|
+
const agentName = entry.name.slice(0, -5);
|
|
64
|
+
const configPath = path.join(bundlesRoot, entry.name, "agent.json");
|
|
65
|
+
let enabled = true;
|
|
66
|
+
try {
|
|
67
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
68
|
+
const parsed = JSON.parse(raw);
|
|
69
|
+
if (typeof parsed.enabled === "boolean") {
|
|
70
|
+
enabled = parsed.enabled;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (enabled) {
|
|
77
|
+
discovered.push(agentName);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return discovered.sort((left, right) => left.localeCompare(right));
|
|
81
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.readAgentConfigForAgent = readAgentConfigForAgent;
|
|
37
|
+
exports.writeAgentProviderSelection = writeAgentProviderSelection;
|
|
38
|
+
exports.loadAgentSecrets = loadAgentSecrets;
|
|
39
|
+
exports.writeProviderCredentials = writeProviderCredentials;
|
|
40
|
+
exports.collectRuntimeAuthCredentials = collectRuntimeAuthCredentials;
|
|
41
|
+
exports.resolveHatchCredentials = resolveHatchCredentials;
|
|
42
|
+
exports.runRuntimeAuthFlow = runRuntimeAuthFlow;
|
|
43
|
+
const child_process_1 = require("child_process");
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const os = __importStar(require("os"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
48
|
+
const identity_1 = require("../identity");
|
|
49
|
+
const ANTHROPIC_SETUP_TOKEN_PREFIX = "sk-ant-oat01-";
|
|
50
|
+
const ANTHROPIC_SETUP_TOKEN_MIN_LENGTH = 80;
|
|
51
|
+
const DEFAULT_SECRETS_TEMPLATE = {
|
|
52
|
+
providers: {
|
|
53
|
+
azure: {
|
|
54
|
+
modelName: "gpt-4o-mini",
|
|
55
|
+
apiKey: "",
|
|
56
|
+
endpoint: "",
|
|
57
|
+
deployment: "",
|
|
58
|
+
apiVersion: "2025-04-01-preview",
|
|
59
|
+
},
|
|
60
|
+
minimax: {
|
|
61
|
+
model: "minimax-text-01",
|
|
62
|
+
apiKey: "",
|
|
63
|
+
},
|
|
64
|
+
anthropic: {
|
|
65
|
+
model: "claude-opus-4-6",
|
|
66
|
+
setupToken: "",
|
|
67
|
+
},
|
|
68
|
+
"openai-codex": {
|
|
69
|
+
model: "gpt-5.4",
|
|
70
|
+
oauthAccessToken: "",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
teams: {
|
|
74
|
+
clientId: "",
|
|
75
|
+
clientSecret: "",
|
|
76
|
+
tenantId: "",
|
|
77
|
+
},
|
|
78
|
+
oauth: {
|
|
79
|
+
graphConnectionName: "graph",
|
|
80
|
+
adoConnectionName: "ado",
|
|
81
|
+
githubConnectionName: "",
|
|
82
|
+
},
|
|
83
|
+
teamsChannel: {
|
|
84
|
+
skipConfirmation: true,
|
|
85
|
+
port: 3978,
|
|
86
|
+
},
|
|
87
|
+
integrations: {
|
|
88
|
+
perplexityApiKey: "",
|
|
89
|
+
openaiEmbeddingsApiKey: "",
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
function deepMerge(defaults, partial) {
|
|
93
|
+
const result = { ...defaults };
|
|
94
|
+
for (const key of Object.keys(partial)) {
|
|
95
|
+
const left = result[key];
|
|
96
|
+
const right = partial[key];
|
|
97
|
+
if (right !== null &&
|
|
98
|
+
typeof right === "object" &&
|
|
99
|
+
!Array.isArray(right) &&
|
|
100
|
+
left !== null &&
|
|
101
|
+
typeof left === "object" &&
|
|
102
|
+
!Array.isArray(left)) {
|
|
103
|
+
result[key] = deepMerge(left, right);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
result[key] = right;
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
function readJsonRecord(filePath, label) {
|
|
111
|
+
try {
|
|
112
|
+
const raw = fs.readFileSync(filePath, "utf8");
|
|
113
|
+
const parsed = JSON.parse(raw);
|
|
114
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
115
|
+
throw new Error("expected object");
|
|
116
|
+
}
|
|
117
|
+
return parsed;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new Error(`Failed to read ${label} at ${filePath}: ${String(error)}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function readAgentConfigForAgent(agentName, bundlesRoot = (0, identity_1.getAgentBundlesRoot)()) {
|
|
124
|
+
const configPath = path.join(bundlesRoot, `${agentName}.ouro`, "agent.json");
|
|
125
|
+
const parsed = readJsonRecord(configPath, "agent config");
|
|
126
|
+
const provider = parsed.provider;
|
|
127
|
+
if (provider !== "azure" &&
|
|
128
|
+
provider !== "anthropic" &&
|
|
129
|
+
provider !== "minimax" &&
|
|
130
|
+
provider !== "openai-codex") {
|
|
131
|
+
throw new Error(`agent.json at ${configPath} has unsupported provider '${String(provider)}'`);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
configPath,
|
|
135
|
+
config: parsed,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function writeAgentProviderSelection(agentName, provider, bundlesRoot = (0, identity_1.getAgentBundlesRoot)()) {
|
|
139
|
+
const { configPath, config } = readAgentConfigForAgent(agentName, bundlesRoot);
|
|
140
|
+
const nextConfig = { ...config, provider };
|
|
141
|
+
fs.writeFileSync(configPath, `${JSON.stringify(nextConfig, null, 2)}\n`, "utf8");
|
|
142
|
+
(0, runtime_1.emitNervesEvent)({
|
|
143
|
+
component: "daemon",
|
|
144
|
+
event: "daemon.auth_provider_selected",
|
|
145
|
+
message: "updated agent provider selection after auth flow",
|
|
146
|
+
meta: { agentName, provider, configPath },
|
|
147
|
+
});
|
|
148
|
+
return configPath;
|
|
149
|
+
}
|
|
150
|
+
function resolveAgentSecretsPath(agentName, deps = {}) {
|
|
151
|
+
if (deps.secretsRoot)
|
|
152
|
+
return path.join(deps.secretsRoot, agentName, "secrets.json");
|
|
153
|
+
const homeDir = deps.homeDir ?? os.homedir();
|
|
154
|
+
return (0, identity_1.getAgentSecretsPath)(agentName).replace(os.homedir(), homeDir);
|
|
155
|
+
}
|
|
156
|
+
function loadAgentSecrets(agentName, deps = {}) {
|
|
157
|
+
const secretsPath = resolveAgentSecretsPath(agentName, deps);
|
|
158
|
+
const secretsDir = path.dirname(secretsPath);
|
|
159
|
+
fs.mkdirSync(secretsDir, { recursive: true });
|
|
160
|
+
let onDisk = {};
|
|
161
|
+
try {
|
|
162
|
+
onDisk = readJsonRecord(secretsPath, "secrets config");
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
const message = error.message;
|
|
166
|
+
if (!message.includes("ENOENT"))
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
secretsPath,
|
|
171
|
+
secrets: deepMerge(DEFAULT_SECRETS_TEMPLATE, onDisk),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function writeSecrets(secretsPath, secrets) {
|
|
175
|
+
fs.writeFileSync(secretsPath, `${JSON.stringify(secrets, null, 2)}\n`, "utf8");
|
|
176
|
+
}
|
|
177
|
+
function writeProviderCredentials(agentName, provider, credentials, deps = {}) {
|
|
178
|
+
const { secretsPath, secrets } = loadAgentSecrets(agentName, deps);
|
|
179
|
+
applyCredentials(secrets, provider, credentials);
|
|
180
|
+
writeSecrets(secretsPath, secrets);
|
|
181
|
+
return { secretsPath, secrets };
|
|
182
|
+
}
|
|
183
|
+
function readCodexAccessToken(homeDir) {
|
|
184
|
+
const authPath = path.join(homeDir, ".codex", "auth.json");
|
|
185
|
+
try {
|
|
186
|
+
const raw = fs.readFileSync(authPath, "utf8");
|
|
187
|
+
const parsed = JSON.parse(raw);
|
|
188
|
+
const token = parsed?.tokens?.access_token;
|
|
189
|
+
return typeof token === "string" ? token.trim() : "";
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return "";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function ensurePromptInput(promptInput, provider) {
|
|
196
|
+
if (promptInput)
|
|
197
|
+
return promptInput;
|
|
198
|
+
throw new Error(`No prompt input is available for ${provider} authentication.`);
|
|
199
|
+
}
|
|
200
|
+
function validateAnthropicToken(token) {
|
|
201
|
+
const trimmed = token.trim();
|
|
202
|
+
if (!trimmed) {
|
|
203
|
+
throw new Error("No Anthropic setup token was provided.");
|
|
204
|
+
}
|
|
205
|
+
if (!trimmed.startsWith(ANTHROPIC_SETUP_TOKEN_PREFIX)) {
|
|
206
|
+
throw new Error(`Invalid Anthropic setup token format. Expected prefix ${ANTHROPIC_SETUP_TOKEN_PREFIX}.`);
|
|
207
|
+
}
|
|
208
|
+
if (trimmed.length < ANTHROPIC_SETUP_TOKEN_MIN_LENGTH) {
|
|
209
|
+
throw new Error("Anthropic setup token looks too short.");
|
|
210
|
+
}
|
|
211
|
+
return trimmed;
|
|
212
|
+
}
|
|
213
|
+
async function collectRuntimeAuthCredentials(input, deps) {
|
|
214
|
+
const spawnSync = deps.spawnSync ?? child_process_1.spawnSync;
|
|
215
|
+
const homeDir = deps.homeDir ?? os.homedir();
|
|
216
|
+
if (input.provider === "openai-codex") {
|
|
217
|
+
let token = readCodexAccessToken(homeDir);
|
|
218
|
+
if (!token) {
|
|
219
|
+
(0, runtime_1.emitNervesEvent)({
|
|
220
|
+
component: "daemon",
|
|
221
|
+
event: "daemon.auth_codex_login_start",
|
|
222
|
+
message: "starting codex login for runtime auth",
|
|
223
|
+
meta: { agentName: input.agentName },
|
|
224
|
+
});
|
|
225
|
+
const result = spawnSync("codex", ["login"], { stdio: "inherit" });
|
|
226
|
+
if (result.error) {
|
|
227
|
+
throw new Error(`Failed to run 'codex login': ${result.error.message}`);
|
|
228
|
+
}
|
|
229
|
+
if (result.status !== 0) {
|
|
230
|
+
throw new Error(`'codex login' exited with status ${result.status}.`);
|
|
231
|
+
}
|
|
232
|
+
token = readCodexAccessToken(homeDir);
|
|
233
|
+
if (!token) {
|
|
234
|
+
throw new Error("Codex login completed but no token was found in ~/.codex/auth.json. Re-run `codex login` and try again.");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { oauthAccessToken: token };
|
|
238
|
+
}
|
|
239
|
+
if (input.provider === "anthropic") {
|
|
240
|
+
(0, runtime_1.emitNervesEvent)({
|
|
241
|
+
component: "daemon",
|
|
242
|
+
event: "daemon.auth_claude_setup_start",
|
|
243
|
+
message: "starting claude setup-token for runtime auth",
|
|
244
|
+
meta: { agentName: input.agentName },
|
|
245
|
+
});
|
|
246
|
+
const result = spawnSync("claude", ["setup-token"], { stdio: "inherit" });
|
|
247
|
+
if (result.error) {
|
|
248
|
+
throw new Error(`Failed to run 'claude setup-token': ${result.error.message}`);
|
|
249
|
+
}
|
|
250
|
+
if (result.status !== 0) {
|
|
251
|
+
throw new Error(`'claude setup-token' exited with status ${result.status}.`);
|
|
252
|
+
}
|
|
253
|
+
const prompt = ensurePromptInput(input.promptInput, input.provider);
|
|
254
|
+
const setupToken = validateAnthropicToken(await prompt("Paste the setup token from `claude setup-token`: "));
|
|
255
|
+
return { setupToken };
|
|
256
|
+
}
|
|
257
|
+
if (input.provider === "minimax") {
|
|
258
|
+
const prompt = ensurePromptInput(input.promptInput, input.provider);
|
|
259
|
+
const apiKey = (await prompt("MiniMax API key: ")).trim();
|
|
260
|
+
if (!apiKey)
|
|
261
|
+
throw new Error("MiniMax API key is required.");
|
|
262
|
+
return { apiKey };
|
|
263
|
+
}
|
|
264
|
+
const prompt = ensurePromptInput(input.promptInput, input.provider);
|
|
265
|
+
const apiKey = (await prompt("Azure API key: ")).trim();
|
|
266
|
+
const endpoint = (await prompt("Azure endpoint: ")).trim();
|
|
267
|
+
const deployment = (await prompt("Azure deployment: ")).trim();
|
|
268
|
+
if (!apiKey || !endpoint || !deployment) {
|
|
269
|
+
throw new Error("Azure API key, endpoint, and deployment are required.");
|
|
270
|
+
}
|
|
271
|
+
return { apiKey, endpoint, deployment };
|
|
272
|
+
}
|
|
273
|
+
async function resolveHatchCredentials(input) {
|
|
274
|
+
const prompt = input.promptInput;
|
|
275
|
+
const credentials = { ...(input.credentials ?? {}) };
|
|
276
|
+
if (input.provider === "anthropic" && !credentials.setupToken && input.runAuthFlow) {
|
|
277
|
+
const result = await input.runAuthFlow({
|
|
278
|
+
agentName: input.agentName,
|
|
279
|
+
provider: "anthropic",
|
|
280
|
+
promptInput: prompt,
|
|
281
|
+
});
|
|
282
|
+
Object.assign(credentials, result.credentials);
|
|
283
|
+
}
|
|
284
|
+
if (input.provider === "anthropic" && !credentials.setupToken && prompt) {
|
|
285
|
+
credentials.setupToken = await prompt("Anthropic setup-token: ");
|
|
286
|
+
}
|
|
287
|
+
if (input.provider === "openai-codex" && !credentials.oauthAccessToken && input.runAuthFlow) {
|
|
288
|
+
const result = await input.runAuthFlow({
|
|
289
|
+
agentName: input.agentName,
|
|
290
|
+
provider: "openai-codex",
|
|
291
|
+
promptInput: prompt,
|
|
292
|
+
});
|
|
293
|
+
Object.assign(credentials, result.credentials);
|
|
294
|
+
}
|
|
295
|
+
if (input.provider === "openai-codex" && !credentials.oauthAccessToken && prompt) {
|
|
296
|
+
credentials.oauthAccessToken = await prompt("OpenAI Codex OAuth token: ");
|
|
297
|
+
}
|
|
298
|
+
if (input.provider === "minimax" && !credentials.apiKey && prompt) {
|
|
299
|
+
credentials.apiKey = await prompt("MiniMax API key: ");
|
|
300
|
+
}
|
|
301
|
+
if (input.provider === "azure") {
|
|
302
|
+
if (!credentials.apiKey && prompt)
|
|
303
|
+
credentials.apiKey = await prompt("Azure API key: ");
|
|
304
|
+
if (!credentials.endpoint && prompt)
|
|
305
|
+
credentials.endpoint = await prompt("Azure endpoint: ");
|
|
306
|
+
if (!credentials.deployment && prompt)
|
|
307
|
+
credentials.deployment = await prompt("Azure deployment: ");
|
|
308
|
+
}
|
|
309
|
+
return credentials;
|
|
310
|
+
}
|
|
311
|
+
function applyCredentials(secrets, provider, credentials) {
|
|
312
|
+
if (provider === "anthropic") {
|
|
313
|
+
secrets.providers.anthropic.setupToken = credentials.setupToken.trim();
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (provider === "openai-codex") {
|
|
317
|
+
secrets.providers["openai-codex"].oauthAccessToken = credentials.oauthAccessToken.trim();
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (provider === "minimax") {
|
|
321
|
+
secrets.providers.minimax.apiKey = credentials.apiKey.trim();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
secrets.providers.azure.apiKey = credentials.apiKey.trim();
|
|
325
|
+
secrets.providers.azure.endpoint = credentials.endpoint.trim();
|
|
326
|
+
secrets.providers.azure.deployment = credentials.deployment.trim();
|
|
327
|
+
}
|
|
328
|
+
async function runRuntimeAuthFlow(input, deps = {}) {
|
|
329
|
+
(0, runtime_1.emitNervesEvent)({
|
|
330
|
+
component: "daemon",
|
|
331
|
+
event: "daemon.auth_flow_start",
|
|
332
|
+
message: "starting runtime auth flow",
|
|
333
|
+
meta: { agentName: input.agentName, provider: input.provider },
|
|
334
|
+
});
|
|
335
|
+
const homeDir = deps.homeDir ?? os.homedir();
|
|
336
|
+
const credentials = await collectRuntimeAuthCredentials(input, deps);
|
|
337
|
+
const { secretsPath } = writeProviderCredentials(input.agentName, input.provider, credentials, { homeDir });
|
|
338
|
+
(0, runtime_1.emitNervesEvent)({
|
|
339
|
+
component: "daemon",
|
|
340
|
+
event: "daemon.auth_flow_end",
|
|
341
|
+
message: "completed runtime auth flow",
|
|
342
|
+
meta: { agentName: input.agentName, provider: input.provider, secretsPath },
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
agentName: input.agentName,
|
|
346
|
+
provider: input.provider,
|
|
347
|
+
secretsPath,
|
|
348
|
+
message: `authenticated ${input.agentName} with ${input.provider}`,
|
|
349
|
+
credentials,
|
|
350
|
+
};
|
|
351
|
+
}
|