lsd-pi 1.1.4 → 1.1.6
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 +2 -1
- package/dist/headless-ui.js +2 -0
- package/dist/onboarding.js +11 -8
- package/dist/resources/extensions/async-jobs/async-bash-tool.js +14 -0
- package/dist/resources/extensions/async-jobs/await-tool.js +14 -0
- package/dist/resources/extensions/async-jobs/cancel-job-tool.js +7 -0
- package/dist/resources/extensions/cache-timer/index.js +5 -0
- package/dist/resources/extensions/codex-rotate/IMPLEMENTATION.md +18 -13
- package/dist/resources/extensions/codex-rotate/README.md +9 -3
- package/dist/resources/extensions/codex-rotate/commands.js +15 -8
- package/dist/resources/extensions/codex-rotate/index.js +17 -8
- package/dist/resources/extensions/memory/auto-extract.js +196 -80
- package/dist/resources/extensions/memory/dream.js +86 -19
- package/dist/resources/extensions/shared/rtk.js +89 -87
- package/dist/resources/extensions/subagent/index.js +33 -7
- package/dist/startup-model-validation.js +12 -2
- package/dist/update-check.js +2 -2
- package/dist/update-cmd.js +3 -3
- package/dist/welcome-screen.js +43 -14
- package/package.json +3 -2
- package/packages/pi-coding-agent/dist/core/agent-session.clear-queue.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/agent-session.clear-queue.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/agent-session.clear-queue.test.js +46 -0
- package/packages/pi-coding-agent/dist/core/agent-session.clear-queue.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts +8 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +43 -4
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +3 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/keybindings.d.ts +1 -1
- package/packages/pi-coding-agent/dist/core/keybindings.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/keybindings.js +2 -0
- package/packages/pi-coding-agent/dist/core/keybindings.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/pty-executor.d.ts +48 -0
- package/packages/pi-coding-agent/dist/core/pty-executor.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/pty-executor.js +173 -0
- package/packages/pi-coding-agent/dist/core/pty-executor.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +16 -3
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +9 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.js +18 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/tool-approval.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/tool-approval.js +2 -2
- package/packages/pi-coding-agent/dist/core/tool-approval.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/index.d.ts +7 -0
- package/packages/pi-coding-agent/dist/core/tools/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/index.js +23 -2
- package/packages/pi-coding-agent/dist/core/tools/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/pty.d.ts +50 -0
- package/packages/pi-coding-agent/dist/core/tools/pty.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/tools/pty.js +289 -0
- package/packages/pi-coding-agent/dist/core/tools/pty.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts +3 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +36 -22
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts +3 -5
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.js +23 -62
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js +1 -4
- package/packages/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js +1 -4
- package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/embedded-terminal.d.ts +39 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/embedded-terminal.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/embedded-terminal.js +182 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/embedded-terminal.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts +6 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.js +36 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +2 -4
- package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +1 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +106 -77
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.d.ts +2 -5
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.js +4 -13
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts +11 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +49 -13
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.js +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts +3 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +27 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +251 -39
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +2 -2
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -1
- package/packages/pi-coding-agent/dist/utils/terminal-screen.d.ts +10 -0
- package/packages/pi-coding-agent/dist/utils/terminal-screen.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/utils/terminal-screen.js +67 -0
- package/packages/pi-coding-agent/dist/utils/terminal-screen.js.map +1 -0
- package/packages/pi-coding-agent/dist/utils/terminal-serializer.d.ts +7 -0
- package/packages/pi-coding-agent/dist/utils/terminal-serializer.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/utils/terminal-serializer.js +67 -0
- package/packages/pi-coding-agent/dist/utils/terminal-serializer.js.map +1 -0
- package/packages/pi-coding-agent/package.json +9 -4
- package/packages/pi-coding-agent/src/core/agent-session.clear-queue.test.ts +50 -0
- package/packages/pi-coding-agent/src/core/agent-session.ts +50 -4
- package/packages/pi-coding-agent/src/core/extensions/types.ts +1 -1
- package/packages/pi-coding-agent/src/core/keybindings.ts +4 -1
- package/packages/pi-coding-agent/src/core/pty-executor.ts +229 -0
- package/packages/pi-coding-agent/src/core/sdk.ts +16 -3
- package/packages/pi-coding-agent/src/core/settings-manager.ts +27 -0
- package/packages/pi-coding-agent/src/core/tool-approval.ts +2 -2
- package/packages/pi-coding-agent/src/core/tools/index.ts +35 -2
- package/packages/pi-coding-agent/src/core/tools/pty.ts +354 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +37 -24
- package/packages/pi-coding-agent/src/modes/interactive/components/bash-execution.ts +22 -70
- package/packages/pi-coding-agent/src/modes/interactive/components/branch-summary-message.ts +1 -3
- package/packages/pi-coding-agent/src/modes/interactive/components/compaction-summary-message.ts +1 -3
- package/packages/pi-coding-agent/src/modes/interactive/components/embedded-terminal.ts +224 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/settings-selector.ts +45 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/skill-invocation-message.ts +2 -3
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +104 -81
- package/packages/pi-coding-agent/src/modes/interactive/components/user-message.ts +5 -19
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +55 -13
- package/packages/pi-coding-agent/src/modes/interactive/controllers/extension-ui-controller.ts +1 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.ts +2 -0
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode-state.ts +3 -0
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +296 -48
- package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +2 -2
- package/packages/pi-coding-agent/src/utils/terminal-screen.ts +77 -0
- package/packages/pi-coding-agent/src/utils/terminal-serializer.ts +72 -0
- package/packages/pi-tui/dist/components/__tests__/editor-dropped-image.test.d.ts +2 -0
- package/packages/pi-tui/dist/components/__tests__/editor-dropped-image.test.d.ts.map +1 -0
- package/packages/pi-tui/dist/components/__tests__/editor-dropped-image.test.js +105 -0
- package/packages/pi-tui/dist/components/__tests__/editor-dropped-image.test.js.map +1 -0
- package/packages/pi-tui/dist/components/editor.d.ts +4 -0
- package/packages/pi-tui/dist/components/editor.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/editor.js +57 -3
- package/packages/pi-tui/dist/components/editor.js.map +1 -1
- package/packages/pi-tui/dist/components/loader.d.ts +26 -6
- package/packages/pi-tui/dist/components/loader.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/loader.js +178 -18
- package/packages/pi-tui/dist/components/loader.js.map +1 -1
- package/packages/pi-tui/src/components/editor.ts +65 -3
- package/packages/pi-tui/src/components/loader.ts +196 -19
- package/pkg/dist/modes/interactive/theme/themes.js +2 -2
- package/pkg/dist/modes/interactive/theme/themes.js.map +1 -1
- package/pkg/package.json +1 -1
- package/src/resources/extensions/async-jobs/async-bash-tool.ts +13 -0
- package/src/resources/extensions/async-jobs/await-tool.ts +13 -0
- package/src/resources/extensions/async-jobs/cancel-job-tool.ts +8 -0
- package/src/resources/extensions/cache-timer/index.ts +102 -96
- package/src/resources/extensions/codex-rotate/IMPLEMENTATION.md +18 -13
- package/src/resources/extensions/codex-rotate/README.md +9 -3
- package/src/resources/extensions/codex-rotate/commands.ts +335 -329
- package/src/resources/extensions/codex-rotate/index.ts +85 -75
- package/src/resources/extensions/memory/auto-extract.ts +330 -204
- package/src/resources/extensions/memory/dream.ts +88 -21
- package/src/resources/extensions/memory/tests/auto-extract.test.ts +200 -144
- package/src/resources/extensions/shared/rtk.js +112 -0
- package/src/resources/extensions/subagent/index.ts +35 -6
|
@@ -2,361 +2,367 @@
|
|
|
2
2
|
* /codex slash command handlers
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { ExtensionAPI } from "@gsd/pi-coding-agent";
|
|
5
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent";
|
|
6
6
|
import type { CodexAccount } from "./types.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
markAccountUsed,
|
|
8
|
+
addAccount,
|
|
9
|
+
getAccountByEmail,
|
|
10
|
+
getAccountById,
|
|
11
|
+
getAllAccounts,
|
|
12
|
+
removeAccount,
|
|
13
|
+
updateAccount,
|
|
15
14
|
} from "./accounts.js";
|
|
16
15
|
import { performOAuthLogin, refreshAccountToken, importFromExistingCodexAuth, importFromCockpit } from "./oauth.js";
|
|
17
|
-
import { syncAccountsToAuth
|
|
18
|
-
import { PROVIDER_NAME } from "./config.js";
|
|
16
|
+
import { syncAccountsToAuth } from "./sync.js";
|
|
19
17
|
import { logCodexRotateError } from "./logger.js";
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* Format a timestamp for display
|
|
23
21
|
*/
|
|
24
22
|
function formatTimestamp(timestamp?: number): string {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
if (!timestamp) return "never";
|
|
24
|
+
const date = new Date(timestamp);
|
|
25
|
+
const now = new Date();
|
|
26
|
+
const diffMs = now.getTime() - date.getTime();
|
|
27
|
+
const diffMins = Math.floor(diffMs / 60000);
|
|
28
|
+
|
|
29
|
+
if (diffMins < 1) return "just now";
|
|
30
|
+
if (diffMins < 60) return `${diffMins}m ago`;
|
|
31
|
+
const diffHours = Math.floor(diffMins / 60);
|
|
32
|
+
if (diffHours < 24) return `${diffHours}h ago`;
|
|
33
|
+
return date.toLocaleDateString();
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
37
|
* Format expiry time for display
|
|
40
38
|
*/
|
|
41
39
|
function formatExpiry(expiresAt: number): string {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
const date = new Date(expiresAt);
|
|
41
|
+
const now = new Date();
|
|
42
|
+
const diffMs = date.getTime() - now.getTime();
|
|
43
|
+
const diffMins = Math.floor(diffMs / 60000);
|
|
44
|
+
|
|
45
|
+
if (diffMins < 0) return "expired";
|
|
46
|
+
if (diffMins < 5) return "expires soon";
|
|
47
|
+
if (diffMins < 60) return `${diffMins}m`;
|
|
48
|
+
const diffHours = Math.floor(diffMins / 60);
|
|
49
|
+
return `${diffHours}h`;
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* Display list of accounts
|
|
56
54
|
*/
|
|
57
55
|
function displayAccounts(ctx: any, accounts: CodexAccount[]): void {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
if (accounts.length === 0) {
|
|
57
|
+
ctx.ui.notify("No Codex accounts configured.", "info");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const lines: string[] = [];
|
|
62
|
+
accounts.forEach((acc, index) => {
|
|
63
|
+
const status = acc.disabled ? "✗" : "✓";
|
|
64
|
+
const email = acc.email || acc.accountId;
|
|
65
|
+
const lastUsed = acc.lastUsed ? formatTimestamp(acc.lastUsed) : "never";
|
|
66
|
+
const expiry = formatExpiry(acc.expiresAt);
|
|
67
|
+
|
|
68
|
+
lines.push(`${index + 1}. ${status} ${email}`);
|
|
69
|
+
lines.push(` Last used: ${lastUsed}, Token: ${expiry}`);
|
|
70
|
+
if (acc.disabled && acc.disabledReason) {
|
|
71
|
+
lines.push(` Reason: ${acc.disabledReason}`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function syncAccountsToAuthAndReload(ctx: ExtensionCommandContext): Promise<boolean> {
|
|
79
|
+
const synced = await syncAccountsToAuth(getAllAccounts());
|
|
80
|
+
if (synced) {
|
|
81
|
+
ctx.modelRegistry.authStorage.reload();
|
|
82
|
+
}
|
|
83
|
+
return synced;
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
/**
|
|
81
87
|
* Register the /codex command
|
|
82
88
|
*/
|
|
83
89
|
export function registerCodexCommand(pi: ExtensionAPI): void {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
90
|
+
pi.registerCommand("codex", {
|
|
91
|
+
description: "Manage Codex OAuth accounts: /codex [add|list|status|remove|enable|disable|import|import-cockpit|sync]",
|
|
92
|
+
|
|
93
|
+
getArgumentCompletions: (prefix: string) => {
|
|
94
|
+
const subcommands = [
|
|
95
|
+
"add",
|
|
96
|
+
"list",
|
|
97
|
+
"status",
|
|
98
|
+
"remove",
|
|
99
|
+
"enable",
|
|
100
|
+
"disable",
|
|
101
|
+
"import",
|
|
102
|
+
"import-cockpit",
|
|
103
|
+
"sync",
|
|
104
|
+
];
|
|
105
|
+
const parts = prefix.trim().split(/\s+/);
|
|
106
|
+
|
|
107
|
+
if (parts.length <= 1) {
|
|
108
|
+
return subcommands
|
|
109
|
+
.filter((cmd) => cmd.startsWith(parts[0] ?? ""))
|
|
110
|
+
.map((cmd) => ({ value: cmd, label: cmd }));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// For remove/enable/disable, suggest account indices
|
|
114
|
+
if (["remove", "enable", "disable"].includes(parts[0])) {
|
|
115
|
+
const accounts = getAllAccounts();
|
|
116
|
+
return accounts.map((acc, idx) => ({
|
|
117
|
+
value: `${parts[0]} ${idx + 1}`,
|
|
118
|
+
label: `${idx + 1} — ${acc.email || acc.accountId}`,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return [];
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
handler: async (args, ctx) => {
|
|
126
|
+
const parts = args.trim().split(/\s+/);
|
|
127
|
+
const sub = parts[0] || "list";
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
switch (sub) {
|
|
131
|
+
case "add": {
|
|
132
|
+
ctx.ui.notify("Starting OAuth login flow...", "info");
|
|
133
|
+
const accountData = await performOAuthLogin(undefined, {
|
|
134
|
+
onStatus: (msg: string) => ctx.ui.notify(msg, "info"),
|
|
135
|
+
onManualCodeInput: async () =>
|
|
136
|
+
(await ctx.ui.input(
|
|
137
|
+
"Paste the redirect URL from your browser:",
|
|
138
|
+
"http://localhost:...",
|
|
139
|
+
)) ?? "",
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Prompt for email (optional)
|
|
143
|
+
const emailInput = await ctx.ui.input("Email for this account (optional, press Enter to skip)", "");
|
|
144
|
+
const email = emailInput || undefined;
|
|
145
|
+
|
|
146
|
+
const account = addAccount({
|
|
147
|
+
...accountData,
|
|
148
|
+
email,
|
|
149
|
+
lastUsed: undefined,
|
|
150
|
+
disabled: false,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Sync to auth.json
|
|
154
|
+
const success = await syncAccountsToAuthAndReload(ctx);
|
|
155
|
+
if (success) {
|
|
156
|
+
ctx.ui.notify(`Added account: ${email || account.accountId}. Synced to auth.json.`, "success");
|
|
157
|
+
} else {
|
|
158
|
+
ctx.ui.notify(`Added account: ${email || account.accountId}. Failed to sync to auth.json.`, "warning");
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
case "list": {
|
|
164
|
+
const accounts = getAllAccounts();
|
|
165
|
+
displayAccounts(ctx, accounts);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
case "status": {
|
|
170
|
+
const accounts = getAllAccounts();
|
|
171
|
+
const activeCount = accounts.filter((a) => !a.disabled).length;
|
|
172
|
+
const disabledCount = accounts.length - activeCount;
|
|
173
|
+
const expiringSoon = accounts.filter((a) => !a.disabled && a.expiresAt - Date.now() < 5 * 60 * 1000).length;
|
|
174
|
+
|
|
175
|
+
const lines: string[] = [];
|
|
176
|
+
lines.push(`Codex OAuth Rotation Status`);
|
|
177
|
+
lines.push(`===========================`);
|
|
178
|
+
lines.push(`Total accounts: ${accounts.length}`);
|
|
179
|
+
lines.push(`Active: ${activeCount}, Disabled: ${disabledCount}`);
|
|
180
|
+
lines.push(`Expiring soon: ${expiringSoon}`);
|
|
181
|
+
|
|
182
|
+
if (accounts.length > 0) {
|
|
183
|
+
lines.push(`\nAccounts:`);
|
|
184
|
+
accounts.forEach((acc, index) => {
|
|
185
|
+
const status = acc.disabled ? "✗" : "✓";
|
|
186
|
+
const email = acc.email || acc.accountId;
|
|
187
|
+
const expiry = formatExpiry(acc.expiresAt);
|
|
188
|
+
lines.push(` ${index + 1}. ${status} ${email} (${expiry})`);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
case "remove": {
|
|
197
|
+
const indexStr = parts[1];
|
|
198
|
+
if (!indexStr) {
|
|
199
|
+
ctx.ui.notify("Usage: /codex remove <index|email>", "error");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let account: CodexAccount | undefined;
|
|
204
|
+
const index = parseInt(indexStr, 10);
|
|
205
|
+
|
|
206
|
+
if (!isNaN(index) && index > 0 && index <= getAllAccounts().length) {
|
|
207
|
+
account = getAllAccounts()[index - 1];
|
|
208
|
+
} else {
|
|
209
|
+
account = getAccountByEmail(indexStr) || getAccountById(indexStr);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!account) {
|
|
213
|
+
ctx.ui.notify(`Account not found: ${indexStr}`, "error");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const confirmed = await ctx.ui.select(
|
|
218
|
+
`Remove account: ${account.email || account.accountId}?`,
|
|
219
|
+
["Yes, remove", "Cancel"],
|
|
220
|
+
{ signal: AbortSignal.timeout(30000) },
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
if (confirmed === "Yes, remove") {
|
|
224
|
+
removeAccount(account.id);
|
|
225
|
+
await syncAccountsToAuthAndReload(ctx);
|
|
226
|
+
ctx.ui.notify(`Removed account: ${account.email || account.accountId}`, "success");
|
|
227
|
+
}
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
case "enable": {
|
|
232
|
+
const indexStr = parts[1];
|
|
233
|
+
if (!indexStr) {
|
|
234
|
+
ctx.ui.notify("Usage: /codex enable <index|email>", "error");
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
let account: CodexAccount | undefined;
|
|
239
|
+
const index = parseInt(indexStr, 10);
|
|
240
|
+
|
|
241
|
+
if (!isNaN(index) && index > 0 && index <= getAllAccounts().length) {
|
|
242
|
+
account = getAllAccounts()[index - 1];
|
|
243
|
+
} else {
|
|
244
|
+
account = getAccountByEmail(indexStr) || getAccountById(indexStr);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (!account) {
|
|
248
|
+
ctx.ui.notify(`Account not found: ${indexStr}`, "error");
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
updateAccount(account.id, { disabled: false, disabledReason: undefined });
|
|
253
|
+
await syncAccountsToAuthAndReload(ctx);
|
|
254
|
+
ctx.ui.notify(`Enabled account: ${account.email || account.accountId}`, "success");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
case "disable": {
|
|
259
|
+
const indexStr = parts[1];
|
|
260
|
+
if (!indexStr) {
|
|
261
|
+
ctx.ui.notify("Usage: /codex disable <index|email>", "error");
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
let account: CodexAccount | undefined;
|
|
266
|
+
const index = parseInt(indexStr, 10);
|
|
267
|
+
|
|
268
|
+
if (!isNaN(index) && index > 0 && index <= getAllAccounts().length) {
|
|
269
|
+
account = getAllAccounts()[index - 1];
|
|
270
|
+
} else {
|
|
271
|
+
account = getAccountByEmail(indexStr) || getAccountById(indexStr);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!account) {
|
|
275
|
+
ctx.ui.notify(`Account not found: ${indexStr}`, "error");
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
updateAccount(account.id, { disabled: true, disabledReason: "manually disabled" });
|
|
280
|
+
await syncAccountsToAuthAndReload(ctx);
|
|
281
|
+
ctx.ui.notify(`Disabled account: ${account.email || account.accountId}`, "success");
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
case "import": {
|
|
286
|
+
ctx.ui.notify("Importing from ~/.codex/auth.json...", "info");
|
|
287
|
+
const imported = await importFromExistingCodexAuth();
|
|
288
|
+
|
|
289
|
+
if (!imported) {
|
|
290
|
+
ctx.ui.notify("No account found to import.", "warning");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
addAccount({
|
|
295
|
+
email: imported.email,
|
|
296
|
+
accountId: imported.accountId,
|
|
297
|
+
refreshToken: imported.refreshToken,
|
|
298
|
+
accessToken: imported.accessToken,
|
|
299
|
+
expiresAt: imported.expiresAt,
|
|
300
|
+
lastUsed: undefined,
|
|
301
|
+
disabled: false,
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
await syncAccountsToAuthAndReload(ctx);
|
|
305
|
+
ctx.ui.notify(`Imported account: ${imported.email || imported.accountId}`, "success");
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
case "import-cockpit": {
|
|
310
|
+
ctx.ui.notify("Importing from Cockpit Tools...", "info");
|
|
311
|
+
const imported = await importFromCockpit();
|
|
312
|
+
|
|
313
|
+
if (imported.length === 0) {
|
|
314
|
+
ctx.ui.notify("No accounts found to import.", "warning");
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
for (const acc of imported) {
|
|
319
|
+
addAccount(acc);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
await syncAccountsToAuthAndReload(ctx);
|
|
323
|
+
ctx.ui.notify(`Imported ${imported.length} account(s) from Cockpit Tools`, "success");
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
case "sync": {
|
|
328
|
+
ctx.ui.notify("Refreshing all tokens and syncing to auth.json...", "info");
|
|
329
|
+
|
|
330
|
+
const accounts = getAllAccounts();
|
|
331
|
+
const results: { success: number; failed: number } = { success: 0, failed: 0 };
|
|
332
|
+
|
|
333
|
+
for (const acc of accounts) {
|
|
334
|
+
if (acc.disabled) continue;
|
|
335
|
+
|
|
336
|
+
try {
|
|
337
|
+
const refreshed = await refreshAccountToken(acc);
|
|
338
|
+
updateAccount(acc.id, refreshed);
|
|
339
|
+
results.success++;
|
|
340
|
+
} catch (error) {
|
|
341
|
+
logCodexRotateError(`Failed to refresh ${acc.id}:`, error);
|
|
342
|
+
results.failed++;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
await syncAccountsToAuthAndReload(ctx);
|
|
347
|
+
|
|
348
|
+
if (results.failed === 0) {
|
|
349
|
+
ctx.ui.notify(`Synced ${results.success} account(s) to auth.json`, "success");
|
|
350
|
+
} else {
|
|
351
|
+
ctx.ui.notify(`Synced ${results.success} account(s), ${results.failed} failed`, "warning");
|
|
352
|
+
}
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
default:
|
|
357
|
+
ctx.ui.notify(
|
|
358
|
+
`Usage: /codex [add|list|status|remove|enable|disable|import|import-cockpit|sync]`,
|
|
359
|
+
"info",
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
} catch (error) {
|
|
363
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
364
|
+
ctx.ui.notify(`Error: ${message}`, "error");
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
});
|
|
362
368
|
}
|