@zhongqian97-code/ecode 0.5.31 → 0.5.32

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.
Files changed (2) hide show
  1. package/dist/index.js +32 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1380,10 +1380,10 @@ function metadataPathFromLogFile(logFilePath2) {
1380
1380
  const dir = path6.dirname(logFilePath2);
1381
1381
  return path6.join(dir, `${base}-session.json`);
1382
1382
  }
1383
- function createSessionMetadata(logFilePath2, model) {
1383
+ function createSessionMetadata(logFilePath2, model, id) {
1384
1384
  const now = (/* @__PURE__ */ new Date()).toISOString();
1385
1385
  return {
1386
- id: crypto2.randomUUID(),
1386
+ id: id ?? crypto2.randomUUID(),
1387
1387
  startTime: now,
1388
1388
  lastActivity: now,
1389
1389
  cwd: process.cwd(),
@@ -7190,13 +7190,21 @@ var SessionRuntime = class {
7190
7190
  _totalTokens = 0;
7191
7191
  startedAt = (/* @__PURE__ */ new Date()).toISOString();
7192
7192
  lastActivity = (/* @__PURE__ */ new Date()).toISOString();
7193
- title = "New Session";
7193
+ _title = "New Session";
7194
+ logger;
7194
7195
  constructor(config2, opts = {}) {
7195
7196
  this.id = opts.sessionId ?? crypto.randomUUID();
7196
7197
  this.config = config2;
7197
7198
  this.llm = opts.llm ?? createProvider(resolveActiveProfile(config2));
7198
7199
  this.model = config2.model;
7199
7200
  this.autoApproveNormal = opts.autoApproveNormal ?? false;
7201
+ if (config2.logDir) {
7202
+ this.logger = createLogger(config2.logDir, /* @__PURE__ */ new Date());
7203
+ const meta = createSessionMetadata(this.logger.filePath, this.model, this.id);
7204
+ writeSessionMetadata(this.logger.filePath, meta);
7205
+ } else {
7206
+ this.logger = null;
7207
+ }
7200
7208
  const systemContent = opts.systemPrompt ?? (config2.systemPrompt ?? DEFAULT_SYSTEM_PROMPT);
7201
7209
  this.messages = systemContent ? [{ role: "system", content: systemContent }] : [];
7202
7210
  if (opts.initialMessages) {
@@ -7221,6 +7229,7 @@ var SessionRuntime = class {
7221
7229
  */
7222
7230
  async submit(userInput) {
7223
7231
  this.messages.push({ role: "user", content: userInput });
7232
+ this.logger?.append({ ts: (/* @__PURE__ */ new Date()).toISOString(), role: "user", content: userInput });
7224
7233
  this.abortController = new AbortController();
7225
7234
  const signal = this.abortController.signal;
7226
7235
  try {
@@ -7236,6 +7245,17 @@ var SessionRuntime = class {
7236
7245
  }
7237
7246
  this._turnCount++;
7238
7247
  this.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
7248
+ if (this.logger) {
7249
+ if (this._turnCount === 1) {
7250
+ this._title = generateTitle(userInput);
7251
+ }
7252
+ updateSessionMetadata(this.logger.filePath, {
7253
+ title: this._title,
7254
+ turnCount: this._turnCount,
7255
+ totalTokens: this._totalTokens,
7256
+ lastActivity: this.lastActivity
7257
+ });
7258
+ }
7239
7259
  this._status = "idle";
7240
7260
  this.bus.emit({ type: "session.idle", sessionId: this.id });
7241
7261
  }
@@ -7298,12 +7318,19 @@ var SessionRuntime = class {
7298
7318
  ...assistantReasoning ? { reasoning_content: assistantReasoning } : {},
7299
7319
  ...lastReasoningDetails ? { reasoning_details: lastReasoningDetails } : {}
7300
7320
  });
7321
+ this.logger?.append({
7322
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
7323
+ role: "assistant",
7324
+ content: assistantText || null,
7325
+ tool_calls: toolCalls.map((tc) => ({ id: tc.id, type: "function", function: { name: tc.name, arguments: tc.arguments } }))
7326
+ });
7301
7327
  for (const tc of toolCalls) {
7302
7328
  if (signal.aborted) break;
7303
7329
  this.bus.emit({ type: "tool.started", callId: tc.id, toolName: tc.name, argsPreview: tc.arguments });
7304
7330
  const toolResult = await this.executeToolCall(tc, signal);
7305
7331
  this.bus.emit({ type: "tool.completed", callId: tc.id, toolName: tc.name, output: toolResult });
7306
7332
  this.messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
7333
+ this.logger?.append({ ts: (/* @__PURE__ */ new Date()).toISOString(), role: "tool", tool_call_id: tc.id, content: toolResult });
7307
7334
  }
7308
7335
  if (this._stopAfterToolRound) {
7309
7336
  this._stopAfterToolRound = false;
@@ -7316,6 +7343,7 @@ var SessionRuntime = class {
7316
7343
  content: assistantText,
7317
7344
  ...assistantReasoning ? { reasoning_content: assistantReasoning } : {}
7318
7345
  });
7346
+ this.logger?.append({ ts: (/* @__PURE__ */ new Date()).toISOString(), role: "assistant", content: assistantText || null });
7319
7347
  }
7320
7348
  break;
7321
7349
  }
@@ -7428,7 +7456,7 @@ Proceed?`;
7428
7456
  snapshot() {
7429
7457
  return {
7430
7458
  id: this.id,
7431
- title: this.title,
7459
+ title: this._title,
7432
7460
  model: this.model,
7433
7461
  status: this._status,
7434
7462
  turnCount: this._turnCount,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhongqian97-code/ecode",
3
- "version": "0.5.31",
3
+ "version": "0.5.32",
4
4
  "description": "A minimal Claude Code clone with REPL interface and bash tool calling",
5
5
  "type": "module",
6
6
  "author": "zhongqian97-code",