pi-agent-ide 0.3.0 → 0.4.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.
Files changed (124) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +1 -0
  3. package/dist/{chunk-RHV5STR3.js → chunk-3SE372WC.js} +3 -3
  4. package/dist/{chunk-EWNWKDMP.js → chunk-6DZA4CLO.js} +1 -1
  5. package/dist/{chunk-VZJIZXSH.js → chunk-7JYQMAEL.js} +1 -1
  6. package/dist/{chunk-SSHZEWWV.js → chunk-DQF5QMJ2.js} +1 -1
  7. package/dist/chunk-EJ5OACQM.js +1 -0
  8. package/dist/{chunk-CW53ZTU3.js → chunk-GFW5QPQV.js} +1 -1
  9. package/dist/chunk-J34VKQGJ.js +1 -0
  10. package/dist/{chunk-CEKXBS55.js → chunk-TI5GMJ7Q.js} +1 -1
  11. package/dist/chunk-XSTHESNR.js +25 -0
  12. package/dist/{chunk-LRYE2WCN.js → chunk-Y7ZMR4LT.js} +1 -1
  13. package/dist/entry-10.js +1 -1
  14. package/dist/entry-14.js +1 -1
  15. package/dist/entry-21.js +1 -1
  16. package/dist/entry-26.js +1 -1
  17. package/dist/entry-28.js +1 -1
  18. package/dist/entry-32.js +1 -1
  19. package/dist/entry-37.js +1 -1
  20. package/dist/entry-40.js +1 -1
  21. package/dist/entry-46.js +1 -1
  22. package/dist/entry-49.js +1 -1
  23. package/dist/entry-51.js +1 -1
  24. package/dist/entry-53.js +1 -1
  25. package/dist/entry-54.js +1 -1
  26. package/dist/entry-56.js +1 -1
  27. package/dist/entry-59.js +1 -1
  28. package/dist/entry-62.js +1 -1
  29. package/dist/entry-69.js +1 -1
  30. package/dist/entry-70.js +18 -18
  31. package/dist/entry-71.js +2 -2
  32. package/dist/entry-72.js +1 -1
  33. package/dist/entry-75.js +1 -1
  34. package/dist/pi-agent-ide.js +3 -3
  35. package/docs/tools.md +11 -0
  36. package/node_modules/pi-agent-doctor/package.json +1 -1
  37. package/node_modules/pi-agent-filesystem/package.json +6 -6
  38. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  39. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  40. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  41. package/node_modules/pi-agent-ide-ast/package.json +9 -9
  42. package/node_modules/pi-agent-ide-changes/package.json +6 -6
  43. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  44. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  45. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  46. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  47. package/node_modules/pi-agent-image/package.json +2 -2
  48. package/node_modules/pi-agent-invariant/package.json +1 -1
  49. package/node_modules/pi-agent-pdf/package.json +2 -2
  50. package/node_modules/pi-agent-read/package.json +6 -6
  51. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +3 -0
  52. package/node_modules/pi-agent-resource/package.json +1 -1
  53. package/node_modules/pi-agent-resource/src/resource.ts +2 -0
  54. package/node_modules/pi-agent-search/package.json +3 -3
  55. package/node_modules/pi-agent-search-text/package.json +6 -6
  56. package/node_modules/pi-agent-text/package.json +2 -2
  57. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  58. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  59. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  60. package/node_modules/pi-agent-text-editor/package.json +8 -8
  61. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -1
  62. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  63. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +41 -4
  64. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +12 -2
  65. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  66. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +1 -2
  67. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  68. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  69. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  70. package/node_modules/pi-agent-web/package.json +6 -6
  71. package/node_modules/pi-agent-web-html/package.json +2 -2
  72. package/node_modules/pi-agent-web-image/package.json +3 -3
  73. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  74. package/node_modules/pi-agent-web-text/package.json +3 -3
  75. package/package.json +36 -33
  76. package/src/composite/builtin-extensions.ts +6 -0
  77. package/src/composite/extensions-config.ts +18 -0
  78. package/src/composite/module-labels.ts +4 -0
  79. package/src/composite/module-settings-store.ts +17 -1
  80. package/src/composite/module-settings.ts +34 -4
  81. package/src/composite/preferences.ts +26 -0
  82. package/src/composite/settings-panel.ts +62 -30
  83. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
  84. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  85. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  86. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  87. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +6 -6
  88. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  89. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  90. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  91. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  92. package/src/extensions/pi-agent-read/package.json +6 -6
  93. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +3 -0
  94. package/src/extensions/pi-agent-search/package.json +3 -3
  95. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  96. package/src/extensions/pi-agent-text-editor/package.json +8 -8
  97. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  98. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  99. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  100. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  101. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +1 -2
  102. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  103. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -1
  104. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  105. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +41 -4
  106. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +12 -2
  107. package/src/pi-agent-ide.ts +2 -1
  108. package/src/plugins/pi-agent-ide-ast/package.json +9 -9
  109. package/src/plugins/pi-agent-ide-changes/package.json +6 -6
  110. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  111. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  112. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  113. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  114. package/src/plugins/pi-agent-ide-terminal/index.ts +34 -0
  115. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +238 -0
  116. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +461 -0
  117. package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +127 -0
  118. package/src/plugins/pi-agent-ide-terminal/src/search.ts +159 -0
  119. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +529 -0
  120. package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +56 -0
  121. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +157 -0
  122. package/src/plugins/pi-agent-ide-terminal/src/types.ts +66 -0
  123. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +336 -0
  124. package/dist/chunk-VCCMVQXU.js +0 -1
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "pi-agent-text-editor-stale-anchor",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-invariant": "0.3.0",
7
- "pi-agent-read": "0.3.0",
8
- "pi-agent-text-editor": "0.3.0"
6
+ "pi-agent-invariant": "0.4.0",
7
+ "pi-agent-read": "0.4.0",
8
+ "pi-agent-text-editor": "0.4.0"
9
9
  },
