flavor-code 1.4.2 → 1.4.3-beta.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 (74) hide show
  1. package/README.md +28 -1
  2. package/README.zh-CN.md +28 -1
  3. package/dist/{app-4CUS3GEJ.js → app-G35YBHPR.js} +593 -536
  4. package/dist/apply-WOW3QU5I.js +51 -0
  5. package/dist/broker-cli-X5H46FZV.js +15 -0
  6. package/dist/check-CSKTV4O2.js +16 -0
  7. package/dist/chunk-3563SW4X.js +10513 -0
  8. package/dist/chunk-3UX2CGDW.js +1955 -0
  9. package/dist/chunk-4TMLXZVZ.js +75 -0
  10. package/dist/chunk-6F66UXBI.js +48 -0
  11. package/dist/{chunk-KMBDK4SN.js → chunk-6URQ7FIF.js} +24 -88
  12. package/dist/chunk-6X62CGMA.js +193 -0
  13. package/dist/chunk-7Y64WNBB.js +8930 -0
  14. package/dist/chunk-AA4QNKTF.js +501 -0
  15. package/dist/chunk-BDX777JR.js +11 -0
  16. package/dist/chunk-CVP5OUHD.js +103 -0
  17. package/dist/chunk-EWD7FWTH.js +14547 -0
  18. package/dist/chunk-FAJ6YDZK.js +630 -0
  19. package/dist/{chunk-N5MXHJKD.js → chunk-GTFP2R5I.js} +1 -1
  20. package/dist/{chunk-7YFHRORG.js → chunk-HGTCIHWA.js} +383 -172
  21. package/dist/chunk-IDJAHEG6.js +43501 -0
  22. package/dist/chunk-IQEEFDEE.js +389 -0
  23. package/dist/chunk-IU3UBETC.js +30 -0
  24. package/dist/chunk-K7UGGWJV.js +1003 -0
  25. package/dist/chunk-KRWWCVXA.js +74 -0
  26. package/dist/chunk-OKHV7CTB.js +482 -0
  27. package/dist/chunk-PULWAH6E.js +474 -0
  28. package/dist/chunk-PZ5NKRVA.js +85 -0
  29. package/dist/chunk-RBAZLFKB.js +1022 -0
  30. package/dist/chunk-RV3EXUXM.js +30 -0
  31. package/dist/chunk-SJUIIHIA.js +2130 -0
  32. package/dist/{chunk-W2TIY6JY.js → chunk-T6RE76D2.js} +1993 -493
  33. package/dist/chunk-TIEOVQW6.js +61 -0
  34. package/dist/chunk-WLZUAVVU.js +15 -0
  35. package/dist/chunk-X442CJJH.js +114 -0
  36. package/dist/{chunk-RAYH6K2H.js → chunk-Y7EH4NVO.js} +1 -1
  37. package/dist/{chunk-S32JRDZK.js → chunk-ZKKVSR37.js} +6 -1
  38. package/dist/{claude-ink-VQU3C5UL.js → claude-ink-BE56DB6N.js} +9 -4
  39. package/dist/cli-3MF6EL2H.js +163 -0
  40. package/dist/cli-main.js +3805 -473
  41. package/dist/cli.js +50 -4
  42. package/dist/config/load.d.ts +8 -0
  43. package/dist/config/schema.d.ts +11 -0
  44. package/dist/context/manager.d.ts +2 -0
  45. package/dist/desktop/main.js +4299 -1150
  46. package/dist/desktop/preload.cjs +30 -0
  47. package/dist/desktop-renderer/assets/index-BWklSoOO.css +1 -0
  48. package/dist/desktop-renderer/assets/index-DCqIrF1S.js +153 -0
  49. package/dist/desktop-renderer/assets/{interactive-terminal-ouQQ3brz.js → interactive-terminal-B6GbpzIn.js} +1 -1
  50. package/dist/desktop-renderer/index.html +2 -2
  51. package/dist/doctor-OHCGK52S.js +20 -0
  52. package/dist/load-QK6CMLDF.js +25 -0
  53. package/dist/log-ATFIPRNU.js +19 -0
  54. package/dist/manager-5SI4MPES.js +191 -0
  55. package/dist/models/anthropic.d.ts +3 -0
  56. package/dist/node-LOIXT44J.js +879 -0
  57. package/dist/plugin-worker-entry.js +1 -1
  58. package/dist/production-6DIZ6YLQ.js +46 -0
  59. package/dist/production.d.ts +28 -1
  60. package/dist/project-3QXE22TG.js +11 -0
  61. package/dist/react-M6JGXSJZ.js +7 -0
  62. package/dist/recorder-FAGJJH3N.js +11 -0
  63. package/dist/sdk/index.js +30 -8
  64. package/dist/server-2KLKPHPL.js +11 -0
  65. package/dist/session/store.d.ts +1 -0
  66. package/dist/store-ZIHN6363.js +18 -0
  67. package/dist/usage-summary-G5FBOJLK.js +13 -0
  68. package/dist/write-stream-CGD57URC.js +77 -0
  69. package/package.json +1 -1
  70. package/dist/chunk-B23V72YR.js +0 -170
  71. package/dist/chunk-QKND3FX7.js +0 -26103
  72. package/dist/desktop-renderer/assets/index-Bk6FYhyh.css +0 -1
  73. package/dist/desktop-renderer/assets/index-CPXrzFgv.js +0 -154
  74. package/dist/load-UPOG3XQR.js +0 -19
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
3
 
