@cjhyy/code-shell 0.1.0-alpha.1 → 0.1.0-alpha.2
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 +8 -0
- package/dist/anthropic-P5VETAFI.cjs +10 -0
- package/dist/{anthropic-NENYS535.js → anthropic-W2GU3D76.js} +3 -2
- package/dist/arena/context/context-tools.d.ts +1 -1
- package/dist/arena/index.cjs +4 -4
- package/dist/arena/index.js +3 -3
- package/dist/arena/providers/index.d.ts +19 -3
- package/dist/arena/strategies/utils.d.ts +6 -1
- package/dist/arena/types.d.ts +10 -1
- package/dist/{arena-46QQ6BZQ.js → arena-ENHBHB2W.js} +5 -7
- package/dist/{arena-HZZZ2GJH.cjs → arena-HHDYYVHJ.cjs} +19 -21
- package/dist/{chunk-BE6IPRDM.js → chunk-2EUAE7AY.js} +1 -1
- package/dist/{chunk-WYKNZ54E.cjs → chunk-3CAZIWUA.cjs} +6 -6
- package/dist/{chunk-J5XW6UYL.js → chunk-5C5HIOML.js} +63 -4
- package/dist/chunk-75E4BBFC.js +224 -0
- package/dist/{chunk-ZJV3YSY3.cjs → chunk-BUJ5KYCI.cjs} +53 -11
- package/dist/{chunk-BMH65OVB.cjs → chunk-C7C7ZZY4.cjs} +8 -8
- package/dist/{chunk-KO2FPF7G.js → chunk-F5BS3GUC.js} +20 -2
- package/dist/chunk-FA5KD34T.js +54 -0
- package/dist/chunk-FV2ARONZ.cjs +224 -0
- package/dist/chunk-G76E5FOB.cjs +54 -0
- package/dist/{chunk-DICG4AB7.cjs → chunk-GZBD6QRS.cjs} +42 -3
- package/dist/{chunk-FVP7XJGS.cjs → chunk-HOXQLX5R.cjs} +406 -196
- package/dist/{chunk-4PKZPFCD.js → chunk-I57ZD5IQ.js} +47 -14
- package/dist/{chunk-JUHRV2XF.js → chunk-ID6EJUHP.js} +1703 -438
- package/dist/chunk-JHNCK7JP.cjs +202 -0
- package/dist/{chunk-MOILS4WE.cjs → chunk-JHXNOB5G.cjs} +3 -3
- package/dist/{chunk-UK2SU23S.cjs → chunk-KOGV6PDQ.cjs} +20 -2
- package/dist/{chunk-VKGNCYRL.js → chunk-LMEKCQX4.js} +95 -13
- package/dist/{chunk-3EAEC566.cjs → chunk-M2QI5X3X.cjs} +51 -18
- package/dist/{chunk-YZ25SSWJ.js → chunk-M2SVOKC6.js} +46 -4
- package/dist/chunk-OMRGA6TI.js +4753 -0
- package/dist/{chunk-NG73UR3L.cjs → chunk-OP57WUWQ.cjs} +23 -1
- package/dist/{chunk-ZXYDDJEJ.js → chunk-OUC2DFA7.js} +2 -2
- package/dist/{chunk-AP5F6VYE.js → chunk-REFCCVDM.js} +1 -1
- package/dist/{chunk-O6F2EF2Z.js → chunk-SCDKLTN3.js} +41 -2
- package/dist/{chunk-FECTK5KJ.js → chunk-SW3L7HIM.js} +1 -1
- package/dist/chunk-TATCTZSB.cjs +4753 -0
- package/dist/{chunk-Q6BYFYGD.cjs → chunk-VWFET3MG.cjs} +1886 -621
- package/dist/{chunk-3EUDE77E.cjs → chunk-X2DNIMPC.cjs} +19 -19
- package/dist/{chunk-SQZHPD3S.js → chunk-Y7TSCDF6.js} +297 -87
- package/dist/{chunk-WHRTARDJ.cjs → chunk-YAFCN7ZW.cjs} +112 -30
- package/dist/{chunk-LRAY5IYC.cjs → chunk-YD7XTI7T.cjs} +65 -6
- package/dist/{chunk-S74VVJBF.js → chunk-ZLPJJZUW.js} +23 -1
- package/dist/chunk-ZRVPCXI7.js +202 -0
- package/dist/cli/commands/builtin/advanced-commands.d.ts +1 -1
- package/dist/cli/commands/builtin/extra-commands.d.ts +2 -2
- package/dist/cli/commands/builtin/more-commands.d.ts +1 -3
- package/dist/cli/commands/registry.d.ts +8 -0
- package/dist/cli/cost-tracker.d.ts +6 -0
- package/dist/cli/main.cjs +3534 -1996
- package/dist/cli/main.js +3646 -2108
- package/dist/cli/onboarding.d.ts +67 -14
- package/dist/client-base-TOVE25FA.js +9 -0
- package/dist/client-base-VDDIADAC.cjs +9 -0
- package/dist/compaction-D3KV2NWY.cjs +31 -0
- package/dist/{compaction-CCHWA4G6.js → compaction-YNWCEF7B.js} +1 -2
- package/dist/context/manager.d.ts +9 -0
- package/dist/data/openrouter-models.d.ts +35 -0
- package/dist/data/openrouter-sync.d.ts +16 -0
- package/dist/{devtools-KIY3LWQJ.js → devtools-IRQQPIRY.js} +1 -1
- package/dist/{devtools-LRP47DDV.cjs → devtools-WTC3NFNE.cjs} +1 -1
- package/dist/engine/engine.d.ts +29 -6
- package/dist/engine/turn-loop.d.ts +7 -0
- package/dist/engine/turn-state.d.ts +6 -0
- package/dist/index.cjs +19 -28
- package/dist/index.js +28 -37
- package/dist/llm/client-base.d.ts +7 -0
- package/dist/llm/model-pool.d.ts +4 -0
- package/dist/logging/logger.d.ts +69 -8
- package/dist/manager-FWLOVEEK.cjs +7 -0
- package/dist/manager-GEXJLOIS.js +7 -0
- package/dist/{mcp-manager-OKXHHWYR.js → mcp-manager-37GQLFGX.js} +2 -2
- package/dist/mcp-manager-U77NEXBY.cjs +8 -0
- package/dist/memory-ADGOWADP.cjs +9 -0
- package/dist/memory-EPFDBPII.js +9 -0
- package/dist/native-ts/yoga-layout/index.d.ts +2 -2
- package/dist/{openai-5HQGBL4L.js → openai-RXU5URYI.js} +3 -2
- package/dist/openai-SQW4H2K4.cjs +10 -0
- package/dist/openrouter-models-OL725CL6.js +15 -0
- package/dist/openrouter-models-UM3AOGZ4.cjs +15 -0
- package/dist/openrouter-sync-CWD5VNW2.js +11 -0
- package/dist/openrouter-sync-HYZZC6RX.cjs +11 -0
- package/dist/product/index.cjs +12 -16
- package/dist/product/index.js +11 -15
- package/dist/protocol/types.d.ts +11 -3
- package/dist/{ink → render}/hooks/use-input.d.ts +1 -1
- package/dist/run/index.cjs +12 -16
- package/dist/run/index.js +11 -15
- package/dist/session/memory.d.ts +23 -3
- package/dist/session/session-manager.d.ts +4 -1
- package/dist/{session-manager-UQKB564H.cjs → session-manager-HRSKENKB.cjs} +2 -2
- package/dist/{session-manager-JIIBCFTC.js → session-manager-NEKFEHF3.js} +1 -1
- package/dist/settings/manager.d.ts +9 -0
- package/dist/settings/schema.d.ts +48 -39
- package/dist/{tool-summary-J2ICNMWP.js → tool-summary-2RUFL5QK.js} +1 -1
- package/dist/{tool-summary-5P2GKRA4.cjs → tool-summary-RYNR4DDB.cjs} +2 -2
- package/dist/tool-system/builtin/agent.d.ts +3 -26
- package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
- package/dist/tool-system/builtin/apply-patch/index.d.ts +19 -0
- package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
- package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
- package/dist/tool-system/builtin/arena.d.ts +18 -5
- package/dist/tool-system/builtin/ask-user.d.ts +6 -6
- package/dist/tool-system/builtin/index.d.ts +11 -1
- package/dist/tool-system/builtin/tool-search.d.ts +2 -3
- package/dist/tool-system/context.d.ts +74 -0
- package/dist/tool-system/executor.d.ts +16 -0
- package/dist/tool-system/permission.d.ts +40 -5
- package/dist/tool-system/registry.d.ts +2 -0
- package/dist/types.d.ts +28 -1
- package/dist/ui/App.d.ts +1 -1
- package/dist/ui/components/AgentBlock.d.ts +1 -1
- package/dist/ui/components/AskUserPrompt.d.ts +7 -0
- package/dist/ui/components/MessageContent.d.ts +7 -3
- package/dist/ui/components/ModelManager.d.ts +35 -0
- package/dist/ui/components/ModelSelector.d.ts +10 -0
- package/dist/ui/components/OnboardingPrompt.d.ts +7 -0
- package/dist/ui/components/PermissionPrompt.d.ts +5 -2
- package/dist/ui/components/SessionPicker.d.ts +14 -0
- package/dist/ui/components/StatusLine.d.ts +4 -2
- package/dist/ui/components/ThemedBox.d.ts +1 -1
- package/dist/ui/components/ToolCall.d.ts +8 -1
- package/dist/ui/components/WelcomeTips.d.ts +5 -0
- package/dist/ui/onboarding-runner.d.ts +2 -0
- package/dist/ui/store.d.ts +1 -0
- package/dist/{updater-2N6745WR.cjs → updater-M7L42ASZ.cjs} +4 -4
- package/dist/{updater-PV7FKSUI.js → updater-ZRTONIR4.js} +4 -4
- package/dist/utils/debug.d.ts +17 -33
- package/package.json +4 -4
- package/dist/anthropic-XMTTVNSH.cjs +0 -9
- package/dist/bridge-4ZRXVWBN.js +0 -98
- package/dist/bridge-W476QDFH.cjs +0 -98
- package/dist/chunk-4RRUP4MM.js +0 -86
- package/dist/chunk-4SFPFHMG.js +0 -132
- package/dist/chunk-5LHVI777.cjs +0 -246
- package/dist/chunk-6ZIROYXX.js +0 -207
- package/dist/chunk-C7JBCO5V.js +0 -80
- package/dist/chunk-CSO5EOEP.cjs +0 -132
- package/dist/chunk-FGZGCFJX.cjs +0 -207
- package/dist/chunk-HD7MT5XU.cjs +0 -86
- package/dist/chunk-IMMTBZ33.cjs +0 -63
- package/dist/chunk-JT2WSQSR.cjs +0 -335
- package/dist/chunk-NZ4DQ72D.cjs +0 -664
- package/dist/chunk-OG4MIQJ6.js +0 -335
- package/dist/chunk-WRZJUQ5Z.js +0 -664
- package/dist/chunk-X4HAERTQ.js +0 -63
- package/dist/chunk-XHC2JMEC.cjs +0 -80
- package/dist/chunk-ZRSSGYA5.js +0 -246
- package/dist/compaction-44I55TLI.cjs +0 -32
- package/dist/coordinator-5HY7ALO2.js +0 -7
- package/dist/coordinator-INDLPVMF.cjs +0 -7
- package/dist/cost-tracker-IWYAUPXH.js +0 -9
- package/dist/cost-tracker-JXTJQQWE.cjs +0 -9
- package/dist/loader-DXFSUB4R.cjs +0 -91
- package/dist/loader-J5UID6CV.js +0 -91
- package/dist/manager-ETWDOCHN.cjs +0 -9
- package/dist/manager-HGMQNEJB.cjs +0 -11
- package/dist/manager-HUAQOORS.js +0 -9
- package/dist/manager-VJIZ2CQC.js +0 -11
- package/dist/mcp-manager-G4G2QASE.cjs +0 -8
- package/dist/memory-AP747G5H.js +0 -7
- package/dist/memory-BH3BYUN5.cjs +0 -7
- package/dist/onboarding-6WEPV7C2.js +0 -11
- package/dist/onboarding-QM5DY2TU.cjs +0 -11
- package/dist/openai-656VWUQW.cjs +0 -9
- package/dist/skills-63RBYQRX.js +0 -13
- package/dist/skills-V3BPLW3D.cjs +0 -13
- package/dist/token-counter-CHAXW5O7.cjs +0 -13
- package/dist/token-counter-DSOZGZ5Q.js +0 -13
- package/dist/utils/log.d.ts +0 -56
- package/dist/voice-KTZ7PAGO.js +0 -80
- package/dist/voice-KZE25GKB.cjs +0 -80
- /package/dist/{ink → render}/Ansi.d.ts +0 -0
- /package/dist/{ink → render}/bidi.d.ts +0 -0
- /package/dist/{ink → render}/clearTerminal.d.ts +0 -0
- /package/dist/{ink → render}/colorize.d.ts +0 -0
- /package/dist/{ink → render}/components/AlternateScreen.d.ts +0 -0
- /package/dist/{ink → render}/components/App.d.ts +0 -0
- /package/dist/{ink → render}/components/AppContext.d.ts +0 -0
- /package/dist/{ink → render}/components/Box.d.ts +0 -0
- /package/dist/{ink → render}/components/Button.d.ts +0 -0
- /package/dist/{ink → render}/components/ClockContext.d.ts +0 -0
- /package/dist/{ink → render}/components/CursorDeclarationContext.d.ts +0 -0
- /package/dist/{ink → render}/components/ErrorOverview.d.ts +0 -0
- /package/dist/{ink → render}/components/Link.d.ts +0 -0
- /package/dist/{ink → render}/components/Newline.d.ts +0 -0
- /package/dist/{ink → render}/components/NoSelect.d.ts +0 -0
- /package/dist/{ink → render}/components/RawAnsi.d.ts +0 -0
- /package/dist/{ink → render}/components/ScrollBox.d.ts +0 -0
- /package/dist/{ink → render}/components/Spacer.d.ts +0 -0
- /package/dist/{ink → render}/components/StdinContext.d.ts +0 -0
- /package/dist/{ink → render}/components/TerminalFocusContext.d.ts +0 -0
- /package/dist/{ink → render}/components/TerminalSizeContext.d.ts +0 -0
- /package/dist/{ink → render}/components/Text.d.ts +0 -0
- /package/dist/{ink → render}/constants.d.ts +0 -0
- /package/dist/{ink → render}/cursor.d.ts +0 -0
- /package/dist/{ink → render}/devtools.d.ts +0 -0
- /package/dist/{ink → render}/dom.d.ts +0 -0
- /package/dist/{ink → render}/events/click-event.d.ts +0 -0
- /package/dist/{ink → render}/events/dispatcher.d.ts +0 -0
- /package/dist/{ink → render}/events/emitter.d.ts +0 -0
- /package/dist/{ink → render}/events/event-handlers.d.ts +0 -0
- /package/dist/{ink → render}/events/event.d.ts +0 -0
- /package/dist/{ink → render}/events/focus-event.d.ts +0 -0
- /package/dist/{ink → render}/events/input-event.d.ts +0 -0
- /package/dist/{ink → render}/events/keyboard-event.d.ts +0 -0
- /package/dist/{ink → render}/events/paste-event.d.ts +0 -0
- /package/dist/{ink → render}/events/resize-event.d.ts +0 -0
- /package/dist/{ink → render}/events/terminal-event.d.ts +0 -0
- /package/dist/{ink → render}/events/terminal-focus-event.d.ts +0 -0
- /package/dist/{ink → render}/focus.d.ts +0 -0
- /package/dist/{ink → render}/frame.d.ts +0 -0
- /package/dist/{ink → render}/get-max-width.d.ts +0 -0
- /package/dist/{ink → render}/hit-test.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-animation-frame.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-app.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-declared-cursor.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-interval.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-search-highlight.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-selection.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-stdin.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-tab-status.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-terminal-focus.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-terminal-title.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-terminal-viewport.d.ts +0 -0
- /package/dist/{ink → render}/index.d.ts +0 -0
- /package/dist/{ink → render}/ink.d.ts +0 -0
- /package/dist/{ink → render}/instances.d.ts +0 -0
- /package/dist/{ink → render}/layout/engine.d.ts +0 -0
- /package/dist/{ink → render}/layout/geometry.d.ts +0 -0
- /package/dist/{ink → render}/layout/node.d.ts +0 -0
- /package/dist/{ink → render}/layout/yoga.d.ts +0 -0
- /package/dist/{ink → render}/line-width-cache.d.ts +0 -0
- /package/dist/{ink → render}/log-update.d.ts +0 -0
- /package/dist/{ink → render}/measure-element.d.ts +0 -0
- /package/dist/{ink → render}/measure-text.d.ts +0 -0
- /package/dist/{ink → render}/node-cache.d.ts +0 -0
- /package/dist/{ink → render}/optimizer.d.ts +0 -0
- /package/dist/{ink → render}/output.d.ts +0 -0
- /package/dist/{ink → render}/parse-keypress.d.ts +0 -0
- /package/dist/{ink → render}/reconciler.d.ts +0 -0
- /package/dist/{ink → render}/render-border.d.ts +0 -0
- /package/dist/{ink → render}/render-node-to-output.d.ts +0 -0
- /package/dist/{ink → render}/render-to-screen.d.ts +0 -0
- /package/dist/{ink → render}/renderer.d.ts +0 -0
- /package/dist/{ink → render}/root.d.ts +0 -0
- /package/dist/{ink → render}/screen.d.ts +0 -0
- /package/dist/{ink → render}/searchHighlight.d.ts +0 -0
- /package/dist/{ink → render}/selection.d.ts +0 -0
- /package/dist/{ink → render}/squash-text-nodes.d.ts +0 -0
- /package/dist/{ink → render}/stringWidth.d.ts +0 -0
- /package/dist/{ink → render}/styles.d.ts +0 -0
- /package/dist/{ink → render}/supports-hyperlinks.d.ts +0 -0
- /package/dist/{ink → render}/tabstops.d.ts +0 -0
- /package/dist/{ink → render}/terminal-focus-state.d.ts +0 -0
- /package/dist/{ink → render}/terminal-querier.d.ts +0 -0
- /package/dist/{ink → render}/terminal.d.ts +0 -0
- /package/dist/{ink → render}/termio/ansi.d.ts +0 -0
- /package/dist/{ink → render}/termio/csi.d.ts +0 -0
- /package/dist/{ink → render}/termio/dec.d.ts +0 -0
- /package/dist/{ink → render}/termio/esc.d.ts +0 -0
- /package/dist/{ink → render}/termio/osc.d.ts +0 -0
- /package/dist/{ink → render}/termio/parser.d.ts +0 -0
- /package/dist/{ink → render}/termio/sgr.d.ts +0 -0
- /package/dist/{ink → render}/termio/tokenize.d.ts +0 -0
- /package/dist/{ink → render}/termio/types.d.ts +0 -0
- /package/dist/{ink → render}/termio.d.ts +0 -0
- /package/dist/{ink → render}/useTerminalNotification.d.ts +0 -0
- /package/dist/{ink → render}/warn.d.ts +0 -0
- /package/dist/{ink → render}/widest-line.d.ts +0 -0
- /package/dist/{ink → render}/wrap-text.d.ts +0 -0
- /package/dist/{ink → render}/wrapAnsi.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkGZBD6QRScjs = require('./chunk-GZBD6QRS.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -8,12 +8,15 @@ var _chunkDICG4AB7cjs = require('./chunk-DICG4AB7.cjs');
|
|
|
8
8
|
var _chunkEL2RL5DGcjs = require('./chunk-EL2RL5DG.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
var _chunkJHNCK7JPcjs = require('./chunk-JHNCK7JP.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
11
14
|
var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
|
|
12
15
|
|
|
13
16
|
// src/llm/providers/openai.ts
|
|
14
17
|
_chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
|
|
15
18
|
var _openai = require('openai'); var _openai2 = _interopRequireDefault(_openai);
|
|
16
|
-
var OpenAIClient = (_class = class extends
|
|
19
|
+
var OpenAIClient = (_class = class extends _chunkGZBD6QRScjs.LLMClientBase {
|
|
17
20
|
__init() {this._client = null}
|
|
18
21
|
constructor(config) {
|
|
19
22
|
super(config);_class.prototype.__init.call(this);;
|
|
@@ -34,10 +37,28 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
34
37
|
return this.withRetry(async () => {
|
|
35
38
|
const messages = this.buildMessages(options.systemPrompt, options.messages);
|
|
36
39
|
const tools = _optionalChain([options, 'access', _ => _.tools, 'optionalAccess', _2 => _2.length]) ? this.convertTools(options.tools) : void 0;
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
const span = _chunkJHNCK7JPcjs.logger.span("llm.request", {
|
|
41
|
+
cat: "llm",
|
|
42
|
+
provider: this.provider,
|
|
43
|
+
model: this.model,
|
|
44
|
+
stream: !!(options.stream && options.onChunk),
|
|
45
|
+
messageCount: messages.length,
|
|
46
|
+
toolCount: _nullishCoalesce(_optionalChain([tools, 'optionalAccess', _3 => _3.length]), () => ( 0))
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
const response = options.stream && options.onChunk ? await this.streamMessage(options, messages, tools) : await this.nonStreamMessage(options, messages, tools);
|
|
50
|
+
span.end({
|
|
51
|
+
stopReason: response.stopReason,
|
|
52
|
+
promptTokens: _optionalChain([response, 'access', _4 => _4.usage, 'optionalAccess', _5 => _5.promptTokens]),
|
|
53
|
+
completionTokens: _optionalChain([response, 'access', _6 => _6.usage, 'optionalAccess', _7 => _7.completionTokens]),
|
|
54
|
+
cacheReadTokens: _optionalChain([response, 'access', _8 => _8.usage, 'optionalAccess', _9 => _9.cacheReadTokens]),
|
|
55
|
+
cacheCreationTokens: _optionalChain([response, 'access', _10 => _10.usage, 'optionalAccess', _11 => _11.cacheCreationTokens])
|
|
56
|
+
});
|
|
57
|
+
return response;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
span.fail(err);
|
|
60
|
+
throw err;
|
|
39
61
|
}
|
|
40
|
-
return this.nonStreamMessage(options, messages, tools);
|
|
41
62
|
});
|
|
42
63
|
}
|
|
43
64
|
async nonStreamMessage(options, messages, tools) {
|
|
@@ -55,9 +76,9 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
55
76
|
const choice = response.choices[0];
|
|
56
77
|
if (!choice) throw new (0, _chunkEL2RL5DGcjs.LLMError)("No response from OpenAI", "openai");
|
|
57
78
|
const usage = {
|
|
58
|
-
promptTokens: _nullishCoalesce(_optionalChain([response, 'access',
|
|
59
|
-
completionTokens: _nullishCoalesce(_optionalChain([response, 'access',
|
|
60
|
-
totalTokens: _nullishCoalesce(_optionalChain([response, 'access',
|
|
79
|
+
promptTokens: _nullishCoalesce(_optionalChain([response, 'access', _12 => _12.usage, 'optionalAccess', _13 => _13.prompt_tokens]), () => ( 0)),
|
|
80
|
+
completionTokens: _nullishCoalesce(_optionalChain([response, 'access', _14 => _14.usage, 'optionalAccess', _15 => _15.completion_tokens]), () => ( 0)),
|
|
81
|
+
totalTokens: _nullishCoalesce(_optionalChain([response, 'access', _16 => _16.usage, 'optionalAccess', _17 => _17.total_tokens]), () => ( 0))
|
|
61
82
|
};
|
|
62
83
|
this.recordUsage(usage);
|
|
63
84
|
return this.processChoice(choice, usage);
|
|
@@ -81,36 +102,64 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
81
102
|
{ signal: options.signal }
|
|
82
103
|
);
|
|
83
104
|
let text = "";
|
|
105
|
+
let reasoningContent = "";
|
|
84
106
|
const toolCallsMap = /* @__PURE__ */ new Map();
|
|
85
107
|
let streamUsage;
|
|
108
|
+
const streamStartedAt = Date.now();
|
|
109
|
+
let firstByteLogged = false;
|
|
86
110
|
for await (const chunk of stream) {
|
|
87
111
|
if (chunk.usage) {
|
|
88
112
|
streamUsage = chunk.usage;
|
|
89
113
|
}
|
|
90
|
-
const delta = _optionalChain([chunk, 'access',
|
|
114
|
+
const delta = _optionalChain([chunk, 'access', _18 => _18.choices, 'access', _19 => _19[0], 'optionalAccess', _20 => _20.delta]);
|
|
91
115
|
if (!delta) continue;
|
|
116
|
+
const reasoningDelta = delta.reasoning_content;
|
|
117
|
+
if (typeof reasoningDelta === "string" && reasoningDelta.length > 0) {
|
|
118
|
+
reasoningContent += reasoningDelta;
|
|
119
|
+
}
|
|
92
120
|
if (delta.content) {
|
|
121
|
+
if (!firstByteLogged) {
|
|
122
|
+
firstByteLogged = true;
|
|
123
|
+
_chunkJHNCK7JPcjs.logger.debug("llm.first_byte", {
|
|
124
|
+
cat: "llm",
|
|
125
|
+
provider: this.provider,
|
|
126
|
+
model: this.model,
|
|
127
|
+
ttft_ms: Date.now() - streamStartedAt
|
|
128
|
+
});
|
|
129
|
+
}
|
|
93
130
|
text += delta.content;
|
|
94
|
-
_optionalChain([options, 'access',
|
|
131
|
+
_optionalChain([options, 'access', _21 => _21.onChunk, 'optionalCall', _22 => _22({ type: "text", text: delta.content })]);
|
|
95
132
|
}
|
|
96
133
|
if (delta.tool_calls) {
|
|
97
134
|
for (const tc of delta.tool_calls) {
|
|
98
135
|
const idx = tc.index;
|
|
99
136
|
if (!toolCallsMap.has(idx)) {
|
|
100
|
-
toolCallsMap.set(idx, { id: _nullishCoalesce(tc.id, () => ( "")), name: _nullishCoalesce(_optionalChain([tc, 'access',
|
|
101
|
-
_optionalChain([options, 'access',
|
|
137
|
+
toolCallsMap.set(idx, { id: _nullishCoalesce(tc.id, () => ( "")), name: _nullishCoalesce(_optionalChain([tc, 'access', _23 => _23.function, 'optionalAccess', _24 => _24.name]), () => ( "")), args: "" });
|
|
138
|
+
_optionalChain([options, 'access', _25 => _25.onChunk, 'optionalCall', _26 => _26({
|
|
102
139
|
type: "tool_use_start",
|
|
103
|
-
toolCall: { id: tc.id, toolName: _optionalChain([tc, 'access',
|
|
140
|
+
toolCall: { id: tc.id, toolName: _optionalChain([tc, 'access', _27 => _27.function, 'optionalAccess', _28 => _28.name]) }
|
|
104
141
|
})]);
|
|
105
142
|
}
|
|
106
143
|
const existing = toolCallsMap.get(idx);
|
|
107
144
|
if (tc.id) existing.id = tc.id;
|
|
108
|
-
if (_optionalChain([tc, 'access',
|
|
109
|
-
if (_optionalChain([tc, 'access',
|
|
145
|
+
if (_optionalChain([tc, 'access', _29 => _29.function, 'optionalAccess', _30 => _30.name])) existing.name = tc.function.name;
|
|
146
|
+
if (_optionalChain([tc, 'access', _31 => _31.function, 'optionalAccess', _32 => _32.arguments])) {
|
|
147
|
+
existing.args += tc.function.arguments;
|
|
148
|
+
if (existing.id) {
|
|
149
|
+
try {
|
|
150
|
+
const parsed = JSON.parse(existing.args || "{}");
|
|
151
|
+
_optionalChain([options, 'access', _33 => _33.onChunk, 'optionalCall', _34 => _34({
|
|
152
|
+
type: "tool_use_delta",
|
|
153
|
+
toolCall: { id: existing.id, toolName: existing.name, args: parsed }
|
|
154
|
+
})]);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
110
159
|
}
|
|
111
160
|
}
|
|
112
|
-
if (_optionalChain([chunk, 'access',
|
|
113
|
-
_optionalChain([options, 'access',
|
|
161
|
+
if (_optionalChain([chunk, 'access', _35 => _35.choices, 'access', _36 => _36[0], 'optionalAccess', _37 => _37.finish_reason])) {
|
|
162
|
+
_optionalChain([options, 'access', _38 => _38.onChunk, 'optionalCall', _39 => _39({ type: "stop", stopReason: chunk.choices[0].finish_reason })]);
|
|
114
163
|
}
|
|
115
164
|
}
|
|
116
165
|
const toolCalls = [];
|
|
@@ -118,17 +167,23 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
118
167
|
let args = {};
|
|
119
168
|
try {
|
|
120
169
|
args = JSON.parse(tc.args || "{}");
|
|
121
|
-
} catch (
|
|
170
|
+
} catch (e2) {
|
|
122
171
|
}
|
|
123
172
|
toolCalls.push({ id: tc.id, toolName: tc.name, args });
|
|
124
173
|
}
|
|
125
174
|
const usage = {
|
|
126
|
-
promptTokens: _nullishCoalesce(_optionalChain([streamUsage, 'optionalAccess',
|
|
127
|
-
completionTokens: _nullishCoalesce(_optionalChain([streamUsage, 'optionalAccess',
|
|
128
|
-
totalTokens: _nullishCoalesce(_optionalChain([streamUsage, 'optionalAccess',
|
|
175
|
+
promptTokens: _nullishCoalesce(_optionalChain([streamUsage, 'optionalAccess', _40 => _40.prompt_tokens]), () => ( 0)),
|
|
176
|
+
completionTokens: _nullishCoalesce(_optionalChain([streamUsage, 'optionalAccess', _41 => _41.completion_tokens]), () => ( 0)),
|
|
177
|
+
totalTokens: _nullishCoalesce(_optionalChain([streamUsage, 'optionalAccess', _42 => _42.total_tokens]), () => ( 0))
|
|
129
178
|
};
|
|
130
179
|
this.recordUsage(usage);
|
|
131
|
-
return {
|
|
180
|
+
return {
|
|
181
|
+
text,
|
|
182
|
+
toolCalls,
|
|
183
|
+
usage,
|
|
184
|
+
stopReason: "stop",
|
|
185
|
+
...reasoningContent ? { reasoningContent } : {}
|
|
186
|
+
};
|
|
132
187
|
} catch (err) {
|
|
133
188
|
this.handleApiError(err);
|
|
134
189
|
throw err;
|
|
@@ -142,7 +197,7 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
142
197
|
let args = {};
|
|
143
198
|
try {
|
|
144
199
|
args = JSON.parse(tc.function.arguments || "{}");
|
|
145
|
-
} catch (
|
|
200
|
+
} catch (e3) {
|
|
146
201
|
}
|
|
147
202
|
toolCalls.push({
|
|
148
203
|
id: tc.id,
|
|
@@ -151,17 +206,27 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
151
206
|
});
|
|
152
207
|
}
|
|
153
208
|
}
|
|
154
|
-
|
|
209
|
+
const reasoningContent = extractReasoningContent(
|
|
210
|
+
choice.message
|
|
211
|
+
);
|
|
212
|
+
return {
|
|
213
|
+
text,
|
|
214
|
+
toolCalls,
|
|
215
|
+
usage,
|
|
216
|
+
stopReason: _nullishCoalesce(choice.finish_reason, () => ( void 0)),
|
|
217
|
+
...reasoningContent ? { reasoningContent } : {}
|
|
218
|
+
};
|
|
155
219
|
}
|
|
156
220
|
buildMessages(systemPrompt, messages) {
|
|
157
|
-
const result = [
|
|
158
|
-
|
|
159
|
-
];
|
|
221
|
+
const result = [{ role: "system", content: systemPrompt }];
|
|
222
|
+
const needsReasoningBackfill = isDeepSeekThinkingModel(this.model);
|
|
160
223
|
for (const msg of messages) {
|
|
161
224
|
if (msg.role === "system") continue;
|
|
162
225
|
if (msg.role === "assistant") {
|
|
226
|
+
const param = { role: "assistant" };
|
|
227
|
+
let reasoningContent;
|
|
163
228
|
if (typeof msg.content === "string") {
|
|
164
|
-
|
|
229
|
+
param.content = msg.content;
|
|
165
230
|
} else {
|
|
166
231
|
const textParts = [];
|
|
167
232
|
const toolCalls = [];
|
|
@@ -177,13 +242,23 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
177
242
|
arguments: JSON.stringify(_nullishCoalesce(block.input, () => ( {})))
|
|
178
243
|
}
|
|
179
244
|
});
|
|
245
|
+
} else if (block.type === "reasoning" && block.reasoningContent) {
|
|
246
|
+
reasoningContent = block.reasoningContent;
|
|
247
|
+
}
|
|
248
|
+
if (!reasoningContent && block.reasoningContent) {
|
|
249
|
+
reasoningContent = block.reasoningContent;
|
|
180
250
|
}
|
|
181
251
|
}
|
|
182
|
-
const param = { role: "assistant" };
|
|
183
252
|
if (textParts.length) param.content = textParts.join("\n");
|
|
184
253
|
if (toolCalls.length) param.tool_calls = toolCalls;
|
|
185
|
-
result.push(param);
|
|
186
254
|
}
|
|
255
|
+
if (!reasoningContent && needsReasoningBackfill) {
|
|
256
|
+
reasoningContent = "";
|
|
257
|
+
}
|
|
258
|
+
if (reasoningContent !== void 0) {
|
|
259
|
+
param.reasoning_content = reasoningContent;
|
|
260
|
+
}
|
|
261
|
+
result.push(param);
|
|
187
262
|
} else if (msg.role === "tool") {
|
|
188
263
|
result.push({
|
|
189
264
|
role: "tool",
|
|
@@ -252,6 +327,13 @@ var OpenAIClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
252
327
|
throw err;
|
|
253
328
|
}
|
|
254
329
|
}, _class);
|
|
330
|
+
function extractReasoningContent(msg) {
|
|
331
|
+
const candidate = _nullishCoalesce(msg.reasoning_content, () => ( msg.reasoning));
|
|
332
|
+
return typeof candidate === "string" && candidate.length > 0 ? candidate : void 0;
|
|
333
|
+
}
|
|
334
|
+
function isDeepSeekThinkingModel(model) {
|
|
335
|
+
return /^deepseek-v4(?:-|$)/i.test(model);
|
|
336
|
+
}
|
|
255
337
|
|
|
256
338
|
|
|
257
339
|
|
|
@@ -1,13 +1,72 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var _chunkHD7MT5XUcjs = require('./chunk-HD7MT5XU.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
4
|
|
|
9
5
|
var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
|
|
10
6
|
|
|
7
|
+
// src/context/token-counter.ts
|
|
8
|
+
function estimateStringTokens(text) {
|
|
9
|
+
if (!text) return 0;
|
|
10
|
+
const cjkChars = (_nullishCoalesce(text.match(/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g), () => ( []))).length;
|
|
11
|
+
const cjkRatio = cjkChars / text.length;
|
|
12
|
+
if (cjkRatio > 0.3) {
|
|
13
|
+
const cjkTokens = cjkChars / RATIOS.cjk;
|
|
14
|
+
const otherChars = text.length - cjkChars;
|
|
15
|
+
const otherTokens = otherChars / RATIOS.english;
|
|
16
|
+
return Math.ceil(cjkTokens + otherTokens);
|
|
17
|
+
}
|
|
18
|
+
const codeIndicators = ["{", "}", "(", ")", ";", "=>", "import ", "function ", "class ", "const "];
|
|
19
|
+
const codeScore = codeIndicators.reduce((s, ind) => s + (text.includes(ind) ? 1 : 0), 0);
|
|
20
|
+
if (codeScore >= 3) return Math.ceil(text.length / RATIOS.code);
|
|
21
|
+
if (text.startsWith("{") || text.startsWith("[")) return Math.ceil(text.length / RATIOS.json);
|
|
22
|
+
return Math.ceil(text.length / RATIOS.english);
|
|
23
|
+
}
|
|
24
|
+
function estimateMessagesTokens(messages) {
|
|
25
|
+
let total = 0;
|
|
26
|
+
for (const msg of messages) {
|
|
27
|
+
total += 4;
|
|
28
|
+
if (typeof msg.content === "string") {
|
|
29
|
+
total += estimateStringTokens(msg.content);
|
|
30
|
+
} else if (Array.isArray(msg.content)) {
|
|
31
|
+
for (const block of msg.content) {
|
|
32
|
+
total += estimateBlockTokens(block);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return total;
|
|
37
|
+
}
|
|
38
|
+
function estimateBlockTokens(block) {
|
|
39
|
+
let tokens = 2;
|
|
40
|
+
if (block.text) tokens += estimateStringTokens(block.text);
|
|
41
|
+
if (block.content && typeof block.content === "string") {
|
|
42
|
+
tokens += estimateStringTokens(block.content);
|
|
43
|
+
}
|
|
44
|
+
if (block.input) {
|
|
45
|
+
tokens += estimateStringTokens(JSON.stringify(block.input));
|
|
46
|
+
}
|
|
47
|
+
if (block.name) tokens += estimateStringTokens(block.name);
|
|
48
|
+
return tokens;
|
|
49
|
+
}
|
|
50
|
+
var RATIOS;
|
|
51
|
+
var init_token_counter = _chunkIJSHQGMPcjs.__esm.call(void 0, {
|
|
52
|
+
"src/context/token-counter.ts"() {
|
|
53
|
+
"use strict";
|
|
54
|
+
_chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
|
|
55
|
+
RATIOS = {
|
|
56
|
+
english: 4,
|
|
57
|
+
// ~4 chars per token for English prose
|
|
58
|
+
code: 3.2,
|
|
59
|
+
// ~3.2 chars per token for code (more tokens per char)
|
|
60
|
+
json: 3.5,
|
|
61
|
+
// JSON structures
|
|
62
|
+
mixed: 3.6,
|
|
63
|
+
// Mixed content (typical for tool results)
|
|
64
|
+
cjk: 1.5
|
|
65
|
+
// CJK characters: ~1.5 chars per token
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
11
70
|
// src/context/compaction.ts
|
|
12
71
|
var compaction_exports = {};
|
|
13
72
|
_chunkIJSHQGMPcjs.__export.call(void 0, compaction_exports, {
|
|
@@ -25,7 +84,7 @@ _chunkIJSHQGMPcjs.__export.call(void 0, compaction_exports, {
|
|
|
25
84
|
windowCompact: () => windowCompact
|
|
26
85
|
});
|
|
27
86
|
function estimateTokens(messages) {
|
|
28
|
-
return Math.ceil(
|
|
87
|
+
return Math.ceil(estimateMessagesTokens(messages) * (4 / 3));
|
|
29
88
|
}
|
|
30
89
|
function adjustIndexToPreserveAPIInvariants(messages, startIndex) {
|
|
31
90
|
let adjusted = startIndex;
|
|
@@ -269,7 +328,7 @@ function extractReferencedFilePaths(messages) {
|
|
|
269
328
|
var init_compaction = _chunkIJSHQGMPcjs.__esm.call(void 0, {
|
|
270
329
|
"src/context/compaction.ts"() {
|
|
271
330
|
_chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
|
|
272
|
-
|
|
331
|
+
init_token_counter();
|
|
273
332
|
}
|
|
274
333
|
});
|
|
275
334
|
|
|
@@ -271,13 +271,35 @@ var SessionManager = class {
|
|
|
271
271
|
if (!existsSync2(stateFile)) continue;
|
|
272
272
|
try {
|
|
273
273
|
const state = JSON.parse(readFileSync2(stateFile, "utf-8"));
|
|
274
|
-
|
|
274
|
+
const transcriptFile = join(this.sessionsDir, dir, "transcript.jsonl");
|
|
275
|
+
const preview = readFirstUserMessage(transcriptFile);
|
|
276
|
+
sessions.push({ ...state, preview });
|
|
275
277
|
} catch {
|
|
276
278
|
}
|
|
277
279
|
}
|
|
278
280
|
return sessions.sort((a, b) => b.startedAt - a.startedAt).slice(0, limit);
|
|
279
281
|
}
|
|
280
282
|
};
|
|
283
|
+
function readFirstUserMessage(transcriptFile) {
|
|
284
|
+
if (!existsSync2(transcriptFile)) return void 0;
|
|
285
|
+
const raw = readFileSync2(transcriptFile, "utf-8");
|
|
286
|
+
for (const line of raw.split("\n")) {
|
|
287
|
+
if (!line) continue;
|
|
288
|
+
let event;
|
|
289
|
+
try {
|
|
290
|
+
event = JSON.parse(line);
|
|
291
|
+
} catch {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (event.type !== "message") continue;
|
|
295
|
+
if (event.data?.role !== "user") continue;
|
|
296
|
+
const content = event.data.content;
|
|
297
|
+
const text = typeof content === "string" ? content : Array.isArray(content) ? content.find((b) => b.type === "text")?.text ?? "" : "";
|
|
298
|
+
if (!text.trim()) continue;
|
|
299
|
+
return text.replace(/\s+/g, " ").trim();
|
|
300
|
+
}
|
|
301
|
+
return void 0;
|
|
302
|
+
}
|
|
281
303
|
|
|
282
304
|
export {
|
|
283
305
|
Transcript,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_esm_shims
|
|
3
|
+
} from "./chunk-DI7RDLOS.js";
|
|
4
|
+
|
|
5
|
+
// src/logging/logger.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
import {
|
|
8
|
+
appendFileSync,
|
|
9
|
+
mkdirSync,
|
|
10
|
+
existsSync,
|
|
11
|
+
readdirSync,
|
|
12
|
+
unlinkSync,
|
|
13
|
+
readFileSync
|
|
14
|
+
} from "fs";
|
|
15
|
+
import { join, dirname } from "path";
|
|
16
|
+
import { homedir } from "os";
|
|
17
|
+
var LEVEL_ORDER = {
|
|
18
|
+
debug: 0,
|
|
19
|
+
info: 1,
|
|
20
|
+
warn: 2,
|
|
21
|
+
error: 3
|
|
22
|
+
};
|
|
23
|
+
var LOGS_DIR = join(homedir(), ".code-shell", "logs");
|
|
24
|
+
var MAX_LOG_FILES = 7;
|
|
25
|
+
var MAX_IN_MEMORY_ERRORS = 100;
|
|
26
|
+
function isLocalDev() {
|
|
27
|
+
if (process.env.CODE_SHELL_DEV === "1") return true;
|
|
28
|
+
if (process.argv.includes("--debug") || process.argv.includes("-d")) return true;
|
|
29
|
+
if (process.argv.some((a) => a.startsWith("--debug="))) return true;
|
|
30
|
+
if (process.env.NODE_ENV === "test" || process.env.BUN_TEST === "1") return false;
|
|
31
|
+
if (process.argv.some((a) => a.includes("/tests/") || a.endsWith(".test.ts"))) return false;
|
|
32
|
+
const entry = process.argv[1] ?? "";
|
|
33
|
+
if (entry.includes(`${"/"}src${"/"}`)) return true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function resolveDefaultLevel() {
|
|
37
|
+
const raw = process.env.CODE_SHELL_LOG_LEVEL?.toLowerCase().trim();
|
|
38
|
+
if (raw && Object.hasOwn(LEVEL_ORDER, raw)) return raw;
|
|
39
|
+
return isLocalDev() ? "debug" : "info";
|
|
40
|
+
}
|
|
41
|
+
function resolveCategoryFilter() {
|
|
42
|
+
const cliArg = process.argv.find((a) => a.startsWith("--debug="));
|
|
43
|
+
let raw;
|
|
44
|
+
if (cliArg) raw = cliArg.slice("--debug=".length);
|
|
45
|
+
else {
|
|
46
|
+
const env = process.env.CODE_SHELL_DEBUG;
|
|
47
|
+
if (env && env !== "1" && env !== "true") raw = env;
|
|
48
|
+
}
|
|
49
|
+
if (!raw) return null;
|
|
50
|
+
const set = new Set(
|
|
51
|
+
raw.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean)
|
|
52
|
+
);
|
|
53
|
+
return set.size > 0 ? set : null;
|
|
54
|
+
}
|
|
55
|
+
var _currentSid = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
56
|
+
function setCurrentSid(sid) {
|
|
57
|
+
_currentSid = sid;
|
|
58
|
+
}
|
|
59
|
+
function getCurrentSid() {
|
|
60
|
+
return _currentSid;
|
|
61
|
+
}
|
|
62
|
+
var inMemoryErrors = [];
|
|
63
|
+
var errorLogSink = null;
|
|
64
|
+
var Logger = class _Logger {
|
|
65
|
+
constructor(context = {}) {
|
|
66
|
+
this.context = context;
|
|
67
|
+
this.enabled = process.env.CODE_SHELL_LOG !== "0";
|
|
68
|
+
this.minLevel = resolveDefaultLevel();
|
|
69
|
+
this.categoryFilter = resolveCategoryFilter();
|
|
70
|
+
this.stderrEcho = process.env.CODE_SHELL_DEBUG === "1" || process.argv.includes("--debug-to-stderr") || process.argv.includes("-d2e");
|
|
71
|
+
}
|
|
72
|
+
enabled;
|
|
73
|
+
minLevel;
|
|
74
|
+
categoryFilter;
|
|
75
|
+
stderrEcho;
|
|
76
|
+
dirReady = false;
|
|
77
|
+
child(extra) {
|
|
78
|
+
return new _Logger({ ...this.context, ...extra });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set the session id stamped on every subsequent log entry written by
|
|
82
|
+
* any logger in the process. Called by Engine once a run's
|
|
83
|
+
* authoritative session id is known.
|
|
84
|
+
*/
|
|
85
|
+
setSid(sid) {
|
|
86
|
+
setCurrentSid(sid);
|
|
87
|
+
}
|
|
88
|
+
getSid() {
|
|
89
|
+
return getCurrentSid();
|
|
90
|
+
}
|
|
91
|
+
debug(msg, data) {
|
|
92
|
+
this.write("debug", msg, data);
|
|
93
|
+
}
|
|
94
|
+
info(msg, data) {
|
|
95
|
+
this.write("info", msg, data);
|
|
96
|
+
}
|
|
97
|
+
warn(msg, data) {
|
|
98
|
+
this.write("warn", msg, data);
|
|
99
|
+
}
|
|
100
|
+
error(msgOrErr, data) {
|
|
101
|
+
let msg;
|
|
102
|
+
let entryData;
|
|
103
|
+
let errObj;
|
|
104
|
+
if (typeof msgOrErr === "string") {
|
|
105
|
+
msg = msgOrErr;
|
|
106
|
+
if (data instanceof Error) {
|
|
107
|
+
errObj = data;
|
|
108
|
+
entryData = { error: data.message, stack: data.stack };
|
|
109
|
+
} else {
|
|
110
|
+
entryData = data;
|
|
111
|
+
}
|
|
112
|
+
} else if (msgOrErr instanceof Error) {
|
|
113
|
+
msg = msgOrErr.message;
|
|
114
|
+
errObj = msgOrErr;
|
|
115
|
+
entryData = { stack: msgOrErr.stack };
|
|
116
|
+
} else {
|
|
117
|
+
msg = String(msgOrErr);
|
|
118
|
+
}
|
|
119
|
+
this.recordError(msg, entryData);
|
|
120
|
+
this.write("error", msg, entryData);
|
|
121
|
+
if (errObj) errorLogSink?.logError(errObj);
|
|
122
|
+
}
|
|
123
|
+
recordError(msg, data) {
|
|
124
|
+
if (inMemoryErrors.length >= MAX_IN_MEMORY_ERRORS) inMemoryErrors.shift();
|
|
125
|
+
inMemoryErrors.push({ msg, t: (/* @__PURE__ */ new Date()).toISOString(), data });
|
|
126
|
+
}
|
|
127
|
+
write(level, msg, data) {
|
|
128
|
+
if (!this.enabled) return;
|
|
129
|
+
if (LEVEL_ORDER[level] < LEVEL_ORDER[this.minLevel]) return;
|
|
130
|
+
const cat = data?.cat ?? this.context.cat;
|
|
131
|
+
if (level === "debug" && this.categoryFilter) {
|
|
132
|
+
if (!cat || !this.categoryFilter.has(cat.toLowerCase())) return;
|
|
133
|
+
}
|
|
134
|
+
const t = (/* @__PURE__ */ new Date()).toISOString();
|
|
135
|
+
const entry = { t, l: level, msg, ...this.context };
|
|
136
|
+
if (cat && !entry.cat) entry.cat = cat;
|
|
137
|
+
if (entry.sid === void 0) entry.sid = _currentSid;
|
|
138
|
+
if (data) entry.d = data;
|
|
139
|
+
const line = JSON.stringify(entry) + "\n";
|
|
140
|
+
if (this.stderrEcho) {
|
|
141
|
+
process.stderr.write(line);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
if (!this.dirReady) {
|
|
146
|
+
if (!existsSync(LOGS_DIR)) mkdirSync(LOGS_DIR, { recursive: true });
|
|
147
|
+
this.dirReady = true;
|
|
148
|
+
}
|
|
149
|
+
const dateStr = t.slice(0, 10);
|
|
150
|
+
appendFileSync(join(LOGS_DIR, `${dateStr}.log`), line, "utf-8");
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
getMinLevel() {
|
|
155
|
+
return this.minLevel;
|
|
156
|
+
}
|
|
157
|
+
isCategoryActive(cat) {
|
|
158
|
+
return !this.categoryFilter || this.categoryFilter.has(cat.toLowerCase());
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Open a span: writes a `<name>.begin` debug entry now and returns a handle
|
|
162
|
+
* whose `end()` writes `<name>.end` with `duration_ms` populated. Use for
|
|
163
|
+
* any "I want begin → end + how long" pattern (tool exec, LLM request,
|
|
164
|
+
* permission ask, etc.) so the begin/end pair is grouped under one cat
|
|
165
|
+
* and the duration is computed once instead of by hand from timestamps.
|
|
166
|
+
*/
|
|
167
|
+
span(name, data) {
|
|
168
|
+
const startedAt = Date.now();
|
|
169
|
+
this.write("debug", `${name}.begin`, data);
|
|
170
|
+
return {
|
|
171
|
+
end: (extra) => {
|
|
172
|
+
const duration_ms = Date.now() - startedAt;
|
|
173
|
+
this.write("info", `${name}.end`, { ...data, ...extra, duration_ms });
|
|
174
|
+
},
|
|
175
|
+
fail: (err, extra) => {
|
|
176
|
+
const duration_ms = Date.now() - startedAt;
|
|
177
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
178
|
+
this.write("error", `${name}.fail`, { ...data, ...extra, duration_ms, error: message });
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var logger = new Logger();
|
|
184
|
+
function rotateLogs() {
|
|
185
|
+
try {
|
|
186
|
+
if (!existsSync(LOGS_DIR)) return;
|
|
187
|
+
const files = readdirSync(LOGS_DIR).filter((f) => f.endsWith(".log")).sort();
|
|
188
|
+
if (files.length <= MAX_LOG_FILES) return;
|
|
189
|
+
for (const f of files.slice(0, files.length - MAX_LOG_FILES)) {
|
|
190
|
+
try {
|
|
191
|
+
unlinkSync(join(LOGS_DIR, f));
|
|
192
|
+
} catch {
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export {
|
|
200
|
+
logger,
|
|
201
|
+
rotateLogs
|
|
202
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Extra slash commands — /
|
|
3
|
-
* /
|
|
2
|
+
* Extra slash commands — /login, /logout, /mcp (config & auth);
|
|
3
|
+
* /skills, /log (read-only inspection); /models (interactive panel).
|
|
4
4
|
*/
|
|
5
5
|
import type { SlashCommand } from "../registry.js";
|
|
6
6
|
export declare const extraCommands: SlashCommand[];
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Additional slash commands
|
|
3
|
-
* /fast, /rewind, /usage, /files, /release-notes, /security-review,
|
|
4
|
-
* /env, /brief, /feedback, /tag
|
|
2
|
+
* Additional slash commands — /files, /release-notes, /security-review, /feedback
|
|
5
3
|
*/
|
|
6
4
|
import type { SlashCommand } from "../registry.js";
|
|
7
5
|
export declare const moreCommands: SlashCommand[];
|
|
@@ -37,6 +37,14 @@ export interface CommandContext {
|
|
|
37
37
|
chatLog: unknown[];
|
|
38
38
|
/** Load restored chat entries into the UI (used by /resume). */
|
|
39
39
|
loadChatEntries?: (entries: RestoredChatEntry[]) => void;
|
|
40
|
+
/** Open the Ink onboarding wizard (used by /login). */
|
|
41
|
+
startOnboarding?: () => void;
|
|
42
|
+
/** Open the Ink model selector (used by /model with no args). */
|
|
43
|
+
openModelSelector?: () => void;
|
|
44
|
+
/** Open the Ink session picker (used by /resume with no args). */
|
|
45
|
+
openSessionPicker?: () => void;
|
|
46
|
+
/** Open the Ink model management panel (used by /models). */
|
|
47
|
+
openModelManager?: () => void;
|
|
40
48
|
}
|
|
41
49
|
export type CommandGroup = "core" | "git" | "context" | "config" | "advanced";
|
|
42
50
|
export interface SlashCommand {
|
|
@@ -55,3 +55,9 @@ export interface SessionCostState {
|
|
|
55
55
|
estimatedCost: number;
|
|
56
56
|
}
|
|
57
57
|
export declare const costTracker: CostTracker;
|
|
58
|
+
/**
|
|
59
|
+
* Wire the LLM base-class usage hook into the singleton cost tracker.
|
|
60
|
+
* Called once from main.ts so every LLM call (REPL, run, arena, sub-agents)
|
|
61
|
+
* records into a single tracker without each call site having to remember.
|
|
62
|
+
*/
|
|
63
|
+
export declare function installCostTracking(): Promise<void>;
|