10
10
  "pi": {
11
11
  "extensions": [
@@ -40,7 +40,7 @@ export interface ScriptIndexOperation {
40
40
  }
41
41
  export const TEXT_EDITOR_PROTOCOL = "pi-agent-text-editor";
42
42
 
43
- export const TEXT_EDITOR_API_VERSION = 20;
43
+ export const TEXT_EDITOR_API_VERSION = 21;
44
44
 
45
45
  export const TEXT_POSITION_ANCHOR_KIND = "pi-agent-text-editor/position";
46
46
 
@@ -13,12 +13,15 @@ export type TextEditorToolRendererRegistration = Pick<
13
13
  > & {
14
14
  readonly tool: TextEditorToolId;
15
15
  readonly fallback?: boolean;
16
+ /** Select this renderer for matching tool arguments or results; unmatched values use the previous renderer. */
17
+ readonly matches?: (value: unknown, phase: "call" | "result") => boolean;
16
18
  };
17
19
 
18
20
  const rendererFunctionSchema = Type.Function([], Type.Unknown());
19
21
  const toolRendererRegistrationSchema = Type.Object({
20
22
  tool: Type.String({ pattern: "\\S" }),
21
23
  fallback: Type.Optional(Type.Boolean()),
24
+ matches: Type.Optional(rendererFunctionSchema),
22
25
  renderCall: Type.Optional(rendererFunctionSchema),
23
26
  renderResult: Type.Optional(rendererFunctionSchema),
24
27
  renderShell: Type.Optional(Type.Union([Type.Literal("default"), Type.Literal("self")])),
@@ -1352,7 +1352,13 @@ interface FinalizeTextResourceRequest<Result> {
1352
1352
  async function finalizeTextResource<Result>(
1353
1353
  request: FinalizeTextResourceRequest<Result>,
1354
1354
  ): Promise<Exclude<TextResourceEditOutcome<Result>, { readonly kind: "failed" }>> {
1355
- if (request.postProcessingFinal && !request.context.signal?.aborted && request.resource.read) {
1355
+ const skipPostEdit = request.resource.skipPostEdit === true;
1356
+ if (
1357
+ !skipPostEdit &&
1358
+ request.postProcessingFinal &&
1359
+ !request.context.signal?.aborted &&
1360
+ request.resource.read
1361
+ ) {
1356
1362
  const current = await request.resource.read(
1357
1363
  request.context.signal ? { signal: request.context.signal } : {},
1358
1364
  );
@@ -1368,6 +1374,7 @@ async function finalizeTextResource<Result>(
1368
1374
  );
1369
1375
  }
1370
1376
  const deferred =
1377
+ !skipPostEdit &&
1371
1378
  !request.postProcessingFinal &&
1372
1379
  deferPostEdit(request.resource.source, () =>
1373
1380
  finalizeTextResource({ ...request, postProcessingFinal: true }),
@@ -1386,7 +1393,7 @@ async function finalizeTextResource<Result>(
1386
1393
  ? [{ id: "post-edit-scope", data: { formatting: { status: "deferred" } } }]
1387
1394
  : [];
1388
1395
 
1389
- for (const registration of deferred || request.context.signal?.aborted
1396
+ for (const registration of skipPostEdit || deferred || request.context.signal?.aborted
1390
1397
  ? []
1391
1398
  : request.postEditHandlers) {
1392
1399
  try {
@@ -1402,7 +1409,7 @@ async function finalizeTextResource<Result>(
1402
1409
 
1403
1410
  let finalText = request.requestedText;
1404
1411
 
1405
- if (request.resource.read !== undefined) {
1412
+ if (!skipPostEdit && request.resource.read !== undefined) {
1406
1413
  try {
1407
1414
  const reread = await request.resource.read(
1408
1415
  request.context.signal === undefined ? {} : { signal: request.context.signal },
@@ -2296,11 +2303,41 @@ function mergeToolRenderer(
2296
2303
  current: TextEditorToolRendererRegistration | undefined,
2297
2304
  registration: TextEditorToolRendererRegistration,
2298
2305
  ): TextEditorToolRendererRegistration {
2306
+ if (registration.matches !== undefined) {
2307
+ const renderCall = registration.renderCall;
2308
+ const renderResult = registration.renderResult;
2309
+ const currentRenderCall = current?.renderCall;
2310
+ const currentRenderResult = current?.renderResult;
2311
+ return {
2312
+ ...current,
2313
+ tool: registration.tool,
2314
+ ...(renderCall === undefined
2315
+ ? {}
2316
+ : currentRenderCall === undefined
2317
+ ? { renderCall }
2318
+ : {
2319
+ renderCall: (...arguments_: Parameters<typeof renderCall>) =>
2320
+ registration.matches?.(arguments_[0], "call") === true
2321
+ ? renderCall(...arguments_)
2322
+ : currentRenderCall(...arguments_),
2323
+ }),
2324
+ ...(renderResult === undefined
2325
+ ? {}
2326
+ : currentRenderResult === undefined
2327
+ ? { renderResult }
2328
+ : {
2329
+ renderResult: (...arguments_: Parameters<typeof renderResult>) =>
2330
+ registration.matches?.(arguments_[0], "result") === true
2331
+ ? renderResult(...arguments_)
2332
+ : currentRenderResult(...arguments_),
2333
+ }),
2334
+ };
2335
+ }
2299
2336
  const merged =
2300
2337
  registration.fallback === true
2301
2338
  ? { ...registration, ...current, tool: registration.tool }
2302
2339
  : { ...current, ...registration, tool: registration.tool };
2303
- const { fallback: _fallback, ...renderer } = merged;
2340
+ const { fallback: _fallback, matches: _matches, ...renderer } = merged;
2304
2341
  return renderer;
2305
2342
  }
2306
2343
 
@@ -84,6 +84,8 @@ export function createTextTool<TParameters extends TSchema>(
84
84
  getLastResolvedSource: () => string | undefined,
85
85
  ): ToolDefinition<TParameters, FileMutationBatchResult> {
86
86
  const renderer = core.getToolRenderer(definition.name);
87
+ const initialRenderCall = renderer?.renderCall;
88
+ const initialRenderResult = renderer?.renderResult;
87
89
 
88
90
  const tool = withToolCallInterceptionRendering<TParameters, FileMutationBatchResult, unknown>(
89
91
  defineTool<TParameters, FileMutationBatchResult, unknown>({
@@ -105,8 +107,16 @@ export function createTextTool<TParameters extends TSchema>(
105
107
  definition.anchors ?? [],
106
108
  ),
107
109
  ...(renderer?.renderShell !== undefined && { renderShell: renderer.renderShell }),
108
- ...(renderer?.renderCall !== undefined && { renderCall: renderer.renderCall }),
109
- ...(renderer?.renderResult !== undefined && { renderResult: renderer.renderResult }),
110
+ ...(initialRenderCall !== undefined && {
111
+ renderCall: (...arguments_: Parameters<typeof initialRenderCall>) =>
112
+ (core.getToolRenderer(definition.name)?.renderCall ?? initialRenderCall)(...arguments_),
113
+ }),
114
+ ...(initialRenderResult !== undefined && {
115
+ renderResult: (...arguments_: Parameters<typeof initialRenderResult>) =>
116
+ (core.getToolRenderer(definition.name)?.renderResult ?? initialRenderResult)(
117
+ ...arguments_,
118
+ ),
119
+ }),
110
120
  async execute(toolCallId, parameters, signal, onUpdate, context) {
111
121
  const directExecute = () =>
112
122
  executeTextMutation(
@@ -3,6 +3,7 @@ import {
3
3
  readPiAgentIdeExtensionsConfig,
4
4
  resolvePiAgentIdeExtensionsConfigPaths,
5
5
  } from "#src/composite/extensions-config.js";
6
+ import { AGENT_IDE_PREFERENCES } from "#src/composite/preferences.js";
6
7
  import { selectBuiltinExtensions } from "#src/composite/selection.js";
7
8
  import { registerModuleSettings } from "#src/composite/module-settings.js";
8
9
  import { createFeatureFlags } from "#src/composite/feature-flags.js";
@@ -65,7 +66,7 @@ export default async function registerUnifiedPiAgentIde(pi: ExtensionAPI): Promi
65
66
  group: "ui",
66
67
  default: false,
67
68
  });
68
- registerModuleSettings(pi, flags.definitions);
69
+ registerModuleSettings(pi, flags.definitions, AGENT_IDE_PREFERENCES);
69
70
  const { enabled } = selectBuiltinExtensions(BUILTIN_EXTENSIONS, config.disabled, config.enabled);
70
71
 
71
72
  for (const extension of enabled) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-ide-ast",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -14,13 +14,13 @@
14
14
  "dependencies": {
15
15
  "@tree-sitter-grammars/tree-sitter-toml": "^0.7.0",
16
16
  "@tree-sitter-grammars/tree-sitter-yaml": "^0.7.1",
17
- "pi-agent-doctor": "0.3.0",
18
- "pi-agent-invariant": "0.3.0",
19
- "pi-agent-read": "0.3.0",
20
- "pi-agent-resource": "0.3.0",
21
- "pi-agent-search": "0.3.0",
22
- "pi-agent-text": "0.3.0",
23
- "pi-agent-text-editor": "0.3.0",
17
+ "pi-agent-doctor": "0.4.0",
18
+ "pi-agent-invariant": "0.4.0",
19
+ "pi-agent-read": "0.4.0",
20
+ "pi-agent-resource": "0.4.0",
21
+ "pi-agent-search": "0.4.0",
22
+ "pi-agent-text": "0.4.0",
23
+ "pi-agent-text-editor": "0.4.0",
24
24
  "tree-sitter-cpp": "^0.23.4",
25
25
  "tree-sitter-javascript": "^0.25.0",
26
26
  "tree-sitter-json": "^0.24.8",
@@ -36,6 +36,6 @@
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@earendil-works/pi-coding-agent": "*",
39
- "pi-agent-ide": "0.3.0"
39
+ "pi-agent-ide": "0.4.0"
40
40
  }
41
41
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-ide-changes",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -13,11 +13,11 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "diff": "^9.0.0",
16
- "pi-agent-doctor": "0.3.0",
17
- "pi-agent-invariant": "0.3.0",
18
- "pi-agent-read": "0.3.0",
19
- "pi-agent-text": "0.3.0",
20
- "pi-agent-text-editor": "0.3.0"
16
+ "pi-agent-doctor": "0.4.0",
17
+ "pi-agent-invariant": "0.4.0",
18
+ "pi-agent-read": "0.4.0",
19
+ "pi-agent-text": "0.4.0",
20
+ "pi-agent-text-editor": "0.4.0"
21
21
  },
22
22
  "pi": {
23
23
  "extensions": [
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "pi-agent-ide-formatter",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-doctor": "0.3.0"
6
+ "pi-agent-doctor": "0.4.0"
7
7
  },
8
8
  "pi": {
9
9
  "extensions": [
@@ -12,6 +12,6 @@
12
12
  },
13
13
  "peerDependencies": {
14
14
  "@earendil-works/pi-coding-agent": "*",
15
- "pi-agent-ide": "0.3.0"
15
+ "pi-agent-ide": "0.4.0"
16
16
  }
17
17
  }
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "pi-agent-ide-languages",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-doctor": "0.3.0"
6
+ "pi-agent-doctor": "0.4.0"
7
7
  },
8
8
  "pi": {
9
9
  "extensions": [
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "pi-agent-ide-lint",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-doctor": "0.3.0",
7
- "pi-agent-invariant": "0.3.0",
8
- "pi-agent-read": "0.3.0",
9
- "pi-agent-resource": "0.3.0",
10
- "pi-agent-text": "0.3.0"
6
+ "pi-agent-doctor": "0.4.0",
7
+ "pi-agent-invariant": "0.4.0",
8
+ "pi-agent-read": "0.4.0",
9
+ "pi-agent-resource": "0.4.0",
10
+ "pi-agent-text": "0.4.0"
11
11
  },
12
12
  "pi": {
13
13
  "extensions": [
@@ -16,6 +16,6 @@
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@earendil-works/pi-coding-agent": "*",
19
- "pi-agent-ide": "0.3.0"
19
+ "pi-agent-ide": "0.4.0"
20
20
  }
21
21
  }
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "pi-agent-ide-lsp",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "cross-spawn": "^7.0.6",
7
- "pi-agent-doctor": "0.3.0",
8
- "pi-agent-invariant": "0.3.0",
9
- "pi-agent-read": "0.3.0",
10
- "pi-agent-resource": "0.3.0",
11
- "pi-agent-search": "0.3.0",
12
- "pi-agent-text": "0.3.0",
13
- "pi-agent-text-editor": "0.3.0",
7
+ "pi-agent-doctor": "0.4.0",
8
+ "pi-agent-invariant": "0.4.0",
9
+ "pi-agent-read": "0.4.0",
10
+ "pi-agent-resource": "0.4.0",
11
+ "pi-agent-search": "0.4.0",
12
+ "pi-agent-text": "0.4.0",
13
+ "pi-agent-text-editor": "0.4.0",
14
14
  "vscode-jsonrpc": "^9.0.0",
15
15
  "vscode-uri": "^3.1.0"
16
16
  },
@@ -21,6 +21,6 @@
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@earendil-works/pi-coding-agent": "*",
24
- "pi-agent-ide": "0.3.0"
24
+ "pi-agent-ide": "0.4.0"
25
25
  }
26
26
  }
@@ -0,0 +1,34 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import {
3
+ readPiAgentIdeExtensionsConfig,
4
+ resolvePiAgentIdeExtensionsConfigPaths,
5
+ } from "#src/composite/extensions-config.js";
6
+
7
+ import { registerTerminalResources } from "#src/plugins/pi-agent-ide-terminal/src/resources.js";
8
+ import { registerTerminalSearch } from "#src/plugins/pi-agent-ide-terminal/src/search.js";
9
+ import { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
10
+ import { resolveShellProfile } from "#src/plugins/pi-agent-ide-terminal/src/shell-profile.js";
11
+ import { registerTerminalTools } from "#src/plugins/pi-agent-ide-terminal/src/tools.js";
12
+ import { TerminalUi } from "#src/plugins/pi-agent-ide-terminal/src/ui.js";
13
+
14
+ /** Register the platform-aware terminal runner and shell session resources. */
15
+ export default async function registerTerminal(pi: ExtensionAPI): Promise<void> {
16
+ const manager = new TerminalSessionManager();
17
+ const profile = resolveShellProfile();
18
+ const config = await readPiAgentIdeExtensionsConfig(resolvePiAgentIdeExtensionsConfigPaths());
19
+ const activity = terminalActivityMode(config.preferences?.["terminal.activity"]);
20
+ const ui = new TerminalUi(pi, manager, activity);
21
+
22
+ await Promise.all([registerTerminalResources(pi, manager), registerTerminalSearch(pi, manager)]);
23
+ registerTerminalTools(pi, manager, profile, ui);
24
+
25
+ pi.on("session_start", (_event, context) => ui.bind(context));
26
+ pi.on("session_shutdown", async () => {
27
+ ui.dispose();
28
+ await manager.dispose();
29
+ });
30
+ }
31
+
32
+ function terminalActivityMode(value: string | undefined): "detailed" | "compact" | "off" {
33
+ return value === "compact" || value === "off" ? value : "detailed";
34
+ }
@@ -0,0 +1,238 @@
1
+ import path from "node:path";
2
+ import { stripVTControlCharacters } from "node:util";
3
+
4
+ import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
5
+ import { Text, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
6
+
7
+ import { COMPACT_READ_ROWS } from "#src/extensions/pi-agent-read/src/core/tools/read/read-renderer.js";
8
+ import type {
9
+ ShellProfile,
10
+ TerminalSessionSnapshot,
11
+ TerminalSessionStatus,
12
+ } from "#src/plugins/pi-agent-ide-terminal/src/types.js";
13
+
14
+ type TerminalTheme = Pick<Theme, "fg">;
15
+
16
+ /** Render a stable shell prompt for a run tool call. */
17
+ export function renderRunCall(
18
+ command: string,
19
+ background: boolean,
20
+ cwd: string,
21
+ profile: ShellProfile,
22
+ theme: TerminalTheme,
23
+ ): Component {
24
+ const mode = background ? "background" : "wait";
25
+ const heading = `${theme.fg("toolTitle", profile.displayName.toLocaleLowerCase())} ${theme.fg("muted", `· ${shortCwd(cwd)} · ${mode}`)}`;
26
+ return new Text(
27
+ `${heading}\n${theme.fg("accent", promptMarker(profile.family))} ${command}`,
28
+ 0,
29
+ 0,
30
+ );
31
+ }
32
+
33
+ /** Render only the outcome below an already-visible terminal action call. */
34
+ export function renderTerminalActionResult(
35
+ action: "write" | "insert" | "delete",
36
+ changedLines: readonly string[],
37
+ theme: TerminalTheme,
38
+ ): Component {
39
+ const lines = changedLines.map((line) => ` ${theme.fg("dim", line)}`);
40
+ lines.push(theme.fg("success", action === "delete" ? "✓ stopped" : "✓ sent"));
41
+ return new Text(lines.join("\n"), 0, 0);
42
+ }
43
+
44
+ /** Render a terminal resource action without exposing its internal shell address. */
45
+ export function renderTerminalAction(
46
+ snapshot: Partial<TerminalSessionSnapshot>,
47
+ action: "read" | "write" | "insert" | "delete" | "search",
48
+ value: string,
49
+ changedLines: readonly string[],
50
+ theme: TerminalTheme,
51
+ ): Component {
52
+ const lines = [terminalIdentity(snapshot, theme), theme.fg("accent", `${action} ${value}`)];
53
+ if (changedLines.length > 0)
54
+ lines.push(...changedLines.map((line) => ` ${theme.fg("dim", line)}`));
55
+ return new Text(lines.join("\n"), 0, 0);
56
+ }
57
+ /** Render a terminal result as a compact or expanded pseudo-terminal card. */
58
+ export function renderTerminalResult(
59
+ snapshot: Partial<TerminalSessionSnapshot>,
60
+ expanded: boolean,
61
+ theme: TerminalTheme,
62
+ action?: string,
63
+ ): Component {
64
+ const lines = terminalCardLines(
65
+ snapshot,
66
+ expanded ? Number.POSITIVE_INFINITY : COMPACT_READ_ROWS,
67
+ theme,
68
+ );
69
+ if (action !== undefined) lines.splice(1, 1, theme.fg("accent", action));
70
+ return new Text(lines.join("\n"), 0, 0);
71
+ }
72
+
73
+ /** Render the result beneath the already-visible run prompt without repeating the command. */
74
+ export function renderRunResult(
75
+ snapshot: Partial<TerminalSessionSnapshot>,
76
+ expanded: boolean,
77
+ theme: TerminalTheme,
78
+ ): Component {
79
+ if (expanded) return renderTerminalResult(snapshot, true, theme);
80
+ const window = outputWindow(snapshot.output ?? "", COMPACT_READ_ROWS);
81
+ const lines = [
82
+ ...(window.omitted > 0 ? [` ${theme.fg("muted", `… ${window.omitted} earlier lines`)}`] : []),
83
+ ...window.lines.map((line) => ` ${theme.fg("dim", line)}`),
84
+ ];
85
+ lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
86
+ return new Text(lines.join("\n"), 0, 0);
87
+ }
88
+ /** Render one live below-editor mini-card with changing state only at its tail. */
89
+ export function renderActiveTerminal(
90
+ snapshot: TerminalSessionSnapshot,
91
+ theme?: TerminalTheme,
92
+ ): string {
93
+ const color = (name: ThemeColor, text: string): string => theme?.fg(name, text) ?? text;
94
+ const heading = `${color("accent", snapshot.shell.toLocaleLowerCase())} ${color("muted", `· ${shortCwd(snapshot.cwd)} · ${snapshot.background ? "background" : "wait"}`)}`;
95
+ const lines = [
96
+ heading,
97
+ `${color("accent", promptMarker(snapshot.shellFamily))} ${oneLine(snapshot.command, 84)}`,
98
+ ];
99
+ const tail = outputTail(snapshot.output, 2);
100
+ if (tail.length > 0) lines.push(...tail.map((line) => ` ${color("dim", oneLine(line, 90))}`));
101
+ lines.push(statusLine(snapshot, color));
102
+ return lines.join("\n");
103
+ }
104
+
105
+ /** Build a concise completion or result card from immutable session data. */
106
+ export function terminalCardLines(
107
+ snapshot: Partial<TerminalSessionSnapshot>,
108
+ outputLines: number,
109
+ theme: TerminalTheme,
110
+ ): string[] {
111
+ const shell = (snapshot.shell ?? "terminal").toLocaleLowerCase();
112
+ const mode = snapshot.background === true ? "background" : "wait";
113
+ const cwd = snapshot.cwd === undefined ? "workspace" : shortCwd(snapshot.cwd);
114
+ const family = snapshot.shellFamily ?? "posix";
115
+ const lines = [
116
+ `${theme.fg("accent", shell)} ${theme.fg("muted", `· ${cwd} · ${mode}`)}`,
117
+ `${theme.fg("accent", promptMarker(family))} ${snapshot.command ?? ""}`,
118
+ ];
119
+ const window = outputWindow(snapshot.output ?? "", outputLines);
120
+ if (window.omitted > 0) lines.push(` ${theme.fg("muted", `… ${window.omitted} earlier lines`)}`);
121
+ if (window.lines.length > 0)
122
+ lines.push(...window.lines.map((line) => ` ${theme.fg("dim", line)}`));
123
+ lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
124
+ return lines;
125
+ }
126
+
127
+ /** Render bordered mini-cards modeled after the Herdr subagent activity widget. */
128
+ export function renderTerminalWidgetLines(
129
+ snapshots: readonly TerminalSessionSnapshot[],
130
+ width: number,
131
+ theme: TerminalTheme,
132
+ ): string[] {
133
+ if (snapshots.length === 0) return [];
134
+ const accent = (text: string): string => theme.fg("accent", text);
135
+ const lines = [borderTop("Terminals", `${snapshots.length} active`, width, accent)];
136
+ for (const snapshot of snapshots) {
137
+ const card = renderActiveTerminal(snapshot, theme).split("\n");
138
+ for (const line of card) lines.push(borderLine(` ${line} `, width, accent));
139
+ if (snapshot !== snapshots.at(-1)) lines.push(borderLine("", width, accent));
140
+ }
141
+ lines.push(borderBottom(width, accent));
142
+ return lines;
143
+ }
144
+
145
+ function borderTop(
146
+ title: string,
147
+ info: string,
148
+ width: number,
149
+ accent: (text: string) => string,
150
+ ): string {
151
+ if (width <= 1) return accent("╭");
152
+ const inner = width - 2;
153
+ const left = `─ ${title} `;
154
+ const right = ` ${info} ─`;
155
+ const fill = "─".repeat(Math.max(0, inner - visibleWidth(left) - visibleWidth(right)));
156
+ return accent(`╭${truncateToWidth(`${left}${fill}${right}`, inner).padEnd(inner, "─")}╮`);
157
+ }
158
+
159
+ function borderLine(line: string, width: number, accent: (text: string) => string): string {
160
+ if (width <= 1) return accent("│");
161
+ const inner = width - 2;
162
+ const clipped = truncateToWidth(line, inner);
163
+ return `${accent("│")}${clipped}${" ".repeat(Math.max(0, inner - visibleWidth(clipped)))}${accent("│")}`;
164
+ }
165
+
166
+ function borderBottom(width: number, accent: (text: string) => string): string {
167
+ return accent(width <= 1 ? "╰" : `╰${"─".repeat(width - 2)}╯`);
168
+ }
169
+ export function outputTail(output: string, count: number): readonly string[] {
170
+ return outputWindow(output, count).lines;
171
+ }
172
+
173
+ function outputWindow(
174
+ output: string,
175
+ count: number,
176
+ ): { readonly lines: readonly string[]; readonly omitted: number } {
177
+ const lines = stripVTControlCharacters(output)
178
+ .replaceAll("\r", "")
179
+ .split("\n")
180
+ .map((line) => line.trimEnd());
181
+ if (lines.at(-1) === "") lines.pop();
182
+ const limit = Number.isFinite(count) ? Math.max(0, count) : lines.length;
183
+ const omitted = Math.max(0, lines.length - limit);
184
+ return { lines: lines.slice(omitted), omitted };
185
+ }
186
+
187
+ function statusLine(
188
+ snapshot: Partial<TerminalSessionSnapshot>,
189
+ color: (name: ThemeColor, text: string) => string,
190
+ ): string {
191
+ const status = snapshot.status ?? "running";
192
+ const icon = statusIcon(status);
193
+ const tone: ThemeColor =
194
+ status === "completed" ? "success" : status === "running" ? "accent" : "error";
195
+ const parts = [`${icon} ${status}`, formatElapsed(snapshot.elapsedMs ?? 0)];
196
+ if (snapshot.exitCode !== undefined) parts.push(`exit ${snapshot.exitCode}`);
197
+ else if (snapshot.signal !== undefined) parts.push(`signal ${snapshot.signal}`);
198
+ return color(tone, parts.join(" · "));
199
+ }
200
+
201
+ function statusIcon(status: TerminalSessionStatus): string {
202
+ if (status === "completed") return "✓";
203
+ if (status === "running") return "●";
204
+ if (status === "stopping") return "◌";
205
+ return "✗";
206
+ }
207
+
208
+ function promptMarker(family: ShellProfile["family"]): string {
209
+ return family === "powershell" ? "PS>" : family === "cmd" ? ">" : "$";
210
+ }
211
+
212
+ function terminalIdentity(
213
+ snapshot: Partial<TerminalSessionSnapshot>,
214
+ theme: TerminalTheme,
215
+ ): string {
216
+ const shell = (snapshot.shell ?? "terminal").toLocaleLowerCase();
217
+ const cwd = snapshot.cwd === undefined ? "workspace" : shortCwd(snapshot.cwd);
218
+ const mode = snapshot.background === true ? "background" : "wait";
219
+ const command = oneLine(snapshot.command ?? "process", 48);
220
+ return `${theme.fg("toolTitle", shell)} ${theme.fg("muted", `· ${cwd} · ${mode} · ${command}`)}`;
221
+ }
222
+ function shortCwd(cwd: string): string {
223
+ const home = process.env.HOME;
224
+ if (home !== undefined && (cwd === home || cwd.startsWith(`${home}${path.sep}`))) {
225
+ return `~${cwd.slice(home.length)}`;
226
+ }
227
+ return cwd;
228
+ }
229
+
230
+ function oneLine(value: string, max: number): string {
231
+ const line = value.replaceAll(/\s+/gu, " ").trim();
232
+ return line.length <= max ? line : `${line.slice(0, max - 1)}…`;
233
+ }
234
+
235
+ function formatElapsed(milliseconds: number): string {
236
+ if (milliseconds < 1_000) return `${milliseconds}ms`;
237
+ return `${(milliseconds / 1_000).toFixed(milliseconds < 10_000 ? 1 : 0)}s`;
238
+ }