4
4
  // src/plugins/plugin-worker-entry.ts
5
5
  import { readFile, realpath } from "fs/promises";
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ ApprovalBridge,
5
+ DEFAULT_SHUTDOWN_STEP_TIMEOUT_MS,
6
+ compileHeadlessToolAllowlist,
7
+ createProductionRuntime,
8
+ createPromptEnvironment,
9
+ matchesHeadlessAllowlist,
10
+ runGoalSession,
11
+ runResumeGoalSession
12
+ } from "./chunk-IDJAHEG6.js";
13
+ import "./chunk-TIEOVQW6.js";
14
+ import "./chunk-OKHV7CTB.js";
15
+ import "./chunk-K7UGGWJV.js";
16
+ import "./chunk-IU3UBETC.js";
17
+ import "./chunk-PZ5NKRVA.js";
18
+ import "./chunk-6F66UXBI.js";
19
+ import "./chunk-3UX2CGDW.js";
20
+ import "./chunk-7Y64WNBB.js";
21
+ import "./chunk-CVP5OUHD.js";
22
+ import "./chunk-3563SW4X.js";
23
+ import "./chunk-RBAZLFKB.js";
24
+ import "./chunk-FAJ6YDZK.js";
25
+ import "./chunk-WLZUAVVU.js";
26
+ import "./chunk-RV3EXUXM.js";
27
+ import "./chunk-IQEEFDEE.js";
28
+ import "./chunk-GTFP2R5I.js";
29
+ import "./chunk-HGTCIHWA.js";
30
+ import "./chunk-SJUIIHIA.js";
31
+ import "./chunk-BDX777JR.js";
32
+ import "./chunk-6X62CGMA.js";
33
+ import "./chunk-EWD7FWTH.js";
34
+ import "./chunk-KRWWCVXA.js";
35
+ import "./chunk-X442CJJH.js";
36
+ import "./chunk-ZKKVSR37.js";
37
+ export {
38
+ ApprovalBridge,
39
+ DEFAULT_SHUTDOWN_STEP_TIMEOUT_MS,
40
+ compileHeadlessToolAllowlist,
41
+ createProductionRuntime,
42
+ createPromptEnvironment,
43
+ matchesHeadlessAllowlist,
44
+ runGoalSession,
45
+ runResumeGoalSession
46
+ };
@@ -1,7 +1,7 @@
1
1
  import type { AgentEvent } from "./agent/types.js";
2
2
  import { GoalOrchestrator } from "./goal/orchestrator.js";
3
3
  import { type McpClientFactory } from "./mcp/client.js";
4
- import type { PermissionProfile, PermissionRequest } from "./permissions/engine.js";
4
+ import type { PermissionMode, PermissionProfile, PermissionRequest } from "./permissions/engine.js";
5
5
  import { type PromptEnvironment } from "./prompts/system.js";
6
6
  import type { ApprovalDecision } from "./tools/runtime.js";
7
7
  import { type MemoryRestartContinuation } from "./utils/memory-restart.js";
