Skip to content

Commit 4b5a3bd

Browse files
committed
improve path to url mapping in opencode ui
SQUASHED: AUTO-COMMIT-doc-notes-terminal.md,
1 parent 80d1a45 commit 4b5a3bd

8 files changed

Lines changed: 238 additions & 151 deletions

File tree

doc/notes/terminal.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Terminal
2+
3+
With authentication, we can run a command or a complete terminal session on the lively4server.
4+
5+
```javascript
6+
7+
import Terminal from "src/client/terminal.js"
8+
var terminal = new Terminal()
9+
terminal.url // http://localhost:9005/lively4-core
10+
(await terminal.run("pwd")).stdout.replace(/\n/,"") // /home/jens/lively4
11+
```

src/ai-workspace/components/lively-agent-board.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Morph from 'src/components/widgets/lively-morph.js';
2+
import LivelyOpencode from './lively-opencode.js';
23

34
/*MD
45
# Lively Agent Board
@@ -70,7 +71,6 @@ export default class LivelyAgentBoard extends Morph {
7071
this.fileWriteCounts = new Map();
7172
this.workingDirectory = null;
7273
this.projectPath = null;
73-
this.urlBase = null;
7474
this.currentProject = null; // Store full project object
7575
this.sessionCost = null; // Session cost in USD
7676
}
@@ -93,7 +93,6 @@ export default class LivelyAgentBoard extends Morph {
9393
setContext(context) {
9494
this.workingDirectory = context.workingDirectory;
9595
this.projectPath = context.projectPath;
96-
this.urlBase = context.urlBase;
9796
this.render();
9897
}
9998

@@ -123,7 +122,6 @@ export default class LivelyAgentBoard extends Morph {
123122
* @param {Object} context - Optional context for URL building and path shortening
124123
* @param {string} context.workingDirectory - Current working directory
125124
* @param {string} context.projectPath - Project path for URL shortening
126-
* @param {string} context.urlBase - Base URL for building file links
127125
*/
128126
updateFromMessage(message, context) {
129127
if (!message) return;
@@ -247,8 +245,7 @@ export default class LivelyAgentBoard extends Morph {
247245
// Set context for URL building and path shortening
248246
this.setContext({
249247
workingDirectory: opencodeComponent.workingDirectory,
250-
projectPath: opencodeComponent.currentProject?.path,
251-
urlBase: opencodeComponent.loadProjectUrlBase()
248+
projectPath: opencodeComponent.currentProject?.path
252249
});
253250

254251
// Clear file operations before loading new session data
@@ -277,8 +274,7 @@ export default class LivelyAgentBoard extends Morph {
277274
for (const message of messages) {
278275
this.updateFromMessage(message, {
279276
workingDirectory: this.workingDirectory,
280-
projectPath: this.projectPath,
281-
urlBase: this.urlBase
277+
projectPath: this.projectPath
282278
});
283279
}
284280
}
@@ -292,25 +288,34 @@ export default class LivelyAgentBoard extends Morph {
292288
* @param {string} filePath - Absolute file path
293289
* @returns {string} Full URL for lively.openBrowser
294290
*/
295-
buildFileUrl(filePath) {
296-
if (!this.urlBase || !this.workingDirectory) {
297-
// No context - return path as-is
298-
return filePath;
291+
async buildFileUrl(filePath) {
292+
return await LivelyOpencode.filePathToUrl(filePath, {
293+
workingDirectory: this.workingDirectory
294+
}) || filePath;
295+
}
296+
297+
async buildProjectFocusUrl() {
298+
if (!this.currentProject) return this.links.projectFocus;
299+
if (this.links.projectFocus && /^https?:\/\//.test(this.links.projectFocus)) {
300+
return this.links.projectFocus;
299301
}
300302

301-
// Remove working directory prefix to get relative path
302-
let relativePath = filePath;
303-
if (filePath.startsWith(this.workingDirectory)) {
304-
relativePath = filePath.substring(this.workingDirectory.length);
305-
// Remove leading slash if present
306-
if (relativePath.startsWith('/')) {
307-
relativePath = relativePath.substring(1);
308-
}
303+
if (this.currentProject.isFile) {
304+
return await LivelyOpencode.filePathToUrl(this.currentProject.path, {
305+
workingDirectory: this.workingDirectory
306+
}) || this.currentProject.path;
309307
}
310308

311-
// Build full URL
312-
const base = this.urlBase.endsWith('/') ? this.urlBase : this.urlBase + '/';
313-
return base + relativePath;
309+
return await LivelyOpencode.filePathToUrl(`${this.currentProject.path}/index.md`, {
310+
workingDirectory: this.workingDirectory
311+
}) || `${this.currentProject.path}/index.md`;
312+
}
313+
314+
async buildProjectTasksUrl() {
315+
if (!this.currentProject || this.currentProject.isFile) return null;
316+
return await LivelyOpencode.filePathToUrl(`${this.currentProject.path}/tasks.md`, {
317+
workingDirectory: this.workingDirectory
318+
}) || `${this.currentProject.path}/tasks.md`;
314319
}
315320

316321
/**
@@ -491,7 +496,7 @@ export default class LivelyAgentBoard extends Morph {
491496
<div class="link-item">
492497
<span class="link-icon">📁</span>
493498
<a class="link-path" click={() => {
494-
lively.openBrowser(this.links.projectFocus, true)
499+
this.buildProjectFocusUrl().then(url => lively.openBrowser(url, true))
495500
}} title={this.links.projectFocus}>
496501
Project Focus
497502
</a>
@@ -502,15 +507,12 @@ export default class LivelyAgentBoard extends Morph {
502507
// Project Tasks - only show for directory-based projects
503508
if (this.currentProject && !this.currentProject.isFile) {
504509
const tasksPath = this.currentProject.path + '/tasks.md';
505-
const tasksUrl = this.currentProject.url
506-
? this.currentProject.url + 'tasks.md'
507-
: tasksPath;
508510

509511
section.appendChild(
510512
<div class="link-item">
511513
<span class="link-icon">📋</span>
512514
<a class="link-path" click={() => {
513-
lively.openBrowser(tasksUrl, true)
515+
this.buildProjectTasksUrl().then(url => lively.openBrowser(url, true))
514516
}} title={tasksPath}>
515517
Project Tasks
516518
</a>
@@ -530,7 +532,7 @@ export default class LivelyAgentBoard extends Morph {
530532
const readCount = this.fileReadCounts.get(path) || 0;
531533
const linkItem = <div class="link-item file-read">
532534
<span class="link-icon">📖</span>
533-
<a class="link-path" click={() => lively.openBrowser(url, true)} title={path}>
535+
<a class="link-path" click={() => url.then(resolvedUrl => lively.openBrowser(resolvedUrl, true))} title={path}>
534536
{displayPath}
535537
</a>
536538
</div>;
@@ -555,7 +557,7 @@ export default class LivelyAgentBoard extends Morph {
555557
const writeCount = this.fileWriteCounts.get(path) || 0;
556558
const linkItem = <div class="link-item file-written">
557559
<span class="link-icon">✏️</span>
558-
<a class="link-path" click={() => lively.openBrowser(url, true)} title={path}>
560+
<a class="link-path" click={() => url.then(resolvedUrl => lively.openBrowser(resolvedUrl, true))} title={path}>
559561
{displayPath}
560562
</a>
561563
</div>;
@@ -636,8 +638,7 @@ export default class LivelyAgentBoard extends Morph {
636638
// Set context for URL building and path shortening
637639
this.setContext({
638640
workingDirectory: '/home/jens/lively4/lively4-core',
639-
projectPath: 'src/ai-workspace',
640-
urlBase: 'http://localhost:9005/lively4-core'
641+
projectPath: 'src/ai-workspace'
641642
});
642643

643644
// Set project focus using proper project object

src/ai-workspace/components/lively-ai-workspace.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ export default class LivelyAiWorkspace extends LivelyChat {
580580
// Let board handle message parsing and updates
581581
board.updateFromMessage(message, {
582582
workingDirectory: this.opencodeComponent.workingDirectory,
583-
projectPath: this.opencodeComponent.currentProject?.path,
584-
urlBase: this.opencodeComponent.loadProjectUrlBase()
583+
projectPath: this.opencodeComponent.currentProject?.path
585584
});
586585

587586
// Update project focus link if opencode has a project selected

src/ai-workspace/components/lively-opencode.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,6 @@ <h3>
632632
</div>
633633
</div>
634634
<input-combobox id="projectCombobox"></input-combobox>
635-
<input id="projectUrlBase" type="text" class="project-url-base"
636-
placeholder="URL base, e.g. http://localhost:9005/lively4-core/"
637-
title="Base URL for fetching project files (maps local path to lively4 server URL)">
638635
<div id="projectIndicator" class="project-indicator" style="display:none;"></div>
639636
</div>
640637
<lively-chat-sessions id="sessionsComponent"></lively-chat-sessions>

0 commit comments

Comments
 (0)