@polka-codes/cli 0.4.6 → 0.4.7

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 (2) hide show
  1. package/dist/index.js +38 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24629,7 +24629,7 @@ var {
24629
24629
  Help
24630
24630
  } = import__.default;
24631
24631
  // package.json
24632
- var version = "0.4.6";
24632
+ var version = "0.4.7";
24633
24633
 
24634
24634
  // ../../node_modules/@anthropic-ai/sdk/version.mjs
24635
24635
  var VERSION = "0.36.2";
@@ -35149,9 +35149,9 @@ async function searchFiles(path2, regex, filePattern, cwd, excludeFiles) {
35149
35149
  }
35150
35150
 
35151
35151
  // src/provider.ts
35152
- var getProvider = (options) => {
35152
+ var getProvider = (agentName, config, options) => {
35153
35153
  const ig = import_ignore2.default().add(options.excludeFiles ?? []);
35154
- return {
35154
+ const provider2 = {
35155
35155
  readFile: async (path2) => {
35156
35156
  if (ig.ignores(path2)) {
35157
35157
  throw new Error(`Not allow to access file ${path2}`);
@@ -35215,8 +35215,31 @@ var getProvider = (options) => {
35215
35215
  reject(err);
35216
35216
  });
35217
35217
  });
35218
+ },
35219
+ attemptCompletion: async (result) => {
35220
+ const cmd = (config.hooks?.agents?.[agentName]?.beforeCompletion ?? config.hooks?.agents?.default?.beforeCompletion)?.trim();
35221
+ if (cmd) {
35222
+ try {
35223
+ const { exitCode, stdout, stderr } = await provider2.executeCommand(cmd, false);
35224
+ if (exitCode !== 0) {
35225
+ return `
35226
+ <command>${cmd}</command>
35227
+ <command_exit_code>${exitCode}</command_exit_code>
35228
+ <command_stdout>
35229
+ ${stdout}
35230
+ </command_stdout>
35231
+ <command_stderr>
35232
+ ${stderr}
35233
+ </command_stderr>`;
35234
+ }
35235
+ } catch (error) {
35236
+ console.warn(`Failed to execute hook: ${error}`);
35237
+ }
35238
+ }
35239
+ return;
35218
35240
  }
35219
35241
  };
35242
+ return provider2;
35220
35243
  };
35221
35244
 
35222
35245
  // src/Runner.ts
@@ -35240,7 +35263,7 @@ class Runner {
35240
35263
  if (typeof rules2 === "string") {
35241
35264
  rules2 = [rules2];
35242
35265
  }
35243
- const provider2 = getProvider({
35266
+ const providerOptions = {
35244
35267
  command: {
35245
35268
  onStarted(command) {
35246
35269
  console.log(`$ >>>> $ ${command}`);
@@ -35259,19 +35282,20 @@ class Runner {
35259
35282
  }
35260
35283
  },
35261
35284
  excludeFiles: options.config.excludeFiles
35262
- });
35285
+ };
35263
35286
  const platform = os.platform();
35264
35287
  const agents = [coderAgentInfo, architectAgentInfo];
35265
35288
  this.#multiAgent = new MultiAgent({
35266
35289
  createAgent: async (name) => {
35267
- switch (name.trim().toLowerCase()) {
35290
+ const agentName = name.trim().toLowerCase();
35291
+ switch (agentName) {
35268
35292
  case coderAgentInfo.name.toLowerCase():
35269
35293
  return new CoderAgent({
35270
35294
  ai: service,
35271
35295
  os: platform,
35272
35296
  customInstructions: rules2,
35273
35297
  scripts: options.config.scripts,
35274
- provider: provider2,
35298
+ provider: getProvider("coder", options.config, providerOptions),
35275
35299
  interactive: options.interactive,
35276
35300
  agents
35277
35301
  });
@@ -35281,7 +35305,7 @@ class Runner {
35281
35305
  os: platform,
35282
35306
  customInstructions: rules2,
35283
35307
  scripts: options.config.scripts,
35284
- provider: provider2,
35308
+ provider: getProvider("architect", options.config, providerOptions),
35285
35309
  interactive: options.interactive,
35286
35310
  agents
35287
35311
  });
@@ -39420,6 +39444,8 @@ var z2 = /* @__PURE__ */ Object.freeze({
39420
39444
  });
39421
39445
 
39422
39446
  // src/config.ts
39447
+ var agentNames = z2.enum(["coder", "architect"]);
39448
+ var agentNameOrDefault = z2.union([agentNames, z2.literal("default")]);
39423
39449
  var providerModelSchema = z2.object({
39424
39450
  provider: z2.string().optional(),
39425
39451
  model: z2.string().optional()
@@ -39438,13 +39464,14 @@ var configSchema = z2.object({
39438
39464
  defaultProvider: z2.string().optional(),
39439
39465
  defaultModel: z2.string().optional(),
39440
39466
  maxIterations: z2.number().int().positive().optional(),
39467
+ hooks: z2.object({
39468
+ agents: z2.record(agentNameOrDefault, z2.object({ beforeCompletion: z2.string().optional() })).optional()
39469
+ }).optional(),
39441
39470
  scripts: z2.record(z2.string(), z2.string().or(z2.object({
39442
39471
  command: z2.string(),
39443
39472
  description: z2.string()
39444
39473
  }))).optional(),
39445
- agents: z2.object({
39446
- default: agentSchema.optional()
39447
- }).catchall(agentSchema).optional(),
39474
+ agents: z2.record(agentNameOrDefault, agentSchema).optional(),
39448
39475
  commands: z2.object({
39449
39476
  default: providerModelSchema.optional()
39450
39477
  }).catchall(providerModelSchema).optional(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "license": "AGPL-3.0",
5
5
  "type": "module",
6
6
  "bin": {