@@ -35,6 +35,12 @@ export interface ProductionRuntimeOptions {
35
35
  onToolsChange?(): void;
36
36
  /** Non-interactive callers must deny requests instead of waiting for input. */
37
37
  approvalPolicy?: "prompt" | "deny";
38
+ /** Override the resolved permission mode for this runtime (CLI --permission-mode). Takes precedence over recovered and configured modes. */
39
+ permissionMode?: PermissionMode;
40
+ /** Override the main model for this runtime (CLI --model), validated against the registry and any PKCE allowlist. */
41
+ modelOverride?: string;
42
+ /** Tool patterns auto-approved when approvalPolicy is "deny" (CLI --allowed-tools), e.g. "Read", "mcp__docs__*", "Shell(npm test:*)". */
43
+ headlessToolAllowlist?: readonly string[];
38
44
  /** Allow a protocol host to resolve tool approvals without enabling other interactive UI bridges. */
39
45
  rpcToolApprovals?: boolean;
40
46
  /** Optional pre-commit gate used by protocol hosts to stream a proposed text write before it reaches disk. */
@@ -118,5 +124,26 @@ export interface MemoryRestartRotation {
118
124
  /** Retention census holders reported by the major in-memory owners. */
119
125
  holders?: Record<string, RotationCensusHolder>;
120
126
  }
127
+ interface HeadlessAllowlistEntry {
128
+ /** Exact tool name match. */
129
+ tool?: string;
130
+ /** `pattern*` matches any tool name starting with the pattern. */
131
+ prefix?: string;
132
+ /** `Shell(prefix:*)` additionally requires the raw shell command to start with prefix. */
133
+ command?: string;
134
+ }
135
+ /**
136
+ * Compiles CLI --allowed-tools patterns for headless runs. Supported forms:
137
+ * `Read` (exact tool), `mcp__docs__*` (name prefix), `Shell(npm test:*)`
138
+ * (shell command prefix). Malformed patterns are ignored.
139
+ */
140
+ export declare function compileHeadlessToolAllowlist(patterns: readonly string[]): readonly HeadlessAllowlistEntry[];
141
+ /**
142
+ * Decides whether an "ask" permission request is pre-approved by the headless
143
+ * allowlist. Monotonic denials from the permission engine never reach here,
144
+ * and wrapped/opaque shell commands are never auto-approved.
145
+ */
146
+ export declare function matchesHeadlessAllowlist(entries: readonly HeadlessAllowlistEntry[], request: Pick<PermissionRequest, "tool" | "command" | "args">): boolean;
121
147
  export declare function runGoalSession(orchestrator: GoalOrchestrator, goal: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
122
148
  export declare function runResumeGoalSession(orchestrator: GoalOrchestrator, goalId: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
149
+ export {};
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ initializeFlavor,
5
+ inspectProject
6
+ } from "./chunk-OKHV7CTB.js";
7
+ import "./chunk-ZKKVSR37.js";
8
+ export {
9
+ initializeFlavor,
10
+ inspectProject
11
+ };
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ require_react
5
+ } from "./chunk-PULWAH6E.js";
6
+ import "./chunk-ZKKVSR37.js";
7
+ export default require_react();
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ TraceRecorder
5
+ } from "./chunk-4TMLXZVZ.js";
6
+ import "./chunk-WLZUAVVU.js";
7
+ import "./chunk-EWD7FWTH.js";
8
+ import "./chunk-ZKKVSR37.js";
9
+ export {
10
+ TraceRecorder
11
+ };
package/dist/sdk/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ FlavorRpcServer
5
+ } from "../chunk-6URQ7FIF.js";
3
6
  import {
4
- FlavorRpcServer,
5
7
  TraceRecordSchema,
6
8
  TraceRecorder
7
- } from "../chunk-KMBDK4SN.js";
9
+ } from "../chunk-4TMLXZVZ.js";
8
10
  import {
9
11
  AgentMessageQueue,
10
12
  DockerExecutionEnvironment,
@@ -13,11 +15,31 @@ import {
13
15
  WorkspaceCheckpointStore,
14
16
  buildDockerInvocation,
15
17
  createProductionRuntime
16
- } from "../chunk-QKND3FX7.js";
17
- import "../chunk-N5MXHJKD.js";
18
- import "../chunk-7YFHRORG.js";
19
- import "../chunk-B23V72YR.js";
20
- import "../chunk-S32JRDZK.js";
18
+ } from "../chunk-IDJAHEG6.js";
19
+ import "../chunk-TIEOVQW6.js";
20
+ import "../chunk-OKHV7CTB.js";
21
+ import "../chunk-K7UGGWJV.js";
22
+ import "../chunk-IU3UBETC.js";
23
+ import "../chunk-PZ5NKRVA.js";
24
+ import "../chunk-6F66UXBI.js";
25
+ import "../chunk-3UX2CGDW.js";
26
+ import "../chunk-7Y64WNBB.js";
27
+ import "../chunk-CVP5OUHD.js";
28
+ import "../chunk-3563SW4X.js";
29
+ import "../chunk-RBAZLFKB.js";
30
+ import "../chunk-FAJ6YDZK.js";
31
+ import "../chunk-WLZUAVVU.js";
32
+ import "../chunk-RV3EXUXM.js";
33
+ import "../chunk-IQEEFDEE.js";
34
+ import "../chunk-GTFP2R5I.js";
35
+ import "../chunk-HGTCIHWA.js";
36
+ import "../chunk-SJUIIHIA.js";
37
+ import "../chunk-BDX777JR.js";
38
+ import "../chunk-6X62CGMA.js";
39
+ import "../chunk-EWD7FWTH.js";
40
+ import "../chunk-KRWWCVXA.js";
41
+ import "../chunk-X442CJJH.js";
42
+ import "../chunk-ZKKVSR37.js";
21
43
 
