@celljs/ta-harness 4.12.0 → 4.13.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 CHANGED
@@ -11,5 +11,5 @@ Ta's runtime component on pi: the `ta` command and `ta serve` share this code. C
11
11
  | `ExecExtension`(`ta:exec`) | When the execution environment is not local, replaces read / bash / edit / write / ls / find tools and takes over the `!` command. pi's grep always runs ripgrep locally, so it's disabled (models call rg through bash) |
12
12
  | `ExecOperations` | Adapts `ExecEnvironment` to pi tool `*Operations` |
13
13
  | `ExecMcpTransport` | Starts a stdio MCP server in the execution environment, passes it to pi's `createMcpExtension({ createTransport })` |
14
- | `TaPackages` | Ta's built-in pi packages (`@celljs/ta-workspace`, `@celljs/ta-channels`, `@celljs/ta-extensions`, `@celljs/ta-launcher`, `@celljs/ta-computer-use`, `@celljs/ta-changes`, `@celljs/ta-cron`, `@celljs/ta-bots`, `@celljs/ta-agents`): on release they are in `dist/pi/packages/<name>`, in the repo they're resolved from the workspace. Enabled by default; disabled ones are recorded in `ta.json` in the agent directory. The `ta` command loads pi extensions, skills and prompt templates of enabled packages with `--extension` (except package management commands and `--no-extensions`); `ta serve` uses pi ResourceLoader's `additionalExtensionPaths` + `extensionsOverride` / `skillsOverride` / `promptsOverride`, and on `reload` selects by the current switches |
14
+ | `TaPackages` | Ta's built-in pi packages (`@celljs/ta-workspace`, `@celljs/ta-channels`, `@celljs/ta-extensions`, `@celljs/ta-launcher`, `@celljs/ta-computer-use`, `@celljs/ta-changes`, `@celljs/ta-cron`, `@celljs/ta-bots`, `@celljs/ta-agents`): on release they are in `dist/pi/packages/<name>`, in the repo they're resolved from the workspace. Enabled by default; disabled ones are recorded in `ta.json` in the agent directory. The `ta` command loads pi extensions, skills and prompt templates of enabled packages with `--extension` (except package management commands and `--no-extensions`); `ta serve` uses pi ResourceLoader's `additionalExtensionPaths` + `extensionsOverride` / `skillsOverride` / `promptsOverride`, and on `reload` selects by the current switches. Given pi's `loadSkillsFromDir`, `skillsOverride` also loads the skills the packages of `<agent>/extensions/` and of `.ta/extensions/` of a trusted project declare (pi loads only their pi extensions), while the package is on (its pi extensions loaded, or, with none, not in `disabledWeb` of `ta.json`), giving way to a skill of the same name pi has |
15
15
  | `TaExtension` / `TaExtensionUtil` | The shape of Ta's built-in extension: a plain object; `bundle()` combines built-in extensions into one, shown in pi's loaded extension list as `ta` |
package/README.md CHANGED
@@ -11,5 +11,5 @@ Ta 在 pi 之上的运行时部件,`ta` 命令和 ta serve 共用。这里的
11
11
  | `ExecExtension`(`ta:exec`) | 执行环境不在本机时,用同名工具替换 read / bash / edit / write / ls / find 并接管 `!` 命令;pi 的 grep 总在本机跑 ripgrep,所以停用它(模型会通过 bash 用 rg) |
12
12
  | `ExecOperations` | 把 `ExecEnvironment` 适配成 pi 工具的 `*Operations` |
13
13
  | `ExecMcpTransport` | 在执行环境里启动 stdio MCP 服务,交给 pi 的 `createMcpExtension({ createTransport })` |
