shark-ai 0.4.18 → 0.4.20

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/dist/bin/shark.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  replaceLineRange,
38
38
  startSmartReplace,
39
39
  workflowManager
40
- } from "../chunk-VS6HH2CF.js";
40
+ } from "../chunk-O6YG3GZN.js";
41
41
  import {
42
42
  ConfigManager,
43
43
  FileLogger,
@@ -721,6 +721,7 @@ ${prompt}` : prompt;
721
721
  stackspot_knowledge: false,
722
722
  return_ks_in_response: true,
723
723
  deep_search_ks: false,
724
+ use_conversation: true,
724
725
  conversation_id: options.conversationId
725
726
  };
726
727
  const agentVersion = this.getAgentVersion();
@@ -3227,6 +3228,7 @@ var SkillManager = class {
3227
3228
  if (this.activeSkills.has(skillName)) {
3228
3229
  return `Skill ${skillName} is already active.`;
3229
3230
  }
3231
+ this.reset();
3230
3232
  const globalPath = path7.join(os.homedir(), ".shark", "skills", skillName, "SKILL.md");
3231
3233
  const localPath = path7.join(process.cwd(), ".agents", "skills", skillName, "SKILL.md");
3232
3234
  let skillPath = "";
@@ -3311,6 +3313,15 @@ var SubagentManager = class {
3311
3313
  hasSubagent(id) {
3312
3314
  return this.subagents.has(id);
3313
3315
  }
3316
+ getSubagentState(id) {
3317
+ return this.subagents.get(id);
3318
+ }
3319
+ updateSubagentSummary(id, summary) {
3320
+ const state = this.subagents.get(id);
3321
+ if (state) {
3322
+ state.summary = summary;
3323
+ }
3324
+ }
3314
3325
  sendMessage(recipient, message) {
3315
3326
  if (!this.mailbox.has(recipient)) {
3316
3327
  this.mailbox.set(recipient, []);
@@ -3353,7 +3364,7 @@ var SubagentManager = class {
3353
3364
  this.registerSubagent(id, sub.TypeName, sub.Role);
3354
3365
  const promise = (async () => {
3355
3366
  try {
3356
- const { interactiveDeveloperAgent: interactiveDeveloperAgent2 } = await import("./developer-agent-Z535MYGI.js");
3367
+ const { interactiveDeveloperAgent: interactiveDeveloperAgent2 } = await import("./developer-agent-7KAQMMOK.js");
3357
3368
  const customType = this.customTypes.get(sub.TypeName);
3358
3369
  let customContext = `[Subagent Context] ID: ${id}, Parent ID: ${parentId}, Role: ${sub.Role}
3359
3370
  `;
@@ -3366,6 +3377,7 @@ var SubagentManager = class {
3366
3377
  taskInstruction: customContext + "\n\n" + sub.Prompt,
3367
3378
  auto: true
3368
3379
  });
3380
+ this.updateSubagentSummary(id, result.summary || "Completed");
3369
3381
  this.terminateSubagent(id, result.success);
3370
3382
  } catch (error) {
3371
3383
  console.error(`Subagent ${id} failed:`, error);
@@ -3384,40 +3396,60 @@ var SubagentManager = class {
3384
3396
  var subagentManager = new SubagentManager();
3385
3397
 
3386
3398
  // src/core/agents/developer-agent.ts
3399
+ async function promptUser(message, initialValue, placeholder, prefix = "") {
3400
+ let userReply = await tui.text({ message: `${prefix}${message}`, initialValue, placeholder });
3401
+ while (userReply === "/skills") {
3402
+ const availableSkills = await skillManager.listAvailableSkills();
3403
+ const options = availableSkills.map((name) => ({ value: name, label: name }));
3404
+ if (options.length === 0) {
3405
+ tui.log.warning("Nenhuma skill encontrada. Execute `shark super` para instalar as skills.");
3406
+ } else {
3407
+ const selectedSkill = await tui.select({
3408
+ message: "Selecione a Skill do Superpowers para ativar:",
3409
+ options
3410
+ });
3411
+ if (!tui.isCancel(selectedSkill)) {
3412
+ await skillManager.activateSkill(selectedSkill);
3413
+ tui.log.success(`\u2714 Skill '${selectedSkill}' ativada com sucesso!`);
3414
+ }
3415
+ }
3416
+ userReply = await tui.text({
3417
+ message: `${prefix}${message}`,
3418
+ initialValue,
3419
+ placeholder: "digite a instru\xE7\xE3o da tarefa..."
3420
+ });
3421
+ }
3422
+ return userReply;
3423
+ }
3387
3424
  async function interactiveDeveloperAgent(options = {}) {
3388
3425
  const isAuto = options.auto === true || process.argv.includes("--auto");
3389
3426
  const projectRoot = process.cwd();
3390
3427
  let currentTask = options.taskInstruction;
3391
3428
  if (!currentTask) {
3392
- let userTask = await tui.text({
3393
- message: "O que voc\xEA gostaria que o Shark Dev fizesse?",
3394
- placeholder: "ex: crie uma API REST simples ou digite /skills para ativar diretrizes"
3395
- });
3396
- if (userTask === "/skills") {
3397
- const availableSkills = await skillManager.listAvailableSkills();
3398
- const options2 = availableSkills.map((name) => ({ value: name, label: name }));
3399
- if (options2.length === 0) {
3400
- tui.log.warning("Nenhuma skill encontrada. Execute `shark super` para instalar as skills.");
3401
- } else {
3402
- const selectedSkill = await tui.select({
3403
- message: "Selecione a Skill do Superpowers para ativar:",
3404
- options: options2
3405
- });
3406
- if (!tui.isCancel(selectedSkill)) {
3407
- await skillManager.activateSkill(selectedSkill);
3408
- tui.log.success(`\u2714 Skill '${selectedSkill}' ativada com sucesso!`);
3409
- }
3410
- }
3411
- userTask = await tui.text({
3412
- message: "O que voc\xEA gostaria que o Shark Dev fizesse?",
3413
- placeholder: "digite a instru\xE7\xE3o da tarefa..."
3414
- });
3415
- }
3429
+ const userTask = await promptUser(
3430
+ "O que voc\xEA gostaria que o Shark Dev fizesse?",
3431
+ void 0,
3432
+ "ex: crie uma API REST simples ou digite /skills para ativar diretrizes"
3433
+ );
3416
3434
  if (tui.isCancel(userTask) || !userTask) {
3417
3435
  return { success: false, summary: "Task execution cancelled." };
3418
3436
  }
3419
3437
  currentTask = userTask;
3420
3438
  }
3439
+ let subagentPrefix = "";
3440
+ if (options.taskId) {
3441
+ const subState = subagentManager.getSubagentState(options.taskId);
3442
+ if (subState) {
3443
+ subagentPrefix = `[Subagent: ${subState.role}] `;
3444
+ }
3445
+ }
3446
+ const log = {
3447
+ info: (msg) => tui.log.info(`${subagentPrefix}${msg}`),
3448
+ warning: (msg) => tui.log.warning(`${subagentPrefix}${msg}`),
3449
+ error: (msg) => tui.log.error(`${subagentPrefix}${msg}`),
3450
+ success: (msg) => tui.log.success(`${subagentPrefix}${msg}`),
3451
+ message: (msg) => tui.log.message(`${subagentPrefix}${msg}`)
3452
+ };
3421
3453
  let contextContent = "";
3422
3454
  const defaultContextPath = path8.resolve(projectRoot, "_sharkrc", "project-context.md");
3423
3455
  const specificContextPath = options.context ? path8.resolve(projectRoot, options.context) : defaultContextPath;
@@ -3425,7 +3457,7 @@ async function interactiveDeveloperAgent(options = {}) {
3425
3457
  try {
3426
3458
  contextContent = fs7.readFileSync(specificContextPath, "utf-8");
3427
3459
  } catch (e) {
3428
- tui.log.warning(`Failed to read context file: ${e}`);
3460
+ log.warning(`Failed to read context file: ${e}`);
3429
3461
  }
3430
3462
  }
3431
3463
  let basePrompt = ``;
@@ -3467,7 +3499,7 @@ Your goal is to address the user's request:
3467
3499
  const spinner = tui.spinner();
3468
3500
  while (keepGoing) {
3469
3501
  if (options.taskId && subagentManager.hasSubagent(options.taskId) && !subagentManager.isSubagentActive(options.taskId)) {
3470
- tui.log.warning(`Subagent ${options.taskId} was terminated.`);
3502
+ log.warning(`Subagent ${options.taskId} was terminated.`);
3471
3503
  return { success: false, summary: "Subagent terminated by manager." };
3472
3504
  }
3473
3505
  if (options.taskId) {
@@ -3482,7 +3514,10 @@ ${mailboxMessages.map((m) => `- ${m}`).join("\n")}
3482
3514
  }
3483
3515
  }
3484
3516
  try {
3485
- spinner.start("\u{1F988} Shark Dev working...");
3517
+ const activeSubagents = subagentManager.getActiveSubagents();
3518
+ const activeCount = activeSubagents.length;
3519
+ const spinnerText = activeCount > 0 ? `\u{1F988} Shark Dev working... (Active subagents: ${activeCount})` : "\u{1F988} Shark Dev working...";
3520
+ spinner.start(spinnerText);
3486
3521
  const existingConversationId = await conversationManager.getConversationId(conversationKey);
3487
3522
  const provider = ProviderResolver.getProvider("developer_agent");
3488
3523
  const response = await provider.streamChat(nextPrompt, {
@@ -3495,30 +3530,39 @@ ${mailboxMessages.map((m) => `- ${m}`).join("\n")}
3495
3530
  await conversationManager.saveConversationId(conversationKey, response.conversation_id);
3496
3531
  }
3497
3532
  spinner.stop("Response received");
3533
+ if (response.summary) {
3534
+ if (options.taskId) {
3535
+ subagentManager.updateSubagentSummary(options.taskId, response.summary);
3536
+ }
3537
+ log.info(`\u{1F4CC} Status: ${response.summary}`);
3538
+ }
3498
3539
  if (response.message && response.message.includes("TASK_COMPLETED:")) {
3499
3540
  finalSummary = response.message.split("TASK_COMPLETED:")[1].trim();
3541
+ if (options.taskId) {
3542
+ subagentManager.updateSubagentSummary(options.taskId, finalSummary);
3543
+ }
3500
3544
  keepGoing = false;
3501
3545
  break;
3502
3546
  }
3503
3547
  if (response.message && response.message.includes("TASK_FAILED:")) {
3504
3548
  const failureReason = response.message.split("TASK_FAILED:")[1].trim();
3505
- tui.log.error(`\u274C Agent reported task failure: ${failureReason}`);
3549
+ log.error(`\u274C Agent reported task failure: ${failureReason}`);
3506
3550
  return { success: false, summary: failureReason };
3507
3551
  }
3508
3552
  const action = response.action;
3509
3553
  if (!action) {
3510
3554
  if (response.message) {
3511
- tui.log.info(colors.primary("\u{1F916} Shark Dev:"));
3555
+ log.info(colors.primary("\u{1F916} Shark Dev:"));
3512
3556
  console.log(response.message);
3513
- const userReply = await tui.text({ message: "Your answer:" });
3557
+ const userReply = await promptUser("Your answer:", void 0, void 0, subagentPrefix);
3514
3558
  if (tui.isCancel(userReply)) {
3515
3559
  keepGoing = false;
3516
3560
  break;
3517
3561
  }
3518
3562
  nextPrompt = userReply;
3519
3563
  } else {
3520
- tui.log.warning("No action or message returned by the agent.");
3521
- const userReply = await tui.text({ message: "Agent returned empty response. Type a message to continue or press Ctrl+C to cancel:" });
3564
+ log.warning("No action or message returned by the agent.");
3565
+ const userReply = await promptUser("Agent returned empty response. Type a message to continue or press Ctrl+C to cancel:", void 0, void 0, subagentPrefix);
3522
3566
  if (tui.isCancel(userReply)) {
3523
3567
  keepGoing = false;
3524
3568
  break;
@@ -3530,7 +3574,7 @@ ${mailboxMessages.map((m) => `- ${m}`).join("\n")}
3530
3574
  let resultMsg = "";
3531
3575
  if (action.type === "read_file") {
3532
3576
  const filePath = action.path || "";
3533
- tui.log.info(`\u{1F4D6} Reading (Anchored): ${colors.dim(filePath)}`);
3577
+ log.info(`\u{1F4D6} Reading (Anchored): ${colors.dim(filePath)}`);
3534
3578
  try {
3535
3579
  const content = anchorManager.getAnchoredContent(filePath);
3536
3580
  resultMsg = `[Action read_file(${filePath}) Success]:
@@ -3540,7 +3584,7 @@ ${content}`;
3540
3584
  }
3541
3585
  } else if (action.type === "modify_file") {
3542
3586
  const filePath = action.path || "";
3543
- tui.log.warning(`\u{1F4DD} Modify (Anchored): ${colors.bold(filePath)}`);
3587
+ log.warning(`\u{1F4DD} Modify (Anchored): ${colors.bold(filePath)}`);
3544
3588
  let approved = isAuto;
3545
3589
  if (!approved) {
3546
3590
  approved = await tui.confirm({ message: `Approve modify_file changes to ${filePath}?` });
@@ -3557,7 +3601,7 @@ ${content}`;
3557
3601
  }
