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