14
- | `TaPackages` | Ta 自带的 pi 包(`@celljs/ta-workspace`、`@celljs/ta-channels`、`@celljs/ta-extensions`、`@celljs/ta-launcher`、`@celljs/ta-computer-use`、`@celljs/ta-changes`、`@celljs/ta-cron`、`@celljs/ta-bots`、`@celljs/ta-agents`):发布时在 `dist/pi/packages/<名字>`,仓库里从工作区解析;默认开启,关掉的记在 agent 目录的 `ta.json`。`ta` 命令用 `--extension` 加载开启着的包的 pi 扩展、技能和提示模板(包管理命令和 `--no-extensions` 除外),ta serve 用 pi ResourceLoader 的 `additionalExtensionPaths` + `extensionsOverride` / `skillsOverride` / `promptsOverride`,`reload` 时按当时的开关取舍 |
14
+ | `TaPackages` | Ta 自带的 pi 包(`@celljs/ta-workspace`、`@celljs/ta-channels`、`@celljs/ta-extensions`、`@celljs/ta-launcher`、`@celljs/ta-computer-use`、`@celljs/ta-changes`、`@celljs/ta-cron`、`@celljs/ta-bots`、`@celljs/ta-agents`):发布时在 `dist/pi/packages/<名字>`,仓库里从工作区解析;默认开启,关掉的记在 agent 目录的 `ta.json`。`ta` 命令用 `--extension` 加载开启着的包的 pi 扩展、技能和提示模板(包管理命令和 `--no-extensions` 除外),ta serve 用 pi ResourceLoader 的 `additionalExtensionPaths` + `extensionsOverride` / `skillsOverride` / `promptsOverride`,`reload` 时按当时的开关取舍;传入 pi 的 `loadSkillsFromDir` 时,`skillsOverride` 还加载 `<agent>/extensions/` 和受信任项目 `.ta/extensions/` 里包声明的技能(pi 只从那里加载 pi 扩展),包开着才加载(有 pi 扩展看它是否已加载,只有技能看 `ta.json` 的 `disabledWeb`),同名时让给 pi 已有的技能 |
15
15
  | `TaExtension` / `TaExtensionUtil` | Ta 的内置扩展形状:普通对象;`bundle()` 把内置扩展合成一个,pi 的已加载扩展列表里显示为 `ta` |
@@ -38,21 +38,25 @@ container or a sandbox, while the agent runs elsewhere: ta serve --exec <url>. S
38
38
 
39
39
  Set TA_EXEC_TOKEN to choose the token hosts must present; otherwise a random one is printed.
40
40
  `;
41
- const RELAY_HELP = `Usage: ta relay [--host <host>] [--port <port>]
41
+ const RELAY_HELP = `Usage: ta relay [--host <host>] [--port <port>] [--data <dir>]
42
42
 
43
43
  Runs a relay, through which paired devices reach a ta serve from anywhere (ta pair). It only forwards:
44
44
  what goes through is encrypted end to end. Put it behind HTTPS. Stops on SIGINT or SIGTERM.
45
45
 
46
46
  --host Address to listen on. Default: 127.0.0.1
47
47
  --port Port to listen on. Default: 8080
48
+ --data Directory that keeps rooms, sealed copies and which host holds which id across restarts.
49
+ Without it they live in memory, gone when the relay stops.
48
50
  `;
49
51
  const PAIR_HELP = `Usage: ta pair [<relay url>] [--name <device>]
50
52
  ta pair --list
51
53
  ta pair --remove <device id>
52
54
 
53
55
  Pairs a device, such as a phone, with the ta serve of this user: prints a link to paste in the Ta app on
54
- it, and in a terminal a QR code of it to scan. The relay is https://relay.cellbang.com unless named. With a device paired, ta serve connects to the relay; what goes through it is encrypted end to end,
55
- with a key only the device and ta serve have. The devices are in relay.json in the agent directory.
56
+ it, and in a terminal a QR code of it to scan. The relay is the one named, else the one relays.json uses
57
+ for devices, else https://relay.cellbang.com. With a device paired, ta serve connects to its relay; what
58
+ goes through it is encrypted end to end, with a key only the device and ta serve have. The devices are in
59
+ relay.json in the agent directory, each with its relay.
56
60
  `;
57
61
  export var TaCli;