22
44
  // src/trace/replay.ts
23
45
  import { readFile } from "fs/promises";
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ FlavorRpcServer
5
+ } from "./chunk-6URQ7FIF.js";
6
+ import "./chunk-BDX777JR.js";
7
+ import "./chunk-EWD7FWTH.js";
8
+ import "./chunk-ZKKVSR37.js";
9
+ export {
10
+ FlavorRpcServer
11
+ };
@@ -109,6 +109,7 @@ export declare const SessionDocumentSchema: z.ZodObject<{
109
109
  cacheBreakpoint: z.ZodOptional<z.ZodBoolean>;
110
110
  }, z.core.$strict>>;
111
111
  sources: z.ZodRecord<z.ZodString, z.ZodString>;
112
+ pinnedSources: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
112
113
  stableSourceHash: z.ZodString;
113
114
  }, z.core.$strict>>;
114
115
  visibilityLog: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ DEFAULT_MAX_SESSION_BYTES,
5
+ SESSION_VERSION,
6
+ SessionDocumentSchema,
7
+ SessionStore
8
+ } from "./chunk-SJUIIHIA.js";
9
+ import "./chunk-BDX777JR.js";
10
+ import "./chunk-6X62CGMA.js";
11
+ import "./chunk-EWD7FWTH.js";
12
+ import "./chunk-ZKKVSR37.js";
13
+ export {
14
+ DEFAULT_MAX_SESSION_BYTES,
15
+ SESSION_VERSION,
16
+ SessionDocumentSchema,
17
+ SessionStore
18
+ };
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import {
4
+ formatUsageSummary,
5
+ parseUsageEntries,
6
+ summarizeUsage
7
+ } from "./chunk-X442CJJH.js";
8
+ import "./chunk-ZKKVSR37.js";
9
+ export {
10
+ formatUsageSummary,
11
+ parseUsageEntries,
12
+ summarizeUsage
13
+ };
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
3
+ import "./chunk-ZKKVSR37.js";
4
+
5
+ // src/rpc/write-stream.ts
6
+ import { randomUUID } from "crypto";
7
+ var RpcWriteStreamBridge = class {
8
+ #output;
9
+ #pending;
10
+ constructor(output) {
11
+ this.#output = output;
12
+ }
13
+ get pendingId() {
14
+ return this.#pending?.id;
15
+ }
16
+ async preview(proposal, signal) {
17
+ if (this.#pending !== void 0) throw new Error("Another streamed write is still awaiting commit");
18
+ if (signal.aborted) throw signal.reason;
19
+ const id = randomUUID();
20
+ this.#output({
21
+ type: "write-start",
22
+ id,
23
+ path: proposal.path,
24
+ before: proposal.before,
25
+ totalBytes: Buffer.byteLength(proposal.after)
26
+ });
27
+ for (const delta of streamChunks(proposal.after)) this.#output({ type: "write-delta", id, delta });
28
+ this.#output({ type: "write-ready", id });
29
+ await new Promise((resolve, reject) => {
30
+ const onAbort = () => {
31
+ this.#output({ type: "write-cancelled", id });
32
+ this.#clear(id);
33
+ reject(signal.reason);
34
+ };
35
+ signal.addEventListener("abort", onAbort, { once: true });
36
+ this.#pending = {
37
+ id,
38
+ resolve,
39
+ reject,
40
+ removeAbort: () => signal.removeEventListener("abort", onAbort)
41
+ };
42
+ });
43
+ }
44
+ commit(id) {
45
+ const pending = this.#pending;
46
+ if (pending === void 0 || pending.id !== id) throw new Error("Streamed write is no longer awaiting commit");
47
+ pending.removeAbort();
48
+ this.#pending = void 0;
49
+ pending.resolve();
50
+ }
51
+ dispose() {
52
+ const pending = this.#pending;
53
+ if (pending === void 0) return;
54
+ pending.removeAbort();
55
+ this.#pending = void 0;
56
+ pending.reject(new Error("Streamed write bridge disposed"));
57
+ }
58
+ #clear(id) {
59
+ if (this.#pending?.id !== id) return;
60
+ this.#pending.removeAbort();
61
+ this.#pending = void 0;
62
+ }
63
+ };
64
+ function streamChunks(content, maxChars = 2048) {
65
+ if (!content) return [];
66
+ const chunks = [];
67
+ for (const line of content.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
68
+ for (let offset = 0; offset < line.length; offset += maxChars) {
69
+ chunks.push(line.slice(offset, offset + maxChars));
70
+ }
71
+ }
72
+ return chunks;
73
+ }
74
+ export {
75
+ RpcWriteStreamBridge,
76
+ streamChunks
77
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flavor-code",
3
- "version": "1.4.2",
3
+ "version": "1.4.3-beta.2",
4
4
  "author": "YachuanWzh",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
3
-
4
- // src/utils/execFileNoThrow.ts
5
- import { execFile } from "child_process";
6
- function execFileNoThrow(file, args, options = {}) {
7
- return new Promise((resolve2) => {
8
- const child = execFile(file, args, {
9
- timeout: options.timeout,
10
- maxBuffer: options.maxBuffer,
11
- cwd: options.useCwd === false ? void 0 : process.cwd(),
12
- env: options.env,
13
- encoding: "utf8",
14
- windowsHide: true,
15
- ...options.signal === void 0 ? {} : { signal: options.signal }
16
- }, (error, stdout, stderr) => {
17
- resolve2({
18
- stdout,
19
- stderr,
20
- code: typeof error?.code === "number" ? error.code : error ? 1 : 0,
21
- ...error === null ? {} : { error: error.message }
22
- });
23
- });
24
- if (options.input !== void 0) child.stdin?.end(options.input);
25
- });
26
- }
27
-
28
- // src/utils/log.ts
29
- import { appendFile, mkdir } from "fs/promises";
30
- import { dirname, join, resolve } from "path";
31
- var pending = Promise.resolve();
32
- var usagePending = Promise.resolve();
33
- function logError(error) {
34
- if (process.env.DEBUG) process.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}
35
- `);
36
- }
37
- function usageLogPath() {
38
- return process.env.FLAVOR_USAGE_FILE ?? join(process.cwd(), ".flavor", "usage.jsonl");
39
- }
40
- var usageSessionId = "unknown";
41
- var truncateOnNextAppend = false;
42
- function setUsageSession(sessionId) {
43
- usageSessionId = sessionId;
44
- truncateOnNextAppend = true;
45
- }
46
- function currentUsageSession() {
47
- return usageSessionId;
48
- }
49
- async function appendUsageLog(line) {
50
- usagePending = usagePending.catch(() => void 0).then(async () => {
51
- try {
52
- const path = usageLogPath();
53
- await mkdir(dirname(path), { recursive: true, mode: 448 });
54
- const flag = truncateOnNextAppend ? "w" : "a";
55
- truncateOnNextAppend = false;
56
- await appendFile(path, `${line}
57
- `, { encoding: "utf8", mode: 384, flag });
58
- } catch {
59
- }
60
- });
61
- return usagePending;
62
- }
63
- var AuditLogger = class {
64
- #path;
65
- #closed = false;
66
- constructor(workspace) {
67
- this.#path = join(resolve(workspace), ".flavor", "audit.jsonl");
68
- }
69
- get path() {
70
- return this.#path;
71
- }
72
- async append(entry) {
73
- if (this.#closed) return;
74
- const line = `${JSON.stringify(entry)}
75
- `;
76
- pending = pending.catch(() => void 0).then(() => this.#write(line));
77
- return pending;
78
- }
79
- async #write(line) {
80
- try {
81
- await mkdir(dirname(this.#path), { recursive: true, mode: 448 });
82
- await appendFile(this.#path, line, { encoding: "utf8", mode: 384, flag: "a" });
83
- } catch {
84
- }
85
- }
86
- close() {
87
- this.#closed = true;
88
- }
89
- };
90
-
91
- // src/utils/semver.ts
92
- import { gt as semverGt, gte as semverGte, valid as semverValid } from "semver";
93
- function gte(a, b) {
94
- return semverGte(a, b, { loose: true });
95
- }
96
- function gt(a, b) {
97
- return semverGt(a, b, { loose: true });
98
- }
99
- function isValidVersion(value) {
100
- return semverValid(value, { loose: true }) !== null;
101
- }
102
-
103
- // src/utils/intl.ts
104
- var graphemeSegmenter;
105
- function getGraphemeSegmenter() {
106
- return graphemeSegmenter ??= new Intl.Segmenter(void 0, { granularity: "grapheme" });
107
- }
108
- function detectSystemLocale() {
109
- try {
110
- const locale = Intl.DateTimeFormat().resolvedOptions().locale;
111
- if (locale && locale.length >= 2) return locale;
112
- } catch {
113
- }
114
- for (const key of ["LANG", "LC_ALL", "LC_MESSAGES"]) {
115
- const raw = process.env[key];
116
- if (!raw || raw === "C" || raw === "POSIX") continue;
117
- const match = raw.match(/^([a-z]{2})_([A-Z]{2})(?:[.@].*)?$/);
118
- if (match) return `${match[1]}-${match[2]}`;
119
- }
120
- return "zh-CN";
121
- }
122
- function resolveLanguage(explicit) {
123
- if (explicit !== void 0) return explicit;
124
- return detectSystemLocale();
125
- }
126
- function languageInstruction(language) {
127
- const label = LANG_LABELS.get(language) ?? language;
128
- return `Always respond in ${label}. Do NOT reply in any other language unless the user explicitly asks for it.`;
129
- }
130
- var LANG_LABELS = /* @__PURE__ */ new Map([
131
- ["zh-CN", "Simplified Chinese (zh-CN)"],
132
- ["zh-TW", "Traditional Chinese (zh-TW)"],
133
- ["zh-HK", "Traditional Chinese (zh-HK)"],
134
- ["ja-JP", "Japanese (ja-JP)"],
135
- ["ko-KR", "Korean (ko-KR)"],
136
- ["en-US", "English (en-US)"],
137
- ["en-GB", "English (en-GB)"],
138
- ["fr-FR", "French (fr-FR)"],
139
- ["de-DE", "German (de-DE)"],
140
- ["es-ES", "Spanish (es-ES)"],
141
- ["pt-BR", "Portuguese (pt-BR)"],
142
- ["ru-RU", "Russian (ru-RU)"],
143
- ["ar-SA", "Arabic (ar-SA)"],
144
- ["vi-VN", "Vietnamese (vi-VN)"],
145
- ["th-TH", "Thai (th-TH)"],
146
- ["id-ID", "Indonesian (id-ID)"]
147
- ]);
148
-
149
- // src/utils/envUtils.ts
150
- function isEnvTruthy(value) {
151
- if (typeof value === "boolean") return value;
152
- return value === "1" || value?.toLowerCase() === "true" || value?.toLowerCase() === "yes";
153
- }
154
-
155
- export {
156
- execFileNoThrow,
157
- isEnvTruthy,
158
- logError,
159
- usageLogPath,
160
- setUsageSession,
161
- currentUsageSession,
162
- appendUsageLog,
163
- AuditLogger,
164
- gte,
165
- gt,
166
- isValidVersion,
167
- getGraphemeSegmenter,
168
- resolveLanguage,
169
- languageInstruction
170
- };