@x-code-cli/core 0.3.0 → 0.3.2

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 (59) hide show
  1. package/dist/agent/compression.d.ts.map +1 -1
  2. package/dist/agent/compression.js +21 -1
  3. package/dist/agent/compression.js.map +1 -1
  4. package/dist/agent/light-compact.d.ts +12 -0
  5. package/dist/agent/light-compact.d.ts.map +1 -1
  6. package/dist/agent/light-compact.js +75 -0
  7. package/dist/agent/light-compact.js.map +1 -1
  8. package/dist/agent/loop-state.d.ts +18 -0
  9. package/dist/agent/loop-state.d.ts.map +1 -1
  10. package/dist/agent/loop-state.js +3 -0
  11. package/dist/agent/loop-state.js.map +1 -1
  12. package/dist/agent/loop.d.ts.map +1 -1
  13. package/dist/agent/loop.js +33 -1
  14. package/dist/agent/loop.js.map +1 -1
  15. package/dist/agent/plan-tools.d.ts.map +1 -1
  16. package/dist/agent/plan-tools.js +2 -0
  17. package/dist/agent/plan-tools.js.map +1 -1
  18. package/dist/agent/session-store.d.ts +11 -0
  19. package/dist/agent/session-store.d.ts.map +1 -1
  20. package/dist/agent/session-store.js +59 -15
  21. package/dist/agent/session-store.js.map +1 -1
  22. package/dist/agent/snapshot.d.ts +45 -0
  23. package/dist/agent/snapshot.d.ts.map +1 -0
  24. package/dist/agent/snapshot.js +277 -0
  25. package/dist/agent/snapshot.js.map +1 -0
  26. package/dist/agent/sub-agents/built-in.js +1 -1
  27. package/dist/agent/sub-agents/built-in.js.map +1 -1
  28. package/dist/agent/system-prompt.d.ts.map +1 -1
  29. package/dist/agent/system-prompt.js +16 -7
  30. package/dist/agent/system-prompt.js.map +1 -1
  31. package/dist/commands/loader.d.ts +6 -0
  32. package/dist/commands/loader.d.ts.map +1 -1
  33. package/dist/commands/loader.js +27 -11
  34. package/dist/commands/loader.js.map +1 -1
  35. package/dist/commands/types.d.ts +4 -4
  36. package/dist/commands/types.d.ts.map +1 -1
  37. package/dist/index.d.ts +4 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +4 -2
  40. package/dist/index.js.map +1 -1
  41. package/dist/permissions/index.d.ts +1 -1
  42. package/dist/permissions/index.d.ts.map +1 -1
  43. package/dist/permissions/index.js +10 -4
  44. package/dist/permissions/index.js.map +1 -1
  45. package/dist/permissions/session-store.d.ts +75 -16
  46. package/dist/permissions/session-store.d.ts.map +1 -1
  47. package/dist/permissions/session-store.js +292 -37
  48. package/dist/permissions/session-store.js.map +1 -1
  49. package/dist/plugins/marketplace.d.ts +5 -2
  50. package/dist/plugins/marketplace.d.ts.map +1 -1
  51. package/dist/plugins/marketplace.js +5 -2
  52. package/dist/plugins/marketplace.js.map +1 -1
  53. package/dist/tools/shell-utils.d.ts.map +1 -1
  54. package/dist/tools/shell-utils.js +157 -6
  55. package/dist/tools/shell-utils.js.map +1 -1
  56. package/dist/tools/task.d.ts.map +1 -1
  57. package/dist/tools/task.js +28 -15
  58. package/dist/tools/task.js.map +1 -1
  59. package/package.json +1 -1
@@ -1,10 +1,20 @@
1
1
  /** Split compound shell commands by pipe/chain operators for permission checking */
