edge-pi-cli 0.1.1 → 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.
@@ -139,7 +139,7 @@ class InteractiveMode {
139
139
  // UI Setup
140
140
  // ========================================================================
141
141
  initUI() {
142
- const { provider, modelId, skills = [], contextFiles = [], prompts = [], verbose, sessionManager } = this.options;
142
+ const { provider, modelId, skills = [], contextFiles = [], prompts = [], verbose } = this.options;
143
143
  this.ui = new TUI(new ProcessTerminal());
144
144
  // Header
145
145
  this.headerContainer = new Container();
@@ -159,8 +159,8 @@ class InteractiveMode {
159
159
  this.headerContainer.addChild(new Spacer(1));
160
160
  this.headerContainer.addChild(new Text(`${logo}\n${hints}`, 1, 0));
161
161
  this.headerContainer.addChild(new Spacer(1));
162
- if (verbose && sessionManager?.getSessionFile()) {
163
- this.headerContainer.addChild(new Text(chalk.dim(`Session: ${sessionManager.getSessionFile()}`), 1, 0));
162
+ if (verbose && this.agent.sessionManager?.getSessionFile()) {
163
+ this.headerContainer.addChild(new Text(chalk.dim(`Session: ${this.agent.sessionManager.getSessionFile()}`), 1, 0));
164
164
  }
165
165
  // Show loaded context, skills, and prompts at startup
166
166
  this.showLoadedResources(contextFiles, skills, prompts);
@@ -271,7 +271,6 @@ class InteractiveMode {
271
271
  if (!text)
272
272
  return;
273
273
  if (this.isStreaming) {
274
- this.agent.followUp({ role: "user", content: [{ type: "text", text }] });
275
274
  this.followUpMessages.push(text);
276
275
  this.editor.setText("");
277
276
  this.updatePendingMessagesDisplay();
@@ -373,7 +372,6 @@ class InteractiveMode {
373
372
  await this.streamPrompt(expanded, images);
374
373
  }
375
374
  async handleBashCommand(command, excludeFromContext) {
376
- const { sessionManager } = this.options;
377
375
  this.bashAbortController = new AbortController();
378
376
  this.isBashRunning = true;
379
377
  this.bashComponent = new BashExecutionComponent(command, this.ui, excludeFromContext);
@@ -396,7 +394,7 @@ class InteractiveMode {
396
394
  const msgText = `Ran \`${command}\`\n\n\`\`\`\n${result.output.trimEnd()}\n\`\`\``;
397
395
  const userMsg = { role: "user", content: [{ type: "text", text: msgText }] };
398
396
  this.agent.setMessages([...this.agent.messages, userMsg]);
399
- sessionManager?.appendMessage(userMsg);
397
+ this.agent.sessionManager?.appendMessage(userMsg);
400
398
  }
401
399
  }
402
400
  finally {
@@ -491,8 +489,6 @@ class InteractiveMode {
491
489
  async streamPrompt(prompt, images) {
492
490
  this.isStreaming = true;
493
491
  this.updatePendingMessagesDisplay();
494
- const { sessionManager } = this.options;
495
- const messagesBefore = this.agent.messages.length;
496
492
  // Build image parts from clipboard images
497
493
  const imageParts = (images ?? []).map((img) => ({
498
494
  type: "image",
@@ -574,25 +570,8 @@ class InteractiveMode {
574
570
  }
575
571
  if (errorDisplayed)
576
572
  return;
577
- // Get final response and update messages
578
- const response = await result.response;
579
- const responseMessages = response.messages;
580
- this.agent.setMessages([
581
- ...this.agent.messages.slice(0, messagesBefore),
582
- ...buildUserMessage(prompt, imageParts),
583
- ...responseMessages,
584
- ]);
585
- // Save to session
586
- if (sessionManager) {
587
- const userMsg = {
588
- role: "user",
589
- content: [{ type: "text", text: prompt }, ...imageParts],
590
- };
591
- sessionManager.appendMessage(userMsg);
592
- for (const msg of responseMessages) {
593
- sessionManager.appendMessage(msg);
594
- }
595
- }
573
+ // Wait for stream to complete — the agent auto-updates messages and persists to session
574
+ await result.response;
596
575
  // Update footer token stats
597
576
  this.updateFooterTokens();
598
577
  // Check for auto-compaction after successful response
@@ -673,9 +652,6 @@ class InteractiveMode {
673
652
  const restored = [...this.steeringMessages, ...this.followUpMessages];
674
653
  this.steeringMessages = [];
675
654
  this.followUpMessages = [];
676
- // Force agent to drop its internal queue too if possible, but edge-pi agent doesn't expose that yet.
677
- // However, steering messages are consumed immediately by the agent loop so they might already be gone.
678
- // Follow-ups are managed here in the loop, so clearing this array stops them.
679
655
  return restored;
680
656
  }
681
657
  // ========================================================================
@@ -775,7 +751,7 @@ class InteractiveMode {
775
751
  async executeCompaction(isAuto) {
776
752
  if (this.isCompacting)
777
753
  return undefined;
778
- const { sessionManager } = this.options;
754
+ const sessionManager = this.agent.sessionManager;
779
755
  // Build path entries from session if available, otherwise from agent messages
780
756
  const pathEntries = sessionManager ? sessionManager.getBranch() : this.buildSessionEntriesFromMessages();
781
757
  if (pathEntries.length < 2) {
@@ -1200,7 +1176,7 @@ class InteractiveMode {
1200
1176
  const sessions = [];
1201
1177
  for (const file of files) {
1202
1178
  // Skip the current session file
1203
- if (this.options.sessionManager?.getSessionFile() === file.path)
1179
+ if (this.agent.sessionManager?.getSessionFile() === file.path)
1204
1180
  continue;
1205
1181
  const preview = this.getSessionPreview(file.path);
1206
1182
  const timestamp = new Date(file.mtime).toLocaleString();
@@ -1296,20 +1272,16 @@ class InteractiveMode {
1296
1272
  if (!session)
1297
1273
  return;
1298
1274
  try {
1299
- // Open the selected session
1275
+ // Open the selected session and set on agent (auto-restores messages)
1300
1276
  const sessionDir = this.options.sessionDir;
1301
1277
  const newSessionManager = SessionManagerClass.open(selected, sessionDir);
1302
- // Rebuild agent messages from session context
1303
- const context = newSessionManager.buildSessionContext();
1304
- this.agent.setMessages(context.messages);
1305
- // Update session manager reference
1306
- this.options.sessionManager = newSessionManager;
1278
+ this.agent.sessionManager = newSessionManager;
1307
1279
  // Rebuild the chat UI
1308
1280
  this.chatContainer.clear();
1309
1281
  this.rebuildChatFromSession();
1310
1282
  // Update footer tokens
1311
1283
  this.updateFooterTokens();
1312
- const msgCount = context.messages.length;
1284
+ const msgCount = this.agent.messages.length;
1313
1285
  this.showStatus(chalk.green(`Resumed session (${msgCount} messages)`));
1314
1286
  }
1315
1287
  catch (error) {
@@ -1373,13 +1345,6 @@ class InteractiveMode {
1373
1345
  // ============================================================================
1374
1346
  // Helpers
1375
1347
  // ============================================================================
1376
- function buildUserMessage(text, imageParts) {
1377
- const content = [{ type: "text", text }];
1378
- if (imageParts && imageParts.length > 0) {
1379
- content.push(...imageParts);
1380
- }
1381
- return [{ role: "user", content }];
1382
- }
1383
1348
  function extractTextFromMessage(msg) {
1384
1349
  if (msg.role === "user") {
1385
1350
  const content = msg.content;