@fleetagent/pi-coding-agent 0.0.9 → 0.0.11

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 (136) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +9 -0
  3. package/dist/cli/args.d.ts +3 -0
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +18 -0
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/core/agent-session.d.ts +13 -3
  8. package/dist/core/agent-session.d.ts.map +1 -1
  9. package/dist/core/agent-session.js +42 -8
  10. package/dist/core/agent-session.js.map +1 -1
  11. package/dist/core/bash-executor.d.ts +5 -3
  12. package/dist/core/bash-executor.d.ts.map +1 -1
  13. package/dist/core/bash-executor.js +4 -2
  14. package/dist/core/bash-executor.js.map +1 -1
  15. package/dist/core/extensions/index.d.ts +1 -1
  16. package/dist/core/extensions/index.d.ts.map +1 -1
  17. package/dist/core/extensions/index.js.map +1 -1
  18. package/dist/core/extensions/loader.d.ts.map +1 -1
  19. package/dist/core/extensions/loader.js +86 -0
  20. package/dist/core/extensions/loader.js.map +1 -1
  21. package/dist/core/extensions/runner.d.ts +3 -0
  22. package/dist/core/extensions/runner.d.ts.map +1 -1
  23. package/dist/core/extensions/runner.js +27 -0
  24. package/dist/core/extensions/runner.js.map +1 -1
  25. package/dist/core/extensions/types.d.ts +56 -3
  26. package/dist/core/extensions/types.d.ts.map +1 -1
  27. package/dist/core/extensions/types.js.map +1 -1
  28. package/dist/core/pi-agent.d.ts +2 -0
  29. package/dist/core/pi-agent.d.ts.map +1 -1
  30. package/dist/core/pi-agent.js +3 -0
  31. package/dist/core/pi-agent.js.map +1 -1
  32. package/dist/core/prompt-templates.d.ts +5 -0
  33. package/dist/core/prompt-templates.d.ts.map +1 -1
  34. package/dist/core/prompt-templates.js +115 -0
  35. package/dist/core/prompt-templates.js.map +1 -1
  36. package/dist/core/resource-loader.d.ts +15 -0
  37. package/dist/core/resource-loader.d.ts.map +1 -1
  38. package/dist/core/resource-loader.js +332 -40
  39. package/dist/core/resource-loader.js.map +1 -1
  40. package/dist/core/rules.d.ts +6 -0
  41. package/dist/core/rules.d.ts.map +1 -1
  42. package/dist/core/rules.js +216 -0
  43. package/dist/core/rules.js.map +1 -1
  44. package/dist/core/skills.d.ts +6 -0
  45. package/dist/core/skills.d.ts.map +1 -1
  46. package/dist/core/skills.js +216 -0
  47. package/dist/core/skills.js.map +1 -1
  48. package/dist/core/slash-commands.d.ts.map +1 -1
  49. package/dist/core/slash-commands.js +1 -0
  50. package/dist/core/slash-commands.js.map +1 -1
  51. package/dist/core/source-info.d.ts +2 -0
  52. package/dist/core/source-info.d.ts.map +1 -1
  53. package/dist/core/source-info.js +6 -0
  54. package/dist/core/source-info.js.map +1 -1
  55. package/dist/core/tools/bash.d.ts +6 -29
  56. package/dist/core/tools/bash.d.ts.map +1 -1
  57. package/dist/core/tools/bash.js +27 -101
  58. package/dist/core/tools/bash.js.map +1 -1
  59. package/dist/core/tools/edit-diff.d.ts +3 -2
  60. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  61. package/dist/core/tools/edit-diff.js +6 -8
  62. package/dist/core/tools/edit-diff.js.map +1 -1
  63. package/dist/core/tools/edit.d.ts +3 -16
  64. package/dist/core/tools/edit.d.ts.map +1 -1
  65. package/dist/core/tools/edit.js +12 -18
  66. package/dist/core/tools/edit.js.map +1 -1
  67. package/dist/core/tools/find.d.ts +3 -17
  68. package/dist/core/tools/find.d.ts.map +1 -1
  69. package/dist/core/tools/find.js +13 -25
  70. package/dist/core/tools/find.js.map +1 -1
  71. package/dist/core/tools/grep.d.ts +3 -14
  72. package/dist/core/tools/grep.d.ts.map +1 -1
  73. package/dist/core/tools/grep.js +95 -43
  74. package/dist/core/tools/grep.js.map +1 -1
  75. package/dist/core/tools/index.d.ts +17 -15
  76. package/dist/core/tools/index.d.ts.map +1 -1
  77. package/dist/core/tools/index.js +53 -52
  78. package/dist/core/tools/index.js.map +1 -1
  79. package/dist/core/tools/ls.d.ts +3 -20
  80. package/dist/core/tools/ls.d.ts.map +1 -1
  81. package/dist/core/tools/ls.js +11 -22
  82. package/dist/core/tools/ls.js.map +1 -1
  83. package/dist/core/tools/operations.d.ts +145 -0
  84. package/dist/core/tools/operations.d.ts.map +1 -0
  85. package/dist/core/tools/operations.js +418 -0
  86. package/dist/core/tools/operations.js.map +1 -0
  87. package/dist/core/tools/read.d.ts +3 -16
  88. package/dist/core/tools/read.d.ts.map +1 -1
  89. package/dist/core/tools/read.js +9 -15
  90. package/dist/core/tools/read.js.map +1 -1
  91. package/dist/core/tools/render-utils.d.ts +9 -0
  92. package/dist/core/tools/render-utils.d.ts.map +1 -1
  93. package/dist/core/tools/render-utils.js +14 -0
  94. package/dist/core/tools/render-utils.js.map +1 -1
  95. package/dist/core/tools/write.d.ts +3 -14
  96. package/dist/core/tools/write.d.ts.map +1 -1
  97. package/dist/core/tools/write.js +9 -12
  98. package/dist/core/tools/write.js.map +1 -1
  99. package/dist/index.d.ts +2 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +1 -1
  102. package/dist/index.js.map +1 -1
  103. package/dist/main.d.ts.map +1 -1
  104. package/dist/main.js +40 -5
  105. package/dist/main.js.map +1 -1
  106. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  107. package/dist/modes/interactive/components/tool-execution.js +2 -2
  108. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  109. package/dist/modes/interactive/interactive-mode.d.ts +3 -0
  110. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  111. package/dist/modes/interactive/interactive-mode.js +73 -9
  112. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  113. package/dist/modes/rpc/rpc-client.d.ts +9 -0
  114. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  115. package/dist/modes/rpc/rpc-client.js +14 -0
  116. package/dist/modes/rpc/rpc-client.js.map +1 -1
  117. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  118. package/dist/modes/rpc/rpc-mode.js +9 -0
  119. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  120. package/dist/modes/rpc/rpc-types.d.ts +22 -0
  121. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  122. package/dist/modes/rpc/rpc-types.js.map +1 -1
  123. package/docs/extensions.md +83 -5
  124. package/docs/usage.md +2 -0
  125. package/examples/extensions/README.md +0 -1
  126. package/examples/extensions/bash-spawn-hook.ts +2 -2
  127. package/examples/extensions/built-in-tool-renderer.ts +12 -5
  128. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  129. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  130. package/examples/extensions/minimal-mode.ts +9 -7
  131. package/examples/extensions/sandbox/index.ts +55 -56
  132. package/examples/extensions/sandbox/package.json +1 -1
  133. package/examples/extensions/with-deps/package.json +1 -1
  134. package/npm-shrinkwrap.json +12 -12
  135. package/package.json +4 -4
  136. package/examples/extensions/ssh.ts +0 -220