2
2
  export function splitShellCommands(cmd) {
3
- // Split by |, &&, ;, || — but not inside quotes
3
+ // Split by |, &&, ;, || — but not inside quotes or curly braces.
4
+ //
5
+ // Brace tracking exists to keep PowerShell hash literals / script blocks
6
+ // intact: `Select-Object @{N='Directory';E={$_.Name}},Count` has a `;`
7
+ // inside the hash that's a *field separator*, not a statement boundary.
8
+ // Without depth tracking the splitter chops the literal in half and the
9
+ // tail (`E={$_.Name}},Count`) reads as a separate command, which trips
10
+ // the read-only check and forces an unnecessary prompt. POSIX `{ … ; }`
11
+ // brace groups are caught by the same rule — acceptable side effect,
12
+ // since the contents are still scanned end-to-end by isDestructive.
4
13
  const parts = [];
5
14
  let current = '';
6
15
  let inSingleQuote = false;
7
16
  let inDoubleQuote = false;
17
+ let braceDepth = 0;
8
18
  for (let i = 0; i < cmd.length; i++) {
9
19
  const ch = cmd[i];
10
20
  const next = cmd[i + 1];
@@ -17,7 +27,18 @@ export function splitShellCommands(cmd) {
17
27
  current += ch;
18
28
  }
19
29
  else if (!inSingleQuote && !inDoubleQuote) {
20
- if (ch === '|' && next === '|') {
30
+ if (ch === '{') {
31
+ braceDepth++;
32
+ current += ch;
33
+ }
34
+ else if (ch === '}' && braceDepth > 0) {
35
+ braceDepth--;
36
+ current += ch;
37
+ }
38
+ else if (braceDepth > 0) {
39
+ current += ch;
40
+ }
41
+ else if (ch === '|' && next === '|') {
21
42
  parts.push(current);
22
43
  current = '';
23
44
  i++; // skip next |
@@ -49,6 +70,7 @@ export function splitShellCommands(cmd) {
49
70
  }
50
71
  /** Unix/PowerShell commands that are safe to auto-allow */
51
72
  const READ_ONLY_COMMANDS = [
73
+ // POSIX shell read-only utilities
52
74
  'cd',
53
75
  'ls',
54
76
  'dir',
@@ -68,17 +90,81 @@ const READ_ONLY_COMMANDS = [
68
90
  'printenv',
69
91
  'find',
70
92
  'tree',
71
- // PowerShell
93
+ 'sort',
94
+ 'uniq',
95
+ 'grep',
96
+ 'cut',
97
+ 'nl',
98
+ 'basename',
99
+ 'dirname',
100
+ 'realpath',
101
+ // PowerShell read-only cmdlets — matched case-insensitively below.
102
+ // Curated against the codex/opencode safelists: everything that only
103
+ // reads or only reshapes the object pipeline is here. Anything that
104
+ // can write a file, start a process, or evaluate user-supplied code
105
+ // (`Invoke-Expression`, `Set-*`, `New-*`, `Remove-*`, `Start-Process`,
106
+ // `Set-Content`, `Out-File`, …) is deliberately excluded.
72
107
  'Get-ChildItem',
73
108
  'Get-Location',
109
+ 'Set-Location',
110
+ 'Push-Location',
111
+ 'Pop-Location',
74
112
  'Get-Content',
113
+ 'Get-Item',
114
+ 'Get-ItemProperty',
115
+ 'Get-Date',
116
+ 'Get-Process',
117
+ 'Get-Service',
118
+ 'Get-Command',
119
+ 'Get-Help',
120
+ 'Get-Member',
121
+ 'Get-Variable',
122
+ 'Get-Alias',
123
+ 'Get-PSDrive',
124
+ 'Get-Module',
125
+ 'Get-History',
126
+ 'Get-CimInstance',
75
127
  'Select-String',
128
+ 'Select-Object',
129
+ 'Sort-Object',
130
+ 'Group-Object',
131
+ 'Where-Object',
132
+ 'ForEach-Object',
133
+ 'Measure-Object',
134
+ 'Compare-Object',
135
+ 'Tee-Object',
136
+ 'Format-Table',
137
+ 'Format-List',
138
+ 'Format-Wide',
139
+ 'Format-Custom',
140
+ 'Out-String',
141
+ 'Out-Default',
142
+ 'Out-Host',
143
+ 'Write-Output',
144
+ 'Write-Host',
145
+ 'Write-Verbose',
146
+ 'Write-Debug',
147
+ 'Write-Information',
148
+ 'ConvertTo-Json',
149
+ 'ConvertFrom-Json',
150
+ 'ConvertTo-Csv',
151
+ 'ConvertFrom-Csv',
152
+ 'ConvertTo-Xml',
153
+ 'ConvertFrom-Xml',
154
+ 'ConvertTo-Html',
155
+ 'Resolve-Path',
156
+ 'Split-Path',
157
+ 'Join-Path',
158
+ 'Convert-Path',
76
159
  'Test-Path',
77
160
  ];
78
161
  /** Git sub-commands that are read-only */
79
162
  const READ_ONLY_GIT_SUBCOMMANDS = ['status', 'log', 'diff', 'branch', 'show', 'remote', 'tag', 'stash list', 'reflog'];
80
- // Pre-compiled regexes for performance
81
- const READ_ONLY_REGEX = new RegExp(`^\\s*(${READ_ONLY_COMMANDS.join('|')}|git\\s+(${READ_ONLY_GIT_SUBCOMMANDS.join('|')}))\\b`);
163
+ // Pre-compiled regexes for performance. `/i` flag makes the match
164
+ // case-insensitive so `Get-ChildItem` / `get-childitem` / `GET-CHILDITEM`
165
+ // all hit — PowerShell itself is case-insensitive, and `dir` / `DIR`
166
+ // should both be allowed on Windows cmd shells.
167
+ const READ_ONLY_REGEX = new RegExp(`^\\s*(${READ_ONLY_COMMANDS.join('|')}|git\\s+(${READ_ONLY_GIT_SUBCOMMANDS.join('|')}))\\b`, 'i');
82
168
  const DESTRUCTIVE_PATTERNS = [
83
169
  // ── Filesystem destruction ──
84
170
  /\brm\s+(-[a-z]*f|-[a-z]*r|--force|--recursive)/,
@@ -132,9 +218,74 @@ const DESTRUCTIVE_PATTERNS = [
132
218
  /\bfdisk\b/,
133
219
  /\bparted\b/,
134
220
  ];
221
+ // Lower-cased Verb-Noun subset of READ_ONLY_COMMANDS, pre-built for O(1)
222
+ // lookup inside isReadOnlyControlFlow. Anything without a `-` is a POSIX
223
+ // command and irrelevant to the PowerShell-control-flow heuristic.
224
+ const READ_ONLY_CMDLET_SET = new Set(READ_ONLY_COMMANDS.filter((c) => c.includes('-')).map((c) => c.toLowerCase()));
225
+ // PowerShell control-flow keywords that wrap a `{ … }` body. When a
226
+ // segment starts with one of these, the existing READ_ONLY_REGEX (which
227
+ // only checks the leading token) gives the wrong answer — `if`,
228
+ // `foreach`, `try` etc. aren't commands themselves; the work happens
229
+ // inside the braces. The codex / gemini-cli equivalents crack open the
230
+ // braces via a real PowerShell AST parser; we don't have one, so we use
231
+ // a Verb-Noun cmdlet scan guarded by the exec-invocation patterns below.
232
+ const PS_CONTROL_FLOW_RE = /^\s*(?:if|elseif|else|for|foreach|while|switch|try|catch|finally|do)\b/i;
233
+ // Patterns that, when present anywhere in the control-flow segment,
234
+ // force the readonly heuristic off:
235
+ //
236
+ // `& "C:\bin\foo.exe" arg` — call operator + path/string/variable
237
+ // `& $cmd` — same, via variable
238
+ // `. .\script.ps1` — dot sourcing
239
+ // `. $script` — dot sourcing via variable
240
+ //
241
+ // Both invoke arbitrary code that the Verb-Noun cmdlet scan can't see.
242
+ // The dot-sourcing pattern requires whitespace AFTER the dot so
243
+ // `.Property` access and `Get-Content .\file` don't false-positive.
244
+ const PS_CALL_OP_RE = /&\s*["'$./\\]/;
245
+ const PS_DOT_SOURCING_RE = /(?:^|[\s;{(])\.\s+\S/;
246
+ // Verb-Noun token shape (find + strict-validate). FIND matches anything
247
+ // with a `-`, including paths like `x-code-cli`; STRICT enforces Verb
248
+ // (initial-cap) and Noun(s) (initial-cap), which paths fail.
249
+ const VERB_NOUN_FIND_RE = /\b[A-Za-z]+(?:-[A-Za-z0-9]+)+\b/g;
250
+ const VERB_NOUN_STRICT_RE = /^[A-Z][a-z]+(?:-[A-Z][A-Za-z0-9]*)+$/;
251
+ /**
252
+ * For a PowerShell control-flow segment, return true iff every cmdlet
253
+ * inside it is in the readonly set AND nothing in the segment looks
254
+ * like an arbitrary-code invocation (`&` call operator, dot-sourcing).
255
+ *
256
+ * `if (Test-Path X) { Get-Content X }` → true (Test-Path, Get-Content both readonly)
257
+ * `if (Test-Path X) { Set-Content X foo }` → false (Set-Content not readonly)
258
+ * `if (Test-Path X) { & "evil.exe" }` → false (call operator)
259
+ * `if (Test-Path X) { . .\\evil.ps1 }` → false (dot sourcing)
260
+ * `if ($x -gt 0) { }` → false (no cmdlets found — conservative)
261
+ *
262
+ * Returns false (defer to the caller's "ask" path) for any non-control-flow
263
+ * segment, so the existing leading-token readonly check stays authoritative.
264
+ */
265
+ function isReadOnlyControlFlow(cmd) {
266
+ if (!PS_CONTROL_FLOW_RE.test(cmd))
267
+ return false;
268
+ if (PS_CALL_OP_RE.test(cmd))
269
+ return false;
270
+ if (PS_DOT_SOURCING_RE.test(cmd))
271
+ return false;
272
+ let found = 0;
273
+ for (const match of cmd.matchAll(VERB_NOUN_FIND_RE)) {
274
+ const name = match[0];
275
+ if (!VERB_NOUN_STRICT_RE.test(name))
276
+ continue;
277
+ found++;
278
+ if (!READ_ONLY_CMDLET_SET.has(name.toLowerCase()))
279
+ return false;
280
+ }
281
+ return found > 0;
282
+ }
135
283
  /** Check if a sub-command is read-only (safe to auto-allow) */
136
284
  export function isReadOnly(cmd) {
137
- return READ_ONLY_REGEX.test(cmd.trim());
285
+ const c = cmd.trim();
286
+ if (READ_ONLY_REGEX.test(c))
287
+ return true;
288
+ return isReadOnlyControlFlow(c);
138
289
  }
139
290
  /** Check if a sub-command is destructive (should be denied) */
140
291
  export function isDestructive(cmd) {
@@ -1 +1 @@
1
- {"version":3,"file":"shell-utils.js","sourceRoot":"","sources":["../../src/tools/shell-utils.ts"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AAA;AAED,MAAM,oBAAoB,GAAa;IACrC,+BAA+B;IAC/B,gDAAgD;IAChD,cAAc;IACd,UAAU;IACV,UAAU;IACV,YAAY;IACZ,wBAAwB;IACxB,eAAe;IACf,YAAY;IACZ,6BAA6B;IAC7B,2BAA2B;IAC3B,gBAAgB;IAChB,kBAAkB;IAElB,mCAAmC;IACnC,4BAA4B;IAC5B,qBAAqB;IACrB,0BAA0B;IAC1B,0BAA0B;IAC1B,4BAA4B;IAC5B,kBAAkB;IAClB,yBAAyB;IACzB,2BAA2B;IAC3B,wBAAwB;IAExB,kDAAkD;IAClD,0BAA0B;IAC1B,0BAA0B;IAC1B,uBAAuB;IACvB,uBAAuB;IAEvB,uBAAuB;IACvB,cAAc;IACd,YAAY;IACZ,iBAAiB;IACjB,mDAAmD;IACnD,aAAa;IACb,gBAAgB;IAChB,oBAAoB;IACpB,uBAAuB;IAEvB,6BAA6B;IAC7B,qCAAqC;IACrC,uBAAuB;IACvB,kCAAkC;IAElC,sCAAsC;IACtC,kDAAkD;IAClD,sBAAsB;IAEtB,8BAA8B;IAC9B,mBAAmB;IACnB,oBAAoB;IACpB,oBAAoB;IAEpB,yBAAyB;IACzB,WAAW;IACX,YAAY;CACb,CAAA;AAED,+DAA+D;AAC/D,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;AACzC,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IACpB,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAChE,CAAC"}
1
+ {"version":3,"file":"shell-utils.js","sourceRoot":"","sources":["../../src/tools/shell-utils.ts"],"names":[],"mappings":"AAOA,oFAAoF;AACpF,MAA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qBAAqB,CAAC,CAAC,CAAC,CAAA;AACjC,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IACpB,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAChE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../src/tools/task.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAEvE;;;2DAG2D;AAC3D,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAgE3E;AAED;4DAC4D;AAC5D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB;;;;UAcxD"}
1
+ {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../src/tools/task.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAEvE;;;2DAG2D;AAC3D,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CA6E3E;AAED;4DAC4D;AAC5D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB;;;;UAcxD"}
@@ -14,31 +14,39 @@ import { z } from 'zod';
14
14
  export function buildTaskToolDescription(registry) {
15
15
  const agents = registry.list();
16
16
  const agentList = agents.map((a) => ` - ${a.name}: ${a.description}`).join('\n');
17
- return `Launch a new agent to handle complex, multi-step tasks autonomously.
17
+ return `Launch a sub-agent to handle tasks that genuinely require extensive, multi-step work.
18
18
 
19
- The task tool launches specialized sub-agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it. The sub-agent runs with its own message history and returns only its final conclusion its intermediate tool calls never enter your context window, keeping the main conversation lean.
19
+ Sub-agents run with their own message history and return only their final conclusion intermediate tool calls never enter your context window, keeping the main conversation lean. However, each sub-agent invocation has significant overhead (fresh context, separate cache, extra system prompt tokens). A task completable with 2-3 direct tool calls is always faster and cheaper than delegating.
20
20
 
21
21
  Available sub-agents:
22
22
  ${agentList}
23
23
 
24
24
  When using the task tool, specify a subagent_type parameter to select which agent type to use.
25
25
 
26
- When NOT to use the task tool:
27
- - If you want to read a specific file path, use the readFile or glob tool instead of the task tool, to find the match more quickly
28
- - If you are searching for a specific class definition like "class Foo", use the grep tool instead of the task tool, to find the match more quickly
29
- - If you are searching for code within a specific file or set of 2-3 files, use the readFile tool instead of the task tool, to find the match more quickly
30
- - Other tasks that are not related to the agent descriptions above
26
+ ## When NOT to use the task tool
27
+ - Tasks completable in 3 or fewer tool calls just do them directly
28
+ - Reading a specific file use readFile directly
29
+ - Searching for a known symbol like "class Foo" use grep directly
30
+ - Searching within 1-3 known files use readFile directly
31
+ - Questions answerable from files you've already read in this conversation
32
+ - Direct questions you can answer from your own knowledge
33
+ - Single-file edits, trivial fixes, or any task with an obvious direct path
31
34
 
32
- Usage notes:
35
+ ## When to use the task tool
36
+ - Broad codebase exploration requiring 4+ searches across many directories, AFTER direct search proved insufficient
37
+ - Code review of pending changes (structured reviewer output)
38
+ - Implementation planning requiring 5+ files to read
39
+ - Multi-step investigation where only the conclusion matters
40
+
41
+ ## Usage notes
33
42
  - Always include a short description (3-5 words) summarizing what the agent will do
34
- - Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
35
- - When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
36
- - Each task invocation starts fresh — provide a complete task description.
43
+ - Launch multiple agents concurrently when their tasks are genuinely independent; use a single message with multiple tool uses
44
+ - The result is not visible to the user summarize it back in a text message
45
+ - Each task invocation starts fresh — provide a complete task description
37
46
  - The agent's outputs should generally be trusted
38
- - Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, etc.), since it is not aware of the user's intent
39
- - If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
40
- - If the user specifies that they want you to run agents "in parallel", you MUST send a single message with multiple task tool use content blocks. For example, if you need to launch both a code-reviewer agent and an explore agent in parallel, send a single message with both tool calls.
41
- - NEVER launch multiple sub-agents in one turn if they could modify the same files or resources. Only run multiple sub-agents in parallel when their tasks are genuinely independent.
47
+ - Clearly tell the agent whether you expect it to write code or just to do research
48
+ - If the user specifies that they want you to run agents "in parallel", you MUST send a single message with multiple task tool use content blocks
49
+ - NEVER launch multiple sub-agents in one turn if they could modify the same files or resources
42
50
 
43
51
  ## Writing the prompt
44
52
 
@@ -65,6 +73,11 @@ task({
65
73
  })
66
74
  </example>
67
75
 
76
+ <example>
77
+ user: "Where is the database connection configured?"
78
+ <commentary>Do NOT use task — a single grep for "database" or "connection" will find it. Use grep directly.</commentary>
79
+ </example>
80
+
68
81
  <example>
69
82
  user: "Fix the typo in README"
70
83
  <commentary>Do NOT use task — this is a single-step edit. Just use the edit tool directly.</commentary>
@@ -1 +1 @@
1
- {"version":3,"file":"task.js","sourceRoot":"","sources":["../../src/tools/task.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,sEAAsE;AACtE,kEAAkE;AAClE,gEAAgE;AAChE,kEAAkE;AAClE,mBAAmB;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB;;;2DAG2D;AAC3D,MAAM,UAAU,wBAAwB,CAAC,QAA0B;IACjE,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC9B,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAmEA,CAAA;AACX,CAAC;AAED;4DAC4D;AAC5D,MAAM,UAAU,cAAc,CAAC,QAA0B;IACvD,OAAO,IAAI,CAAC;QACV,WAAW,EAAE,wBAAwB,CAAC,QAAQ,CAAC;QAC/C,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6CAA6C,CAAC;YAC/E,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sCAAsC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACvG,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,QAAQ,CACP,wGAAwG,CACzG;SACJ,CAAC;QACF,qDAAqD;KACtD,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-code-cli/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/woai3c/x-code-cli",