@iam-brain/opencode-codex-auth 0.1.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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/bin/opencode-codex-auth.d.ts +3 -0
- package/dist/bin/opencode-codex-auth.d.ts.map +1 -0
- package/dist/bin/opencode-codex-auth.js +13 -0
- package/dist/bin/opencode-codex-auth.js.map +1 -0
- package/dist/bin/opencode-openai-multi.d.ts +3 -0
- package/dist/bin/opencode-openai-multi.d.ts.map +1 -0
- package/dist/bin/opencode-openai-multi.js +13 -0
- package/dist/bin/opencode-openai-multi.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +137 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/accounts-tools.d.ts +14 -0
- package/dist/lib/accounts-tools.d.ts.map +1 -0
- package/dist/lib/accounts-tools.js +100 -0
- package/dist/lib/accounts-tools.js.map +1 -0
- package/dist/lib/claims.d.ts +20 -0
- package/dist/lib/claims.d.ts.map +1 -0
- package/dist/lib/claims.js +37 -0
- package/dist/lib/claims.js.map +1 -0
- package/dist/lib/codex-native.d.ts +74 -0
- package/dist/lib/codex-native.d.ts.map +1 -0
- package/dist/lib/codex-native.js +2404 -0
- package/dist/lib/codex-native.js.map +1 -0
- package/dist/lib/codex-quota-fetch.d.ts +11 -0
- package/dist/lib/codex-quota-fetch.d.ts.map +1 -0
- package/dist/lib/codex-quota-fetch.js +149 -0
- package/dist/lib/codex-quota-fetch.js.map +1 -0
- package/dist/lib/codex-status-storage.d.ts +5 -0
- package/dist/lib/codex-status-storage.d.ts.map +1 -0
- package/dist/lib/codex-status-storage.js +58 -0
- package/dist/lib/codex-status-storage.js.map +1 -0
- package/dist/lib/codex-status-tool.d.ts +6 -0
- package/dist/lib/codex-status-tool.d.ts.map +1 -0
- package/dist/lib/codex-status-tool.js +37 -0
- package/dist/lib/codex-status-tool.js.map +1 -0
- package/dist/lib/codex-status-ui.d.ts +7 -0
- package/dist/lib/codex-status-ui.d.ts.map +1 -0
- package/dist/lib/codex-status-ui.js +109 -0
- package/dist/lib/codex-status-ui.js.map +1 -0
- package/dist/lib/codex-status.d.ts +14 -0
- package/dist/lib/codex-status.d.ts.map +1 -0
- package/dist/lib/codex-status.js +31 -0
- package/dist/lib/codex-status.js.map +1 -0
- package/dist/lib/compat-sanitizer.d.ts +7 -0
- package/dist/lib/compat-sanitizer.d.ts.map +1 -0
- package/dist/lib/compat-sanitizer.js +101 -0
- package/dist/lib/compat-sanitizer.js.map +1 -0
- package/dist/lib/config.d.ts +94 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +495 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +2 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/fatal-errors.d.ts +17 -0
- package/dist/lib/fatal-errors.d.ts.map +1 -0
- package/dist/lib/fatal-errors.js +42 -0
- package/dist/lib/fatal-errors.js.map +1 -0
- package/dist/lib/fetch-orchestrator.d.ts +56 -0
- package/dist/lib/fetch-orchestrator.d.ts.map +1 -0
- package/dist/lib/fetch-orchestrator.js +240 -0
- package/dist/lib/fetch-orchestrator.js.map +1 -0
- package/dist/lib/identity.d.ts +10 -0
- package/dist/lib/identity.d.ts.map +1 -0
- package/dist/lib/identity.js +31 -0
- package/dist/lib/identity.js.map +1 -0
- package/dist/lib/installer-cli.d.ts +7 -0
- package/dist/lib/installer-cli.d.ts.map +1 -0
- package/dist/lib/installer-cli.js +115 -0
- package/dist/lib/installer-cli.js.map +1 -0
- package/dist/lib/logger.d.ts +11 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +25 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/model-catalog.d.ts +66 -0
- package/dist/lib/model-catalog.d.ts.map +1 -0
- package/dist/lib/model-catalog.js +532 -0
- package/dist/lib/model-catalog.js.map +1 -0
- package/dist/lib/oauth-pages.d.ts +2 -0
- package/dist/lib/oauth-pages.d.ts.map +1 -0
- package/dist/lib/oauth-pages.js +199 -0
- package/dist/lib/oauth-pages.js.map +1 -0
- package/dist/lib/opencode-install.d.ts +15 -0
- package/dist/lib/opencode-install.d.ts.map +1 -0
- package/dist/lib/opencode-install.js +53 -0
- package/dist/lib/opencode-install.js.map +1 -0
- package/dist/lib/orchestrator-agents.d.ts +29 -0
- package/dist/lib/orchestrator-agents.d.ts.map +1 -0
- package/dist/lib/orchestrator-agents.js +212 -0
- package/dist/lib/orchestrator-agents.js.map +1 -0
- package/dist/lib/paths.d.ts +7 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/paths.js +18 -0
- package/dist/lib/paths.js.map +1 -0
- package/dist/lib/personalities.d.ts +5 -0
- package/dist/lib/personalities.d.ts.map +1 -0
- package/dist/lib/personalities.js +69 -0
- package/dist/lib/personalities.js.map +1 -0
- package/dist/lib/proactive-refresh.d.ts +11 -0
- package/dist/lib/proactive-refresh.d.ts.map +1 -0
- package/dist/lib/proactive-refresh.js +110 -0
- package/dist/lib/proactive-refresh.js.map +1 -0
- package/dist/lib/quarantine.d.ts +9 -0
- package/dist/lib/quarantine.d.ts.map +1 -0
- package/dist/lib/quarantine.js +39 -0
- package/dist/lib/quarantine.js.map +1 -0
- package/dist/lib/rate-limit.d.ts +9 -0
- package/dist/lib/rate-limit.d.ts.map +1 -0
- package/dist/lib/rate-limit.js +32 -0
- package/dist/lib/rate-limit.js.map +1 -0
- package/dist/lib/refresh-queue.d.ts +30 -0
- package/dist/lib/refresh-queue.d.ts.map +1 -0
- package/dist/lib/refresh-queue.js +67 -0
- package/dist/lib/refresh-queue.js.map +1 -0
- package/dist/lib/request-snapshots.d.ts +14 -0
- package/dist/lib/request-snapshots.d.ts.map +1 -0
- package/dist/lib/request-snapshots.js +148 -0
- package/dist/lib/request-snapshots.js.map +1 -0
- package/dist/lib/rotation.d.ts +29 -0
- package/dist/lib/rotation.d.ts.map +1 -0
- package/dist/lib/rotation.js +252 -0
- package/dist/lib/rotation.js.map +1 -0
- package/dist/lib/storage.d.ts +27 -0
- package/dist/lib/storage.d.ts.map +1 -0
- package/dist/lib/storage.js +610 -0
- package/dist/lib/storage.js.map +1 -0
- package/dist/lib/toast.d.ts +2 -0
- package/dist/lib/toast.d.ts.map +1 -0
- package/dist/lib/toast.js +47 -0
- package/dist/lib/toast.js.map +1 -0
- package/dist/lib/tools-output.d.ts +6 -0
- package/dist/lib/tools-output.d.ts.map +1 -0
- package/dist/lib/tools-output.js +6 -0
- package/dist/lib/tools-output.js.map +1 -0
- package/dist/lib/types.d.ts +62 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/ui/auth-menu-runner.d.ts +19 -0
- package/dist/lib/ui/auth-menu-runner.d.ts.map +1 -0
- package/dist/lib/ui/auth-menu-runner.js +79 -0
- package/dist/lib/ui/auth-menu-runner.js.map +1 -0
- package/dist/lib/ui/auth-menu.d.ts +80 -0
- package/dist/lib/ui/auth-menu.d.ts.map +1 -0
- package/dist/lib/ui/auth-menu.js +321 -0
- package/dist/lib/ui/auth-menu.js.map +1 -0
- package/dist/lib/ui/tty/ansi.d.ts +18 -0
- package/dist/lib/ui/tty/ansi.d.ts.map +1 -0
- package/dist/lib/ui/tty/ansi.js +37 -0
- package/dist/lib/ui/tty/ansi.js.map +1 -0
- package/dist/lib/ui/tty/confirm.d.ts +7 -0
- package/dist/lib/ui/tty/confirm.d.ts.map +1 -0
- package/dist/lib/ui/tty/confirm.js +20 -0
- package/dist/lib/ui/tty/confirm.js.map +1 -0
- package/dist/lib/ui/tty/select.d.ts +17 -0
- package/dist/lib/ui/tty/select.d.ts.map +1 -0
- package/dist/lib/ui/tty/select.js +223 -0
- package/dist/lib/ui/tty/select.js.map +1 -0
- package/package.json +68 -0
- package/schemas/codex-config.schema.json +146 -0
- package/schemas/opencode.schema.json +23 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
export const CODEX_OAUTH_SUCCESS_HTML = `<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>Sign into Codex</title>
|
|
6
|
+
<link rel="icon" href='data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="none" viewBox="0 0 32 32"%3E%3Cpath stroke="%23000" stroke-linecap="round" stroke-width="2.484" d="M22.356 19.797H17.17M9.662 12.29l1.979 3.576a.511.511 0 0 1-.005.504l-1.974 3.409M30.758 16c0 8.15-6.607 14.758-14.758 14.758-8.15 0-14.758-6.607-14.758-14.758C1.242 7.85 7.85 1.242 16 1.242c8.15 0 14.758 6.608 14.758 14.758Z"/%3E%3C/svg%3E' type="image/svg+xml">
|
|
7
|
+
<style>
|
|
8
|
+
.container {
|
|
9
|
+
margin: auto;
|
|
10
|
+
height: 100%;
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
position: relative;
|
|
15
|
+
background: white;
|
|
16
|
+
|
|
17
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
18
|
+
}
|
|
19
|
+
.inner-container {
|
|
20
|
+
width: 400px;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
justify-content: flex-start;
|
|
23
|
+
align-items: center;
|
|
24
|
+
gap: 20px;
|
|
25
|
+
display: inline-flex;
|
|
26
|
+
}
|
|
27
|
+
.content {
|
|
28
|
+
align-self: stretch;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
justify-content: flex-start;
|
|
31
|
+
align-items: center;
|
|
32
|
+
gap: 20px;
|
|
33
|
+
display: flex;
|
|
34
|
+
margin-top: 15vh;
|
|
35
|
+
}
|
|
36
|
+
.svg-wrapper {
|
|
37
|
+
position: relative;
|
|
38
|
+
}
|
|
39
|
+
.title {
|
|
40
|
+
text-align: center;
|
|
41
|
+
color: var(--text-primary, #0D0D0D);
|
|
42
|
+
font-size: 32px;
|
|
43
|
+
font-weight: 400;
|
|
44
|
+
line-height: 40px;
|
|
45
|
+
word-wrap: break-word;
|
|
46
|
+
}
|
|
47
|
+
.setup-box {
|
|
48
|
+
width: 600px;
|
|
49
|
+
padding: 16px 20px;
|
|
50
|
+
background: var(--bg-primary, white);
|
|
51
|
+
box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.05);
|
|
52
|
+
border-radius: 16px;
|
|
53
|
+
outline: 1px var(--border-default, rgba(13, 13, 13, 0.10)) solid;
|
|
54
|
+
outline-offset: -1px;
|
|
55
|
+
justify-content: flex-start;
|
|
56
|
+
align-items: center;
|
|
57
|
+
gap: 16px;
|
|
58
|
+
display: inline-flex;
|
|
59
|
+
}
|
|
60
|
+
.setup-content {
|
|
61
|
+
flex: 1 1 0;
|
|
62
|
+
justify-content: flex-start;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: 24px;
|
|
65
|
+
display: flex;
|
|
66
|
+
}
|
|
67
|
+
.setup-text {
|
|
68
|
+
flex: 1 1 0;
|
|
69
|
+
flex-direction: column;
|
|
70
|
+
justify-content: flex-start;
|
|
71
|
+
align-items: flex-start;
|
|
72
|
+
gap: 4px;
|
|
73
|
+
display: inline-flex;
|
|
74
|
+
}
|
|
75
|
+
.setup-title {
|
|
76
|
+
align-self: stretch;
|
|
77
|
+
color: var(--text-primary, #0D0D0D);
|
|
78
|
+
font-size: 14px;
|
|
79
|
+
font-weight: 510;
|
|
80
|
+
line-height: 20px;
|
|
81
|
+
word-wrap: break-word;
|
|
82
|
+
}
|
|
83
|
+
.setup-description {
|
|
84
|
+
align-self: stretch;
|
|
85
|
+
color: var(--text-secondary, #5D5D5D);
|
|
86
|
+
font-size: 14px;
|
|
87
|
+
font-weight: 400;
|
|
88
|
+
line-height: 20px;
|
|
89
|
+
word-wrap: break-word;
|
|
90
|
+
}
|
|
91
|
+
.redirect-box {
|
|
92
|
+
justify-content: flex-start;
|
|
93
|
+
align-items: center;
|
|
94
|
+
gap: 8px;
|
|
95
|
+
display: flex;
|
|
96
|
+
}
|
|
97
|
+
.close-button,
|
|
98
|
+
.redirect-button {
|
|
99
|
+
height: 28px;
|
|
100
|
+
padding: 8px 16px;
|
|
101
|
+
background: var(--interactive-bg-primary-default, #0D0D0D);
|
|
102
|
+
border-radius: 999px;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
align-items: center;
|
|
105
|
+
gap: 4px;
|
|
106
|
+
display: flex;
|
|
107
|
+
}
|
|
108
|
+
.close-button,
|
|
109
|
+
.redirect-text {
|
|
110
|
+
color: var(--interactive-label-primary-default, white);
|
|
111
|
+
font-size: 14px;
|
|
112
|
+
font-weight: 510;
|
|
113
|
+
line-height: 20px;
|
|
114
|
+
word-wrap: break-word;
|
|
115
|
+
text-decoration: none;
|
|
116
|
+
}
|
|
117
|
+
.logo {
|
|
118
|
+
display: flex;
|
|
119
|
+
align-items: center;
|
|
120
|
+
justify-content: center;
|
|
121
|
+
width: 4rem;
|
|
122
|
+
height: 4rem;
|
|
123
|
+
border-radius: 16px;
|
|
124
|
+
border: .5px solid rgba(0, 0, 0, 0.1);
|
|
125
|
+
box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 16px 0px;
|
|
126
|
+
box-sizing: border-box;
|
|
127
|
+
background-color: rgb(255, 255, 255);
|
|
128
|
+
}
|
|
129
|
+
</style>
|
|
130
|
+
</head>
|
|
131
|
+
<body>
|
|
132
|
+
<div class="container">
|
|
133
|
+
<div class="inner-container">
|
|
134
|
+
<div class="content">
|
|
135
|
+
<div class="logo">
|
|
136
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="none" viewBox="0 0 32 32"><path stroke="#000" stroke-linecap="round" stroke-width="2.484" d="M22.356 19.797H17.17M9.662 12.29l1.979 3.576a.511.511 0 0 1-.005.504l-1.974 3.409M30.758 16c0 8.15-6.607 14.758-14.758 14.758-8.15 0-14.758-6.607-14.758-14.758C1.242 7.85 7.85 1.242 16 1.242c8.15 0 14.758 6.608 14.758 14.758Z"></path></svg>
|
|
137
|
+
</div>
|
|
138
|
+
<div class="title">Signed in to Codex</div>
|
|
139
|
+
</div>
|
|
140
|
+
<div class="close-box" style="display: none;">
|
|
141
|
+
<div class="setup-description">You may now close this page</div>
|
|
142
|
+
</div>
|
|
143
|
+
<div class="setup-box" style="display: none;">
|
|
144
|
+
<div class="setup-content">
|
|
145
|
+
<div class="setup-text">
|
|
146
|
+
<div class="setup-title">Finish setting up your API organization</div>
|
|
147
|
+
<div class="setup-description">Add a payment method to use your organization.</div>
|
|
148
|
+
</div>
|
|
149
|
+
<div class="redirect-box">
|
|
150
|
+
<div data-hasendicon="false" data-hasstarticon="false" data-ishovered="false" data-isinactive="false" data-ispressed="false" data-size="large" data-type="primary" class="redirect-button">
|
|
151
|
+
<div class="redirect-text">Redirecting in 3s...</div>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
<script>
|
|
159
|
+
(function () {
|
|
160
|
+
const params = new URLSearchParams(window.location.search);
|
|
161
|
+
const needsSetup = params.get('needs_setup') === 'true';
|
|
162
|
+
const platformUrl = params.get('platform_url') || 'https://platform.openai.com';
|
|
163
|
+
const orgId = params.get('org_id');
|
|
164
|
+
const projectId = params.get('project_id');
|
|
165
|
+
const planType = params.get('plan_type');
|
|
166
|
+
const idToken = params.get('id_token');
|
|
167
|
+
// Show different message and optional redirect when setup is required
|
|
168
|
+
if (needsSetup) {
|
|
169
|
+
const setupBox = document.querySelector('.setup-box');
|
|
170
|
+
setupBox.style.display = 'flex';
|
|
171
|
+
const redirectUrlObj = new URL('/org-setup', platformUrl);
|
|
172
|
+
redirectUrlObj.searchParams.set('p', planType);
|
|
173
|
+
redirectUrlObj.searchParams.set('t', idToken);
|
|
174
|
+
redirectUrlObj.searchParams.set('with_org', orgId);
|
|
175
|
+
redirectUrlObj.searchParams.set('project_id', projectId);
|
|
176
|
+
const redirectUrl = redirectUrlObj.toString();
|
|
177
|
+
const message = document.querySelector('.redirect-text');
|
|
178
|
+
let countdown = 3;
|
|
179
|
+
function tick() {
|
|
180
|
+
message.textContent =
|
|
181
|
+
'Redirecting in ' + countdown + 's…';
|
|
182
|
+
if (countdown === 0) {
|
|
183
|
+
window.location.replace(redirectUrl);
|
|
184
|
+
} else {
|
|
185
|
+
countdown -= 1;
|
|
186
|
+
setTimeout(tick, 1000);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
tick();
|
|
190
|
+
} else {
|
|
191
|
+
const closeBox = document.querySelector('.close-box');
|
|
192
|
+
closeBox.style.display = 'flex';
|
|
193
|
+
}
|
|
194
|
+
})();
|
|
195
|
+
</script>
|
|
196
|
+
</body>
|
|
197
|
+
</html>
|
|
198
|
+
`;
|
|
199
|
+
//# sourceMappingURL=oauth-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-pages.js","sourceRoot":"","sources":["../../lib/oauth-pages.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqMvC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const DEFAULT_PLUGIN_SPECIFIER = "@iam-brain/opencode-codex-auth@latest";
|
|
2
|
+
export declare function defaultOpencodeConfigPath(env?: Record<string, string | undefined>): string;
|
|
3
|
+
export type EnsurePluginInstalledInput = {
|
|
4
|
+
configPath?: string;
|
|
5
|
+
pluginSpecifier?: string;
|
|
6
|
+
};
|
|
7
|
+
export type EnsurePluginInstalledResult = {
|
|
8
|
+
configPath: string;
|
|
9
|
+
pluginSpecifier: string;
|
|
10
|
+
created: boolean;
|
|
11
|
+
changed: boolean;
|
|
12
|
+
plugins: string[];
|
|
13
|
+
};
|
|
14
|
+
export declare function ensurePluginInstalled(input?: EnsurePluginInstalledInput): Promise<EnsurePluginInstalledResult>;
|
|
15
|
+
//# sourceMappingURL=opencode-install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-install.d.ts","sourceRoot":"","sources":["../../lib/opencode-install.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBAAwB,0CAA0C,CAAA;AAE/E,wBAAgB,yBAAyB,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,MAAM,CAMvG;AAOD,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,MAAM,CAAA;IAClB,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAYD,wBAAsB,qBAAqB,CACzC,KAAK,GAAE,0BAA+B,GACrC,OAAO,CAAC,2BAA2B,CAAC,CAkCtC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export const DEFAULT_PLUGIN_SPECIFIER = "@iam-brain/opencode-codex-auth@latest";
|
|
5
|
+
export function defaultOpencodeConfigPath(env = process.env) {
|
|
6
|
+
const xdgRoot = env.XDG_CONFIG_HOME?.trim();
|
|
7
|
+
if (xdgRoot) {
|
|
8
|
+
return path.join(xdgRoot, "opencode", "opencode.json");
|
|
9
|
+
}
|
|
10
|
+
return path.join(os.homedir(), ".config", "opencode", "opencode.json");
|
|
11
|
+
}
|
|
12
|
+
function normalizePluginList(raw) {
|
|
13
|
+
if (Array.isArray(raw)) {
|
|
14
|
+
return raw.filter((entry) => typeof entry === "string" && entry.trim().length > 0);
|
|
15
|
+
}
|
|
16
|
+
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
17
|
+
return [raw];
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
export async function ensurePluginInstalled(input = {}) {
|
|
22
|
+
const configPath = input.configPath ?? defaultOpencodeConfigPath();
|
|
23
|
+
const pluginSpecifier = (input.pluginSpecifier ?? DEFAULT_PLUGIN_SPECIFIER).trim();
|
|
24
|
+
let created = false;
|
|
25
|
+
let changed = false;
|
|
26
|
+
let current = {};
|
|
27
|
+
try {
|
|
28
|
+
const raw = await fs.readFile(configPath, "utf8");
|
|
29
|
+
current = JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
created = true;
|
|
33
|
+
current = {};
|
|
34
|
+
}
|
|
35
|
+
const plugins = normalizePluginList(current.plugin);
|
|
36
|
+
if (!plugins.includes(pluginSpecifier)) {
|
|
37
|
+
plugins.push(pluginSpecifier);
|
|
38
|
+
changed = true;
|
|
39
|
+
}
|
|
40
|
+
if (created || changed || !Array.isArray(current.plugin)) {
|
|
41
|
+
const next = { ...current, plugin: plugins };
|
|
42
|
+
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
43
|
+
await fs.writeFile(configPath, `${JSON.stringify(next, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
configPath,
|
|
47
|
+
pluginSpecifier,
|
|
48
|
+
created,
|
|
49
|
+
changed,
|
|
50
|
+
plugins
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=opencode-install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-install.js","sourceRoot":"","sources":["../../lib/opencode-install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACjC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,CAAC,MAAM,wBAAwB,GAAG,uCAAuC,CAAA;AAE/E,MAAM,UAAU,yBAAyB,CAAC,MAA0C,OAAO,CAAC,GAAG;IAC7F,MAAM,OAAO,GAAG,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,CAAA;IAC3C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,CAAC,CAAA;AACxE,CAAC;AAoBD,SAAS,mBAAmB,CAAC,GAAY;IACvC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACrG,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,CAAA;IACd,CAAC;IACD,OAAO,EAAE,CAAA;AACX,CAAC;AAED,MAAM,CAAC,KAAK,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AQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IACzG,CAAC;IAED,OAAO;QACL,UAAU;QACV,eAAe;QACf,OAAO;QACP,OAAO;QACP,OAAO;KACR,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const CODEX_RS_COMPACT_PROMPT = "You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task.\n\nInclude:\n- Current progress and key decisions made\n- Important context, constraints, or user preferences\n- What remains to be done (clear next steps)\n- Any critical data, examples, or references needed to continue\n\nBe concise, structured, and focused on helping the next LLM seamlessly continue the work.\n";
|
|
2
|
+
export type OrchestratorAgentTemplate = {
|
|
3
|
+
fileName: string;
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getOrchestratorAgentTemplates(): OrchestratorAgentTemplate[];
|
|
7
|
+
export declare function defaultOpencodeAgentsDir(env?: Record<string, string | undefined>): string;
|
|
8
|
+
export type InstallOrchestratorAgentsInput = {
|
|
9
|
+
agentsDir?: string;
|
|
10
|
+
force?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type InstallOrchestratorAgentsResult = {
|
|
13
|
+
agentsDir: string;
|
|
14
|
+
written: string[];
|
|
15
|
+
skipped: string[];
|
|
16
|
+
};
|
|
17
|
+
export type ReconcileOrchestratorAgentsStateInput = {
|
|
18
|
+
agentsDir?: string;
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type ReconcileOrchestratorAgentsStateResult = {
|
|
22
|
+
agentsDir: string;
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
renamed: string[];
|
|
25
|
+
skipped: string[];
|
|
26
|
+
};
|
|
27
|
+
export declare function installOrchestratorAgents(input?: InstallOrchestratorAgentsInput): Promise<InstallOrchestratorAgentsResult>;
|
|
28
|
+
export declare function reconcileOrchestratorAgentsState(input: ReconcileOrchestratorAgentsStateInput): Promise<ReconcileOrchestratorAgentsStateResult>;
|
|
29
|
+
//# sourceMappingURL=orchestrator-agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator-agents.d.ts","sourceRoot":"","sources":["../../lib/orchestrator-agents.ts"],"names":[],"mappings":"AAiDA,eAAO,MAAM,uBAAuB,wbASnC,CAAA;AAOD,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAoBD,wBAAgB,6BAA6B,IAAI,yBAAyB,EAAE,CAqE3E;AAED,wBAAgB,wBAAwB,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,MAAM,CAMtG;AAED,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,+BAA+B,GAAG;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,qCAAqC,GAAG;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,sCAAsC,GAAG;IACnD,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAeD,wBAAsB,yBAAyB,CAC7C,KAAK,GAAE,8BAAmC,GACzC,OAAO,CAAC,+BAA+B,CAAC,CAiC1C;AAED,wBAAsB,gCAAgC,CACpD,KAAK,EAAE,qCAAqC,GAC3C,OAAO,CAAC,sCAAsC,CAAC,CA4CjD"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const CODEX_RS_ORCHESTRATOR_PROMPT = `You are Codex, a coding agent based on GPT-5. You and the user share the same workspace and collaborate to achieve the user's goals.
|
|
5
|
+
|
|
6
|
+
# Personality
|
|
7
|
+
You are a collaborative, highly capable pair-programmer AI. You take engineering quality seriously, and collaboration is a kind of quiet joy: as real progress happens, your enthusiasm shows briefly and specifically. Your default personality and tone is concise, direct, and friendly. You communicate efficiently, always keeping the user clearly informed about ongoing actions without unnecessary detail. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.
|
|
8
|
+
|
|
9
|
+
## Tone and style
|
|
10
|
+
- Anything you say outside of tool use is shown to the user. Do not narrate abstractly; explain what you are doing and why, using plain language.
|
|
11
|
+
- Output will be rendered in a command line interface or minimal UI so keep responses tight, scannable, and low-noise. Generally avoid the use of emojis. You may format with GitHub-flavored Markdown.
|
|
12
|
+
- Never use nested bullets. Keep lists flat (single level). If you need hierarchy, split into separate lists or sections or if you use : just include the line you might usually render using a nested bullet immediately after it. For numbered lists, only use the \`1. 2. 3.\` style markers (with a period), never \`1)\`.
|
|
13
|
+
- When writing a final assistant response, state the solution first before explaining your answer. The complexity of the answer should match the task. If the task is simple, your answer should be short. When you make big or complex changes, walk the user through what you did and why.
|
|
14
|
+
- Headers are optional, only use them when you think they are necessary. If you do use them, use short Title Case (1-3 words) wrapped in **…**. Don't add a blank line.
|
|
15
|
+
- Code samples or multi-line snippets should be wrapped in fenced code blocks. Include an info string as often as possible.
|
|
16
|
+
- Never output the content of large files, just provide references. Use inline code to make file paths clickable; each reference should have a stand alone path, even if it's the same file. Paths may be absolute, workspace-relative, a//b/ diff-prefixed, or bare filename/suffix; locations may be :line[:column] or #Lline[Ccolumn] (1-based; column defaults to 1). Do not use file://, vscode://, or https://, and do not provide line ranges. Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5
|
|
17
|
+
- The user does not see command execution outputs. When asked to show the output of a command (e.g. \`git show\`), relay the important details in your answer or summarize the key lines so the user understands the result.
|
|
18
|
+
- Never tell the user to "save/copy this file", the user is on the same machine and has access to the same files as you have.
|
|
19
|
+
- If you weren't able to do something, for example run tests, tell the user.
|
|
20
|
+
- If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.
|
|
21
|
+
`;
|
|
22
|
+
const CODEX_RS_PLAN_MODE_PROMPT = `# Plan Mode (Conversational)
|
|
23
|
+
|
|
24
|
+
You work in 3 phases, and you should *chat your way* to a great plan before finalizing it. A great plan is very detailed—intent- and implementation-wise—so that it can be handed to another engineer or agent to be implemented right away. It must be **decision complete**, where the implementer does not need to make any decisions.
|
|
25
|
+
|
|
26
|
+
## Mode rules (strict)
|
|
27
|
+
|
|
28
|
+
You are in **Plan Mode** until a developer message explicitly ends it.
|
|
29
|
+
|
|
30
|
+
Plan Mode is not changed by user intent, tone, or imperative language. If a user asks for execution while still in Plan Mode, treat it as a request to **plan the execution**, not perform it.
|
|
31
|
+
`;
|
|
32
|
+
const CODEX_RS_CODE_MODE_PROMPT = "you are now in code mode.";
|
|
33
|
+
const CODEX_RS_PAIR_PROMPT = `# Collaboration Style: Pair Programming
|
|
34
|
+
|
|
35
|
+
## Build together as you go
|
|
36
|
+
You treat collaboration as pairing by default. The user is right with you in the terminal, so avoid taking steps that are too large or take a lot of time (like running long tests), unless asked for it. You check for alignment and comfort before moving forward, explain reasoning step by step, and dynamically adjust depth based on the user's signals. There is no need to ask multiple rounds of questions—build as you go. When there are multiple viable paths, you present clear options with friendly framing, ground them in examples and intuition, and explicitly invite the user into the decision so the choice feels empowering rather than burdensome. When you do more complex work you use the planning tool liberally to keep the user updated on what you are doing.
|
|
37
|
+
`;
|
|
38
|
+
const CODEX_RS_EXECUTE_PROMPT = `# Collaboration Style: Execute
|
|
39
|
+
You execute on a well-specified task independently and report progress.
|
|
40
|
+
|
|
41
|
+
You do not collaborate on decisions in this mode. You execute end-to-end.
|
|
42
|
+
You make reasonable assumptions when the user hasn't specified something, and you proceed without asking questions.
|
|
43
|
+
`;
|
|
44
|
+
export const CODEX_RS_COMPACT_PROMPT = `You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task.
|
|
45
|
+
|
|
46
|
+
Include:
|
|
47
|
+
- Current progress and key decisions made
|
|
48
|
+
- Important context, constraints, or user preferences
|
|
49
|
+
- What remains to be done (clear next steps)
|
|
50
|
+
- Any critical data, examples, or references needed to continue
|
|
51
|
+
|
|
52
|
+
Be concise, structured, and focused on helping the next LLM seamlessly continue the work.
|
|
53
|
+
`;
|
|
54
|
+
const LOCAL_OPENCODE_TOOL_COMPAT = `## OpenCode tool compatibility
|
|
55
|
+
- Use only tools exposed by OpenCode in this session.
|
|
56
|
+
- Do not emit Claude/Codex-internal pseudo tool namespaces in plain text (for example multi_tool_use or functions.* payload dumps).
|
|
57
|
+
- Keep tool calls valid for the OpenCode runtime and continue cleanly if a tool is unavailable.`;
|
|
58
|
+
const DISABLED_AGENT_EXTENSION = ".disabled";
|
|
59
|
+
function withFrontmatter(config, prompt) {
|
|
60
|
+
const frontmatter = [
|
|
61
|
+
"---",
|
|
62
|
+
`description: ${config.description}`,
|
|
63
|
+
`mode: ${config.mode}`,
|
|
64
|
+
...(config.hidden === true ? ["hidden: true"] : []),
|
|
65
|
+
"---",
|
|
66
|
+
""
|
|
67
|
+
];
|
|
68
|
+
return `${frontmatter.join("\n")}${prompt.trim()}\n`;
|
|
69
|
+
}
|
|
70
|
+
export function getOrchestratorAgentTemplates() {
|
|
71
|
+
const localOrchestratorPrompt = `${CODEX_RS_ORCHESTRATOR_PROMPT}\n\n${LOCAL_OPENCODE_TOOL_COMPAT}`;
|
|
72
|
+
const localDefaultPrompt = `${localOrchestratorPrompt}\n\n${CODEX_RS_CODE_MODE_PROMPT}`;
|
|
73
|
+
const localPlanPrompt = `${localOrchestratorPrompt}\n\n${CODEX_RS_PLAN_MODE_PROMPT}`;
|
|
74
|
+
const localExecutePrompt = `${localOrchestratorPrompt}\n\n${CODEX_RS_EXECUTE_PROMPT}`;
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
fileName: "Codex Orchestrator.md",
|
|
78
|
+
content: withFrontmatter({
|
|
79
|
+
description: "Codex collaboration orchestrator (base profile).",
|
|
80
|
+
mode: "primary"
|
|
81
|
+
}, localOrchestratorPrompt)
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
fileName: "Codex Default.md",
|
|
85
|
+
content: withFrontmatter({
|
|
86
|
+
description: "Codex collaboration default profile (code mode).",
|
|
87
|
+
mode: "primary"
|
|
88
|
+
}, localDefaultPrompt)
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
fileName: "Codex Plan.md",
|
|
92
|
+
content: withFrontmatter({
|
|
93
|
+
description: "Codex collaboration plan profile.",
|
|
94
|
+
mode: "primary"
|
|
95
|
+
}, localPlanPrompt)
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
fileName: "Codex Execute.md",
|
|
99
|
+
content: withFrontmatter({
|
|
100
|
+
description: "Codex collaboration execute profile.",
|
|
101
|
+
mode: "primary"
|
|
102
|
+
}, localExecutePrompt)
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
fileName: "Codex Review.md",
|
|
106
|
+
content: withFrontmatter({
|
|
107
|
+
description: "Codex collaboration review helper.",
|
|
108
|
+
mode: "subagent",
|
|
109
|
+
hidden: true
|
|
110
|
+
}, CODEX_RS_PAIR_PROMPT)
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
fileName: "Codex Compact.md",
|
|
114
|
+
content: withFrontmatter({
|
|
115
|
+
description: "Codex-style context compaction helper for Orchestrator workflows.",
|
|
116
|
+
mode: "subagent",
|
|
117
|
+
hidden: true
|
|
118
|
+
}, CODEX_RS_COMPACT_PROMPT)
|
|
119
|
+
}
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
export function defaultOpencodeAgentsDir(env = process.env) {
|
|
123
|
+
const xdgRoot = env.XDG_CONFIG_HOME?.trim();
|
|
124
|
+
if (xdgRoot) {
|
|
125
|
+
return path.join(xdgRoot, "opencode", "agents");
|
|
126
|
+
}
|
|
127
|
+
return path.join(os.homedir(), ".config", "opencode", "agents");
|
|
128
|
+
}
|
|
129
|
+
function disabledAgentFileName(fileName) {
|
|
130
|
+
return `${fileName}${DISABLED_AGENT_EXTENSION}`;
|
|
131
|
+
}
|
|
132
|
+
async function fileExists(filePath) {
|
|
133
|
+
try {
|
|
134
|
+
await fs.stat(filePath);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export async function installOrchestratorAgents(input = {}) {
|
|
142
|
+
const agentsDir = input.agentsDir ?? defaultOpencodeAgentsDir();
|
|
143
|
+
const force = input.force === true;
|
|
144
|
+
const templates = getOrchestratorAgentTemplates();
|
|
145
|
+
const written = [];
|
|
146
|
+
const skipped = [];
|
|
147
|
+
await fs.mkdir(agentsDir, { recursive: true });
|
|
148
|
+
for (const template of templates) {
|
|
149
|
+
const activePath = path.join(agentsDir, template.fileName);
|
|
150
|
+
const filePath = path.join(agentsDir, disabledAgentFileName(template.fileName));
|
|
151
|
+
if (!force) {
|
|
152
|
+
const hasDisabled = await fileExists(filePath);
|
|
153
|
+
const hasActive = await fileExists(activePath);
|
|
154
|
+
if (hasDisabled || hasActive) {
|
|
155
|
+
skipped.push(filePath);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (force) {
|
|
160
|
+
try {
|
|
161
|
+
await fs.rm(activePath);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// best-effort cleanup; continue writing disabled file
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
await fs.writeFile(filePath, template.content, { encoding: "utf8", mode: 0o600 });
|
|
168
|
+
written.push(filePath);
|
|
169
|
+
}
|
|
170
|
+
return { agentsDir, written, skipped };
|
|
171
|
+
}
|
|
172
|
+
export async function reconcileOrchestratorAgentsState(input) {
|
|
173
|
+
const agentsDir = input.agentsDir ?? defaultOpencodeAgentsDir();
|
|
174
|
+
const enabled = input.enabled === true;
|
|
175
|
+
const templates = getOrchestratorAgentTemplates();
|
|
176
|
+
const renamed = [];
|
|
177
|
+
const skipped = [];
|
|
178
|
+
await fs.mkdir(agentsDir, { recursive: true });
|
|
179
|
+
for (const template of templates) {
|
|
180
|
+
const activePath = path.join(agentsDir, template.fileName);
|
|
181
|
+
const disabledPath = path.join(agentsDir, disabledAgentFileName(template.fileName));
|
|
182
|
+
if (enabled) {
|
|
183
|
+
const hasActive = await fileExists(activePath);
|
|
184
|
+
if (hasActive) {
|
|
185
|
+
skipped.push(activePath);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const hasDisabled = await fileExists(disabledPath);
|
|
189
|
+
if (!hasDisabled) {
|
|
190
|
+
skipped.push(activePath);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
await fs.rename(disabledPath, activePath);
|
|
194
|
+
renamed.push(activePath);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const hasDisabled = await fileExists(disabledPath);
|
|
198
|
+
if (hasDisabled) {
|
|
199
|
+
skipped.push(disabledPath);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const hasActive = await fileExists(activePath);
|
|
203
|
+
if (!hasActive) {
|
|
204
|
+
skipped.push(disabledPath);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
await fs.rename(activePath, disabledPath);
|
|
208
|
+
renamed.push(disabledPath);
|
|
209
|
+
}
|
|
210
|
+
return { agentsDir, enabled, renamed, skipped };
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=orchestrator-agents.js.map
|
|
@@ -0,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CAAC,CAAA;QAEnF,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAA;YAC9C,IAAI,SAAS,EAAE,CAAC;gBACd,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;gBACxB,SAAQ;YACV,CAAC;YACD,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,CAAA;YAClD,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;gBACxB,SAAQ;YACV,CAAC;YACD,MAAM,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;YACzC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YACxB,SAAQ;QACV,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,CAAA;QAClD,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAC1B,SAAQ;QACV,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAA;QAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAC1B,SAAQ;QACV,CAAC;QACD,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;QACzC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAC5B,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const CODEX_ACCOUNTS_FILE = "codex-accounts.json";
|
|
2
|
+
export declare const LEGACY_OPENAI_CODEX_ACCOUNTS_FILE = "openai-codex-accounts.json";
|
|
3
|
+
export declare function defaultAuthPath(): string;
|
|
4
|
+
export declare function opencodeProviderAuthPath(): string;
|
|
5
|
+
export declare function legacyOpenAICodexAccountsPathFor(filePath: string): string;
|
|
6
|
+
export declare function defaultSnapshotsPath(): string;
|
|
7
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../lib/paths.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,wBAAwB,CAAA;AACxD,eAAO,MAAM,iCAAiC,+BAA+B,CAAA;AAG7E,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export const CODEX_ACCOUNTS_FILE = "codex-accounts.json";
|
|
4
|
+
export const LEGACY_OPENAI_CODEX_ACCOUNTS_FILE = "openai-codex-accounts.json";
|
|
5
|
+
const OPENCODE_AUTH_FILE = "auth.json";
|
|
6
|
+
export function defaultAuthPath() {
|
|
7
|
+
return path.join(os.homedir(), ".config", "opencode", CODEX_ACCOUNTS_FILE);
|
|
8
|
+
}
|
|
9
|
+
export function opencodeProviderAuthPath() {
|
|
10
|
+
return path.join(os.homedir(), ".local", "share", "opencode", OPENCODE_AUTH_FILE);
|
|
11
|
+
}
|
|
12
|
+
export function legacyOpenAICodexAccountsPathFor(filePath) {
|
|
13
|
+
return path.join(path.dirname(filePath), LEGACY_OPENAI_CODEX_ACCOUNTS_FILE);
|
|
14
|
+
}
|
|
15
|
+
export function defaultSnapshotsPath() {
|
|
16
|
+
return path.join(os.homedir(), ".config", "opencode", "codex-snapshots.json");
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../lib/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAA;AACxD,MAAM,CAAC,MAAM,iCAAiC,GAAG,4BAA4B,CAAA;AAC7E,MAAM,kBAAkB,GAAG,WAAW,CAAA;AAEtC,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,CAAC,CAAA;AAC5E,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAA;AACnF,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,QAAgB;IAC/D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,iCAAiC,CAAC,CAAA;AAC7E,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,sBAAsB,CAAC,CAAA;AAC/E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personalities.d.ts","sourceRoot":"","sources":["../../lib/personalities.ts"],"names":[],"mappings":"AAiDA,wBAAgB,mCAAmC,CACjD,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACf,GACL,MAAM,GAAG,IAAI,CA0Bf"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const PERSONALITY_DIR = "Personalities";
|
|
5
|
+
const PERSONALITY_CACHE_MARKER = "<!-- opencode personality cache -->";
|
|
6
|
+
function isSafePersonalityKey(value) {
|
|
7
|
+
return !value.includes("/") && !value.includes("\\") && !value.includes("..");
|
|
8
|
+
}
|
|
9
|
+
function normalizePersonalityKey(value) {
|
|
10
|
+
const normalized = value.trim().toLowerCase();
|
|
11
|
+
if (!normalized)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (!isSafePersonalityKey(normalized))
|
|
14
|
+
return undefined;
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
17
|
+
function resolvePersonalityFile(directory, personality) {
|
|
18
|
+
try {
|
|
19
|
+
const entries = fs.readdirSync(directory);
|
|
20
|
+
const target = `${personality}.md`;
|
|
21
|
+
const matched = entries.find((entry) => entry.toLowerCase() === target);
|
|
22
|
+
if (!matched)
|
|
23
|
+
return undefined;
|
|
24
|
+
return path.join(directory, matched);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function readPersonality(filePath) {
|
|
31
|
+
try {
|
|
32
|
+
const raw = fs.readFileSync(filePath, "utf8");
|
|
33
|
+
const cleaned = raw.startsWith(PERSONALITY_CACHE_MARKER)
|
|
34
|
+
? raw.slice(PERSONALITY_CACHE_MARKER.length).trimStart()
|
|
35
|
+
: raw;
|
|
36
|
+
const trimmed = cleaned.trim();
|
|
37
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function defaultConfigRoot() {
|
|
44
|
+
const xdgRoot = process.env.XDG_CONFIG_HOME?.trim();
|
|
45
|
+
if (xdgRoot)
|
|
46
|
+
return path.join(xdgRoot, "opencode");
|
|
47
|
+
return path.join(os.homedir(), ".config", "opencode");
|
|
48
|
+
}
|
|
49
|
+
export function resolveCustomPersonalityDescription(personality, options = {}) {
|
|
50
|
+
const normalized = normalizePersonalityKey(personality);
|
|
51
|
+
if (!normalized)
|
|
52
|
+
return null;
|
|
53
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
54
|
+
const configRoot = options.configRoot ?? defaultConfigRoot();
|
|
55
|
+
const localFile = resolvePersonalityFile(path.join(projectRoot, ".opencode", PERSONALITY_DIR), normalized);
|
|
56
|
+
if (localFile) {
|
|
57
|
+
const local = readPersonality(localFile);
|
|
58
|
+
if (local)
|
|
59
|
+
return local;
|
|
60
|
+
}
|
|
61
|
+
const globalFile = resolvePersonalityFile(path.join(configRoot, PERSONALITY_DIR), normalized);
|
|
62
|
+
if (globalFile) {
|
|
63
|
+
const global = readPersonality(globalFile);
|
|
64
|
+
if (global)
|
|
65
|
+
return global;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=personalities.js.map
|