@chatcode/chatcode-cli 3.0.5-rc.1 → 3.0.5-rc.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chatcode/chatcode-cli",
3
3
  "description": "ChatCode CLI: TUI-first coding agent, Web launcher, profiles, and legacy DSH-compatible plugins",
4
- "version": "3.0.5-rc.1",
4
+ "version": "3.0.5-rc.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -74,7 +74,7 @@
74
74
  "node-addon-require-builtin": "^0.1.6",
75
75
  "node-pty": "1.2.0-beta.15",
76
76
  "open": "^11.0.0",
77
- "picomatch": "^4.0.3",
77
+ "picomatch": "^4.0.4",
78
78
  "react": "^18.2.0",
79
79
  "react-dom": "^18.2.0",
80
80
  "resolve.exports": "^2.0.3",
@@ -95,46 +95,46 @@
95
95
  "ajv": "^8.20.0",
96
96
  "execa": "^10.0.0",
97
97
  "ws": "8.21.0",
98
- "@deepseek-ai/dsh-acp": "0.1.7-rc.2",
99
- "@deepseek-ai/dsh-bash-local": "0.1.7-rc.2",
100
- "@deepseek-ai/dsh-deepseek-llm-api-extensions": "0.1.7-rc.2",
101
- "@deepseek-ai/dsh-agent": "0.1.7-rc.2",
102
98
  "@deepseek-ai/dsh-attachment-local": "0.1.7-rc.2",
103
- "@deepseek-ai/dsh-agent-loop": "0.1.7-rc.2",
99
+ "@deepseek-ai/dsh-acp": "0.1.7-rc.2",
100
+ "@deepseek-ai/dsh-agent-loop-testkit": "0.1.7-rc.2",
104
101
  "@deepseek-ai/dsh-experimental-agent-team": "0.1.7-rc.2",
105
- "@deepseek-ai/dsh-experimental-tool-agent-team": "0.1.7-rc.2",
102
+ "@deepseek-ai/dsh-agent-loop": "0.1.7-rc.2",
103
+ "@deepseek-ai/dsh-agent": "0.1.7-rc.2",
106
104
  "@deepseek-ai/dsh-credentials-local": "0.1.7-rc.2",
107
- "@deepseek-ai/dsh-agent-loop-testkit": "0.1.7-rc.2",
108
- "@deepseek-ai/dsh-host-frontend-static": "0.1.7-rc.2",
109
- "@deepseek-ai/dsh-fs-sandbox": "0.1.7-rc.2",
110
105
  "@deepseek-ai/dsh-experimental-ptc-runtime-python": "0.1.7-rc.2",
111
- "@deepseek-ai/dsh-llm": "0.1.7-rc.2",
112
- "@deepseek-ai/dsh-host-webserver": "0.1.7-rc.2",
113
- "@deepseek-ai/dsh-llm-deepseek-api-key": "0.1.7-rc.2",
106
+ "@deepseek-ai/dsh-bash-local": "0.1.7-rc.2",
107
+ "@deepseek-ai/dsh-deepseek-llm-api-extensions": "0.1.7-rc.2",
114
108
  "@deepseek-ai/dsh-fs-observation-policy": "0.1.7-rc.2",
109
+ "@deepseek-ai/dsh-fs-sandbox": "0.1.7-rc.2",
110
+ "@deepseek-ai/dsh-host-frontend-static": "0.1.7-rc.2",
115
111
  "@deepseek-ai/dsh-llm-deepseek": "0.1.7-rc.2",
116
- "@deepseek-ai/dsh-llm-mock-server": "0.1.7-rc.2",
117
- "@deepseek-ai/dsh-llm-replay": "0.1.7-rc.2",
118
- "@deepseek-ai/dsh-loader-smoke": "0.1.7-rc.2",
112
+ "@deepseek-ai/dsh-experimental-tool-agent-team": "0.1.7-rc.2",
119
113
  "@deepseek-ai/dsh-llm-deepseek-account": "0.1.7-rc.2",
114
+ "@deepseek-ai/dsh-host-webserver": "0.1.7-rc.2",
115
+ "@deepseek-ai/dsh-llm": "0.1.7-rc.2",
116
+ "@deepseek-ai/dsh-llm-deepseek-api-key": "0.1.7-rc.2",
120
117
  "@deepseek-ai/dsh-sandbox-local": "0.1.7-rc.2",
121
- "@deepseek-ai/dsh-session": "0.1.7-rc.2",
122
- "@deepseek-ai/dsh-llm-pi-ai": "0.1.7-rc.2",
118
+ "@deepseek-ai/dsh-llm-mock-server": "0.1.7-rc.2",
123
119
  "@deepseek-ai/dsh-plugin-package-inventory-deepseek": "0.1.7-rc.2",
