crewx 0.8.9-rc.2 → 0.8.9-rc.21

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 (82) hide show
  1. package/dist/assets/{MarketPage-BpajB_Ex.js → MarketPage-Cl9KvLAo.js} +1 -1
  2. package/dist/assets/PromptTab-gj_BvClc.js +27 -0
  3. package/dist/assets/{arc-B0fFLEOc.js → arc-DDzVSXZh.js} +1 -1
  4. package/dist/assets/{architectureDiagram-UYN6MBPD-CrC7MKTM.js → architectureDiagram-UYN6MBPD-p8OOXe5w.js} +1 -1
  5. package/dist/assets/{blockDiagram-ZHA2E4KO-DJsG-9x2.js → blockDiagram-ZHA2E4KO-BTlfXGnf.js} +7 -7
  6. package/dist/assets/{c4Diagram-6F5ED5ID-DlkyjvkS.js → c4Diagram-6F5ED5ID-CKbrDPWE.js} +1 -1
  7. package/dist/assets/channel-Hzz-cXd0.js +1 -0
  8. package/dist/assets/{chunk-5HRBRIJM-B_Csqjvw.js → chunk-5HRBRIJM-otR_A_1G.js} +1 -1
  9. package/dist/assets/{chunk-7U56Z5CX-BlNdzxbh.js → chunk-7U56Z5CX-BliJIH4-.js} +1 -1
  10. package/dist/assets/{chunk-ASOPGD6M-BiFWfa3w.js → chunk-ASOPGD6M-CmzypD4Z.js} +1 -1
  11. package/dist/assets/{chunk-KFBOBJHC-ocugjY-9.js → chunk-KFBOBJHC-BW4u3lPL.js} +1 -1
  12. package/dist/assets/{chunk-T2TOU4HS-kUreJ-bv.js → chunk-T2TOU4HS-BAp6Xscz.js} +1 -1
  13. package/dist/assets/{chunk-TMUBEWPD-Du19Q8X-.js → chunk-TMUBEWPD-Bv_RKIlz.js} +1 -1
  14. package/dist/assets/classDiagram-LNE6IOMH-CXR-DJKP.js +1 -0
  15. package/dist/assets/classDiagram-v2-MQ7JQ4JX-CXR-DJKP.js +1 -0
  16. package/dist/assets/{dagre-4EVJKHTY-8N5qxubq.js → dagre-4EVJKHTY-sYyP6lkA.js} +1 -1
  17. package/dist/assets/{diagram-QW4FP2JN-CjLH9uYk.js → diagram-QW4FP2JN-XWldv7Gz.js} +1 -1
  18. package/dist/assets/{erDiagram-6RL3IURR-CXgt8NtN.js → erDiagram-6RL3IURR-Cd8OVAQ0.js} +1 -1
  19. package/dist/assets/{flowDiagram-7ASYPVHJ-CdFlmdmT.js → flowDiagram-7ASYPVHJ-Cc3onSB6.js} +1 -1
  20. package/dist/assets/{ganttDiagram-NTVNEXSI-DDjK4yxy.js → ganttDiagram-NTVNEXSI-Q6HxMUkA.js} +1 -1
  21. package/dist/assets/{gitGraph-YCYPL57B-Bd9jYZ-C.js → gitGraph-YCYPL57B-BUh0zUco.js} +1 -1
  22. package/dist/assets/{gitGraphDiagram-NRZ2UAAF-pmwetPkN.js → gitGraphDiagram-NRZ2UAAF-CvPqw-ya.js} +1 -1
  23. package/dist/assets/{infoDiagram-A4XQUW5V-BoDEaOyd.js → infoDiagram-A4XQUW5V-CbKGdGqb.js} +1 -1
  24. package/dist/assets/{journeyDiagram-G5WM74LC-D1LRuhB3.js → journeyDiagram-G5WM74LC-BXyAvuxS.js} +1 -1
  25. package/dist/assets/{kanban-definition-QRCXZQQD-B66SGjA2.js → kanban-definition-QRCXZQQD-CxBFX9if.js} +1 -1
  26. package/dist/assets/{linear-VMCGabuP.js → linear-Bu0P9vdO.js} +1 -1
  27. package/dist/assets/main-AYmbxFu4.css +10 -0
  28. package/dist/assets/main-CcrxU2Tf.js +1454 -0
  29. package/dist/assets/{mindmap-definition-GWI6TPTV--NljwHD9.js → mindmap-definition-GWI6TPTV-BbXI83yG.js} +1 -1
  30. package/dist/assets/{pieDiagram-YF2LJOPJ-CP4IPp3Q.js → pieDiagram-YF2LJOPJ-DuXspLPW.js} +1 -1
  31. package/dist/assets/{quadrantDiagram-OS5C2QUG-baFc-DtQ.js → quadrantDiagram-OS5C2QUG-DnngSA8p.js} +1 -1
  32. package/dist/assets/{requirementDiagram-MIRIMTAZ-BTWwNcnt.js → requirementDiagram-MIRIMTAZ-ChJE8XYc.js} +1 -1
  33. package/dist/assets/{sankeyDiagram-Y46BX6SQ-CnrACC1i.js → sankeyDiagram-Y46BX6SQ-BlkQKMk0.js} +1 -1
  34. package/dist/assets/{sequenceDiagram-G6AWOVSC-Ct5WkHJl.js → sequenceDiagram-G6AWOVSC-BvYCRnWL.js} +1 -1
  35. package/dist/assets/{stateDiagram-MAYHULR4-DeZHZmIy.js → stateDiagram-MAYHULR4-Cb6BiEq_.js} +1 -1
  36. package/dist/assets/stateDiagram-v2-4JROLMXI-31Hvt1M0.js +1 -0
  37. package/dist/assets/{timeline-definition-U7ZMHBDA-BZfUE50X.js → timeline-definition-U7ZMHBDA-w1-dGiEP.js} +1 -1
  38. package/dist/assets/{xychartDiagram-6QU3TZC5-DV6BFyHM.js → xychartDiagram-6QU3TZC5-B85iIKzT.js} +1 -1
  39. package/dist/index.html +2 -2
  40. package/dist-server/__stubs__/ccusage-codex.js +8 -0
  41. package/dist-server/app.module.js +2 -0
  42. package/dist-server/common/limits/defaults.js +3 -3
  43. package/dist-server/domain/agent/agent.service.js +11 -0
  44. package/dist-server/domain/cli/cli.service.js +3 -3
  45. package/dist-server/domain/cron/cron.service.js +5 -1
  46. package/dist-server/domain/doc/doc.controller.js +22 -0
  47. package/dist-server/domain/doc/doc.service.js +42 -10
  48. package/dist-server/domain/git/git.controller.js +180 -0
  49. package/dist-server/domain/git/git.module.js +2 -0
  50. package/dist-server/domain/git/git.service.js +327 -34
  51. package/dist-server/domain/message/message.service.js +18 -8
  52. package/dist-server/domain/onboarding/onboarding.service.js +1 -1
  53. package/dist-server/domain/onboarding/presets/custom.js +2 -2
  54. package/dist-server/domain/onboarding/presets/dev-team.js +7 -7
  55. package/dist-server/domain/onboarding/presets/marketing-team.js +5 -5
  56. package/dist-server/domain/onboarding/presets/planning-team.js +5 -5
  57. package/dist-server/domain/onboarding/presets/solo.js +3 -3
  58. package/dist-server/domain/settings/settings.module.js +2 -0
  59. package/dist-server/domain/settings/settings.service.js +75 -8
  60. package/dist-server/domain/task/task.service.js +7 -7
  61. package/dist-server/domain/thread/thread.service.js +2 -1
  62. package/dist-server/domain/usage/usage.controller.js +30 -0
  63. package/dist-server/domain/usage/usage.service.js +212 -0
  64. package/dist-server/domain/wi/wi.controller.js +43 -0
  65. package/dist-server/domain/wi/wi.module.js +22 -0
  66. package/dist-server/domain/wi/wi.service.js +110 -0
  67. package/dist-server/domain/wi/wi.types.js +2 -0
  68. package/dist-server/domain/workspace/workspace.service.js +4 -1
  69. package/dist-server/modules/crewx-pool.service.js +194 -53
  70. package/dist-server/repository/task.repository.js +5 -1
  71. package/package.json +16 -14
  72. package/packages/cli/dist/commands/agent.js +1 -1
  73. package/packages/cli/dist/commands/init.d.ts +2 -0
  74. package/packages/cli/dist/commands/init.js +198 -6
  75. package/packages/cli/package.json +3 -2
  76. package/dist/assets/PromptTab-HhD4MQcW.js +0 -37
  77. package/dist/assets/channel-ClmdPiZd.js +0 -1
  78. package/dist/assets/classDiagram-LNE6IOMH-Q0hRWLPF.js +0 -1
  79. package/dist/assets/classDiagram-v2-MQ7JQ4JX-Q0hRWLPF.js +0 -1
  80. package/dist/assets/main-AqROOc4i.css +0 -10
  81. package/dist/assets/main-DWCTap27.js +0 -1289
  82. package/dist/assets/stateDiagram-v2-4JROLMXI-DVsMMyDB.js +0 -1