@@ -33,7 +33,7 @@ import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-man
33
33
  import { createSyntheticSourceInfo } from "./source-info.js";
34
34
  import { buildSystemPrompt } from "./system-prompt.js";
35
35
  import { createLocalBashOperations } from "./tools/bash.js";
36
- import { createAllToolDefinitions } from "./tools/index.js";
36
+ import { createAllToolDefinitions, DeferredSshToolOperations, LocalToolOperations, } from "./tools/index.js";
37
37
  import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
38
38
  /**
39
39
  * Parse a skill block from message text.
@@ -133,6 +133,7 @@ export class AgentSession {
133
133
  _initialActiveToolNames;
134
134
  _allowedToolNames;
135
135
  _baseToolsOverride;
136
+ _toolOperations;
136
137
  _sessionStartEvent;
137
138
  _extensionUIContext;
138
139
  _extensionCommandContextActions;
@@ -163,6 +164,7 @@ export class AgentSession {
163
164
  this._initialActiveToolNames = config.initialActiveToolNames;
164
165
  this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
165
166
  this._baseToolsOverride = config.baseToolsOverride;
167
+ this._toolOperations = config.toolOperations;
166
168
  this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
167
169
  // Always subscribe to agent events for internal handling
168
170
  // (session persistence, extensions, auto-compaction, retry logic)
@@ -178,6 +180,25 @@ export class AgentSession {
178
180
  get modelRegistry() {
179
181
  return this._modelRegistry;
180
182
  }
183
+ getToolOperations() {
184
+ const shellPath = this.settingsManager.getShellPath();
185
+ return this._toolOperations ?? createLocalBashOperations({ cwd: this.session.getCwd(), shellPath });
186
+ }
187
+ getToolBackendInfo() {
188
+ return this.getToolOperations().getBackendInfo?.() ?? { type: "local", cwd: this._cwd };
189
+ }
190
+ async configureSshSandbox(options) {
191
+ if (!(this._toolOperations instanceof DeferredSshToolOperations)) {
192
+ throw new Error("SSH sandbox can only be configured when Pi is started with --ssh-deferred");
193
+ }
194
+ return this._toolOperations.configure(options);
195
+ }
196
+ clearSshSandbox() {
197
+ if (!(this._toolOperations instanceof DeferredSshToolOperations)) {
198
+ throw new Error("SSH sandbox can only be cleared when Pi is started with --ssh-deferred");
199
+ }
200
+ this._toolOperations.clear();
201
+ }
181
202
  async _getRequiredRequestAuth(model) {
182
203
  const result = await this._modelRegistry.getApiKeyAndHeaders(model);
183
204
  if (!result.ok) {
@@ -709,7 +730,7 @@ export class AgentSession {
709
730
  const loadedRules = this._resourceLoader.getRules().rules;
710
731
  const loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;
711
732
  this._baseSystemPromptOptions = {
712
- cwd: this._cwd,
733
+ cwd: this._toolOperations?.cwd ?? this._cwd,
713
734
  skills: loadedSkills,
714
735
  rules: loadedRules,
715
736
  contextFiles: loadedContextFiles,
@@ -1120,7 +1141,7 @@ export class AgentSession {
1120
1141
  if (!skill)
1121
1142
  return text; // Unknown skill, pass through
1122
1143
  try {
1123
- const content = readFileSync(skill.filePath, "utf-8");
1144
+ const content = skill.content ?? readFileSync(skill.filePath, "utf-8");
1124
1145
  const body = stripFrontmatter(content).trim();
1125
1146
  const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${skill.baseDir}.\n\n${body}\n</skill>`;
1126
1147
  return args ? `${skillBlock}\n\n${args}` : skillBlock;
@@ -1145,7 +1166,7 @@ export class AgentSession {
1145
1166
  if (!rule)
1146
1167
  return text; // Unknown rule, pass through
1147
1168
  try {
1148
- const content = readFileSync(rule.filePath, "utf-8");
1169
+ const content = rule.content ?? readFileSync(rule.filePath, "utf-8");
1149
1170
  const body = stripFrontmatter(content).trim();
1150
1171
  const ruleBlock = `<rule name="${rule.name}" location="${rule.filePath}">\nReferences are relative to ${rule.baseDir}.\n\n${body}\n</rule>`;
1151
1172
  return args ? `${ruleBlock}\n\n${args}` : ruleBlock;
@@ -2046,6 +2067,7 @@ export class AgentSession {
2046
2067
  this.agent.state.model = refreshedModel;
2047
2068
  }
2048
2069
  _bindExtensionCore(runner) {
2070
+ const getToolOperations = () => this.getToolOperations();
2049
2071
  const getCommands = () => {
2050
2072
  const extensionCommands = runner.getRegisteredCommands().map((command) => ({
2051
2073
  name: command.invocationName,
@@ -2137,6 +2159,14 @@ export class AgentSession {
2137
2159
  this._requestExtensionCompaction(options);
2138
2160
  },
2139
2161
  getSystemPrompt: () => this.systemPrompt,
2162
+ getToolOperations,
2163
+ getToolBackendInfo: () => this.getToolBackendInfo(),
2164
+ execToolBackend: (command, options) => {
2165
+ const operations = getToolOperations();
2166
+ const prefix = this.settingsManager.getShellCommandPrefix();
2167
+ const resolvedCommand = prefix ? `${prefix}\n${command}` : command;
2168
+ return executeBashWithOperations(resolvedCommand, options?.cwd ?? operations.cwd, operations, options);
2169
+ },
2140
2170
  }, {
2141
2171
  registerProvider: (name, config) => {
2142
2172
  this._modelRegistry.registerProvider(name, config);
@@ -2228,14 +2258,15 @@ export class AgentSession {
2228
2258
  const autoResizeImages = this.settingsManager.getImageAutoResize();
2229
2259
  const shellCommandPrefix = this.settingsManager.getShellCommandPrefix();
2230
2260
  const shellPath = this.settingsManager.getShellPath();
2261
+ const operations = this._toolOperations ?? new LocalToolOperations(this._cwd, { shellPath });
2231
2262
  const baseToolDefinitions = this._baseToolsOverride
2232
2263
  ? Object.fromEntries(Object.entries(this._baseToolsOverride).map(([name, tool]) => [
2233
2264
  name,
2234
2265
  createToolDefinitionFromAgentTool(tool),
2235
2266
  ]))
2236
- : createAllToolDefinitions(this._cwd, {
2267
+ : createAllToolDefinitions(operations, {
2237
2268
  read: { autoResizeImages },
2238
- bash: { commandPrefix: shellCommandPrefix, shellPath },
2269
+ bash: { commandPrefix: shellCommandPrefix },
2239
2270
  });
2240
2271
  this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
2241
2272
  const extensionsResult = this._resourceLoader.getExtensions();
@@ -2381,7 +2412,7 @@ export class AgentSession {
2381
2412
  * @param command The bash command to execute
2382
2413
  * @param onChunk Optional streaming callback for output
2383
2414
  * @param options.excludeFromContext If true, command output won't be sent to LLM (!! prefix)
2384
- * @param options.operations Custom BashOperations for remote execution
2415
+ * @param options.operations Custom ToolOperations for remote execution
2385
2416
  */
2386
2417
  async executeBash(command, onChunk, options) {
2387
2418
  this._bashAbortController = new AbortController();
@@ -2390,7 +2421,10 @@ export class AgentSession {
2390
2421
  const shellPath = this.settingsManager.getShellPath();
2391
2422
  const resolvedCommand = prefix ? `${prefix}\n${command}` : command;
2392
2423
  try {
2393
- const result = await executeBashWithOperations(resolvedCommand, this.session.getCwd(), options?.operations ?? createLocalBashOperations({ shellPath }), {
2424
+ const operations = options?.operations ??
2425
+ this._toolOperations ??
2426
+ createLocalBashOperations({ cwd: this.session.getCwd(), shellPath });
2427
+ const result = await executeBashWithOperations(resolvedCommand, operations.cwd, operations, {
2394
2428
  onChunk,
2395
2429
  signal: this._bashAbortController.signal,
2396
2430
  });