3558
3602
  } else if (action.type === "create_file") {
3559
3603
  const filePath = action.path || "";
3560
- tui.log.warning(`\u{1F4DD} Create file: ${colors.bold(filePath)}`);
3604
+ log.warning(`\u{1F4DD} Create file: ${colors.bold(filePath)}`);
3561
3605
  let approved = isAuto;
3562
3606
  if (!approved) {
3563
3607
  approved = await tui.confirm({ message: `Approve create_file changes to ${filePath}?` });
@@ -3579,7 +3623,7 @@ ${content}`;
3579
3623
  }
3580
3624
  } else if (action.type === "delete_file") {
3581
3625
  const filePath = action.path || "";
3582
- tui.log.warning(`\u{1F5D1}\uFE0F Delete file: ${colors.bold(filePath)}`);
3626
+ log.warning(`\u{1F5D1}\uFE0F Delete file: ${colors.bold(filePath)}`);
3583
3627
  let approved = isAuto;
3584
3628
  if (!approved) {
3585
3629
  approved = await tui.confirm({ message: `Approve delete_file changes to ${filePath}?` });
@@ -3599,7 +3643,7 @@ ${content}`;
3599
3643
  }
3600
3644
  } else if (action.type === "run_command") {
3601
3645
  const cmd = action.command || "";
3602
- tui.log.info(`\u{1F4BB} Executing: ${colors.dim(cmd)}`);
3646
+ log.info(`\u{1F4BB} Executing: ${colors.dim(cmd)}`);
3603
3647
  let approved = isAuto;
3604
3648
  if (!approved) {
3605
3649
  approved = await tui.confirm({ message: `Execute run_command: ${cmd}?` });
@@ -3617,7 +3661,7 @@ ${output}`;
3617
3661
  }
3618
3662
  } else if (action.type === "list_files") {
3619
3663
  const dirPath = action.path || ".";
3620
- tui.log.info(`\u{1F4C2} Scanning: ${colors.dim(dirPath)}`);
3664
+ log.info(`\u{1F4C2} Scanning: ${colors.dim(dirPath)}`);
3621
3665
  try {
3622
3666
  const result = handleListFiles(dirPath);
3623
3667
  resultMsg = `[Action list_files(${dirPath}) Success]:
@@ -3627,7 +3671,7 @@ ${result}`;
3627
3671
  }
3628
3672
  } else if (action.type === "search_file") {
3629
3673
  const pattern = action.path || "";
3630
- tui.log.info(`\u{1F50D} Searching files: ${colors.dim(pattern)}`);
3674
+ log.info(`\u{1F50D} Searching files: ${colors.dim(pattern)}`);
3631
3675
  try {
3632
3676
  const result = handleSearchFile(pattern);
3633
3677
  resultMsg = `[Action search_file(${pattern}) Success]:
@@ -3639,7 +3683,7 @@ ${result}`;
3639
3683
  const glob = action.path || "src/**/*";
3640
3684
  const query = action.query || "";
3641
3685
  const isRegex = action.is_regex === true;
3642
- tui.log.info(`\u{1F50E} Search code: ${colors.dim(`"${query}" in ${glob}`)}`);
3686
+ log.info(`\u{1F50E} Search code: ${colors.dim(`"${query}" in ${glob}`)}`);
3643
3687
  try {
3644
3688
  const result = handleSearchCode(glob, query, isRegex);
3645
3689
  resultMsg = `[Action search_code("${query}" in "${glob}") Success]:
@@ -3651,7 +3695,7 @@ ${result}`;
3651
3695
  resultMsg = `[Action use_mcp_tool Failed]: MCP tools are not configured/available in this agent.`;
3652
3696
  } else if (action.type === "activate_skill") {
3653
3697
  const name = action.skill_name || "";
3654
- tui.log.info(`\u26A1 Activating skill: ${colors.bold(name)}`);
3698
+ log.info(`\u26A1 Activating skill: ${colors.bold(name)}`);
3655
3699
  try {
3656
3700
  await skillManager.activateSkill(name);
3657
3701
  resultMsg = `[System]: Skill '${name}' activated successfully.`;
@@ -3661,8 +3705,8 @@ ${result}`;
3661
3705
  } else if (action.type === "talk_with_user") {
3662
3706
  const isSystemError = action.content?.startsWith("[SYSTEM ERROR]");
3663
3707
  if (isSystemError) {
3664
- tui.log.error(`\u26A0\uFE0F Detectado erro na resposta do Agente (truncado ou inv\xE1lido).`);
3665
- tui.log.info(colors.dim(action.content || ""));
3708
+ log.error(`\u26A0\uFE0F Detectado erro na resposta do Agente (truncado ou inv\xE1lido).`);
3709
+ log.info(colors.dim(action.content || ""));
3666
3710
  let approved = isAuto;
3667
3711
  if (!approved) {
3668
3712
  approved = await tui.confirm({ message: `Enviar notifica\xE7\xE3o de erro para o agente tentar se recuperar automaticamente?` });
@@ -3670,7 +3714,7 @@ ${result}`;
3670
3714
  if (approved) {
3671
3715
  resultMsg = action.content || "";
3672
3716
  } else {
3673
- const userReply = await tui.text({ message: "Seu prompt alternativo para o agente:" });
3717
+ const userReply = await promptUser("Seu prompt alternativo para o agente:", void 0, void 0, subagentPrefix);
3674
3718
  if (tui.isCancel(userReply)) {
3675
3719
  keepGoing = false;
3676
3720
  break;
@@ -3678,9 +3722,9 @@ ${result}`;
3678
3722
  resultMsg = userReply;
3679
3723
  }
3680
3724
  } else {
3681
- tui.log.info(colors.primary("\u{1F916} Shark Dev:"));
3725
+ log.info(colors.primary("\u{1F916} Shark Dev:"));
3682
3726
  console.log(action.content);
3683
- const userReply = await tui.text({ message: "Your answer:" });
3727
+ const userReply = await promptUser("Your answer:", void 0, void 0, subagentPrefix);
3684
3728
  if (tui.isCancel(userReply)) {
3685
3729
  keepGoing = false;
3686
3730
  break;
@@ -3696,12 +3740,12 @@ ${result}`;
3696
3740
  enableSubagentTools: action.enable_subagent_tools ?? void 0,
3697
3741
  enableMcpTools: action.enable_mcp_tools ?? void 0
3698
3742
  };
3699
- tui.log.info(`\u{1F6E0}\uFE0F Defining subagent type: ${colors.bold(name)}`);
3743
+ log.info(`\u{1F6E0}\uFE0F Defining subagent type: ${colors.bold(name)}`);
3700
3744
  subagentManager.defineSubagentType(name, desc, sysPrompt, opts);
3701
3745
  resultMsg = `[Action define_subagent Success]: Defined subagent type '${name}'`;
3702
3746
  } else if (action.type === "invoke_subagent") {
3703
3747
  const subagentsToInvoke = action.Subagents || [];
3704
- tui.log.info(`\u{1F680} Invoking ${subagentsToInvoke.length} subagent(s)`);
3748
+ log.info(`\u{1F680} Invoking ${subagentsToInvoke.length} subagent(s)`);
3705
3749
  const parentId = options.taskId || "parent";
3706
3750
  const invoked = await subagentManager.invokeSubagents(subagentsToInvoke, parentId);
3707
3751
  resultMsg = `[Action invoke_subagent Success]: Invoked subagents:
@@ -3709,13 +3753,13 @@ ${invoked.map((s) => `- ID: ${s.id}, Type: ${s.TypeName}, Role: ${s.Role}`).join
3709
3753
  } else if (action.type === "send_message") {
3710
3754
  const recipient = action.Recipient || "";
3711
3755
  const message = action.Message || "";
3712
- tui.log.info(`\u2709\uFE0F Sending message to ${colors.bold(recipient)}`);
3756
+ log.info(`\u2709\uFE0F Sending message to ${colors.bold(recipient)}`);
3713
3757
  subagentManager.sendMessage(recipient, message);
3714
3758
  resultMsg = `[Action send_message Success]: Message sent to '${recipient}'`;
3715
3759
  } else if (action.type === "manage_subagents") {
3716
3760
  const subAction = action.Action || "";
3717
3761
  const ids = action.ConversationIds || [];
3718
- tui.log.info(`\u2699\uFE0F Managing subagents. Action: ${colors.bold(subAction)}`);
3762
+ log.info(`\u2699\uFE0F Managing subagents. Action: ${colors.bold(subAction)}`);
3719
3763
  if (subAction === "list") {
3720
3764
  const active = subagentManager.getActiveSubagents();
3721
3765
  resultMsg = `[Action manage_subagents Success]: Active subagents:
@@ -3737,12 +3781,12 @@ ${active.map((s) => `- ID: ${s.id}, Type: ${s.type}, Role: ${s.role}`).join("\n"
3737
3781
  FileLogger.log("TOOL_EXECUTION", `Action: ${action.type}`, { action, result: resultMsg });
3738
3782
  nextPrompt = resultMsg + skillManager.getSystemInstructionExtension();
3739
3783
  } catch (e) {
3740
- tui.log.error(e.message);
3784
+ log.error(e.message);
3741
3785
  keepGoing = false;
3742
3786
  return { success: false, summary: `Error: ${e.message}` };
3743
3787
  }
3744
3788
  }
3745
- tui.log.success("\u2705 Task Scope Completed");
3789
+ log.success("\u2705 Task Scope Completed");
3746
3790
  return { success: true, summary: finalSummary || "Task completed without summary." };
3747
3791
  }
3748
3792
 
@@ -3781,4 +3825,4 @@ export {
3781
3825
  astOrganizeImports,
3782
3826
  interactiveDeveloperAgent
3783
3827
  };
3784
- //# sourceMappingURL=chunk-VS6HH2CF.js.map
3828
+ //# sourceMappingURL=chunk-O6YG3GZN.js.map