@@ -7,12 +7,79 @@
7
7
  * crewx init Create crewx.yaml in current directory
8
8
  * crewx init --force Overwrite existing configuration
9
9
  */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ var __importDefault = (this && this.__importDefault) || function (mod) {
44
+ return (mod && mod.__esModule) ? mod : { "default": mod };
45
+ };
10
46
  Object.defineProperty(exports, "__esModule", { value: true });
11
47
  exports.handleInit = handleInit;
12
48
  const fs_1 = require("fs");
13
49
  const path_1 = require("path");
50
+ const path = __importStar(require("path"));
51
+ const git = __importStar(require("isomorphic-git"));
52
+ const nodeFs = __importStar(require("fs"));
53
+ const os_1 = __importDefault(require("os"));
14
54
  const repository_1 = require("@crewx/sdk/repository");
15
55
  const install_1 = require("./hook/install");
56
+ const STATUSLINE_SCRIPT_NAME = 'claude-usage-statusline.js';
57
+ const STATUSLINE_SCRIPT_MARKER = 'CrewX claude-usage-statusline';
58
+ // Reads Claude Code rate_limits from stdin payload and dumps to ~/.crewx/claude-usage.json
59
+ const STATUSLINE_SCRIPT_CONTENT = `// ${STATUSLINE_SCRIPT_MARKER}
60
+ // Dumps Claude Code rate_limits (stdin payload) to ~/.crewx/claude-usage.json
61
+ const fs = require('fs');
62
+ const os = require('os');
63
+ const path = require('path');
64
+
65
+ const chunks = [];
66
+ process.stdin.on('data', (d) => chunks.push(d));
67
+ process.stdin.on('end', () => {
68
+ try {
69
+ const payload = JSON.parse(Buffer.concat(chunks).toString('utf-8'));
70
+ if (payload && payload.rate_limits) {
71
+ const out = {
72
+ rate_limits: payload.rate_limits,
73
+ updated_at: new Date().toISOString(),
74
+ };
75
+ const dir = path.join(os.homedir(), '.crewx');
76
+ fs.mkdirSync(dir, { recursive: true });
77
+ fs.writeFileSync(path.join(dir, 'claude-usage.json'), JSON.stringify(out, null, 2), 'utf-8');
78
+ }
79
+ } catch (_) {}
80
+ });
81
+ `;
82
+ const INIT_AUTHOR = { name: 'CrewX', email: 'crewx@local' };
16
83
  const CREWX_MARKER = '# CrewX runtime';