124
- "@deepseek-ai/dsh-sdk-client": "0.1.7-rc.2",
125
- "@deepseek-ai/dsh-session-checkpoint-policy": "0.1.7-rc.2",
120
+ "@deepseek-ai/dsh-loader-smoke": "0.1.7-rc.2",
126
121
  "@deepseek-ai/dsh-sandbox-policy": "0.1.7-rc.2",
127
- "@deepseek-ai/dsh-session-persistence-jsonl": "0.1.7-rc.2",
128
- "@deepseek-ai/dsh-session-log-deepseek": "0.1.7-rc.2",
122
+ "@deepseek-ai/dsh-llm-replay": "0.1.7-rc.2",
129
123
  "@deepseek-ai/dsh-session-query": "0.1.7-rc.2",
124
+ "@deepseek-ai/dsh-session": "0.1.7-rc.2",
125
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.1.7-rc.2",
126
+ "@deepseek-ai/dsh-llm-pi-ai": "0.1.7-rc.2",
130
127
  "@deepseek-ai/dsh-settings": "0.1.7-rc.2",
131
- "@deepseek-ai/dsh-subagent-fork-in-process": "0.1.7-rc.2",
128
+ "@deepseek-ai/dsh-sdk-client": "0.1.7-rc.2",
129
+ "@deepseek-ai/dsh-session-log-deepseek": "0.1.7-rc.2",
132
130
  "@deepseek-ai/dsh-subagent": "0.1.7-rc.2",
133
- "@deepseek-ai/dsh-subagent-spawn-in-process": "0.1.7-rc.2",
131
+ "@deepseek-ai/dsh-subagent-fork-in-process": "0.1.7-rc.2",
134
132
  "@deepseek-ai/dsh-shell-env": "0.1.7-rc.2",
135
133
  "@deepseek-ai/dsh-subprocess-local": "0.1.7-rc.2",
134
+ "@deepseek-ai/dsh-session-checkpoint-policy": "0.1.7-rc.2",
136
135
  "@deepseek-ai/dsh-system-prompt": "0.1.7-rc.2",
137
136
  "@deepseek-ai/dsh-tools": "0.1.7-rc.2",
137
+ "@deepseek-ai/dsh-subagent-spawn-in-process": "0.1.7-rc.2",
138
138
  "@deepseek-ai/dsh-user-approval": "0.1.7-rc.2"
139
139
  },
140
140
  "exports": {
@@ -282,6 +282,6 @@
282
282
  "@deepseek-ai/node-addon-system",
283
283
  "@deepseek-ai/schemastery"
284
284
  ],
285
- "fileCount": 3623,
286
- "byteCount": 68860802
285
+ "fileCount": 3624,
286
+ "byteCount": 68871835
287
287
  }
@@ -1,12 +1,14 @@
1
1
  import { isDeepStrictEqual } from "node:util";
2
2
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
3
- import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
3
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
4
  import z from "@deepseek-ai/schemastery";
5
5
  import { chatCodeCliHomeDisplay, resolveChatCodeCliHome } from "@deepseek-ai/dsh-home-paths";
6
6
  import { createReadStream } from "node:fs";
7
- import { stat } from "node:fs/promises";
7
+ import { readdir, realpath, stat } from "node:fs/promises";
8
8
  import { assertNever } from "@deepseek-ai/dsh-util-values";
9
9
  import { createHash } from "node:crypto";
10
+ import picomatch from "picomatch";
11
+ import { parse } from "yaml";
10
12
  //#region lib/types/config.js
11
13
  /**
12
14
  * Configuration normalization for workspace instruction discovery and rendering.
@@ -40,6 +42,7 @@ const Config = z.object({
40
42
  */