58
62
  (function (TaCli) {
@@ -149,13 +153,21 @@ export var TaCli;
149
153
  }
150
154
  /** Without Cell, as the exec server. */
151
155
  async function relay(argv) {
152
- const { values } = parseArgs({ args: argv, options: { host: { type: 'string' }, port: { type: 'string' }, help: { type: 'boolean', short: 'h' } } });
156
+ const { values } = parseArgs({
157
+ args: argv,
158
+ options: { host: { type: 'string' }, port: { type: 'string' }, data: { type: 'string' }, help: { type: 'boolean', short: 'h' } },
159
+ });
153
160
  if (values.help) {
154
161
  process.stdout.write(RELAY_HELP);
155
162
  return;
156
163
  }
157
164
  const { RelayServer } = await import('@celljs/ta-relay/lib/node/relay-server');
158
- const server = new RelayServer({ host: values.host, port: values.port ? Number(values.port) : 8080 });
165
+ const { resolve } = await import('node:path');
166
+ const server = new RelayServer({
167
+ host: values.host,
168
+ port: values.port ? Number(values.port) : 8080,
169
+ data: values.data ? resolve(values.data) : undefined,
170
+ });
159
171
  console.log(`ta relay: ${await server.listen()}`);
160
172
  const stop = () => void server.close().then(() => process.exit(0));
161
173
  process.once('SIGINT', stop);
@@ -172,10 +184,12 @@ export var TaCli;
172
184
  const { RelayPairingUtil } = await import('@celljs/ta-relay/lib/common/relay-pairing');
173
185
  const store = new RelayStore(TaBrand.agentDir());
174
186
  if (values.list) {
175
- const { url, devices } = store.read();
176
- console.log(devices.length === 0 ? 'No devices are paired.' : `Relay: ${url}`);
177
- for (const device of devices) {
178
- console.log(`${device.id} ${device.name} ${new Date(device.createdAt).toISOString()}`);
187
+ const config = store.read();
188
+ if (config.devices.length === 0) {
189
+ console.log('No devices are paired.');
190
+ }
191
+ for (const device of config.devices) {
192
+ console.log(`${device.id} ${device.name} ${new Date(device.createdAt).toISOString()} ${RelayStore.relayOf(device, config)}`);
179
193
  }
180
194
  return;
181
195
  }
@@ -186,8 +200,8 @@ export var TaCli;
186
200
  }
187
201
  return;
188
202
  }
189
- const { RELAY_DEFAULT_URL } = await import('@celljs/ta-relay/lib/common/relay-protocol');
190
- const [relayUrl = RELAY_DEFAULT_URL] = positionals;
203
+ const { RelaysFile } = await import('@celljs/ta-relay/lib/node/relays-file');
204
+ const [relayUrl = new RelaysFile(TaBrand.agentDir()).urlFor('devices')] = positionals;
191
205
  if (values.help || !/^https?:\/\//.test(relayUrl)) {
192
206
  process.stdout.write(PAIR_HELP);
193
207
  process.exitCode = values.help ? 0 : 1;
@@ -4,6 +4,7 @@ export interface TaPackageLoaderOptions {
4
4
  additionalExtensionPaths: string[];
5
5
  extensionsOverride(result: LoadExtensionsResult): LoadExtensionsResult;
6
6
  skillsOverride<T extends {
7
+ name: string;
7
8
  filePath: string;
8
9
  }, D extends {
9
10
  path?: string;
@@ -34,6 +35,28 @@ export interface TaBuiltinPackage {
34
35
  /** It has what pi loads: `pi.extensions`, `pi.skills` or `pi.prompts` of its package.json. */
35
36
  resources: boolean;
36
37
  }
38
+ /** What pi's `loadSkillsFromDir` gives: the skills of a directory, as its resource loader keeps them. */
39
+ export type TaSkillLoader = (options: {
40
+ dir: string;
41
+ source: string;
42
+ }) => {
43
+ skills: {
44
+ name: string;
45
+ filePath: string;
46
+ }[];
47
+ diagnostics: {
48
+ path?: string;
49
+ }[];
50
+ };
51
+ /** What a session's loader is told besides the agent directory. */
52
+ export interface TaLoaderSettings {
53
+ /** pi's package directory, of the built-in packages; default PI_PACKAGE_DIR. */
54
+ packageDir?: string;
55
+ /** pi's `loadSkillsFromDir`: with it, the skills of the packages of `extensions/` load too. */
56
+ loadSkills?: TaSkillLoader;
57
+ /** The `.ta` directory of a trusted project, whose `extensions/` holds packages of that project. */
58
+ projectDir?: string;
59
+ }
37
60
  /**
38
61
  * The pi packages that come with ta. They are on unless the user turned them off; they cannot be
39
62
  * removed. The build of apps/ta copies each to `packages/<name without scope>` of pi's package
@@ -60,9 +83,11 @@ export declare namespace TaPackages {
60
83
  /**
61
84
  * For pi's resource loader of a session: it loads every built-in package, its pi extensions, skills
62
85
  * and prompt templates, and keeps those of the packages that are on, read again on each reload, so
63
- * that a reload follows the setting.
86
+ * that a reload follows the setting. pi finds only the pi extensions of the packages of `extensions/`;
87
+ * with `loadSkills`, their skills load too, while the package is on (its pi extensions loaded, or, with
88
+ * none, not turned off in ta.json), so that a package Ta makes there is one thing, whatever it holds.
64
89
  */
65
- function loaderOptions(agentDir: string, packageDir?: string): TaPackageLoaderOptions;
90
+ function loaderOptions(agentDir: string, settings?: TaLoaderSettings): TaPackageLoaderOptions;
66
91
  /** pi's command line with the built-in packages that are on, unless it manages packages or loads no extensions. */
67
92
  function withExtensions(argv: string[], agentDir: string, packageDir?: string): string[];
68
93
  }
@@ -4,7 +4,7 @@ const __filename = __cellFileURLToPath(import.meta.url);
4
4
  const __dirname = __cellDirname(__filename);
5
5
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
6
6
  import { createRequire } from 'node:module';
7
- import { dirname, join, sep } from 'node:path';
7
+ import { dirname, join, resolve, sep } from 'node:path';
8
8
  /** Commands of pi that manage packages and take no `--extension`. */
9
9
  const PACKAGE_COMMANDS = new Set(['install', 'remove', 'uninstall', 'update', 'list', 'config']);
10
10
  /**
@@ -25,6 +25,7 @@ export var TaPackages;
25
25
  '@celljs/ta-cron',
26
26
  '@celljs/ta-notify',
27
27
  '@celljs/ta-recall',
28
+ '@celljs/ta-initiative',
28
29
  '@celljs/ta-glance',
29
30
  '@celljs/ta-games',
30
31
  '@celljs/ta-bots',
@@ -32,6 +33,11 @@ export var TaPackages;
32
33
  '@celljs/ta-manual',
33
34
  '@celljs/ta-share',
34
35
  '@celljs/ta-rooms',
36
+ '@celljs/ta-nearby',
37
+ '@celljs/ta-moments',
38
+ '@celljs/ta-sync',
39
+ '@celljs/ta-sync-cloud',
40
+ '@celljs/ta-team',
35
41
  ];
36
42
  /** In the agent directory. */
37
43
  TaPackages.SETTINGS_FILE = 'ta.json';
@@ -92,9 +98,12 @@ export var TaPackages;
92
98
  /**
93
99
  * For pi's resource loader of a session: it loads every built-in package, its pi extensions, skills
94
100
  * and prompt templates, and keeps those of the packages that are on, read again on each reload, so
95
- * that a reload follows the setting.
101
+ * that a reload follows the setting. pi finds only the pi extensions of the packages of `extensions/`;
102
+ * with `loadSkills`, their skills load too, while the package is on (its pi extensions loaded, or, with
103
+ * none, not turned off in ta.json), so that a package Ta makes there is one thing, whatever it holds.
96
104
  */
97
- function loaderOptions(agentDir, packageDir) {
105
+ function loaderOptions(agentDir, settings = {}) {
106
+ const { packageDir, loadSkills, projectDir } = settings;
98
107
  const roots = builtins(packageDir)
99
108
  .filter(pkg => pkg.resources)
100
109
  .map(pkg => pkg.root);
@@ -104,19 +113,34 @@ export var TaPackages;
104
113
  const off = roots.filter(root => !on.has(root));
105
114
  return (path) => !path || !off.some(root => path === root || path.startsWith(`${root}${sep}`));
106
115
  };
116
+ /** The files of the pi extensions loaded last, which tell the packages of `extensions/` that are on. */
117
+ let loaded = [];
107
118
  return {
108
119
  additionalExtensionPaths: roots,
109
120
  extensionsOverride: result => {
110
121
  const keep = keeper();
111
- return {
112
- ...result,
113
- extensions: result.extensions.filter(extension => keep(extension.resolvedPath) && keep(extension.path)),
114
- errors: result.errors.filter(error => keep(error.path)),
115
- };
122
+ const extensions = result.extensions.filter(extension => keep(extension.resolvedPath) && keep(extension.path));
123
+ loaded = extensions.flatMap(extension => [extension.resolvedPath, extension.path]);
124
+ return { ...result, extensions, errors: result.errors.filter(error => keep(error.path)) };
116
125
  },
117
126
  skillsOverride: result => {
118
127
  const keep = keeper();
119
- return { ...result, skills: result.skills.filter(skill => keep(skill.filePath)), diagnostics: result.diagnostics.filter(d => keep(d.path)) };
128
+ const skills = result.skills.filter(skill => keep(skill.filePath));
129
+ const diagnostics = result.diagnostics.filter(d => keep(d.path));
130
+ if (loadSkills) {
131
+ const dirs = [join(agentDir, 'extensions'), ...(projectDir ? [join(projectDir, 'extensions')] : [])];
132
+ const off = disabledWeb(agentDir);
133
+ const on = (pkg) => (pkg.extensions ? loaded.some(path => within(pkg.root, path)) : !off.has(pkg.root));
134
+ for (const pkg of dirs.flatMap(directoryPackages).filter(on)) {
135
+ for (const dir of pkg.skills) {
136
+ const found = loadSkills({ dir, source: 'user' });
137
+ // A skill of the same name or file pi loaded already stays pi's.
138
+ skills.push(...found.skills.filter(skill => !skills.some(other => other.name === skill.name || other.filePath === skill.filePath)));
139
+ diagnostics.push(...found.diagnostics);
140
+ }
141
+ }
142
+ }
143
+ return { ...result, skills, diagnostics };
120
144
  },
121
145
  promptsOverride: result => {
122
146
  const keep = keeper();
@@ -152,6 +176,35 @@ export var TaPackages;
152
176
  return undefined;
153
177
  }
154
178
  }
179
+ /** The packages of an `extensions/` directory that have skills. */
180
+ function directoryPackages(dir) {
181
+ if (!existsSync(dir)) {
182
+ return [];
183
+ }
184
+ return subdirectories(dir).flatMap(root => {
185
+ let manifest;
186
+ try {
187
+ manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
188
+ }
189
+ catch (_a) {
190
+ return [];
191
+ }
192
+ const paths = (key) => {
193
+ var _a;
194
+ const declared = (_a = manifest === null || manifest === void 0 ? void 0 : manifest.pi) === null || _a === void 0 ? void 0 : _a[key];
195
+ return (Array.isArray(declared) ? declared : typeof declared === 'string' ? [declared] : []).filter((path) => typeof path === 'string' && path !== '');
196
+ };
197
+ // As pi reads a package: what its manifest names, else the conventional directory.
198
+ const skills = ((manifest === null || manifest === void 0 ? void 0 : manifest.pi) ? paths('skills') : ['skills'])
199
+ .map(path => resolve(root, path))
200
+ .filter(path => within(root, path) && existsSync(path));
201
+ const extensions = (manifest === null || manifest === void 0 ? void 0 : manifest.pi) ? paths('extensions').length > 0 : ['index.ts', 'index.js'].some(file => existsSync(join(root, file)));
202
+ return skills.length > 0 ? [{ root, skills, extensions }] : [];
203
+ });
204
+ }
205
+ function within(root, path) {
206
+ return !!path && (path === root || path.startsWith(`${root}${sep}`));
207
+ }
155
208
  function subdirectories(dir) {
156
209
  return readdirSync(dir, { withFileTypes: true })
157
210
  .filter(entry => entry.isDirectory() && !entry.name.startsWith('.'))
@@ -41,21 +41,25 @@ container or a sandbox, while the agent runs elsewhere: ta serve --exec <url>. S
41
41
 
42
42
  Set TA_EXEC_TOKEN to choose the token hosts must present; otherwise a random one is printed.
43
43
  `;
44
- const RELAY_HELP = `Usage: ta relay [--host <host>] [--port <port>]
44
+ const RELAY_HELP = `Usage: ta relay [--host <host>] [--port <port>] [--data <dir>]
45
45
 
46
46
  Runs a relay, through which paired devices reach a ta serve from anywhere (ta pair). It only forwards:
47
47
  what goes through is encrypted end to end. Put it behind HTTPS. Stops on SIGINT or SIGTERM.
48
48
 
49
49
  --host Address to listen on. Default: 127.0.0.1
50
50
  --port Port to listen on. Default: 8080
51
+ --data Directory that keeps rooms, sealed copies and which host holds which id across restarts.
52
+ Without it they live in memory, gone when the relay stops.
51
53
  `;
52
54
  const PAIR_HELP = `Usage: ta pair [<relay url>] [--name <device>]
53
55
  ta pair --list
54
56
  ta pair --remove <device id>
55
57
 
56
58
  Pairs a device, such as a phone, with the ta serve of this user: prints a link to paste in the Ta app on
57
- it, and in a terminal a QR code of it to scan. The relay is https://relay.cellbang.com unless named. With a device paired, ta serve connects to the relay; what goes through it is encrypted end to end,
58
- with a key only the device and ta serve have. The devices are in relay.json in the agent directory.
59
+ it, and in a terminal a QR code of it to scan. The relay is the one named, else the one relays.json uses
60
+ for devices, else https://relay.cellbang.com. With a device paired, ta serve connects to its relay; what
61
+ goes through it is encrypted end to end, with a key only the device and ta serve have. The devices are in
62
+ relay.json in the agent directory, each with its relay.
59
63
  `;
60
64
  var TaCli;
61
65
  (function (TaCli) {
@@ -152,13 +156,21 @@ var TaCli;
152
156
  }
153
157
  /** Without Cell, as the exec server. */
154
158
  async function relay(argv) {
155
- const { values } = (0, node_util_1.parseArgs)({ args: argv, options: { host: { type: 'string' }, port: { type: 'string' }, help: { type: 'boolean', short: 'h' } } });
159
+ const { values } = (0, node_util_1.parseArgs)({
160
+ args: argv,
161
+ options: { host: { type: 'string' }, port: { type: 'string' }, data: { type: 'string' }, help: { type: 'boolean', short: 'h' } },
162
+ });
156
163
  if (values.help) {
157
164
  process.stdout.write(RELAY_HELP);
158
165
  return;
159
166
  }
160
167
  const { RelayServer } = await import('@celljs/ta-relay/lib/node/relay-server');
161
- const server = new RelayServer({ host: values.host, port: values.port ? Number(values.port) : 8080 });
168
+ const { resolve } = await import('node:path');
169
+ const server = new RelayServer({
170
+ host: values.host,
171
+ port: values.port ? Number(values.port) : 8080,
172
+ data: values.data ? resolve(values.data) : undefined,
173
+ });
162
174
  console.log(`ta relay: ${await server.listen()}`);
163
175
  const stop = () => void server.close().then(() => process.exit(0));
164
176
  process.once('SIGINT', stop);
@@ -175,10 +187,12 @@ var TaCli;
175
187
  const { RelayPairingUtil } = await import('@celljs/ta-relay/lib/common/relay-pairing');
176
188
  const store = new RelayStore(ta_brand_1.TaBrand.agentDir());
177
189
  if (values.list) {
178
- const { url, devices } = store.read();
179
- console.log(devices.length === 0 ? 'No devices are paired.' : `Relay: ${url}`);
180
- for (const device of devices) {
181
- console.log(`${device.id} ${device.name} ${new Date(device.createdAt).toISOString()}`);
190
+ const config = store.read();
191
+ if (config.devices.length === 0) {
192
+ console.log('No devices are paired.');
193
+ }
194
+ for (const device of config.devices) {
195
+ console.log(`${device.id} ${device.name} ${new Date(device.createdAt).toISOString()} ${RelayStore.relayOf(device, config)}`);
182
196
  }
183
197
  return;
184
198
  }
@@ -189,8 +203,8 @@ var TaCli;
189
203
  }
190
204
  return;
191
205
  }
192
- const { RELAY_DEFAULT_URL } = await import('@celljs/ta-relay/lib/common/relay-protocol');
193
- const [relayUrl = RELAY_DEFAULT_URL] = positionals;
206
+ const { RelaysFile } = await import('@celljs/ta-relay/lib/node/relays-file');
207
+ const [relayUrl = new RelaysFile(ta_brand_1.TaBrand.agentDir()).urlFor('devices')] = positionals;
194
208
  if (values.help || !/^https?:\/\//.test(relayUrl)) {
195
209
  process.stdout.write(PAIR_HELP);
196
210
  process.exitCode = values.help ? 0 : 1;
@@ -4,6 +4,7 @@ export interface TaPackageLoaderOptions {
4
4
  additionalExtensionPaths: string[];
5
5
  extensionsOverride(result: LoadExtensionsResult): LoadExtensionsResult;
6
6
  skillsOverride<T extends {
7
+ name: string;
7
8
  filePath: string;
8
9
  }, D extends {
9
10
  path?: string;
@@ -34,6 +35,28 @@ export interface TaBuiltinPackage {
34
35
  /** It has what pi loads: `pi.extensions`, `pi.skills` or `pi.prompts` of its package.json. */
35
36
  resources: boolean;
36
37
  }
38
+ /** What pi's `loadSkillsFromDir` gives: the skills of a directory, as its resource loader keeps them. */
39
+ export type TaSkillLoader = (options: {
40
+ dir: string;
41
+ source: string;
42
+ }) => {
43
+ skills: {
44
+ name: string;
45
+ filePath: string;
46
+ }[];
47
+ diagnostics: {
48
+ path?: string;
49
+ }[];
50
+ };
51
+ /** What a session's loader is told besides the agent directory. */
52
+ export interface TaLoaderSettings {
53
+ /** pi's package directory, of the built-in packages; default PI_PACKAGE_DIR. */
54
+ packageDir?: string;
55
+ /** pi's `loadSkillsFromDir`: with it, the skills of the packages of `extensions/` load too. */
56
+ loadSkills?: TaSkillLoader;
57
+ /** The `.ta` directory of a trusted project, whose `extensions/` holds packages of that project. */
58
+ projectDir?: string;
59
+ }
37
60
  /**
38
61
  * The pi packages that come with ta. They are on unless the user turned them off; they cannot be
39
62
  * removed. The build of apps/ta copies each to `packages/<name without scope>` of pi's package
@@ -60,9 +83,11 @@ export declare namespace TaPackages {
60
83
  /**
61
84
  * For pi's resource loader of a session: it loads every built-in package, its pi extensions, skills
62
85
  * and prompt templates, and keeps those of the packages that are on, read again on each reload, so
63
- * that a reload follows the setting.
86
+ * that a reload follows the setting. pi finds only the pi extensions of the packages of `extensions/`;
87
+ * with `loadSkills`, their skills load too, while the package is on (its pi extensions loaded, or, with
88
+ * none, not turned off in ta.json), so that a package Ta makes there is one thing, whatever it holds.
64
89
  */
65
- function loaderOptions(agentDir: string, packageDir?: string): TaPackageLoaderOptions;
90
+ function loaderOptions(agentDir: string, settings?: TaLoaderSettings): TaPackageLoaderOptions;
66
91
  /** pi's command line with the built-in packages that are on, unless it manages packages or loads no extensions. */
67
92
  function withExtensions(argv: string[], agentDir: string, packageDir?: string): string[];
68
93
  }
@@ -24,6 +24,7 @@ var TaPackages;
24
24
  '@celljs/ta-cron',
25
25
  '@celljs/ta-notify',
26
26
  '@celljs/ta-recall',
27
+ '@celljs/ta-initiative',
27
28
  '@celljs/ta-glance',
28
29
  '@celljs/ta-games',
29
30
  '@celljs/ta-bots',
@@ -31,6 +32,11 @@ var TaPackages;
31
32
  '@celljs/ta-manual',
32
33
  '@celljs/ta-share',
33
34
  '@celljs/ta-rooms',
35
+ '@celljs/ta-nearby',
36
+ '@celljs/ta-moments',
37
+ '@celljs/ta-sync',
38
+ '@celljs/ta-sync-cloud',
39
+ '@celljs/ta-team',
34
40
  ];
35
41
  /** In the agent directory. */
36
42
  TaPackages.SETTINGS_FILE = 'ta.json';
@@ -91,9 +97,12 @@ var TaPackages;
91
97
  /**
92
98
  * For pi's resource loader of a session: it loads every built-in package, its pi extensions, skills
93
99
  * and prompt templates, and keeps those of the packages that are on, read again on each reload, so
94
- * that a reload follows the setting.
100
+ * that a reload follows the setting. pi finds only the pi extensions of the packages of `extensions/`;
101
+ * with `loadSkills`, their skills load too, while the package is on (its pi extensions loaded, or, with
102
+ * none, not turned off in ta.json), so that a package Ta makes there is one thing, whatever it holds.
95
103
  */
96
- function loaderOptions(agentDir, packageDir) {
104
+ function loaderOptions(agentDir, settings = {}) {
105
+ const { packageDir, loadSkills, projectDir } = settings;
97
106
  const roots = builtins(packageDir)
98
107
  .filter(pkg => pkg.resources)
99
108
  .map(pkg => pkg.root);
@@ -103,19 +112,34 @@ var TaPackages;
103
112
  const off = roots.filter(root => !on.has(root));
104
113
  return (path) => !path || !off.some(root => path === root || path.startsWith(`${root}${node_path_1.sep}`));
105
114
  };
115
+ /** The files of the pi extensions loaded last, which tell the packages of `extensions/` that are on. */
116
+ let loaded = [];
106
117
  return {
107
118
  additionalExtensionPaths: roots,
108
119
  extensionsOverride: result => {
109
120
  const keep = keeper();
110
- return {
111
- ...result,
112
- extensions: result.extensions.filter(extension => keep(extension.resolvedPath) && keep(extension.path)),
113
- errors: result.errors.filter(error => keep(error.path)),
114
- };
121
+ const extensions = result.extensions.filter(extension => keep(extension.resolvedPath) && keep(extension.path));
122
+ loaded = extensions.flatMap(extension => [extension.resolvedPath, extension.path]);
123
+ return { ...result, extensions, errors: result.errors.filter(error => keep(error.path)) };
115
124
  },
116
125
  skillsOverride: result => {
117
126
  const keep = keeper();
118
- return { ...result, skills: result.skills.filter(skill => keep(skill.filePath)), diagnostics: result.diagnostics.filter(d => keep(d.path)) };
127
+ const skills = result.skills.filter(skill => keep(skill.filePath));
128
+ const diagnostics = result.diagnostics.filter(d => keep(d.path));
129
+ if (loadSkills) {
130
+ const dirs = [(0, node_path_1.join)(agentDir, 'extensions'), ...(projectDir ? [(0, node_path_1.join)(projectDir, 'extensions')] : [])];
131
+ const off = disabledWeb(agentDir);
132
+ const on = (pkg) => (pkg.extensions ? loaded.some(path => within(pkg.root, path)) : !off.has(pkg.root));
133
+ for (const pkg of dirs.flatMap(directoryPackages).filter(on)) {
134
+ for (const dir of pkg.skills) {
135
+ const found = loadSkills({ dir, source: 'user' });
136
+ // A skill of the same name or file pi loaded already stays pi's.
137
+ skills.push(...found.skills.filter(skill => !skills.some(other => other.name === skill.name || other.filePath === skill.filePath)));
138
+ diagnostics.push(...found.diagnostics);
139
+ }
140
+ }
141
+ }
142
+ return { ...result, skills, diagnostics };
119
143
  },
120
144
  promptsOverride: result => {
121
145
  const keep = keeper();
@@ -151,6 +175,35 @@ var TaPackages;
151
175
  return undefined;
152
176
  }
153
177
  }
178
+ /** The packages of an `extensions/` directory that have skills. */
179
+ function directoryPackages(dir) {
180
+ if (!(0, node_fs_1.existsSync)(dir)) {
181
+ return [];
182
+ }
183
+ return subdirectories(dir).flatMap(root => {
184
+ let manifest;
185
+ try {
186
+ manifest = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(root, 'package.json'), 'utf8'));
187
+ }
188
+ catch (_a) {
189
+ return [];
190
+ }
191
+ const paths = (key) => {
192
+ var _a;
193
+ const declared = (_a = manifest === null || manifest === void 0 ? void 0 : manifest.pi) === null || _a === void 0 ? void 0 : _a[key];
194
+ return (Array.isArray(declared) ? declared : typeof declared === 'string' ? [declared] : []).filter((path) => typeof path === 'string' && path !== '');
195
+ };
196
+ // As pi reads a package: what its manifest names, else the conventional directory.
197
+ const skills = ((manifest === null || manifest === void 0 ? void 0 : manifest.pi) ? paths('skills') : ['skills'])
198
+ .map(path => (0, node_path_1.resolve)(root, path))
199
+ .filter(path => within(root, path) && (0, node_fs_1.existsSync)(path));
200
+ const extensions = (manifest === null || manifest === void 0 ? void 0 : manifest.pi) ? paths('extensions').length > 0 : ['index.ts', 'index.js'].some(file => (0, node_fs_1.existsSync)((0, node_path_1.join)(root, file)));
201
+ return skills.length > 0 ? [{ root, skills, extensions }] : [];
202
+ });
203
+ }
204
+ function within(root, path) {
205
+ return !!path && (path === root || path.startsWith(`${root}${node_path_1.sep}`));
206
+ }
154
207
  function subdirectories(dir) {
155
208
  return (0, node_fs_1.readdirSync)(dir, { withFileTypes: true })
156
209
  .filter(entry => entry.isDirectory() && !entry.name.startsWith('.'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-harness",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "description": "The agent runtime of Ta on pi: branding, session locks and execution environment adapters",
5
5
  "homepage": "https://github.com/cellbang/cell",
6
6
  "bugs": {
@@ -29,9 +29,9 @@
29
29
  "watch": "tsc -b -w --preserveWatchOutput"
30
30
  },
31
31
  "dependencies": {
32
- "@celljs/ai-coding-agent": "4.12.0",
33
- "@celljs/ta-exec": "4.12.0",
34
- "@celljs/ta-relay": "4.12.0",
32
+ "@celljs/ai-coding-agent": "4.13.0",
33
+ "@celljs/ta-exec": "4.13.0",
34
+ "@celljs/ta-relay": "4.13.0",
35
35
  "@earendil-works/pi-coding-agent": "^1.5.2",
36
36
  "@earendil-works/pi-mcp": "^1.5.2"
37
37
  },