17
84
  const CREWX_GITIGNORE = `# CrewX runtime
18
85
  .crewx/
@@ -38,7 +105,7 @@ const DEFAULT_AGENTS = [
38
105
  team: 'core',
39
106
  provider: 'acp/claude',
40
107
  working_directory: './',
41
- description: '요구 분석·설계·작업 분해를 담당',
108
+ description: 'Owns requirements analysis, design, and work breakdown',
42
109
  options: {
43
110
  query: { effort: 'high' },
44
111
  execute: { effort: 'high', mode: 'bypassPermissions' },
@@ -55,7 +122,7 @@ const DEFAULT_AGENTS = [
55
122
  team: 'core',
56
123
  provider: 'acp/claude',
57
124
  working_directory: './',
58
- description: '실제 코드 작성과 테스트',
125
+ description: 'Implements code changes and tests',
59
126
  options: {
60
127
  query: { effort: 'high' },
61
128
  execute: { effort: 'high', mode: 'bypassPermissions' },
@@ -72,7 +139,7 @@ const DEFAULT_AGENTS = [
72
139
  team: 'core',
73
140
  provider: 'acp/claude',
74
141
  working_directory: './',
75
- description: '코드 품질·보안·가독성 리뷰',
142
+ description: 'Reviews code quality, security, and readability',
76
143
  options: {
77
144
  query: { effort: 'high' },
78
145
  execute: { effort: 'high', mode: 'bypassPermissions' },
@@ -91,7 +158,7 @@ notation:
91
158
  auto: "N% auto — L1 progress auto-calculated as weighted average of children"
92
159
  ---
93
160
 
94
- # 목표 제목
161
+ # Goal Title
95
162
 
96
163
  ## Period
97
164
  - Start: YYYY-MM-DD
@@ -99,7 +166,7 @@ notation:
99
166
  - Status: active
100
167
 
101
168
  ## Objective
102
- 목표는...
169
+ Describe the goal...
103
170
 
104
171
  ## Key Results
105
172
  - [ ] KR1:
@@ -260,6 +327,7 @@ npx doc section {design_doc} "{spec_id}"
260
327
  - [ ] \`npx vitest run src/server/\` passes (backend work)
261
328
  - [ ] \`npx vitest run src/ui/\` passes (frontend work)
262
329
  - [ ] (add feature-specific AC)
330
+ - [ ] (when worktree: true) Changes committed to the worktree branch (report commit hash). A completion report without a commit is invalid.
263
331
 
264
332
  ## Completion Report Format
265
333
 
@@ -275,6 +343,11 @@ Pass / Fail
275
343
  ### Test result
276
344
  N tests passed
277
345
 
346
+ ### Commit
347
+ - hash: <commit hash>
348
+ - branch: <worktree branch>
349
+ (empty = completion report invalid — worktree tasks only)
350
+
278
351
  ### Remaining items
279
352
  None / (list if any)
280
353
  \`\`\`
@@ -410,5 +483,124 @@ async function handleInit(opts) {
410
483
  console.log('ℹ .gitignore already contains CrewX entries');
411
484
  }
412
485
  }
413
- return { yamlCreated, hookInstalled, errors, skippedReason, workspaceId, slug };
486
+ // Git auto-initialization
487
+ await initGitRepo(target, errors);
488
+ // Idempotent statusLine merge into ~/.claude/settings.json
489
+ const statusLineResult = ensureClaudeStatusLine();
490
+ return { yamlCreated, hookInstalled, errors, skippedReason, workspaceId, slug, ...statusLineResult };
491
+ }
492
+ function ensureClaudeStatusLine() {
493
+ const home = os_1.default.homedir();
494
+ const crewxDir = path.join(home, '.crewx');
495
+ const scriptPath = path.join(crewxDir, STATUSLINE_SCRIPT_NAME);
496
+ const settingsPath = path.join(home, '.claude', 'settings.json');
497
+ // Always write/update the dump script itself (idempotent: same content)
498
+ try {
499
+ (0, fs_1.mkdirSync)(crewxDir, { recursive: true });
500
+ (0, fs_1.writeFileSync)(scriptPath, STATUSLINE_SCRIPT_CONTENT, 'utf-8');
501
+ }
502
+ catch (_) {
503
+ return { statusLineConfigured: false, statusLineSkipped: false };
504
+ }
505
+ const statusLineValue = `node ${scriptPath}`;
506
+ let settings = {};
507
+ if ((0, fs_1.existsSync)(settingsPath)) {
508
+ try {
509
+ settings = JSON.parse((0, fs_1.readFileSync)(settingsPath, 'utf-8'));
510
+ }
511
+ catch (_) {
512
+ settings = {};
513
+ }
514
+ }
515
+ if (typeof settings.statusLine === 'string' && settings.statusLine !== '') {
516
+ // Already our script — no-op
517
+ if (settings.statusLine === statusLineValue) {
518
+ console.log('ℹ statusLine already configured (CrewX claude-usage dump)');
519
+ return { statusLineConfigured: false, statusLineSkipped: false };
520
+ }
521
+ // Existing user statusLine — skip, do not overwrite
522
+ console.log('ℹ statusLine already set in ~/.claude/settings.json — skipping Claude usage dump setup.\n' +
523
+ ' To enable manually, set "statusLine" to: ' +
524
+ statusLineValue);
525
+ return { statusLineConfigured: false, statusLineSkipped: true };
526
+ }
527
+ // No existing statusLine — inject ours
528
+ try {
529
+ settings.statusLine = statusLineValue;
530
+ const claudeDir = path.join(home, '.claude');
531
+ (0, fs_1.mkdirSync)(claudeDir, { recursive: true });
532
+ (0, fs_1.writeFileSync)(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf-8');
533
+ console.log('✅ statusLine configured for Claude usage dump (~/.claude/settings.json)');
534
+ return { statusLineConfigured: true, statusLineSkipped: false };
535
+ }
536
+ catch (_) {
537
+ return { statusLineConfigured: false, statusLineSkipped: false };
538
+ }
539
+ }
540
+ async function initGitRepo(target, errors) {
541
+ // Danger path guards — skip git steps but keep init successful
542
+ const home = os_1.default.homedir();
543
+ if (target === home) {
544
+ console.log('ℹ git init skipped: target is home directory');
545
+ return;
546
+ }
547
+ // Check filesystem root
548
+ const parsedPath = path.parse(target);
549
+ if (parsedPath.root === target || target === '/') {
550
+ console.log('ℹ git init skipped: target is filesystem root');
551
+ return;
552
+ }
553
+ // Check if ancestor has .git (target is inside existing git repo)
554
+ let checkDir = path.dirname(target);
555
+ while (checkDir !== path.parse(checkDir).root) {
556
+ if ((0, fs_1.existsSync)((0, path_1.join)(checkDir, '.git'))) {
557
+ console.log(`ℹ git init skipped: already inside a git repo (${checkDir})`);
558
+ return;
559
+ }
560
+ const parent = path.dirname(checkDir);
561
+ if (parent === checkDir)
562
+ break;
563
+ checkDir = parent;
564
+ }
565
+ // Skip if .git already exists in target
566
+ if ((0, fs_1.existsSync)((0, path_1.join)(target, '.git'))) {
567
+ console.log('ℹ git init skipped: .git already exists');
568
+ return;
569
+ }
570
+ // Initialize git repo
571
+ try {
572
+ await git.init({ fs: nodeFs, dir: target, defaultBranch: 'main' });
573
+ console.log('✅ git repository initialized (main branch)');
574
+ }
575
+ catch (e) {
576
+ errors.push(`GIT_INIT_FAILED: ${e.message}`);
577
+ return;
578
+ }
579
+ // Ensure node_modules/ in .gitignore
580
+ const gitignorePath = (0, path_1.join)(target, '.gitignore');
581
+ if ((0, fs_1.existsSync)(gitignorePath)) {
582
+ const content = (0, fs_1.readFileSync)(gitignorePath, 'utf-8');
583
+ if (!content.includes('node_modules/')) {
584
+ const separator = content.endsWith('\n') ? '' : '\n';
585
+ (0, fs_1.appendFileSync)(gitignorePath, `${separator}node_modules/\n`, 'utf-8');
586
+ }
587
+ }
588
+ else {
589
+ (0, fs_1.writeFileSync)(gitignorePath, 'node_modules/\n', 'utf-8');
590
+ }
591
+ // Initial commit
592
+ try {
593
+ // Stage all files
594
+ await git.add({ fs: nodeFs, dir: target, filepath: '.' });
595
+ await git.commit({
596
+ fs: nodeFs,
597
+ dir: target,
598
+ message: 'chore: crewx init',
599
+ author: INIT_AUTHOR,
600
+ });
601
+ console.log('✅ initial commit created (chore: crewx init)');
602
+ }
603
+ catch (e) {
604
+ errors.push(`GIT_COMMIT_FAILED: ${e.message}`);
605
+ }
414
606
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewx/cli",
3
- "version": "0.8.9-rc.2",
3
+ "version": "0.8.9-rc.21",
4
4
  "license": "UNLICENSED",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"
@@ -39,7 +39,8 @@
39
39
  "@crewx/chromex": "workspace:*",
40
40
  "@crewx/shared": "workspace:*",
41
41
  "@crewx/adapter-slack": "0.1.4",
42
- "better-sqlite3": "*"
42
+ "better-sqlite3": "*",
43
+ "isomorphic-git": "1.37.1"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/better-sqlite3": "*",
@@ -1,37 +0,0 @@
1
- import{aB as H,aE as B,aG as u,aH as r,aZ as ke,aL as J,aS as we,a_ as je,aD as F,a$ as de,aK as ue,b0 as K,aW as Ne,b1 as Ce,b2 as Le,b3 as _e,aP as Ee,b4 as pe,b5 as Se,b6 as De,b7 as Me,b8 as Ae,b9 as $e,ba as Te,bb as Ie,bc as Pe,bd as Re,be as Be,bf as ze,bg as Oe,bh as qe,bi as Fe,bj as He,bk as Ve,bl as Ke,bm as We,bn as Qe,bo as Ue,bp as Je,bq as Xe,br as Ge,bs as Y}from"./main-DWCTap27.js";/**
2
- * @license lucide-react v0.563.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const Ze=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Ye=H("braces",Ze);/**
7
- * @license lucide-react v0.563.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const et=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],tt=H("eye",et);/**
12
- * @license lucide-react v0.563.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const nt=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],rt=H("link-2",nt);/**
17
- * @license lucide-react v0.563.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const st=[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]],at=H("refresh-ccw",st);function ee(e,s){return(e??"").toLowerCase().includes(s)}function me(e,s){const n=s.trim().toLowerCase();if(!n)return{nodes:e,autoExpanded:new Set};const t=new Set;return{nodes:e.flatMap(l=>{const c=ee(l.name,n)||ee(l.path,n);if(l.type==="file")return c?[l]:[];if(c)return t.add(l.path),[{...l,children:l.children}];const p=me(l.children??[],n);return p.nodes.length>0?(t.add(l.path),p.autoExpanded.forEach(m=>t.add(m)),[{...l,children:p.nodes}]):[]}),autoExpanded:t}}function fe(e){return e instanceof Error?/HTTP (404|405|501|503)\b|Failed to fetch|NetworkError/i.test(e.message):!1}const R={id:"agent_id",name:"에이전트 이름",role:"에이전트 역할",team:"팀",description:"에이전트 설명"};function ot(e){return{id:e.id.trim()||R.id,name:e.name.trim()||R.name,role:e.role.trim()||R.role,team:e.team.trim()||R.team,description:e.description.trim()||R.description}}function it(e,s,n){let t=!1;return e.state.doc.descendants(i=>i.type.name==="documentBlock"&&i.attrs.key===s&&i.attrs.variant===n?(t=!0,!1):!t),t}const he=["[&_h1]:mt-0","[&_h1]:mb-3","[&_h1]:text-2xl","[&_h1]:font-bold","[&_h2]:mt-0","[&_h2]:mb-2","[&_h2]:text-xl","[&_h2]:font-semibold","[&_h3]:mt-0","[&_h3]:mb-2","[&_h3]:text-lg","[&_h3]:font-semibold","[&_p]:my-2","[&_p]:leading-7","[&_ul]:my-2","[&_ol]:my-2","[&_ul]:list-disc","[&_ol]:list-decimal","[&_ul]:pl-6","[&_ol]:pl-6","[&_li]:my-1","[&_blockquote]:my-3","[&_blockquote]:border-l-4","[&_blockquote]:border-gray-300","[&_blockquote]:pl-4","[&_blockquote]:text-gray-600","[&_blockquote]:italic","[&_blockquote_p]:my-0","[&_a]:text-blue-600","[&_a]:underline","[&_hr]:my-4","[&_hr]:border-gray-300","[&_code]:rounded","[&_code]:bg-gray-100","[&_code]:px-1.5","[&_code]:py-0.5","[&_code]:font-mono","[&_code]:text-[13px]","[&_pre]:my-3","[&_pre]:overflow-x-auto","[&_pre]:rounded-lg","[&_pre]:bg-gray-900","[&_pre]:p-4","[&_pre]:text-sm","[&_pre]:text-gray-100","[&_pre_code]:bg-transparent","[&_pre_code]:p-0","[&_pre_code]:text-inherit"].join(" "),lt=["min-h-[420px]","rounded-xl","border","border-gray-200","bg-white","px-4","py-3","text-sm","text-gray-900","shadow-sm","focus:outline-none","prose","prose-sm","max-w-none",he,"[&_.is-editor-empty:first-child::before]:pointer-events-none","[&_.is-editor-empty:first-child::before]:float-left","[&_.is-editor-empty:first-child::before]:h-0","[&_.is-editor-empty:first-child::before]:text-gray-400","[&_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]"].join(" ");function ct({open:e,request:s,onClose:n}){const{t}=B(),i=u.useRef(null),l=u.useRef(s),[c,p]=u.useState(""),[m,x]=u.useState(!1),[o,y]=u.useState(null),[b,k]=u.useState(!1),w=t("agent.prompt.preview.error");l.current=s;const h=async()=>{var g;if((g=i.current)==null||g.abort(),!l.current.template.trim()){p(""),y(null),k(!1),x(!1);return}const d=new AbortController;i.current=d,x(!0),y(null),k(!1);try{const v=await F.previewPrompt(l.current,{signal:d.signal});if(d.signal.aborted)return;p(v.rendered),y(null),k(!1)}catch(v){if(d.signal.aborted)return;if(fe(v)){p(""),y(null),k(!0);return}p(""),k(!1),y(v instanceof Error?v.message:w)}finally{i.current===d&&(i.current=null),x(!1)}};return u.useEffect(()=>{var d;if(!e){(d=i.current)==null||d.abort();return}h()},[e]),u.useEffect(()=>{if(!e)return;const d=g=>{g.key==="Escape"&&(g.preventDefault(),n())};return window.addEventListener("keydown",d),()=>{window.removeEventListener("keydown",d)}},[n,e]),u.useEffect(()=>()=>{var d;(d=i.current)==null||d.abort()},[]),e?r.jsx("div",{"data-testid":"preview-modal-backdrop",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:n,children:r.jsxs("div",{role:"dialog","aria-modal":"true","data-testid":"preview-modal",onClick:d=>d.stopPropagation(),className:"flex max-h-[85vh] w-full max-w-4xl flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[r.jsx("div",{children:r.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:t("agent.prompt.preview.title")})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("button",{type:"button",onClick:()=>{h()},disabled:m,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:[r.jsx(at,{size:14,className:m?"animate-spin":""}),t("agent.prompt.preview.refresh")]}),r.jsxs("button",{type:"button",onClick:n,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[r.jsx(ke,{size:14}),t("common.close")]})]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5",children:s.template.trim()?m?r.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[r.jsx(J,{size:16,className:"animate-spin"}),r.jsx("span",{children:t("agent.prompt.preview.loading")})]}):b?r.jsx("div",{className:"text-sm text-gray-500",children:t("agent.prompt.preview.unavailable")}):o?r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"text-sm font-medium text-red-600",children:t("agent.prompt.preview.error")}),r.jsx("div",{className:"text-sm text-red-500",children:o})]}):r.jsx(we,{content:c,className:he}):r.jsx("div",{className:"text-sm text-gray-500",children:t("agent.prompt.preview.empty")})}),r.jsxs("div",{className:"flex justify-end gap-2 border-t border-gray-200 px-6 py-4",children:[r.jsxs("button",{type:"button",onClick:()=>{var d;return void((d=navigator.clipboard)==null?void 0:d.writeText(c))},disabled:!c,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:[r.jsx(je,{size:14}),t("agent.prompt.preview.copy")]}),r.jsx("button",{type:"button",onClick:n,className:"rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:t("common.close")})]})]})}):null}function dt({trigger:e,items:s,searchable:n=!1,searchPlaceholder:t,emptyLabel:i}){const l=u.useRef(null),c=u.useRef(null),[p,m]=u.useState(!1),[x,o]=u.useState(""),[y,b]=u.useState(0),k=u.useMemo(()=>{const d=x.trim().toLowerCase();return d?s.filter(g=>g.label.toLowerCase().includes(d)?!0:g.actions.some(v=>v.label.toLowerCase().includes(d))):s},[s,x]),w=u.useMemo(()=>k.flatMap(d=>d.actions.map(g=>({itemLabel:d.label,actionLabel:g.label,onClick:g.onClick}))),[k]);u.useEffect(()=>{var d;if(!p){o(""),b(0);return}n&&((d=c.current)==null||d.focus())},[p,n]),u.useEffect(()=>{y<w.length||b(Math.max(w.length-1,0))},[w.length,y]),u.useEffect(()=>{if(!p)return;const d=v=>{var _;(_=l.current)!=null&&_.contains(v.target)||m(!1)},g=v=>{var _;if(v.key==="Escape"){v.preventDefault(),m(!1);return}if(w.length!==0){if(v.key==="ArrowDown"){v.preventDefault(),b(M=>(M+1)%w.length);return}if(v.key==="ArrowUp"){v.preventDefault(),b(M=>(M-1+w.length)%w.length);return}v.key==="Enter"&&(v.preventDefault(),(_=w[y])==null||_.onClick(),m(!1))}};return window.addEventListener("mousedown",d),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",g)}},[w,y,p]);let h=-1;return r.jsxs("div",{ref:l,className:"relative",children:[r.jsxs("button",{type:"button",onMouseDown:d=>d.preventDefault(),onClick:()=>m(d=>!d),className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 transition hover:border-gray-300 hover:bg-gray-100",children:[r.jsx("span",{children:e}),r.jsx(de,{size:14})]}),p?r.jsxs("div",{className:"absolute left-0 top-[calc(100%+0.5rem)] z-20 w-72 rounded-xl border border-gray-200 bg-white p-2 shadow-lg",children:[n?r.jsxs("label",{className:"mb-2 flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-xs text-gray-500",children:[r.jsx(ue,{size:14}),r.jsx("input",{ref:c,value:x,onChange:d=>{o(d.target.value),b(0)},className:"w-full bg-transparent text-sm text-gray-700 outline-none","aria-label":t,placeholder:t})]}):null,r.jsx("div",{className:"max-h-80 space-y-1 overflow-y-auto",children:k.length===0?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:i??""}):k.map(d=>r.jsxs("div",{className:"rounded-lg border border-gray-100 px-3 py-2",children:[r.jsx("div",{className:"text-sm font-medium text-gray-900",children:d.label}),d.actions.length>0?r.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:d.actions.map(g=>{h+=1;const v=h===y;return r.jsx("button",{type:"button",onMouseDown:_=>_.preventDefault(),onClick:()=>{g.onClick(),m(!1)},className:`rounded-md px-2.5 py-1 text-xs font-medium transition ${v?"bg-blue-500 text-white":"border border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-100"}`,children:g.label},`${d.label}-${g.label}`)})}):r.jsx("div",{className:"mt-1 text-xs text-gray-500",children:i??d.label})]},d.label))})]}):null]})}function te(e){return e.replace(/\\/g,"/").replace(/^\.?\//,"")}function ne(e,s){return(e??"").toLowerCase().includes(s)}function ut({documents:e,documentsLoading:s,documentsError:n,documentsUnavailable:t,onInsertDocument:i,onRefetchDocuments:l}){const{t:c}=B(),p=u.useRef(null),m=u.useRef(null),[x,o]=u.useState(!1),[y,b]=u.useState(""),[k,w]=u.useState([]),[h,d]=u.useState(!1),[g,v]=u.useState(null),[_,M]=u.useState(new Set),[a,j]=u.useState(!1),[C,D]=u.useState(null);u.useEffect(()=>{var N;if(!x||((N=m.current)==null||N.focus(),k.length>0||h))return;let f=!1;return(async()=>{d(!0),v(null);try{const S=await F.getDocTree();f||w(S)}catch(S){f||v(S instanceof Error?S.message:c("agent.prompt.documentPicker.treeError"))}finally{f||d(!1)}})(),()=>{f=!0}},[x,k.length]),u.useEffect(()=>{x||(b(f=>f&&""),M(f=>f.size>0?new Set:f))},[x]),u.useEffect(()=>{if(!x)return;const f=N=>{var S;(S=p.current)!=null&&S.contains(N.target)||o(!1)},L=N=>{N.key==="Escape"&&(N.preventDefault(),o(!1))};return window.addEventListener("mousedown",f),window.addEventListener("keydown",L),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",L)}},[x]);const E=y.trim().toLowerCase(),$=u.useMemo(()=>e.filter(f=>f.type==="inline"),[e]),z=u.useMemo(()=>{const f=e.filter(L=>L.type==="file"&&L.path);return L=>{const N=te(L),S=f.find(ve=>te(ve.path??"")===N);return S==null?void 0:S.key}},[e]),T=u.useMemo(()=>E?$.filter(f=>ne(f.key,E)||ne(f.summary,E)):$,[$,E]),P=u.useMemo(()=>me(k,E),[E,k]),be=u.useMemo(()=>{if(!E)return _;const f=new Set(_);return P.autoExpanded.forEach(L=>f.add(L)),f},[_,P.autoExpanded,E]),V=f=>{i(f,"content"),o(!1)},ye=async f=>{D(null);const L=z(f);if(L){V(L);return}try{j(!0);const N=await F.registerDocument({path:f});V(N.key),l==null||l()}catch(N){D(N instanceof Error?N.message:c("agent.prompt.documentPicker.registerError"))}finally{j(!1)}},G=s||n||t||T.length>0,Z=h||g||P.nodes.length>0;return r.jsxs("div",{ref:p,className:"relative",children:[r.jsxs("button",{type:"button",onMouseDown:f=>f.preventDefault(),onClick:()=>o(f=>!f),className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 transition hover:border-gray-300 hover:bg-gray-100","aria-label":c("agent.prompt.documentInsert"),children:[r.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[r.jsx(K,{className:"h-4 w-4"}),r.jsx("span",{children:c("agent.prompt.documentInsert")})]}),r.jsx(de,{size:14})]}),x?r.jsxs("div",{className:"absolute left-0 top-[calc(100%+0.5rem)] z-20 w-80 rounded-xl border border-gray-200 bg-white p-2 shadow-lg","data-testid":"document-picker-popover",children:[r.jsxs("label",{className:"mb-2 flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-xs text-gray-500",children:[r.jsx(ue,{size:14}),r.jsx("input",{ref:m,value:y,onChange:f=>b(f.target.value),className:"w-full bg-transparent text-sm text-gray-700 outline-none","aria-label":c("agent.prompt.documentPicker.searchPlaceholder"),placeholder:c("agent.prompt.documentPicker.searchPlaceholder")})]}),r.jsxs("div",{className:"max-h-96 space-y-3 overflow-y-auto",children:[G?r.jsxs("section",{children:[r.jsxs("div",{className:"mb-1 flex items-center gap-2 px-2 py-1 text-xs font-semibold uppercase tracking-wide text-gray-400",children:[r.jsx(Ne,{className:"h-3.5 w-3.5"}),r.jsx("span",{children:c("agent.prompt.documentPicker.inlineSection")})]}),s?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentInsertLoading")}):n?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-red-500",children:n}):t?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentInsertUnavailable")}):T.length===0?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentPicker.noInlineResults")}):r.jsx("div",{className:"space-y-1",children:T.map(f=>r.jsxs("button",{type:"button",onMouseDown:L=>L.preventDefault(),onClick:()=>V(f.key),className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-gray-700 transition hover:bg-gray-100",children:[r.jsx(K,{className:"h-4 w-4 shrink-0 text-gray-400"}),r.jsx("span",{className:"truncate",children:f.key})]},f.key))})]}):null,Z?r.jsxs("section",{children:[r.jsxs("div",{className:"mb-1 flex items-center gap-2 px-2 py-1 text-xs font-semibold uppercase tracking-wide text-gray-400",children:[r.jsx(K,{className:"h-3.5 w-3.5"}),r.jsx("span",{children:c("agent.prompt.documentPicker.docsSection")})]}),h?r.jsxs("div",{className:"flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-gray-500",children:[r.jsx(J,{className:"h-4 w-4 animate-spin"}),r.jsx("span",{children:c("agent.prompt.documentPicker.treeLoading")})]}):g?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-red-500",children:g}):P.nodes.length===0?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentPicker.noTreeResults")}):r.jsxs(r.Fragment,{children:[r.jsx(Ce,{nodes:P.nodes,expandedFolders:be,onToggle:f=>M(L=>{const N=new Set(L);return N.has(f)?N.delete(f):N.add(f),N}),onSelect:f=>{a||ye(f)},selectedPath:null,isFileDisabled:()=>a,renderFileSuffix:f=>z(f.path)?r.jsx(rt,{className:"h-3.5 w-3.5 shrink-0 text-blue-500","aria-label":c("agent.prompt.documentPicker.linked")}):a?r.jsx(J,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-gray-400"}):null}),C?r.jsx("div",{className:"mt-1 rounded-lg px-3 py-2 text-sm text-red-500",role:"alert",children:C}):null]})]}):null,!G&&!Z?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentInsertEmpty")}):null]})]}):null]})}function pt({deleteNode:e,extension:s,node:n,updateAttributes:t}){const{t:i}=B(),l=u.useRef(null),[c,p]=u.useState(!1),m=String(n.attrs.key??""),x=String(n.attrs.variant??"content"),o=s.options.getVariantLabel;u.useEffect(()=>{if(!c)return;const b=w=>{var h;(h=l.current)!=null&&h.contains(w.target)||p(!1)},k=w=>{w.key==="Escape"&&(w.preventDefault(),p(!1))};return window.addEventListener("mousedown",b),window.addEventListener("keydown",k),()=>{window.removeEventListener("mousedown",b),window.removeEventListener("keydown",k)}},[c]);const y=[{value:"content",label:o("content")},{value:"toc",label:o("toc")}];return r.jsxs(Le,{as:"span",ref:l,className:"relative inline-flex","data-testid":"document-block-node",children:[r.jsx("button",{type:"button","data-testid":"document-block-trigger",onMouseDown:b=>b.preventDefault(),onClick:()=>p(b=>!b),className:"inline-flex items-center rounded-lg border border-amber-200 bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-700",children:`📄 ${m} · ${o(x)}`}),c?r.jsxs("span",{className:"absolute left-0 top-[calc(100%+0.375rem)] z-20 min-w-32 rounded-lg border border-gray-200 bg-white p-1 shadow-lg","data-testid":"document-block-popover",children:[y.map(b=>{const k=b.value===x;return r.jsxs("button",{type:"button","data-testid":`document-block-option-${b.value}`,onMouseDown:w=>w.preventDefault(),onClick:()=>{t({variant:b.value}),p(!1)},className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-gray-700 transition hover:bg-gray-100",children:[r.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center",children:k?r.jsx(_e,{className:"h-4 w-4 text-blue-500"}):null}),r.jsx("span",{children:b.label})]},b.value)}),r.jsx("div",{className:"my-1 border-t border-gray-100"}),r.jsxs("button",{type:"button","data-testid":"document-block-delete",onMouseDown:b=>b.preventDefault(),onClick:()=>{e(),p(!1)},className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-red-600 transition hover:bg-red-50",children:[r.jsx(Ee,{className:"h-4 w-4"}),r.jsx("span",{children:i("agent.prompt.documentChip.delete")})]})]}):null]})}const mt=pe.create({name:"documentBlock",addOptions(){return{getVariantLabel:e=>String(e)}},inline:!0,group:"inline",atom:!0,draggable:!0,selectable:!0,addAttributes(){return{key:{default:""},variant:{default:"content"}}},parseHTML(){return[{tag:"span[data-doc-block]"}]},renderHTML({HTMLAttributes:e,node:s}){const n=String(s.attrs.key??""),t=String(s.attrs.variant??"content"),i=this.options.getVariantLabel(t);return["span",De(e,{"data-doc-block":"true","data-key":n,"data-variant":t,"data-testid":"document-block",class:"inline-flex items-center rounded-lg border border-amber-200 bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-700"}),`📄 ${n} · ${i}`]},addNodeView(){return Se(pt)}}),ft=Me.extend({name:"variableMention",addAttributes(){return{variable:{default:"",parseHTML:e=>e.getAttribute("data-variable")??"",renderHTML:e=>({"data-variable":e.variable})}}},renderText({node:e}){return`{{${String(e.attrs.variable??"")}}}`},renderHTML({node:e,HTMLAttributes:s}){return["span",{...s,class:"inline-flex items-center rounded-full bg-blue-500 px-2 py-0.5 text-xs font-semibold text-white","data-testid":"variable-chip"},String(e.attrs.variable??"")]}}),ge=["agent.id","agent.name","agent.role","agent.team","agent.description"],re=["bold","italic","strike","code"],se={bold:{open:"**",close:"**"},italic:{open:"*",close:"*"},strike:{open:"~~",close:"~~"},code:{open:"`",close:"`"}};function ht(e){return ge.includes(e)}function xe(e,s){return s&&s.length>0?{type:"text",text:e,marks:s}:{type:"text",text:e}}function W(e,s,n){if(!s)return;const t=e[e.length-1],i=JSON.stringify(n??[]),l=JSON.stringify((t==null?void 0:t.marks)??[]);if((t==null?void 0:t.type)==="text"&&i===l){t.text=`${t.text??""}${s}`;return}e.push(xe(s,n))}function O(e,...s){return e.map(n=>{if(n.type!=="text")return n;const t=new Set((n.marks??[]).map(l=>l.type)),i=s.filter(l=>!t.has(l)).map(l=>({type:l}));return{...n,marks:[...n.marks??[],...i]}})}function gt(e){const s=e.match(/^\{\{(agent\.(?:id|name|role|team|description))\}\}$/);return!s||!ht(s[1])?null:{type:"variableMention",attrs:{variable:s[1]}}}function X(e){const s=e.match(/^\{\{\{documents\.([^.\s}]+)\.(content|toc)\}\}\}$/);return s?{type:"documentBlock",attrs:{key:s[1],variant:s[2]}}:null}function xt(e,s){const n=e[s].match(/^<document\b[^>]*>\s*(\{\{\{documents\.([^.\s}]+)\.(content|toc)\}\}\})\s*<\/document>\s*$/);if(n){const m=X(n[1]);if(m)return{node:{type:"paragraph",content:[m]},nextIndex:s+1}}if(!/^<document\b[^>]*>\s*$/.test(e[s]??""))return null;let t=s+1;for(;t<e.length&&(e[t]??"").trim()==="";)t+=1;const l=(e[t]??"").trim();for(t+=1;t<e.length&&(e[t]??"").trim()==="";)t+=1;if((e[t]??"").trim()!=="</document>")return null;const p=X(l);return p?{node:{type:"paragraph",content:[p]},nextIndex:t+1}:null}function Q(e,s,n,t){return e.startsWith(s,t)?e.indexOf(n,t+s.length):-1}function bt(e,s){const n=[e.indexOf("{{{documents.",s),e.indexOf("{{agent.",s),e.indexOf("**",s),e.indexOf("~~",s),e.indexOf("`",s),e.indexOf("*",s)].filter(t=>t>=0);return n.length>0?Math.min(...n):-1}function A(e,s=!1){const n=[];let t=0;for(;t<e.length;){const i=Q(e,"***","***",t);if(i>t){const o=e.slice(t+3,i);n.push(...O(A(o,s),"bold","italic")),t=i+3;continue}if(!s&&e.startsWith("{{{documents.",t)){const o=e.indexOf("}}}",t);if(o>t){const y=e.slice(t,o+3),b=X(y);if(b){n.push(b),t=o+3;continue}}}if(!s&&e.startsWith("{{agent.",t)){const o=e.indexOf("}}",t);if(o>t){const y=e.slice(t,o+2),b=gt(y);if(b){n.push(b),t=o+2;continue}}}const l=Q(e,"**","**",t);if(l>t){const o=e.slice(t+2,l);n.push(...O(A(o,s),"bold")),t=l+2;continue}const c=Q(e,"~~","~~",t);if(c>t){const o=e.slice(t+2,c);n.push(...O(A(o,s),"strike")),t=c+2;continue}const p=e[t]==="*"&&!e.startsWith("**",t)?e.indexOf("*",t+1):-1;if(p>t){const o=e.slice(t+1,p);n.push(...O(A(o,s),"italic")),t=p+1;continue}if(e[t]==="`"){const o=e.indexOf("`",t+1);if(o>t){W(n,e.slice(t+1,o),[{type:"code"}]),t=o+1;continue}}const m=bt(e,t),x=m>=0?m:e.length;if(x===t){W(n,e[t]),t+=1;continue}W(n,e.slice(t,x)),t=x}return n}function yt(e){const s=e.split(`
22
- `),n=[];return s.forEach((t,i)=>{n.push(...A(t)),i<s.length-1&&n.push({type:"hardBreak"})}),{type:"paragraph",content:n}}function ae(e,s){const n=s?"orderedList":"bulletList",t=s?/^\d+\.\s+/:/^[-*]\s+/;return{type:n,content:e.map(i=>({type:"listItem",content:[{type:"paragraph",content:A(i.replace(t,""))}]}))}}function vt(e){return/^#{1,3}\s+/.test(e)||/^```/.test(e)||/^---+$/.test(e)||/^[-*]\s+/.test(e)||/^\d+\.\s+/.test(e)}function kt(e){const s=new Set((e??[]).map(n=>n.type).filter(n=>re.includes(n)));return re.filter(n=>s.has(n))}function wt(e,s){let n=0;for(;n<e.length&&n<s.length&&e[n]===s[n];)n+=1;return n}function oe(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").trim()}function jt(e,s,n){var t,i,l,c;if(e.type==="hardBreak")return`
23
- `;if(e.type==="variableMention"){const p=String(((t=e.attrs)==null?void 0:t.variable)??"");return s==="preview"?`**{{${p}}}**`:`{{${p}}}`}if(e.type==="documentBlock"){const p=String(((i=e.attrs)==null?void 0:i.key)??""),m=String(((l=e.attrs)==null?void 0:l.variant)??"content"),x=`{{{documents.${p}.${m}}}}`,o=((c=n==null?void 0:n.getDocumentMeta)==null?void 0:c.call(n,p))??{name:p},y=[`name="${oe(o.name)}"`];return o.path&&y.push(`path="${oe(o.path)}"`),y.push(`type="${m}"`),`<document ${y.join(" ")}>
24
-
25
- ${x}
26
-
27
- </document>`}return I(e.content,s,n)}function I(e,s,n){let t="",i=[];const l=c=>{const p=wt(i,c);for(let m=i.length-1;m>=p;m-=1)t+=se[i[m]].close;for(let m=p;m<c.length;m+=1)t+=se[c[m]].open;i=c};for(const c of e??[]){if(c.type==="text"){l(kt(c.marks)),t+=c.text??"";continue}l([]),t+=jt(c,s,n)}return l([]),t}function U(e){const s=e.replace(/\r\n?/g,`
28
- `);if(!s.trim())return{type:"doc",content:[]};const n=s.split(`
29
- `),t=[];let i=0;for(;i<n.length;){const l=n[i];if(!l.trim()){i+=1;continue}const c=xt(n,i);if(c){t.push(c.node),i=c.nextIndex;continue}const p=l.match(/^```(\S+)?\s*$/);if(p){const o=p[1]??null,y=[];for(i+=1;i<n.length&&!/^```/.test(n[i]);)y.push(n[i]),i+=1;i<n.length&&(i+=1),t.push({type:"codeBlock",attrs:o?{language:o}:{},content:[xe(y.join(`
30
- `))]});continue}const m=l.match(/^(#{1,3})\s+(.*)$/);if(m){t.push({type:"heading",attrs:{level:m[1].length},content:A(m[2])}),i+=1;continue}if(/^---+$/.test(l)){t.push({type:"horizontalRule"}),i+=1;continue}if(/^[-*]\s+/.test(l)){const o=[];for(;i<n.length&&/^[-*]\s+/.test(n[i]);)o.push(n[i]),i+=1;t.push(ae(o,!1));continue}if(/^\d+\.\s+/.test(l)){const o=[];for(;i<n.length&&/^\d+\.\s+/.test(n[i]);)o.push(n[i]),i+=1;t.push(ae(o,!0));continue}const x=[l];for(i+=1;i<n.length&&n[i].trim()&&!vt(n[i]);)x.push(n[i]),i+=1;t.push(yt(x.join(`
31
- `)))}return{type:"doc",content:t}}function Nt(e,s,n){var t,i,l,c;switch(e.type){case"heading":{const p=Number(((t=e.attrs)==null?void 0:t.level)??1);return`${"#".repeat(Math.max(1,Math.min(3,p)))} ${I(e.content,s,n)}`}case"bulletList":return(e.content??[]).map(p=>{var m,x;return`- ${I((x=(m=p.content)==null?void 0:m[0])==null?void 0:x.content,s,n)}`}).join(`
32
- `);case"orderedList":return(e.content??[]).map((p,m)=>{var x,o;return`${m+1}. ${I((o=(x=p.content)==null?void 0:x[0])==null?void 0:o.content,s,n)}`}).join(`
33
- `);case"codeBlock":{const p=typeof((i=e.attrs)==null?void 0:i.language)=="string"?e.attrs.language:"",m=((c=(l=e.content)==null?void 0:l[0])==null?void 0:c.text)??"";return`\`\`\`${p}
34
- ${m}
35
- \`\`\``}case"horizontalRule":return"---";case"paragraph":return I(e.content,s,n);default:return I(e.content,s,n)}}function ie(e,s){return(e.content??[]).map(n=>Nt(n,"hbs",s)).join(`
36
-
37
- `)}function Ct(e){return/\{\{agent\.(?:id|name|role|team|description)\}\}|\{\{\{documents\.[^.\s}]+\.(?:content|toc)\}\}\}|<document\b[^>]*>/.test(e)}function Lt(e,s){return{type:"documentBlock",attrs:{key:e,variant:s}}}function le(e){return{type:"variableMention",attrs:{variable:e}}}function q(e){return!e.isActive("codeBlock")&&!e.isActive("code")}function ce(e,s,n){return q(e)?it(e,s,n)?!1:(e.chain().focus().insertContent(Lt(s,n)).run(),!0):(e.chain().focus().insertContent(`{{{documents.${s}.${n}}}}`).run(),!0)}const _t=u.forwardRef(function({value:s,onChange:n,documents:t,documentsLoading:i,documentsError:l,documentsUnavailable:c,onPreview:p,onRefetchDocuments:m},x){const{t:o}=B(),y=u.useRef(null),b=u.useMemo(()=>({content:o("agent.prompt.variantContent"),toc:o("agent.prompt.variantToc")}),[o]),k=u.useMemo(()=>a=>{var C;const j=t.find(D=>D.key===a);if((j==null?void 0:j.type)==="file"&&j.path){const D=j.path.split("/").filter(Boolean);return{name:D[D.length-1]??a,path:j.path}}return{name:((C=j==null?void 0:j.summary)==null?void 0:C.trim())||a}},[t]),w=u.useMemo(()=>[{key:"headings",buttons:[{key:"h1",label:o("agent.prompt.toolbar.h1"),icon:Ae,shortcut:"Cmd+Alt+1",action:a=>{a.chain().focus().toggleHeading({level:1}).run()},isActive:a=>a.isActive("heading",{level:1})},{key:"h2",label:o("agent.prompt.toolbar.h2"),icon:$e,shortcut:"Cmd+Alt+2",action:a=>{a.chain().focus().toggleHeading({level:2}).run()},isActive:a=>a.isActive("heading",{level:2})},{key:"h3",label:o("agent.prompt.toolbar.h3"),icon:Te,shortcut:"Cmd+Alt+3",action:a=>{a.chain().focus().toggleHeading({level:3}).run()},isActive:a=>a.isActive("heading",{level:3})}]},{key:"text",buttons:[{key:"bold",label:o("agent.prompt.toolbar.bold"),icon:Ie,shortcut:"Cmd+B",action:a=>{a.chain().focus().toggleBold().run()},isActive:a=>a.isActive("bold")},{key:"italic",label:o("agent.prompt.toolbar.italic"),icon:Pe,shortcut:"Cmd+I",action:a=>{a.chain().focus().toggleItalic().run()},isActive:a=>a.isActive("italic")},{key:"strike",label:o("agent.prompt.toolbar.strike"),icon:Re,shortcut:"Cmd+Shift+S",action:a=>{a.chain().focus().toggleStrike().run()},isActive:a=>a.isActive("strike")}]},{key:"lists",buttons:[{key:"bulletList",label:o("agent.prompt.toolbar.bulletList"),icon:Be,shortcut:"Cmd+Shift+8",action:a=>{a.chain().focus().toggleBulletList().run()},isActive:a=>a.isActive("bulletList")},{key:"orderedList",label:o("agent.prompt.toolbar.orderedList"),icon:ze,shortcut:"Cmd+Shift+7",action:a=>{a.chain().focus().toggleOrderedList().run()},isActive:a=>a.isActive("orderedList")},{key:"blockquote",label:o("agent.prompt.toolbar.blockquote"),icon:Oe,shortcut:"Cmd+Shift+B",action:a=>{a.chain().focus().toggleBlockquote().run()},isActive:a=>a.isActive("blockquote")}]},{key:"code",buttons:[{key:"code",label:o("agent.prompt.toolbar.code"),icon:qe,shortcut:"Cmd+E",action:a=>{a.chain().focus().toggleCode().run()},isActive:a=>a.isActive("code")},{key:"codeBlock",label:o("agent.prompt.toolbar.codeBlock"),icon:Fe,shortcut:"Cmd+Alt+C",action:a=>{a.chain().focus().toggleCodeBlock().run()},isActive:a=>a.isActive("codeBlock")},{key:"horizontalRule",label:o("agent.prompt.toolbar.horizontalRule"),icon:He,shortcut:"Cmd+Alt+-",action:a=>{a.chain().focus().setHorizontalRule().run()}}]},{key:"history",buttons:[{key:"undo",label:o("agent.prompt.toolbar.undo"),icon:Ve,shortcut:"Cmd+Z",action:a=>{a.chain().focus().undo().run()},isDisabled:a=>!a.can().chain().focus().undo().run()},{key:"redo",label:o("agent.prompt.toolbar.redo"),icon:Ke,shortcut:"Cmd+Shift+Z",action:a=>{a.chain().focus().redo().run()},isDisabled:a=>!a.can().chain().focus().redo().run()}]}],[o]),h=We({immediatelyRender:!1,extensions:[Qe.configure({heading:{levels:[1,2,3]}}),Ue.configure({placeholder:o("agent.prompt.placeholder")}),ft.configure({HTMLAttributes:{class:"inline-flex items-center rounded-full bg-blue-500 px-2 py-0.5 text-xs font-semibold text-white"}}),mt.configure({getVariantLabel:a=>a==="toc"?b.toc:b.content}),pe.create({name:"fallbackInline",inline:!0,group:"inline"})],content:U(s),editorProps:{attributes:{class:lt,"data-testid":"prompt-editor-content","aria-label":o("agent.prompt.editorLabel"),role:"textbox"}},onUpdate({editor:a}){const j=ie(a.getJSON(),{getDocumentMeta:k});y.current=j,n(j)}}),d=Je({editor:h,selector:({editor:a})=>a?{active:{h1:a.isActive("heading",{level:1}),h2:a.isActive("heading",{level:2}),h3:a.isActive("heading",{level:3}),bold:a.isActive("bold"),italic:a.isActive("italic"),strike:a.isActive("strike"),bulletList:a.isActive("bulletList"),orderedList:a.isActive("orderedList"),blockquote:a.isActive("blockquote"),code:a.isActive("code"),codeBlock:a.isActive("codeBlock")},disabled:{undo:!a.can().chain().focus().undo().run(),redo:!a.can().chain().focus().redo().run()}}:{active:{},disabled:{}}}),g=u.useMemo(()=>ge.map(a=>({label:a,actions:[{label:o("agent.prompt.toolbar.insert"),onClick:()=>{if(h){if(q(h)){h.chain().focus().insertContent(le(a)).run();return}h.chain().focus().insertContent(`{{${a}}}`).run()}}}]})),[h,o]);u.useEffect(()=>{if(!h)return;const a=ie(h.getJSON(),{getDocumentMeta:k});s===a||s===y.current||(h.commands.setContent(U(s)),y.current=s)},[h,k,s]),u.useImperativeHandle(x,()=>({insertVariable(a){if(h){if(q(h)){h.chain().focus().insertContent(le(a)).run();return}h.chain().focus().insertContent(`{{${a}}}`).run()}},insertDocumentBlock(a,j){return h?ce(h,a,j):!1},selectAll(){h==null||h.chain().focus().selectAll().run()}}),[h]);const v=a=>{if(!h||!q(h))return;const j=a.clipboardData.getData("text/plain");if(!j||!Ct(j))return;a.preventDefault();const C=U(j);h.chain().focus().insertContent(C.content??[]).run()},_=a=>`${a.label} (${a.shortcut})`,M=(a,j)=>h?ce(h,a,j):!1;return r.jsxs("section",{className:"rounded-xl border border-gray-200 bg-gray-50 p-4 shadow-sm",children:[r.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 rounded-xl border border-gray-200 bg-white p-2 shadow-sm",children:[w.map((a,j)=>r.jsxs("div",{className:"flex items-center gap-1",children:[j>0?r.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}):null,a.buttons.map(C=>{var T;const D=_(C),E=(d==null?void 0:d.active[C.key])??!1,$=h?(((T=C.isDisabled)==null?void 0:T.call(C,h))??!1)||((d==null?void 0:d.disabled[C.key])??!1):!0,z=C.icon;return r.jsx("button",{type:"button",title:D,"aria-label":D,"data-testid":`prompt-toolbar-${C.key}`,disabled:$,onClick:()=>h&&C.action(h),className:`flex h-8 w-8 items-center justify-center rounded-md transition-colors ${E?"bg-gray-200 text-gray-900":"text-gray-600 hover:bg-gray-100 hover:text-gray-900"} ${$?"cursor-not-allowed opacity-40":""}`,children:r.jsx(z,{className:"h-4 w-4"})},C.key)})]},a.key)),r.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[r.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}),r.jsx(dt,{trigger:r.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[r.jsx(Ye,{className:"h-4 w-4"}),r.jsx("span",{children:o("agent.prompt.toolbar.variable")})]}),items:g,emptyLabel:o("agent.prompt.toolbar.empty")}),r.jsx(ut,{documents:t,documentsLoading:i,documentsError:l,documentsUnavailable:c,onInsertDocument:M,onRefetchDocuments:m}),r.jsx("button",{type:"button",title:`${o("agent.prompt.preview.button")} (Cmd+P)`,"aria-label":`${o("agent.prompt.preview.button")} (Cmd+P)`,"data-testid":"prompt-toolbar-preview",onClick:p,className:"flex h-8 w-8 items-center justify-center rounded-md text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900",children:r.jsx(tt,{className:"h-4 w-4"})})]})]}),r.jsx("div",{"data-testid":"prompt-editor",onPaste:v,children:r.jsx(Xe,{editor:h})})]})});function St({previewAgentId:e=null}){const{t:s}=B(),n=Ge(g=>g.currentWorkspaceId),t=Y(g=>g.form),i=Y(g=>g.setField),[l,c]=u.useState([]),[p,m]=u.useState(!0),[x,o]=u.useState(null),[y,b]=u.useState(!1),[k,w]=u.useState(!1),h=u.useMemo(()=>{const g=ot(t);return{template:t.prompt,...e?{agentId:e}:{},context:{agent:g}}},[t,e]),d=u.useCallback(async()=>{m(!0),o(null),b(!1);try{const g=await F.getDocuments();c(g.documents)}catch(g){if(fe(g)){c([]),b(!0);return}o(g instanceof Error?g.message:s("agent.prompt.documentInsertError"))}finally{m(!1)}},[s]);return u.useEffect(()=>{d()},[n,d]),u.useEffect(()=>{const g=v=>{!(v.metaKey||v.ctrlKey)||v.key.toLowerCase()!=="p"||(v.preventDefault(),w(!0))};return window.addEventListener("keydown",g),()=>{window.removeEventListener("keydown",g)}},[]),r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold text-gray-900",children:s("agent.section.promptTitle")}),r.jsx("p",{className:"mt-1 text-sm text-gray-500",children:s("agent.section.promptDescription")})]}),r.jsx("div",{className:"grid grid-cols-1 gap-5",children:r.jsx(_t,{value:t.prompt,onChange:g=>i("prompt",g),documents:l,documentsLoading:p,documentsError:x,documentsUnavailable:y,onPreview:()=>w(!0),onRefetchDocuments:()=>void d()})}),r.jsx(ct,{open:k,request:h,onClose:()=>w(!1)})]})}export{St as default};
@@ -1 +0,0 @@
1
- import{ah as o,ai as n}from"./main-DWCTap27.js";const t=(a,r)=>o.lang.round(n.parse(a)[r]);export{t as c};
@@ -1 +0,0 @@
1
- import{s,c as e,a as r,b as l}from"./chunk-T2TOU4HS-kUreJ-bv.js";import{_ as t}from"./main-DWCTap27.js";import"./chunk-5HRBRIJM-B_Csqjvw.js";var _={parser:l,db:r,renderer:e,styles:s,init:t(a=>{a.class||(a.class={}),a.class.arrowMarkerAbsolute=a.arrowMarkerAbsolute,r.clear()},"init")};export{_ as diagram};
@@ -1 +0,0 @@
1
- import{s,c as e,a as r,b as l}from"./chunk-T2TOU4HS-kUreJ-bv.js";import{_ as t}from"./main-DWCTap27.js";import"./chunk-5HRBRIJM-B_Csqjvw.js";var _={parser:l,db:r,renderer:e,styles:s,init:t(a=>{a.class||(a.class={}),a.class.arrowMarkerAbsolute=a.arrowMarkerAbsolute,r.clear()},"init")};export{_ as diagram};