@celljs/ta-channels 4.6.1 → 4.7.0

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.en.md ADDED
@@ -0,0 +1,48 @@
1
+ # Cell - Ta Channels
2
+
3
+ A built-in Ta package (enabled by default but can be toggled in the Web client's Settings → Packages): agents and channels. It is composed of three parts, none of which modify Ta's core:
4
+
5
+ - **Server side** (`pi.host`, `web-src/host.ts` → `host/index.mjs`): ta serve runs it once in the same process. Teams, messages, and queues of pending answers are all managed and processed by it; **forwarding happens on the server and continues even when the page is closed**.
6
+ - **pi extension** (`pi.extensions`, `web-src/extension.ts` → `extension/index.mjs`): adds team tools to Ta's sessions and obtains teams from the server via `pi.events`.
7
+ - **Web extension** (`pi.web`, `web-src/index.tsx` → `web/index.js`): responsible only for display and initiating changes.
8
+
9
+ ## Concepts
10
+
11
+ - **Agent**: a normal Ta session plus a name and responsibility (as `appendSystemPrompt`); the session name is the agent's name, and the session belongs to the `@celljs/ta-channels` group (folded into one row in the conversation list). Each agent has its own cartoon avatar (`web-src/faces.tsx`, with 16 shapes and color schemes stored in `face`; on creation, it tries to avoid duplicates with existing avatars; old data without `face` is assigned by id), blinks, and looks left and right while answering; Ta itself remains the Cell logo. The session file is recorded when first opened and reopened from the file next time. A session with an agent has no team tools.
12
+ - **Channel**: members (agents, with the first being the lead) and messages. Messages are sent to members `@`-mentioned; agents' answers are posted back to the channel, and if they `@` someone in their answer, it is passed on to them. Each agent processes one message at a time. Users can mute members in a channel (`muted`): they do not answer anything in this channel, even if `@`-mentioned; when the lead is muted, messages with no one `@`-mentioned go to the next unmuted member.
13
+ - **Loop prevention** (`ChannelsUtil.limit`): relaying between agents is at most 3 hops; one message yields at most 8 answers, with at most 2 per agent. When cut off, after this round a light-colored note is appended to the channel ("reached relay limit, waiting for you to continue"), only once per round; the return from `post_to_channel` includes this note too.
14
+ - **Tools**: each session in Ta (web pages and other clients connected to ta serve) has `create_agent`, `create_channel`, `add_to_channel`, `post_to_channel`, and `list_channels`. When a user specifies a goal ("assemble a team to do the landing page"), Ta creates agents and channels, posts the goal, and waits for answers from each member before replying to the user. When a role is missing from a channel, Ta uses `add_to_channel` to add an existing agent (added after existing members; lead unchanged). The open page marks this channel with a green dot in the sidebar, which disappears when opened. Pausing Ta just stops waiting; agents continue to answer in the channel.
15
+ - **UI**: the "Agents" tab at the top of the sidebar (next to the "Conversations" tab) puts the double, channels, and agents together (the double is a built-in page from ta-web, and once enabled is listed at the top, no longer appears separately in the navigation bar); the search box and + are on the right of the tab. + → create agent opens a draft page in the main area: first assigns an unused name and avatar, clicking the name in the top bar can rename or pick from 16 avatars, the sidebar has one more line "not started"; the agent is truly created when the first message is sent from the input box (responsibility is generic, what to do is written in this message), then switches to its session and sends the message. + → create channel is a dialog: name, search and check agents (1–12, first checked is lead), create; channel row has lead first, next member in overlapping avatars, lead is labeled beside the name, second line is the most recent message or who's answering; agents are grouped by working directory, second line is "idle" or which channel they're answering in, right side is time of most recent message. Click agent to open its session (`openAgent` request, server opens or finds the session then `pi.switchSession` displays it as the current conversation). Hovering over agent row (long-press on touch) shows …, menu has: stop (abort its current answer), restart (open new session), rename, responsibility (edit the role in the system prompt, takes effect in next session), move to… (switch working directory, open new session in that directory), copy working directory, export conversation (Markdown, strip channel context blocks), add to channel, delete (leave all channels it's in, delete channels that only have it, keep the session file); when near the bottom the menu expands upward. Channel is a page in the main area (not in the right workbench), displayed as a group chat: others' messages on the left with avatar and name, user's on the right, consecutive messages are grouped, after a long pause insert a time line; top bar is channel name and member avatars, click avatar to open "Channel Members" (`members`, `location: 'panel'` view, follows the current channel) in the right workbench: lists members, lead has a marker, answering ones are marked green; each row opens that agent's session, hovering (long-press on touch) shows set as lead, mute, restart session (forget earlier conversation, open new session next time it answers, old session stays in conversation list), and remove from channel (at least one left); top has "Add Members" as a searchable agent list, check to add, bottom of list has "New Agent" to open the draft page for creating a new agent; bottom has delete channel (confirm once more, messages deleted too, ongoing answers no longer posted). Input box is the conversation input box (`pi.ui.Composer`), `@` lists members, + allows naming members or adding members (opens the member list for adding); messages use the conversation's Markdown rendering (`pi.ui.Markdown`), `@`-mentioned members are bold.
16
+
17
+ ## Data and Forwarding
18
+
19
+ Data is stored on the server in `<agentDir>/extension-data/@celljs/ta-channels.json`; only the server writes to it. Each channel keeps the most recent 200 messages.
20
+
21
+ | Key | Content |
22
+ | --- | --- |
23
+ | `team` | agents and channels |
24
+ | `messages/<channel>` | messages in the channel |
25
+ | `queue` | pending answers (job: which agent answers which message, how many hops, which round) and counts per round |
26
+ | `working` | agents currently answering |
27
+ | `focus` | channels Ta has created tools for or posted messages to; pages use this to mark them in the sidebar |
28
+ | `requests/<id>` / `results/<id>` | requests initiated by the page (create agent, create channel, add channel member, set lead / mute / remove member, delete channel, restart agent session, modify or delete agent, post message as user, open agent session) and server's responses; pages only write `requests/*` |
29
+
30
+ The page learns of changes via `pi.storage.onChange` and rereads them. Each answer is first recorded as a job in `queue` and removed only after the answer is posted to the channel. After ta serve restarts, it continues processing remaining jobs: jobs that already have an answer (the channel has this agent's reply to that message) are not asked again, and messages already forwarded are not forwarded again, so processed messages do not duplicate. On restart, the one message that was being answered and not yet posted is asked again.
31
+
32
+ ## Limitations
33
+
34
+ - Only ta serve has teams: when running plain `ta` (CLI, without ta serve), the team tools still exist but calling them returns "ta serve required" and does not create or forward anything. When the package's server side fails to start, the tool explains the failure and asks to check ta serve's logs.
35
+ - Messages with no `@` to anyone (user or Ta) go to the lead, the first unmuted member of the channel; when an agent's answer has no `@` to anyone, relay ends.
36
+ - Changes on the page wait for server processing; when ta serve is not running or the package is disabled, operations on the page report "Ta service not responding" after 30 seconds.
37
+
38
+ ## Future
39
+
40
+ - A task board can be another package, based on the same agents and channels.
41
+
42
+ ## Why Not in Core
43
+
44
+ pi's core only manages how one session runs; multi-session is provided by ta serve (`openSession` with `appendSystemPrompt` and `group`, `prompt`, `getState`, `getLastAssistantText`); the server part of the package runs on the host (`pi.host`). Agents and channels are just one product form of combining these concepts. Switching to another organization (task board, pipeline) makes another package, so it is an optional pi package like ones users build themselves. The core only provides host capabilities: loading and toggling built-in packages, the server part of packages, package server data and its change notifications.
45
+
46
+ ## Development
47
+
48
+ Source is in `web-src/` with three entry points: `index.tsx` (page), `host.ts` (server), and `extension.ts` (pi extension); `team.ts` is the server-side team, `channels.ts` is what the page sees, and `channels-util.ts` is shared pure logic. `bun run build` first checks with tsc and outputs to `lib/` (tests run `lib/**/*.spec.js`); then uses `bun build` to bundle the three entry points into separate files with no imports. React comes from the page (`web-src/react.ts`'s `bind(pi.React)`), and icons use `pi.ui.icons`. End-to-end tests (faux models, real ta serve) are in `apps/ta/test/builtin-packages.spec.ts`.
package/README.md CHANGED
@@ -33,7 +33,7 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 包 关
33
33
 
34
34
  - 只有 ta serve 有团队:单独运行 `ta`(CLI,没有 ta serve)时,团队工具仍然存在,但调用时会返回"需要 ta serve"的说明,不会创建或转发任何东西。包的服务端没能启动时,工具会说明启动失败,请看 ta serve 的日志。
35
35
  - 没有 `@` 任何人的消息(用户或 Ta 发的)交给负责人,即频道的第一个没有免打扰的成员;智能体的回答没有 `@` 谁时,接力到此结束。
36
- - 页面的修改要等服务端处理;ta serve 没有在运行或包被关掉时,页面上的操作会在 30 秒后报"ta serve 没有回应"。
36
+ - 页面的修改要等服务端处理;Ta 服务(ta serve)没有在运行或包被关掉时,页面上的操作会在 30 秒后报"Ta 服务没有回应"。
37
37
 
38
38
  ## 以后
39
39
 
@@ -137,6 +137,10 @@ var ChannelsUtil;
137
137
  return team.channels.find((channel) => channel.id === ref || channel.name.toLowerCase() === key);
138
138
  }
139
139
  ChannelsUtil.findChannel = findChannel;
140
+ function directory(value) {
141
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
142
+ }
143
+ ChannelsUtil.directory = directory;
140
144
  function addAgent(team, input) {
141
145
  const name = checkName(input.name, "agent");
142
146
  if (findAgent(team, name)) {
@@ -146,7 +150,7 @@ var ChannelsUtil;
146
150
  if (!role) {
147
151
  throw new Error(`Say what ${name} does: its role.`);
148
152
  }
149
- const cwd = typeof input.cwd === "string" && input.cwd.trim() ? input.cwd.trim() : undefined;
153
+ const cwd = directory(input.cwd);
150
154
  const id = newId("agent");
151
155
  const face = isFace(input.face) ? input.face : freeFace(hash(id), new Set(faces(team.agents).values()));
152
156
  const agent = { id, name, role, mark: mark(name), face, cwd, createdAt: Date.now() };
@@ -509,7 +513,7 @@ var TeamTools;
509
513
  properties: {
510
514
  name: { type: "string", description: "Short and unique, without spaces; channels mention it as @name." },
511
515
  role: { type: "string", description: "What the agent does and how, in the second person: its instructions." },
512
- cwd: { type: "string", description: "The directory it works in; default: the server's directory." }
516
+ cwd: { type: "string", description: "The directory it works in, for good; default: the server's directory now." }
513
517
  },
514
518
  required: ["name", "role"]
515
519
  },
@@ -585,8 +589,8 @@ var TeamTools;
585
589
  // web-src/extension.ts
586
590
  var TA_HOST_EVENT = "ta:host";
587
591
  var HOST_WAIT_MS = 1000;
588
- var NO_SERVER = "The team tools need ta serve, which runs the agents: start `ta serve` and talk to Ta in its web page. In Ta on its own there are no agents or channels.";
589
- var NO_TEAM = "The team of ta-channels did not start in ta serve; its log says why.";
592
+ var NO_SERVER = "The team tools need the Ta service, which runs the agents: start it with `ta serve` and talk to Ta in its web page. In Ta in a terminal there are no agents or channels.";
593
+ var NO_TEAM = "The team did not start in the Ta service; its log says why.";
590
594
  var NOT_FOR_AGENTS = "Agents do not build teams or post to channels: answer in your reply, and name a member with @ to hand on.";
591
595
  function activate(pi) {
592
596
  let reached;
package/host/index.mjs CHANGED
@@ -138,6 +138,10 @@ var ChannelsUtil;
138
138
  return team.channels.find((channel) => channel.id === ref || channel.name.toLowerCase() === key);
139
139
  }
140
140
  ChannelsUtil.findChannel = findChannel;
141
+ function directory(value) {
142
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
143
+ }
144
+ ChannelsUtil.directory = directory;
141
145
  function addAgent(team, input) {
142
146
  const name = checkName(input.name, "agent");
143
147
  if (findAgent(team, name)) {
@@ -147,7 +151,7 @@ var ChannelsUtil;
147
151
  if (!role) {
148
152
  throw new Error(`Say what ${name} does: its role.`);
149
153
  }
150
- const cwd = typeof input.cwd === "string" && input.cwd.trim() ? input.cwd.trim() : undefined;
154
+ const cwd = directory(input.cwd);
151
155
  const id = newId("agent");
152
156
  const face = isFace(input.face) ? input.face : freeFace(hash(id), new Set(faces(team.agents).values()));
153
157
  const agent = { id, name, role, mark: mark(name), face, cwd, createdAt: Date.now() };
@@ -523,6 +527,7 @@ class TeamService {
523
527
  }
524
528
  async start() {
525
529
  this.team = await this.get(Keys.TEAM) ?? ChannelsUtil.emptyTeam();
530
+ await this.pinDirectories();
526
531
  this.queue = await this.get(Keys.QUEUE) ?? { jobs: [], rounds: {} };
527
532
  await this.set(Keys.WORKING, null);
528
533
  this.unlisten = this.host.onExtensionData((name, key) => {
@@ -542,7 +547,8 @@ class TeamService {
542
547
  this.unlisten?.();
543
548
  }
544
549
  async createAgent(input) {
545
- const { team, agent } = ChannelsUtil.addAgent(this.team, input);
550
+ const cwd = ChannelsUtil.directory(input.cwd) ?? (await this.host.getServerInfo()).cwd;
551
+ const { team, agent } = ChannelsUtil.addAgent(this.team, { ...input, cwd });
546
552
  await this.saveTeam(team);
547
553
  return agent;
548
554
  }
@@ -575,7 +581,8 @@ class TeamService {
575
581
  return channel;
576
582
  }
577
583
  async updateAgent(input) {
578
- const { team, agent, before } = ChannelsUtil.updateAgent(this.team, input);
584
+ const cwd = input.cwd === undefined ? undefined : ChannelsUtil.directory(input.cwd) ?? (await this.host.getServerInfo()).cwd;
585
+ const { team, agent, before } = ChannelsUtil.updateAgent(this.team, cwd === undefined ? input : { ...input, cwd });
579
586
  await this.saveTeam(team);
580
587
  if (agent.name !== before.name && agent.sessionFile) {
581
588
  const open = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
@@ -824,6 +831,18 @@ class TeamService {
824
831
  }
825
832
  return text.trim();
826
833
  }
834
+ async pinDirectories() {
835
+ const loose = this.team.agents.filter((agent) => !agent.cwd);
836
+ if (loose.length === 0) {
837
+ return;
838
+ }
839
+ const serverCwd = (await this.host.getServerInfo()).cwd;
840
+ const pinned = new Map;
841
+ for (const agent of loose) {
842
+ pinned.set(agent.id, agent.sessionFile && await this.host.sessionCwd(agent.sessionFile) || serverCwd);
843
+ }
844
+ await this.saveTeam({ ...this.team, agents: this.team.agents.map((agent) => pinned.has(agent.id) ? { ...agent, cwd: pinned.get(agent.id) } : agent) });
845
+ }
827
846
  session(agent) {
828
847
  let opening = this.opening.get(agent.id);
829
848
  if (!opening) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-channels",
3
- "version": "4.6.1",
3
+ "version": "4.7.0",
4
4
  "description": "A pi package for Ta: agents with roles of their own and channels where the user, Ta and the agents talk; Ta builds the team for what the user wants",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.6.1",
31
- "@celljs/ta-web": "4.6.1",
30
+ "@celljs/ta-protocol": "4.7.0",
31
+ "@celljs/ta-web": "4.7.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
package/web/index.js CHANGED
@@ -138,6 +138,10 @@ var ChannelsUtil;
138
138
  return team.channels.find((channel) => channel.id === ref || channel.name.toLowerCase() === key);
139
139
  }
140
140
  ChannelsUtil.findChannel = findChannel;
141
+ function directory(value) {
142
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
143
+ }
144
+ ChannelsUtil.directory = directory;
141
145
  function addAgent(team, input) {
142
146
  const name = checkName(input.name, "agent");
143
147
  if (findAgent(team, name)) {
@@ -147,7 +151,7 @@ var ChannelsUtil;
147
151
  if (!role) {
148
152
  throw new Error(`Say what ${name} does: its role.`);
149
153
  }
150
- const cwd = typeof input.cwd === "string" && input.cwd.trim() ? input.cwd.trim() : undefined;
154
+ const cwd = directory(input.cwd);
151
155
  const id = newId("agent");
152
156
  const face = isFace(input.face) ? input.face : freeFace(hash(id), new Set(faces(team.agents).values()));
153
157
  const agent = { id, name, role, mark: mark(name), face, cwd, createdAt: Date.now() };
@@ -602,7 +606,7 @@ class ChannelsClient {
602
606
  const result = new Promise((resolve, reject) => {
603
607
  const timer = setTimeout(() => {
604
608
  this.pending.delete(id);
605
- reject(new Error("ta serve did not answer: the package may be off, or the server still starting."));
609
+ reject(new Error("The Ta service did not answer: the extension may be off, or the service still starting."));
606
610
  }, this.options.timeoutMs);
607
611
  this.pending.set(id, { resolve, reject, timer });
608
612
  });
@@ -1404,6 +1408,10 @@ var SidebarUtil;
1404
1408
  return date.toLocaleDateString(language, { year: "2-digit", month: "numeric", day: "numeric" });
1405
1409
  }
1406
1410
  SidebarUtil.time = time;
1411
+ function host(cwd) {
1412
+ return /^ssh:\/\/([^/]+)/.exec(cwd)?.[1];
1413
+ }
1414
+ SidebarUtil.host = host;
1407
1415
  function folder(cwd) {
1408
1416
  const parts = cwd.split(/[\\/]+/).filter(Boolean);
1409
1417
  return parts[parts.length - 1] ?? cwd;
@@ -2677,6 +2685,7 @@ function AgentsSidebar({ context }) {
2677
2685
  const agentPage = pi.ui.useView(AGENT_PAGE);
2678
2686
  const [opening, setOpening] = React.useState();
2679
2687
  const Folder = ChannelViews.icon(pi, "Folder");
2688
+ const Server = ChannelViews.icon(pi, "Server");
2680
2689
  const Avatar = pi.ui.Avatar;
2681
2690
  const { team, working } = state;
2682
2691
  React.useEffect(() => {
@@ -2782,9 +2791,13 @@ function AgentsSidebar({ context }) {
2782
2791
  }, /* @__PURE__ */ React.createElement("div", {
2783
2792
  className: "tac-folder",
2784
2793
  title: group.cwd
2785
- }, /* @__PURE__ */ React.createElement(Folder, {
2794
+ }, SidebarUtil.host(group.cwd) ? /* @__PURE__ */ React.createElement(Server, {
2795
+ size: 12
2796
+ }) : /* @__PURE__ */ React.createElement(Folder, {
2786
2797
  size: 12
2787
- }), /* @__PURE__ */ React.createElement("span", null, SidebarUtil.folder(group.cwd))), group.agents.map((agent) => {
2798
+ }), /* @__PURE__ */ React.createElement("span", null, SidebarUtil.folder(group.cwd)), SidebarUtil.host(group.cwd) && /* @__PURE__ */ React.createElement("span", {
2799
+ className: "tac-host"
2800
+ }, SidebarUtil.host(group.cwd))), group.agents.map((agent) => {
2788
2801
  const where = team.channels.find((channel) => working[channel.id]?.includes(agent.id));
2789
2802
  return /* @__PURE__ */ React.createElement(Row, {
2790
2803
  key: agent.id,
@@ -2949,6 +2962,7 @@ div.tac-dialog-label { flex-direction: row; justify-content: space-between; marg
2949
2962
  .tac-lead svg { flex: none; }
2950
2963
  .tac-folder { display: flex; align-items: center; gap: 5px; margin: 12px 18px 4px; color: var(--ta-muted); font-size: 11.5px; line-height: 16px; }
2951
2964
  .tac-folder span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2965
+ .tac-folder .tac-host { flex: none; max-width: 140px; height: 16px; padding: 0 5px; border-radius: 4px; background: var(--ta-hover-strong); color: var(--ta-secondary); font-size: 10.5px; line-height: 16px; }
2952
2966
  .tac-face { display: inline-flex; flex: none; }
2953
2967
  .tac-face svg { display: block; overflow: visible; }
2954
2968
  .tac-face-eyes { transform-box: fill-box; transform-origin: center; animation: tac-blink 5.2s infinite; }
@@ -9,7 +9,10 @@ export interface Agent {
9
9
  mark: string;
10
10
  /** Which of the {@link FACES} faces it has; agents made before faces get one by their id (ChannelsUtil.faces). */
11
11
  face?: number;
12
- /** Where its session works; default: the server's directory. */
12
+ /**
13
+ * Where its session works: a path, or an `ssh://` location. Kept from when it is made (the server's
14
+ * directory then, when none is given), so that changing the server's does not move it.
15
+ */
13
16
  cwd?: string;
14
17
  sessionFile?: string;
15
18
  createdAt: number;
@@ -150,6 +150,11 @@ export namespace ChannelsUtil {
150
150
  }
151
151
 
152
152
  /** `face`: one of the {@link FACES}, else one no other agent has while some are free. */
153
+ /** A directory given, trimmed; undefined for none. */
154
+ export function directory(value: unknown): string | undefined {
155
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
156
+ }
157
+
153
158
  export function addAgent(team: Team, input: { name: unknown; role: unknown; cwd?: unknown; face?: unknown }): { team: Team; agent: Agent } {
154
159
  const name = checkName(input.name, 'agent');
155
160
  if (findAgent(team, name)) {
@@ -159,7 +164,7 @@ export namespace ChannelsUtil {
159
164
  if (!role) {
160
165
  throw new Error(`Say what ${name} does: its role.`);
161
166
  }
162
- const cwd = typeof input.cwd === 'string' && input.cwd.trim() ? input.cwd.trim() : undefined;
167
+ const cwd = directory(input.cwd);
163
168
  const id = newId('agent');
164
169
  const face = isFace(input.face) ? input.face : freeFace(hash(id), new Set(faces(team.agents).values()));
165
170
  const agent: Agent = { id, name, role, mark: mark(name), face, cwd, createdAt: Date.now() };
@@ -168,7 +168,7 @@ export class ChannelsClient {
168
168
  const result = new Promise<unknown>((resolve, reject) => {
169
169
  const timer = setTimeout(() => {
170
170
  this.pending.delete(id);
171
- reject(new Error('ta serve did not answer: the package may be off, or the server still starting.'));
171
+ reject(new Error('The Ta service did not answer: the extension may be off, or the service still starting.'));
172
172
  }, this.options.timeoutMs);
173
173
  this.pending.set(id, { resolve, reject, timer });
174
174
  });
@@ -11,8 +11,8 @@ const TA_HOST_EVENT = 'ta:host';
11
11
  const HOST_WAIT_MS = 1000;
12
12
 
13
13
  export const NO_SERVER =
14
- 'The team tools need ta serve, which runs the agents: start `ta serve` and talk to Ta in its web page. In Ta on its own there are no agents or channels.';
15
- export const NO_TEAM = 'The team of ta-channels did not start in ta serve; its log says why.';
14
+ 'The team tools need the Ta service, which runs the agents: start it with `ta serve` and talk to Ta in its web page. In Ta in a terminal there are no agents or channels.';
15
+ export const NO_TEAM = 'The team did not start in the Ta service; its log says why.';
16
16
  export const NOT_FOR_AGENTS = 'Agents do not build teams or post to channels: answer in your reply, and name a member with @ to hand on.';
17
17
 
18
18
  /** The little of pi's extension API this uses. */
@@ -152,6 +152,7 @@ export function AgentsSidebar({ context }: { context: ChannelsContext }) {
152
152
  const agentPage = pi.ui.useView(AGENT_PAGE);
153
153
  const [opening, setOpening] = React.useState<string>();
154
154
  const Folder = ChannelViews.icon(pi, 'Folder');
155
+ const Server = ChannelViews.icon(pi, 'Server');
155
156
  const Avatar = pi.ui.Avatar;
156
157
  const { team, working } = state;
157
158
  React.useEffect(() => {
@@ -265,8 +266,9 @@ export function AgentsSidebar({ context }: { context: ChannelsContext }) {
265
266
  {SidebarUtil.byDirectory(agents, serverCwd).map(group => (
266
267
  <React.Fragment key={group.cwd}>
267
268
  <div className="tac-folder" title={group.cwd}>
268
- <Folder size={12} />
269
+ {SidebarUtil.host(group.cwd) ? <Server size={12} /> : <Folder size={12} />}
269
270
  <span>{SidebarUtil.folder(group.cwd)}</span>
271
+ {SidebarUtil.host(group.cwd) && <span className="tac-host">{SidebarUtil.host(group.cwd)}</span>}
270
272
  </div>
271
273
  {group.agents.map(agent => {
272
274
  const where = team.channels.find(channel => working[channel.id]?.includes(agent.id));
package/web-src/style.ts CHANGED
@@ -136,6 +136,7 @@ div.tac-dialog-label { flex-direction: row; justify-content: space-between; marg
136
136
  .tac-lead svg { flex: none; }
137
137
  .tac-folder { display: flex; align-items: center; gap: 5px; margin: 12px 18px 4px; color: var(--ta-muted); font-size: 11.5px; line-height: 16px; }
138
138
  .tac-folder span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
139
+ .tac-folder .tac-host { flex: none; max-width: 140px; height: 16px; padding: 0 5px; border-radius: 4px; background: var(--ta-hover-strong); color: var(--ta-secondary); font-size: 10.5px; line-height: 16px; }
139
140
  .tac-face { display: inline-flex; flex: none; }
140
141
  .tac-face svg { display: block; overflow: visible; }
141
142
  .tac-face-eyes { transform-box: fill-box; transform-origin: center; animation: tac-blink 5.2s infinite; }
@@ -23,7 +23,7 @@ export namespace TeamTools {
23
23
  properties: {
24
24
  name: { type: 'string', description: 'Short and unique, without spaces; channels mention it as @name.' },
25
25
  role: { type: 'string', description: 'What the agent does and how, in the second person: its instructions.' },
26
- cwd: { type: 'string', description: "The directory it works in; default: the server's directory." },
26
+ cwd: { type: 'string', description: "The directory it works in, for good; default: the server's directory now." },
27
27
  },
28
28
  required: ['name', 'role'],
29
29
  },
@@ -12,6 +12,10 @@ class FakeHost {
12
12
  readonly prompts: { name?: string; message: string }[] = [];
13
13
  readonly sessions = new Map<string, { name?: string; file: string; count: number; last?: string }>();
14
14
  readonly data = new Map<string, unknown>();
15
+ /** The directory of ta serve, which the user may change. */
16
+ serverCwd = '/work';
17
+ /** What the header of each session file says. */
18
+ readonly headers = new Map<string, string>();
15
19
  readonly listeners = new Set<(name: string, key: string) => void>();
16
20
  reply: (name: string, prompt: string) => string = name => `${name} here.`;
17
21
 
@@ -20,7 +24,11 @@ class FakeHost {
20
24
  }
21
25
 
22
26
  async getServerInfo() {
23
- return { version: '0', cwd: '/work' };
27
+ return { version: '0', cwd: this.serverCwd, user: 'me', host: 'box' };
28
+ }
29
+
30
+ async sessionCwd(file: string) {
31
+ return this.headers.get(file);
24
32
  }
25
33
 
26
34
  async listSessions() {
@@ -106,6 +114,30 @@ const until = async (check: () => boolean) => {
106
114
  };
107
115
 
108
116
  describe('TeamService', () => {
117
+ it('keeps the directory of an agent when the server moves to another', async () => {
118
+ const host = new FakeHost();
119
+ const team = new TeamService(host.asHost(), { pollMs: 1 });
120
+ await team.start();
121
+ expect((await team.createAgent({ name: 'pm', role: 'You plan.' })).cwd).toBe('/work');
122
+ host.serverCwd = 'ssh://dev/srv';
123
+ expect((await team.createAgent({ name: 'dev', role: 'You build.' })).cwd).toBe('ssh://dev/srv');
124
+ await team.createChannel({ name: 'launch', members: ['pm'] });
125
+ await (await team.post('launch', USER, 'Go')).done;
126
+ expect(host.opened[0].cwd).toBe('/work');
127
+ expect((await team.updateAgent({ agent: 'pm', cwd: '' })).cwd).toBe('ssh://dev/srv');
128
+ });
129
+
130
+ it('gives agents made before each kept a directory the one of their conversation', async () => {
131
+ const host = new FakeHost();
132
+ const agent = (name: string, sessionFile?: string) => ({ id: name, name, role: 'x', mark: 'X', createdAt: 0, sessionFile });
133
+ host.data.set(`${NAME}:${Keys.TEAM}`, { agents: [agent('old', '/s/old.jsonl'), agent('gone', '/s/gone.jsonl'), agent('new')], channels: [] });
134
+ host.headers.set('/s/old.jsonl', 'ssh://dev/app');
135
+ host.serverCwd = '/home';
136
+ const team = new TeamService(host.asHost(), { pollMs: 1 });
137
+ await team.start();
138
+ expect(host.value<Team>(Keys.TEAM).agents.map(item => item.cwd)).toEqual(['ssh://dev/app', '/home', '/home']);
139
+ });
140
+
109
141
  it('opens a session per agent with its role, in the group of the package, and posts its answer', async () => {
110
142
  const { host, team, channel } = await setUp();
111
143
  const { done } = await team.post('launch', USER, 'What first?');
@@ -278,7 +310,7 @@ describe('ChannelsClient', () => {
278
310
  it('says so when nobody answers', async () => {
279
311
  const host = new FakeHost();
280
312
  const client = new ChannelsClient(host.storage(), { timeoutMs: 20 });
281
- await expect(client.post('c', 'hi')).rejects.toThrow('ta serve did not answer');
313
+ await expect(client.post('c', 'hi')).rejects.toThrow('The Ta service did not answer');
282
314
  });
283
315
  });
284
316
 
package/web-src/team.ts CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  export type TeamHost = Pick<
21
21
  TaExtensionHost,
22
22
  | 'getServerInfo'
23
+ | 'sessionCwd'
23
24
  | 'listSessions'
24
25
  | 'openSession'
25
26
  | 'setSessionName'
@@ -87,6 +88,7 @@ export class TeamService {
87
88
  /** Reads the data, answers the pages, and goes on with the jobs left from before. */
88
89
  async start(): Promise<void> {
89
90
  this.team = (await this.get<Team>(Keys.TEAM)) ?? ChannelsUtil.emptyTeam();
91
+ await this.pinDirectories();
90
92
  this.queue = (await this.get<Queue>(Keys.QUEUE)) ?? { jobs: [], rounds: {} };
91
93
  await this.set(Keys.WORKING, null);
92
94
  this.unlisten = this.host.onExtensionData((name, key) => {
@@ -108,8 +110,10 @@ export class TeamService {
108
110
  this.unlisten?.();
109
111
  }
110
112
 
113
+ /** Without a directory, it works in that of ta serve now, and stays there when the server's changes. */
111
114
  async createAgent(input: { name: unknown; role: unknown; cwd?: unknown; face?: unknown }): Promise<Agent> {
112
- const { team, agent } = ChannelsUtil.addAgent(this.team, input);
115
+ const cwd = ChannelsUtil.directory(input.cwd) ?? (await this.host.getServerInfo()).cwd;
116
+ const { team, agent } = ChannelsUtil.addAgent(this.team, { ...input, cwd });
113
117
  await this.saveTeam(team);
114
118
  return agent;
115
119
  }
@@ -150,7 +154,9 @@ export class TeamService {
150
154
 
151
155
  /** Its name, face, role or directory; an open session takes the new name at once, the rest when it opens again. */
152
156
  async updateAgent(input: { agent: unknown; name?: unknown; role?: unknown; face?: unknown; cwd?: unknown }): Promise<Agent> {
153
- const { team, agent, before } = ChannelsUtil.updateAgent(this.team, input);
157
+ // No directory is the server's of now: an agent keeps one of its own.
158
+ const cwd = input.cwd === undefined ? undefined : (ChannelsUtil.directory(input.cwd) ?? (await this.host.getServerInfo()).cwd);
159
+ const { team, agent, before } = ChannelsUtil.updateAgent(this.team, cwd === undefined ? input : { ...input, cwd });
154
160
  await this.saveTeam(team);
155
161
  if (agent.name !== before.name && agent.sessionFile) {
156
162
  const open = (await this.host.listSessions()).find(session => session.sessionFile === agent.sessionFile);
@@ -436,6 +442,23 @@ export class TeamService {
436
442
  return text.trim();
437
443
  }
438
444
 
445
+ /**
446
+ * Agents made before each kept a directory followed the server's: each gets the one its conversation
447
+ * works in (from its session file), or the server's of now when it has none yet.
448
+ */
449
+ protected async pinDirectories(): Promise<void> {
450
+ const loose = this.team.agents.filter(agent => !agent.cwd);
451
+ if (loose.length === 0) {
452
+ return;
453
+ }
454
+ const serverCwd = (await this.host.getServerInfo()).cwd;
455
+ const pinned = new Map<string, string>();
456
+ for (const agent of loose) {
457
+ pinned.set(agent.id, (agent.sessionFile && (await this.host.sessionCwd(agent.sessionFile))) || serverCwd);
458
+ }
459
+ await this.saveTeam({ ...this.team, agents: this.team.agents.map(agent => (pinned.has(agent.id) ? { ...agent, cwd: pinned.get(agent.id) } : agent)) });
460
+ }
461
+
439
462
  /** The open session of the agent, or its file opened again, or a new one, whose file is kept at once. */
440
463
  protected session(agent: Agent): Promise<string> {
441
464
  let opening = this.opening.get(agent.id);
package/web-src/views.tsx CHANGED
@@ -16,7 +16,7 @@ const CHANNEL_KEY = 'ta-channels.channel';
16
16
  /** What the side bar and the page of a channel share while the page is open. */
17
17
  export interface ChannelsUi {
18
18
  query: string;
19
- /** The agent being made on its page (create.tsx); without `cwd`, it works in the directory of ta serve. */
19
+ /** The agent being made on its page (create.tsx); without `cwd`, it works in the directory of ta serve when it is made. */
20
20
  draft?: { name: string; face: number; cwd?: string };
21
21
  /** The card to change its name and face is open. */
22
22
  editing: boolean;
@@ -182,6 +182,11 @@ export namespace SidebarUtil {
182
182
  return date.toLocaleDateString(language, { year: '2-digit', month: 'numeric', day: 'numeric' });
183
183
  }
184
184
 
185
+ /** The host of an `ssh://` directory; undefined for one of the machine of ta serve. */
186
+ export function host(cwd: string): string | undefined {
187
+ return /^ssh:\/\/([^/]+)/.exec(cwd)?.[1];
188
+ }
189
+
185
190
  export function folder(cwd: string): string {
186
191
  const parts = cwd.split(/[\\/]+/).filter(Boolean);
187
192
  return parts[parts.length - 1] ?? cwd;