41
43
  function workspaceBaselineIdentity(config, cwd, projectRoot) {
42
44
  return JSON.stringify({
45
+ chatCodeRules: true,
43
46
  projectRoot: relative(cwd, projectRoot),
44
47
  projectRootMarkers: config.projectRootMarkers,
45
48
  maxBytes: config.maxBytes,
@@ -103,6 +106,92 @@ function trimmedInstructionDigest(content) {
103
106
  return instructionContentSha1(content.trim());
104
107
  }
105
108
  //#endregion
109
+ //#region lib/types/rules.js
110
+ /**
111
+ * Recursive ChatCode rule discovery and path-conditional applicability.
112
+ *
113
+ * @module @deepseek-ai/dsh-agent-instructions/rules
114
+ */
115
+ /**
116
+ * List Markdown rules recursively, following each directory identity at most once.
117
+ * @param root - absolute rules directory.
118
+ * @param fileSystem - optional filesystem provider used for all probes.
119
+ * @param signal - cancellation for directory probes.
120
+ * @returns paths in deterministic depth-first filename order; absent roots contribute none.
121
+ */
122
+ async function discoverRulePaths(root, fileSystem, signal) {
123
+ const seen = /* @__PURE__ */ new Set();
124
+ const visit = async (directory) => {
125
+ signal?.throwIfAborted();
126
+ try {
127
+ const target = fileSystem === void 0 ? void 0 : await fileSystem.resolve(directory, signal === void 0 ? void 0 : { signal });
128
+ const identity = target?.targetKey ?? await realpath(directory);
129
+ if (seen.has(identity)) return [];
130
+ seen.add(identity);
131
+ const entries = fileSystem !== void 0 && target !== void 0 ? (await fileSystem.listDir(target, signal)).map((entry) => ({
132
+ name: entry.name,
133
+ directory: entry.type === "directory",
134
+ file: entry.type === "file"
135
+ })) : (await readdir(directory, { withFileTypes: true })).map((entry) => ({
136
+ name: entry.name,
137
+ directory: entry.isDirectory(),
138
+ file: entry.isFile()
139
+ }));
140
+ const paths = [];
141
+ for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
142
+ const path = join(directory, entry.name);
143
+ if (entry.directory) paths.push(...await visit(path));
144
+ else if (entry.file && entry.name.endsWith(".md")) paths.push(path);
145
+ }
146
+ return paths;
147
+ } catch (error) {
148
+ signal?.throwIfAborted();
149
+ if (typeof error === "object" && error !== null && "code" in error && [
150
+ "ENOENT",
151
+ "ENOTDIR",
152
+ "FS_NOT_FOUND",
153
+ "FS_NOT_DIRECTORY"
154
+ ].includes(String(error.code))) return [];
155
+ throw error;
156
+ }
157
+ };
158
+ return visit(root);
159
+ }
160
+ /**
161
+ * Decide whether a rule applies to this request's file activity.
162
+ * @param content - rule Markdown, optionally carrying YAML `paths` frontmatter.
163
+ * @param base - project directory against which rule patterns are evaluated.
164
+ * @param cwd - session directory used for relative tool paths.
165
+ * @param touchedPaths - successful first-party filesystem targets.
166
+ * @param active - whether this rule has already entered the session.
167
+ * @returns whether to retain the rule; malformed conditions never become unconditional.
168
+ */
169
+ function ruleApplies(content, base, cwd, touchedPaths, active = false) {
170
+ const normalized = content.replace(/^\uFEFF/, "").replaceAll("\r\n", "\n");
171
+ if (!normalized.startsWith("---\n")) return true;
172
+ const frontmatter = /^---\n([\s\S]*?)^---(?:\n|$)/m.exec(normalized);
173
+ if (frontmatter === null) return false;
174
+ let data;
175
+ try {
176
+ data = parse(frontmatter[1] ?? "");
177
+ } catch {
178
+ return false;
179
+ }
180
+ if (data === null || data === void 0) return true;
181
+ if (typeof data !== "object" || Array.isArray(data)) return false;
182
+ if (!("paths" in data) || data.paths === void 0) return true;
183
+ const paths = typeof data.paths === "string" ? [data.paths] : data.paths;
184
+ if (!Array.isArray(paths) || paths.some((path) => typeof path !== "string" || path.trim() === "")) return false;
185
+ if (paths.length === 0) return true;
186
+ if (active) return true;
187
+ const matches = picomatch(paths, { dot: true });
188
+ return touchedPaths.some((path) => {
189
+ const child = relative(base, resolve(cwd, path));
190
+ if (child === ".." || child.startsWith(`..${sep}`) || isAbsolute(child)) return false;
191
+ return matches(child.split(sep).join("/"));
192
+ });
193
+ }
194
+ //#endregion
106
195
  //#region lib/types/render.js
107
196
  /**
108
197
  * Model-facing workspace instruction rendering within an explicit byte budget.
@@ -146,7 +235,10 @@ const USER_GLOBAL_FILE = "AGENTS.md";
146
235
  * @returns `user-global`, `.`, or the containing project-relative directory.
147
236
  */
148
237
  function scopeForDisplayPath(displayPath) {
149
- if (displayPath === "~/.chatcode-cli/AGENTS.md" || displayPath === "$CHATCODE_CLI_HOME/AGENTS.md") return USER_GLOBAL_DIRECTORY;
238
+ const path = displayPath.replaceAll("\\", "/");
239
+ if (path.startsWith("~/.chatcode-cli/") || path.startsWith("$CHATCODE_CLI_HOME/")) return USER_GLOBAL_DIRECTORY;
240
+ const config = path.indexOf(".chatcode-cli/");
241
+ if (config >= 0) return path.slice(0, config).replace(/\/$/, "") || ".";
150
242
  return dirname(displayPath);
151
243
  }
152
244
  const SCOPE_SEPARATOR = "\0";
@@ -170,7 +262,9 @@ function candidateScopeKey(directory, candidateName) {
170
262
  * @returns the scope key pairing the file's directory with its name.
171
263
  */
172
264
  function instructionScopeKey(displayPath) {
173
- return candidateScopeKey(scopeForDisplayPath(displayPath), basename(displayPath));
265
+ const path = displayPath.replaceAll("\\", "/");
266
+ for (const prefix of ["~/.chatcode-cli/", "$CHATCODE_CLI_HOME/"]) if (path.startsWith(prefix)) return candidateScopeKey(USER_GLOBAL_DIRECTORY, path.slice(prefix.length));
267
+ return candidateScopeKey(dirname(displayPath), basename(displayPath));
174
268
  }
175
269
  /**
176
270
  * Recover the directory and candidate name that {@link candidateScopeKey} encoded.
@@ -402,6 +496,47 @@ function renderAgentInstructions(files, options) {
402
496
  *
403
497
  * @module @deepseek-ai/dsh-agent-instructions/files
404
498
  */
499
+ /**
500
+ * Discover additive ChatCode project instructions and recursive Markdown rules.
501
+ * @param dir - project directory, or the ChatCode home for a global scan.
502
+ * @param root - project display base.
503
+ * @param fileSystem - optional filesystem provider.
504
+ * @param signal - cancellation for filesystem probes.
505
+ * @param userGlobal - whether `dir` is the ChatCode home.
506
+ * @returns present files in base-before-rules order.
507
+ */
508
+ async function discoverChatCodeInstructions(dir, root, fileSystem, signal, userGlobal = false) {
509
+ const configDir = userGlobal ? dir : join(dir, ".chatcode-cli");
510
+ const files = [];
511
+ if (!userGlobal) files.push(...await allExistingInstructionFiles(configDir, root, ["AGENTS.md"], fileSystem, signal));
512
+ for (const absolutePath of await discoverRulePaths(join(configDir, "rules"), fileSystem, signal)) {
513
+ const probe = await statFile(absolutePath, fileSystem, signal);
514
+ if (probe.kind !== "present") continue;
515
+ files.push({
516
+ absolutePath,
517
+ ...probe.info,
518
+ displayPath: userGlobal ? `${chatCodeCliHomeDisplay(dir)}/${relative(dir, absolutePath).split("\\").join("/")}` : relativeDisplay(root, absolutePath)
519
+ });
520
+ }
521
+ return files;
522
+ }
523
+ /**
524
+ * Check a loaded ChatCode rule's path conditions without changing ordinary instruction files.
525
+ * @param file - loaded instruction file.
526
+ * @param projectRoot - project base for global rule patterns.
527
+ * @param cwd - session directory.
528
+ * @param touchedPaths - successful filesystem targets for conditional activation.
529
+ * @param active - whether this rule is already visible in the session.
530
+ * @returns whether the file is applicable.
531
+ */
532
+ function instructionApplies(file, projectRoot, cwd, touchedPaths, active = false) {
533
+ const display = file.displayPath.split("\\").join("/");
534
+ const projectRules = display.indexOf(".chatcode-cli/rules/");
535
+ const global = display.startsWith("~/.chatcode-cli/rules/") || display.startsWith("$CHATCODE_CLI_HOME/rules/");
536
+ if (!global && projectRules < 0) return true;
537
+ const base = global ? projectRoot : resolve(projectRoot, display.slice(0, projectRules) || ".");
538
+ return ruleApplies(file.content, base, cwd, touchedPaths, active);
539
+ }
405
540
  function signalOptions(signal) {
406
541
  return signal === void 0 ? void 0 : { signal };
407
542
  }
@@ -574,9 +709,13 @@ async function discoverInstructionFiles(options, fileSystem) {
574
709
  /* v8 ignore next 2 -- StatFileProbe is closed; this arm only makes adding a kind a compile error. */
575
710
  default: assertNever(userGlobalProbe, "StatFileProbe");
576
711
  }
712
+ for (const file of await discoverChatCodeInstructions(config.dshHome, options.cwd, fileSystem, options.signal, true)) addFile(file);
577
713
  const cwd = resolve(options.cwd);
578
714
  const projectRoot = options.projectRoot ?? await findProjectRoot(cwd, config.projectRootMarkers, fileSystem, options.signal);
579
- for (const dir of ancestorChain(projectRoot, cwd)) for (const candidates of [config.instructionFileCandidates, config.localInstructionFileCandidates]) for (const file of await allExistingInstructionFiles(dir, projectRoot, candidates, fileSystem, options.signal)) addFile(file);
715
+ for (const dir of ancestorChain(projectRoot, cwd)) {
716
+ for (const candidates of [config.instructionFileCandidates, config.localInstructionFileCandidates]) for (const file of await allExistingInstructionFiles(dir, projectRoot, candidates, fileSystem, options.signal)) addFile(file);
717
+ for (const file of await discoverChatCodeInstructions(dir, projectRoot, fileSystem, options.signal)) addFile(file);
718
+ }
580
719
  return files;
581
720
  }
582
721
  /**
@@ -668,11 +807,18 @@ async function loadBaselineInstructionSet(options, fileSystem) {
668
807
  const config = resolveConfig(options);
669
808
  if (config.maxBytes <= 0 || !Number.isFinite(config.maxBytes)) return void 0;
670
809
  if (config.maxSourceBytes <= 0 || !Number.isFinite(config.maxSourceBytes)) return void 0;
671
- const discovered = await discoverInstructionFiles(options, fileSystem);
810
+ const projectRoot = options.projectRoot ?? await findProjectRoot(options.cwd, config.projectRootMarkers, fileSystem, options.signal);
811
+ const discovered = await discoverInstructionFiles({
812
+ ...options,
813
+ projectRoot
814
+ }, fileSystem);
672
815
  const loaded = [];
673
816
  for (const file of discovered) {
674
817
  const content = await readBounded(file, config.maxSourceBytes, fileSystem, options.signal);
675
- if (content !== void 0) loaded.push({
818
+ if (content !== void 0 && instructionApplies({
819
+ ...file,
820
+ content
821
+ }, projectRoot, options.cwd, [])) loaded.push({
676
822
  absolutePath: file.absolutePath,
677
823
  displayPath: file.displayPath,
678
824
  content,
@@ -728,7 +874,7 @@ async function probeScopeInstruction(scope, projectRoot, resolved, fileSystem, s
728
874
  kind: "present",
729
875
  file: {
730
876
  absolutePath,
731
- displayPath: directory === "user-global" ? userGlobalDisplayPath(resolved.dshHome) : relativeDisplay(projectRoot, absolutePath),
877
+ displayPath: directory === "user-global" ? `${chatCodeCliHomeDisplay(resolved.dshHome)}/${candidateName.split("\\").join("/")}` : relativeDisplay(projectRoot, absolutePath),
732
878
  target,
733
879
  version: info.version,
734
880
  ...info.size === void 0 ? {} : { size: info.size }
@@ -922,7 +1068,14 @@ async function reconcileInstructionContext(agent, resolved, versionCache, fileSy
922
1068
  addDirScopes(target, relativeScope(projectRoot, dir));
923
1069
  };
924
1070
  baselineScopes.add(candidateScopeKey(USER_GLOBAL_DIRECTORY, USER_GLOBAL_FILE));
925
- for (const dir of ancestorChain(projectRoot, cwd)) addProjectScopes(baselineScopes, dir);
1071
+ const addChatCodeScopes = async (target, dir, userGlobal = false) => {
1072
+ for (const file of await discoverChatCodeInstructions(dir, projectRoot, fileSystem, options.signal, userGlobal)) target.add(instructionScopeKey(file.displayPath));
1073
+ };
1074
+ await addChatCodeScopes(baselineScopes, resolved.dshHome, true);
1075
+ for (const dir of ancestorChain(projectRoot, cwd)) {
1076
+ addProjectScopes(baselineScopes, dir);
1077
+ await addChatCodeScopes(baselineScopes, dir);
1078
+ }
926
1079
  if (options.includeBaselineScopes) for (const scope of baselineScopes) scopes.add(scope);
927
1080
  for (const message of options.scopeMessages) {
928
1081
  /* v8 ignore next -- the plugin passes its workspace-only pending projection. */
@@ -935,10 +1088,14 @@ async function reconcileInstructionContext(agent, resolved, versionCache, fileSy
935
1088
  for (const scope of effective.keys()) {
936
1089
  if (!options.includeBaselineScopes && baselineScopes.has(scope)) continue;
937
1090
  const { directory } = decodeScopeKey(scope);
938
- if (directory === "user-global") scopes.add(candidateScopeKey(USER_GLOBAL_DIRECTORY, USER_GLOBAL_FILE));
1091
+ if (directory === "user-global" || directory.replaceAll("\\", "/").split("/").includes(".chatcode-cli")) scopes.add(scope);
939
1092
  else addDirScopes(scopes, directory);
940
1093
  }
941
- for (const touchedPath of options.touchedPaths) for (const dir of descendantDirsBetween(cwd, touchedPath)) addProjectScopes(scopes, dir);
1094
+ if (options.touchedPaths.length > 0) for (const scope of baselineScopes) scopes.add(scope);
1095
+ for (const touchedPath of options.touchedPaths) for (const dir of descendantDirsBetween(cwd, touchedPath)) {
1096
+ addProjectScopes(scopes, dir);
1097
+ await addChatCodeScopes(scopes, dir);
1098
+ }
942
1099
  const versions = versionStatesFor(session, versionCache);
943
1100
  const seenAbsolutePaths = /* @__PURE__ */ new Set();
944
1101
  const keptTrimmedByDir = /* @__PURE__ */ new Map();
@@ -1017,6 +1174,7 @@ async function reconcileInstructionContext(agent, resolved, versionCache, fileSy
1017
1174
  }
1018
1175
  const file = await readScopeInstruction(probedFile, resolved.maxSourceBytes, fileSystem, options.signal);
1019
1176
  if (file === void 0) continue;
1177
+ if (!instructionApplies(file, projectRoot, cwd, options.touchedPaths, previous !== void 0 && previous.action !== "remove")) continue;
1020
1178
  const currentDigest = instructionContentSha1(file.content);
1021
1179
  const trimmedDigest = trimmedInstructionDigest(file.content);
1022
1180
  if (registerKeptTrimmed(directory, trimmedDigest)) {
@@ -17,6 +17,11 @@ export interface LoadedInstructionFile extends InstructionFile {
17
17
  /** Provider freshness token when the file was loaded through `ctx.fs`. */
18
18
  version?: FsVersion;
19
19
  }
20
+ interface DiscoveredInstructionFile extends InstructionFile {
21
+ target?: FsTarget;
22
+ size?: number;
23
+ version?: FsVersion;
24
+ }
20
25
  /** Provider metadata for a probed scope candidate before its content is read. */
21
26
  export interface ProbedInstructionFile extends InstructionFile {
22
27
  target: FsTarget;
@@ -38,6 +43,26 @@ interface LoadOptions extends DiscoverOptions {
38
43
  maxSourceBytes?: number;
39
44
  replacePreviousBaseline?: boolean;
40
45
  }
46
+ /**
47
+ * Discover additive ChatCode project instructions and recursive Markdown rules.
48
+ * @param dir - project directory, or the ChatCode home for a global scan.
49
+ * @param root - project display base.
50
+ * @param fileSystem - optional filesystem provider.
51
+ * @param signal - cancellation for filesystem probes.
52
+ * @param userGlobal - whether `dir` is the ChatCode home.
53
+ * @returns present files in base-before-rules order.
54
+ */
55
+ export declare function discoverChatCodeInstructions(dir: string, root: string, fileSystem?: FileSystem, signal?: AbortSignal, userGlobal?: boolean): Promise<DiscoveredInstructionFile[]>;
56
+ /**
57
+ * Check a loaded ChatCode rule's path conditions without changing ordinary instruction files.
58
+ * @param file - loaded instruction file.
59
+ * @param projectRoot - project base for global rule patterns.
60
+ * @param cwd - session directory.
61
+ * @param touchedPaths - successful filesystem targets for conditional activation.
62
+ * @param active - whether this rule is already visible in the session.
63
+ * @returns whether the file is applicable.
64
+ */
65
+ export declare function instructionApplies(file: LoadedInstructionFile, projectRoot: string, cwd: string, touchedPaths: readonly string[], active?: boolean): boolean;
41
66
  /** Rendered baseline plus the successfully read and byte-budget-retained files. */
42
67
  export interface RenderedInstructionSet {
43
68
  rendered: RenderedAgentInstructions;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Recursive ChatCode rule discovery and path-conditional applicability.
3
+ *
4
+ * @module @deepseek-ai/dsh-agent-instructions/rules
5
+ */
6
+ import type { FileSystem } from '@deepseek-ai/dsh-fs';
7
+ /**
8
+ * List Markdown rules recursively, following each directory identity at most once.
9
+ * @param root - absolute rules directory.
10
+ * @param fileSystem - optional filesystem provider used for all probes.
11
+ * @param signal - cancellation for directory probes.
12
+ * @returns paths in deterministic depth-first filename order; absent roots contribute none.
13
+ */
14
+ export declare function discoverRulePaths(root: string, fileSystem?: FileSystem, signal?: AbortSignal): Promise<string[]>;
15
+ /**
16
+ * Decide whether a rule applies to this request's file activity.
17
+ * @param content - rule Markdown, optionally carrying YAML `paths` frontmatter.
18
+ * @param base - project directory against which rule patterns are evaluated.
19
+ * @param cwd - session directory used for relative tool paths.
20
+ * @param touchedPaths - successful first-party filesystem targets.
21
+ * @param active - whether this rule has already entered the session.
22
+ * @returns whether to retain the rule; malformed conditions never become unconditional.
23
+ */
24
+ export declare function ruleApplies(content: string, base: string, cwd: string, touchedPaths: readonly string[], active?: boolean): boolean;
25
+ //# sourceMappingURL=rules.d.ts.map
@@ -38,7 +38,9 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@deepseek-ai/dsh-util-values": "workspace:*",
41
- "@deepseek-ai/schemastery": "workspace:~"
41
+ "@deepseek-ai/schemastery": "workspace:~",
42
+ "picomatch": "^4.0.4",
43
+ "yaml": "^2.4.2"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@deepseek-ai/cordis": "workspace:~",
@@ -56,6 +58,7 @@
56
58
  "@deepseek-ai/dsh-session-projection": "workspace:*",
57
59
  "@deepseek-ai/dsh-system-prompt": "workspace:*",
58
60
  "@deepseek-ai/dsh-tool-fs": "workspace:*",
59
- "@deepseek-ai/dsh-tools": "workspace:*"
61
+ "@deepseek-ai/dsh-tools": "workspace:*",
62
+ "@types/picomatch": "^4.0.2"
60
63
  }
61
64
  }
@@ -4125,7 +4125,7 @@ window.__ModuleLoader__.load({
4125
4125
  for (const listener of listeners) listener();
4126
4126
  };
4127
4127
  /** @returns the client identity for one account call, read at call time so it carries the language and zone in effect then. */
4128
- const client = () => accountClientMetadata(ctx.locale.getSnapshot().active, "3.0.5-rc.1");
4128
+ const client = () => accountClientMetadata(ctx.locale.getSnapshot().active, "3.0.5-rc.2");
4129
4129
  const notices = createBonusNoticeController({
4130
4130
  ackRetryDelayMs: config.bonusAckRetryDelayMs,
4131
4131
  ackRetryMaxDelayMs: config.bonusAckRetryMaxDelayMs,
@@ -4256,7 +4256,7 @@ window.__ModuleLoader__.load({
4256
4256
  refreshAccount,
4257
4257
  contactUs() {
4258
4258
  const url = contactUrl(config, {
4259
- version: "3.0.5-rc.1",
4259
+ version: "3.0.5-rc.2",
4260
4260
  locale: ctx.locale.getSnapshot().active === "zh" ? "zh-CN" : "en",
4261
4261
  width: window.screen.width,
4262
4262
  height: window.screen.height,
@@ -657,7 +657,7 @@ window.__ModuleLoader__.load({
657
657
  function CurrentVersionRow({ t }) {
658
658
  return (0, react_jsx_runtime.jsx)("div", {
659
659
  className: CurrentVersionRow_module_css_default.row,
660
- children: t("general.currentVersion", { version: "3.0.5-rc.1" })
660
+ children: t("general.currentVersion", { version: "3.0.5-rc.2" })
661
661
  });
662
662
  }
663
663
  //#endregion
@@ -167,7 +167,7 @@ window.__ModuleLoader__.load({
167
167
  const SCROLLBAR_LINGER_MS = 2e3;
168
168
  /** Format complete-build metadata for the local brand badge. */
169
169
  function localBuildVersion() {
170
- return `3.0.5-rc.1-caccc24-dirty`;
170
+ return `3.0.5-rc.2-caccc24-dirty`;
171
171
  }
172
172
  /** Each panel row subscribes only to its own selection state. */
173
173
  function PanelRow({ id, label, wide, usePanelInfo, selectPanel, renderSlot }) {
@@ -119,7 +119,7 @@ var FileSystemSkillProvider = class {
119
119
  */
120
120
  async get(candidate, options) {
121
121
  const locator = candidate.locator;
122
- const parsed = await parseSkillFile(locator.path, this.ctx, options.signal, candidate.source === "bundled");
122
+ const parsed = await parseSkillFile(locator.path, this.ctx, options.signal, candidate.source === "bundled", locator.commandName);
123
123
  if (parsed === void 0) return void 0;
124
124
  return {
125
125
  name: parsed.name,
@@ -161,6 +161,12 @@ var FileSystemSkillProvider = class {
161
161
  source: "project-chatcode",
162
162
  rank: PROJECT_CHATCODE_RANK,
163
163
  projectRoot
164
+ }, {
165
+ path: join(projectRoot, ".chatcode-cli/commands"),
166
+ source: "project-chatcode",
167
+ rank: 101,
168
+ projectRoot,
169
+ commands: true
164
170
  }, {
165
171
  path: join(projectRoot, ".dsh/skills"),
166
172
  source: "project-dsh",
@@ -183,6 +189,11 @@ var FileSystemSkillProvider = class {
183
189
  source: "user-dsh",
184
190
  rank: USER_DSH_RANK,
185
191
  skipSystem: true
192
+ }, {
193
+ path: join(this.dshHome, "commands"),
194
+ source: "user-dsh",
195
+ rank: 401,
196
+ commands: true
186
197
  }, {
187
198
  path: join(this.agentsHome, "skills"),
188
199
  source: "user-agents",
@@ -593,15 +604,19 @@ async function discoverRoot(root, ctx, provider) {
593
604
  const entries = await listSkillRootEntries(root, ctx);
594
605
  for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
595
606
  if (root.skipSystem && entry.name === ".system") continue;
596
- const locator = entry.type === "directory" ? {
607
+ const location = entry.type === "directory" ? {
597
608
  path: join(entry.path, "SKILL.md"),
598
609
  directory: entry.path
599
610
  } : entry.type === "file" && entry.name.endsWith(".md") ? {
600
611
  path: entry.path,
601
612
  directory: root.path
602
613
  } : void 0;
603
- if (locator === void 0) continue;
604
- const parsed = await parseSkillFile(locator.path, ctx, void 0, root.trustedHost === true);
614
+ if (location === void 0) continue;
615
+ const locator = {
616
+ ...location,
617
+ ...root.commands === true ? { commandName: entry.name.replace(/\.md$/, "") } : {}
618
+ };
619
+ const parsed = await parseSkillFile(locator.path, ctx, void 0, root.trustedHost === true, locator.commandName);
605
620
  if (parsed === void 0) continue;
606
621
  skills.push({
607
622
  name: parsed.name,
@@ -671,13 +686,18 @@ async function listSkillRootEntriesFromNode(root, ctx) {
671
686
  }
672
687
  return result;
673
688
  }
674
- async function parseSkillFile(path, ctx, signal, trustedHost = false) {
689
+ async function parseSkillFile(path, ctx, signal, trustedHost = false, commandName) {
675
690
  const raw = await readSkillText(ctx, path, signal, trustedHost);
676
691
  signal?.throwIfAborted();
677
692
  if (raw === void 0) return;
678
693
  let parsed;
679
694
  try {
680
- parsed = parseFrontmatter(raw.content);
695
+ const content = raw.content.replace(/^\uFEFF/, "");
696
+ parsed = parseFrontmatter(content);
697
+ if (commandName !== void 0 && parsed === void 0 && !/^---\r?\n/.test(content)) parsed = {
698
+ data: {},
699
+ body: content
700
+ };
681
701
  } catch (error) {
682
702
  ctx.logger.warn(`skill file ${path} ignored: invalid YAML frontmatter: ${errorMessage(error)}`);
683
703
  return;
@@ -686,8 +706,8 @@ async function parseSkillFile(path, ctx, signal, trustedHost = false) {
686
706
  ctx.logger.warn(`skill file ${path} ignored: missing YAML frontmatter`);
687
707
  return;
688
708
  }
689
- const name = stringField(parsed.data, "name");
690
- const description = stringField(parsed.data, "description");
709
+ const name = "name" in parsed.data ? stringField(parsed.data, "name") : commandName;
710
+ const description = "description" in parsed.data || commandName === void 0 ? stringField(parsed.data, "description") : parsed.body.trim().split(/\r?\n/)[0]?.replace(/^#+\s*/, "").trim() || commandName;
691
711
  if (name === void 0 || description === void 0) {
692
712
  ctx.logger.warn(`skill file ${path} ignored: frontmatter requires name and description`);
693
713
  return;
@@ -795,7 +815,11 @@ function parseFrontmatter(raw) {
795
815
  const closing = findClosingFrontmatter(raw, start);
796
816
  if (closing === void 0) return void 0;
797
817
  const parsed = parse(raw.slice(start, closing.start));
798
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
818
+ if (parsed === null) return {
819
+ data: {},
820
+ body: raw.slice(closing.bodyStart)
821
+ };
822
+ if (typeof parsed !== "object" || Array.isArray(parsed)) return void 0;
799
823
  return {
800
824
  data: parsed,
801
825
  body: raw.slice(closing.bodyStart)