@jixo/cli 0.10.1 → 0.12.0

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 (54) hide show
  1. package/dist/cli.d.ts.map +1 -1
  2. package/dist/cli.js +6 -5
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/init.d.ts.map +1 -1
  5. package/dist/commands/init.js +18 -12
  6. package/dist/commands/init.js.map +1 -1
  7. package/dist/commands/prompts/list.js +2 -2
  8. package/dist/commands/prompts/list.js.map +1 -1
  9. package/dist/commands/tasks/AiTaskTui.d.ts +22 -0
  10. package/dist/commands/tasks/AiTaskTui.d.ts.map +1 -0
  11. package/dist/commands/tasks/AiTaskTui.js +52 -0
  12. package/dist/commands/tasks/AiTaskTui.js.map +1 -0
  13. package/dist/commands/tasks/ai-tasl-tui.d.ts +22 -0
  14. package/dist/commands/tasks/ai-tasl-tui.d.ts.map +1 -0
  15. package/dist/commands/tasks/ai-tasl-tui.js +53 -0
  16. package/dist/commands/tasks/ai-tasl-tui.js.map +1 -0
  17. package/dist/commands/tasks/ai-tools.d.ts +281 -8
  18. package/dist/commands/tasks/ai-tools.d.ts.map +1 -1
  19. package/dist/commands/tasks/ai-tools.js +55 -16
  20. package/dist/commands/tasks/ai-tools.js.map +1 -1
  21. package/dist/commands/tasks/model-providers.d.ts +5 -1
  22. package/dist/commands/tasks/model-providers.d.ts.map +1 -1
  23. package/dist/commands/tasks/model-providers.js +31 -0
  24. package/dist/commands/tasks/model-providers.js.map +1 -1
  25. package/dist/commands/tasks/run-ai-task.d.ts +1 -1
  26. package/dist/commands/tasks/run-ai-task.d.ts.map +1 -1
  27. package/dist/commands/tasks/run-ai-task.js +141 -115
  28. package/dist/commands/tasks/run-ai-task.js.map +1 -1
  29. package/dist/commands/tasks/run.d.ts.map +1 -1
  30. package/dist/commands/tasks/run.js +24 -14
  31. package/dist/commands/tasks/run.js.map +1 -1
  32. package/dist/config.d.ts +14 -14
  33. package/dist/helper/ai-retry-error.d.ts +1 -1
  34. package/dist/helper/ai-retry-error.d.ts.map +1 -1
  35. package/dist/helper/ai-retry-error.js +63 -30
  36. package/dist/helper/ai-retry-error.js.map +1 -1
  37. package/dist/helper/handle-ai-error.d.ts +5 -0
  38. package/dist/helper/handle-ai-error.d.ts.map +1 -0
  39. package/dist/helper/handle-ai-error.js +122 -0
  40. package/dist/helper/handle-ai-error.js.map +1 -0
  41. package/dist/helper/logger.d.ts +3 -0
  42. package/dist/helper/logger.d.ts.map +1 -0
  43. package/dist/helper/logger.js +26 -0
  44. package/dist/helper/logger.js.map +1 -0
  45. package/dist/helper/prompts-loader.d.ts +9 -3
  46. package/dist/helper/prompts-loader.d.ts.map +1 -1
  47. package/dist/helper/prompts-loader.js +16 -16
  48. package/dist/helper/prompts-loader.js.map +1 -1
  49. package/dist/helper/resolve-ai-tasks.d.ts +24 -10
  50. package/dist/helper/resolve-ai-tasks.d.ts.map +1 -1
  51. package/dist/helper/resolve-ai-tasks.js +68 -26
  52. package/dist/helper/resolve-ai-tasks.js.map +1 -1
  53. package/dist/prompts.json +2 -2
  54. package/package.json +8 -3
@@ -5,24 +5,38 @@ import { type JixoConfig } from "../config.js";
5
5
  * @param config_tasks
6
6
  * @returns
7
7
  */
8
- export declare const resolveAiTasks: (cwd: string, config_tasks: JixoConfig["tasks"]) => ({
8
+ export declare const resolveAiTasks: (cwd: string, config_tasks: JixoConfig["tasks"], current_job_loop_count: number) => ({
9
9
  data: {
10
10
  [key: string]: any;
11
11
  };
12
12
  content: string;
13
- } & {
14
- name: string;
13
+ } & Readonly<{
14
+ runner: string;
15
+ jobName: string;
16
+ loopCount: number;
17
+ filepath: string;
18
+ exitCode: number | null;
19
+ exitReason: string;
20
+ exit: (code: number, reason: string) => void;
15
21
  cwd: string;
16
22
  dirs: string[];
17
23
  agents: string[];
18
24
  model: string;
19
- useMemory: string;
20
- useLog: string;
21
- log: string;
22
25
  startTime: string;
23
- createTime: string;
24
- preUpdateTime: string;
25
- preProgress: number;
26
- })[];
26
+ maxTurns: number;
27
+ otherRunners: string[];
28
+ log: Readonly<{
29
+ name: string;
30
+ filepath: string;
31
+ content: string;
32
+ data: {
33
+ [key: string]: any;
34
+ };
35
+ createTime: string;
36
+ preUpdateTime: string;
37
+ preProgress: number;
38
+ }>;
39
+ reloadLog: () => void;
40
+ }>)[];
27
41
  export type AiTask = ReturnType<typeof resolveAiTasks>[number];
28
42
  //# sourceMappingURL=resolve-ai-tasks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-ai-tasks.d.ts","sourceRoot":"","sources":["../../src/helper/resolve-ai-tasks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,UAAU,EAAC,MAAM,cAAc,CAAC;AAG7C;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,cAAc,UAAU,CAAC,OAAO,CAAC;UAGnE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;aACjB,MAAM;;UAGT,MAAM;SACP,MAAM;UACL,MAAM,EAAE;YACN,MAAM,EAAE;WACT,MAAM;eACF,MAAM;YACT,MAAM;SACT,MAAM;eACA,MAAM;gBACL,MAAM;mBACH,MAAM;iBACR,MAAM;IA+HtB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"resolve-ai-tasks.d.ts","sourceRoot":"","sources":["../../src/helper/resolve-ai-tasks.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,KAAK,UAAU,EAAC,MAAM,cAAc,CAAC;AAK7C;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,cAAc,UAAU,CAAC,OAAO,CAAC,EAAE,wBAAwB,MAAM;UAGnG;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;aACjB,MAAM;;YAIL,MAAM;aACL,MAAM;eACJ,MAAM;cACP,MAAM;cACN,MAAM,GAAG,IAAI;gBACX,MAAM;UACZ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI;SAEvC,MAAM;UACL,MAAM,EAAE;YACN,MAAM,EAAE;WACT,MAAM;eACF,MAAM;cACP,MAAM;kBACF,MAAM,EAAE;SAEjB,QAAQ,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAC,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;eACS,MAAM,IAAI;KA0K1B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -3,16 +3,18 @@ import { str_trim_indent } from "@gaubee/util";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { match, P } from "ts-pattern";
6
+ import { uuidv7 } from "uuidv7";
6
7
  import z from "zod";
7
8
  import {} from "../config.js";
8
9
  import { parseProgress } from "./parse-progress.js";
10
+ const process_runner_uuid_prefix = uuidv7();
9
11
  /**
10
12
  * 将 config.tasks 字段转化成具体的 ai-tasks 信息
11
13
  * @param cwd
12
14
  * @param config_tasks
13
15
  * @returns
14
16
  */
15
- export const resolveAiTasks = (cwd, config_tasks) => {
17
+ export const resolveAiTasks = (cwd, config_tasks, current_job_loop_count) => {
16
18
  const config_tasks_arr = Array.isArray(config_tasks) ? config_tasks : [config_tasks];
17
19
  const tasks = [];
18
20
  const addTask = (ai_task, options) => {
@@ -26,13 +28,27 @@ export const resolveAiTasks = (cwd, config_tasks) => {
26
28
  if (task_dir.length === 0) {
27
29
  task_dir.push(cwd);
28
30
  }
29
- const task_name = inner_task_name || options.defaultName;
30
- const useMemory = ai_task.data.useMemory || task_name;
31
- const useLog = ai_task.data.useLog || task_name;
32
- const log_filepath = path.join(cwd, `.jixo/${useLog}.log.md`);
33
- let log_fileContent = fs.existsSync(log_filepath) ? fs.readFileSync(log_filepath, "utf-8").trim() : "";
34
- if (log_fileContent === "") {
35
- writeMarkdown(log_filepath, str_trim_indent(`
31
+ const job_name = inner_task_name || options.defaultName;
32
+ const useLog = ai_task.data.useLog || job_name;
33
+ const log = {
34
+ name: useLog,
35
+ filepath: path.join(cwd, `.jixo/${useLog}.log.md`),
36
+ content: "",
37
+ data: {},
38
+ get createTime() {
39
+ return log.data.createTime ?? startTime;
40
+ },
41
+ get preUpdateTime() {
42
+ return log.data.updateTime ?? startTime;
43
+ },
44
+ get preProgress() {
45
+ return parseProgress(log.data.progress);
46
+ },
47
+ };
48
+ const reloadLog = () => {
49
+ log.content = fs.existsSync(log.filepath) ? fs.readFileSync(log.filepath, "utf-8").trim() : "";
50
+ if (log.content === "") {
51
+ writeMarkdown(log.filepath, str_trim_indent(`
36
52
  ## 工作计划
37
53
 
38
54
  <!--待定-->
@@ -43,18 +59,35 @@ export const resolveAiTasks = (cwd, config_tasks) => {
43
59
 
44
60
  <!--暂无-->
45
61
  `), {
46
- title: "_待定_",
47
- createTime: new Date().toISOString(),
48
- updateTime: new Date().toISOString(),
49
- progress: "0%",
50
- });
51
- log_fileContent = fs.readFileSync(log_filepath, "utf-8");
52
- }
53
- const log_fileData = matter(log_fileContent).data;
62
+ title: "_待定_",
63
+ createTime: new Date().toISOString(),
64
+ updateTime: new Date().toISOString(),
65
+ progress: "0%",
66
+ });
67
+ log.content = fs.readFileSync(log.filepath, "utf-8");
68
+ }
69
+ log.data = matter(log.content).data;
70
+ };
71
+ reloadLog();
54
72
  const startTime = new Date().toISOString();
73
+ const runner_id = `${job_name}-${process_runner_uuid_prefix}-${current_job_loop_count.toString().padStart(3, "0")}`;
74
+ const task_process = {
75
+ code: null,
76
+ reason: "",
77
+ exit(code, reason) {
78
+ if (task_process.code) {
79
+ return;
80
+ }
81
+ task_process.code = code;
82
+ task_process.reason = reason;
83
+ },
84
+ };
55
85
  tasks.push({
56
86
  ...ai_task,
57
- name: task_name,
87
+ jobName: job_name,
88
+ loopCount: current_job_loop_count,
89
+ runner: runner_id,
90
+ filepath: options.filepath ?? path.join(cwd, `.jixo/${job_name}.job.md`),
58
91
  cwd: cwd,
59
92
  dirs: task_dir,
60
93
  agents: match(z.union([z.string(), z.string().array()]).safeParse(ai_task.data.agents))
@@ -62,16 +95,23 @@ export const resolveAiTasks = (cwd, config_tasks) => {
62
95
  return Array.isArray(agents) ? agents : agents.split(/\s+/);
63
96
  })
64
97
  .otherwise(() => []),
98
+ maxTurns: 40,
99
+ otherRunners: [],
65
100
  model: match(z.string().safeParse(ai_task.data.model))
66
101
  .with({ success: true, data: P.select() }, (model) => model)
67
102
  .otherwise(() => ""),
68
- useMemory,
69
- useLog,
70
- createTime: log_fileData.createTime ?? startTime,
71
- preUpdateTime: log_fileData.updateTime ?? startTime,
72
- preProgress: parseProgress(log_fileData.progress),
73
- log: log_fileContent,
74
103
  startTime: startTime,
104
+ reloadLog: reloadLog,
105
+ log: log,
106
+ get exitCode() {
107
+ return task_process.code;
108
+ },
109
+ get exitReason() {
110
+ return task_process.reason;
111
+ },
112
+ exit(code, reason) {
113
+ task_process.exit(code, reason);
114
+ },
75
115
  });
76
116
  };
77
117
  for (const config_task of config_tasks_arr) {
@@ -82,11 +122,12 @@ export const resolveAiTasks = (cwd, config_tasks) => {
82
122
  }, (dirname) => {
83
123
  for (const entry of walkFiles(path.resolve(cwd, dirname), {
84
124
  matchFile(entry) {
85
- return entry.name.endsWith(".task.md");
125
+ return entry.name.endsWith(".job.md");
86
126
  },
87
127
  })) {
88
128
  addTask(readMarkdown(entry.path), {
89
- defaultName: entry.name.slice(0, -".task.md".length),
129
+ filepath: entry.path,
130
+ defaultName: entry.name.slice(0, -".job.md".length),
90
131
  });
91
132
  }
92
133
  })
@@ -96,7 +137,8 @@ export const resolveAiTasks = (cwd, config_tasks) => {
96
137
  name: P.string.select("name").optional(),
97
138
  }, (m) => {
98
139
  addTask(readMarkdown(m.filename), {
99
- defaultName: m.name ?? m.filename.slice(0, -".task.md".length),
140
+ filepath: m.filename,
141
+ defaultName: m.name ?? m.filename.slice(0, -".job.md".length),
100
142
  });
101
143
  })
102
144
  .with(P.string.select(), (mdContent) => {
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-ai-tasks.js","sourceRoot":"","sources":["../../src/helper/resolve-ai-tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAClG,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,KAAK,EAAE,CAAC,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAiB,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,YAAiC,EAAE,EAAE;IAC/E,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;IAmBrF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,CACd,OAAiB,EACjB,OAEC,EACD,EAAE;QACF,MAAM,EAAC,IAAI,EAAE,eAAe,EAAC,GAAG,OAAO,CAAC,IAAI,CAAC;QAE7C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,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;YACrC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;SACzC,EACD,CAAC,CAAC,EAAE,EAAE;YACJ,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE;gBAChC,WAAW,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;aAC/D,CAAC,CAAC;QACL,CAAC,CACF;aACA,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE;YACrC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;gBACzB,WAAW,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;aACnC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,IAAI,CACH;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;YACnC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;SACzC,EACD,CAAC,CAAC,EAAE,EAAE;YACJ,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE;gBACzB,WAAW,EAAE,CAAC,CAAC,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;aAC7C,CAAC,CAAC;QACL,CAAC,CACF;aACA,UAAU,EAAE,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import {matter, normalizeFilePath, readMarkdown, walkFiles, writeMarkdown} from \"@gaubee/nodekit\";\nimport {str_trim_indent} from \"@gaubee/util\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport {match, P} from \"ts-pattern\";\nimport z from \"zod\";\nimport {type JixoConfig} from \"../config.js\";\nimport {parseProgress} from \"./parse-progress.js\";\n\n/**\n * 将 config.tasks 字段转化成具体的 ai-tasks 信息\n * @param cwd\n * @param config_tasks\n * @returns\n */\nexport const resolveAiTasks = (cwd: string, config_tasks: JixoConfig[\"tasks\"]) => {\n const config_tasks_arr = Array.isArray(config_tasks) ? config_tasks : [config_tasks];\n type TaskBase = {\n data: {[key: string]: any};\n content: string;\n };\n type AiTask = TaskBase & {\n name: string;\n cwd: string;\n dirs: string[];\n agents: string[];\n model: string;\n useMemory: string;\n useLog: string;\n log: string;\n startTime: string;\n createTime: string;\n preUpdateTime: string;\n preProgress: number;\n };\n const tasks: AiTask[] = [];\n const addTask = (\n ai_task: TaskBase,\n options: {\n defaultName: string;\n },\n ) => {\n const {name: inner_task_name} = ai_task.data;\n\n const task_dir = match(z.union([z.string(), z.string().array()]).safeParse(ai_task.data.dirs ?? ai_task.data.dir))\n .with({success: true}, (it) => {\n const dirList = Array.isArray(it.data) ? it.data : [it.data];\n return dirList.map((dir) => normalizeFilePath(path.resolve(cwd, dir)));\n })\n .otherwise(() => []);\n if (task_dir.length === 0) {\n task_dir.push(cwd);\n }\n\n const task_name = inner_task_name || options.defaultName;\n const useMemory = ai_task.data.useMemory || task_name;\n const useLog = ai_task.data.useLog || task_name;\n\n const log_filepath = path.join(cwd, `.jixo/${useLog}.log.md`);\n let log_fileContent = fs.existsSync(log_filepath) ? fs.readFileSync(log_filepath, \"utf-8\").trim() : \"\";\n if (log_fileContent === \"\") {\n writeMarkdown(\n log_filepath,\n str_trim_indent(`\n ## 工作计划\n \n <!--待定-->\n\n ---\n\n ## 工作日志\n\n <!--暂无-->\n `),\n {\n title: \"_待定_\",\n createTime: new Date().toISOString(),\n updateTime: new Date().toISOString(),\n progress: \"0%\",\n },\n );\n log_fileContent = fs.readFileSync(log_filepath, \"utf-8\");\n }\n const log_fileData = matter(log_fileContent).data;\n const startTime = new Date().toISOString();\n\n tasks.push({\n ...ai_task,\n name: task_name,\n cwd: cwd,\n dirs: task_dir,\n agents: match(z.union([z.string(), z.string().array()]).safeParse(ai_task.data.agents))\n .with({success: true, data: P.select()}, (agents) => {\n return Array.isArray(agents) ? agents : agents.split(/\\s+/);\n })\n .otherwise(() => []),\n model: match(z.string().safeParse(ai_task.data.model))\n .with({success: true, data: P.select()}, (model) => model)\n .otherwise(() => \"\"),\n useMemory,\n useLog,\n createTime: log_fileData.createTime ?? startTime,\n preUpdateTime: log_fileData.updateTime ?? startTime,\n preProgress: parseProgress(log_fileData.progress),\n log: log_fileContent,\n startTime: startTime,\n });\n };\n\n for (const config_task of config_tasks_arr) {\n match(config_task)\n .with(\n {\n type: \"dir\",\n dirname: P.string.select(),\n },\n (dirname) => {\n for (const entry of walkFiles(path.resolve(cwd, dirname), {\n matchFile(entry) {\n return entry.name.endsWith(\".task.md\");\n },\n })) {\n addTask(readMarkdown(entry.path), {\n defaultName: entry.name.slice(0, -\".task.md\".length),\n });\n }\n },\n )\n .with(\n {\n type: \"file\",\n filename: P.string.select(\"filename\"),\n name: P.string.select(\"name\").optional(),\n },\n (m) => {\n addTask(readMarkdown(m.filename), {\n defaultName: m.name ?? m.filename.slice(0, -\".task.md\".length),\n });\n },\n )\n .with(P.string.select(), (mdContent) => {\n addTask(matter(mdContent), {\n defaultName: `${tasks.length + 1}`,\n });\n })\n .with(\n {\n type: \"prompt\",\n content: P.string.select(\"content\"),\n name: P.string.select(\"name\").optional(),\n },\n (m) => {\n addTask(matter(m.content), {\n defaultName: m.name ?? `${tasks.length + 1}`,\n });\n },\n )\n .exhaustive();\n }\n return tasks;\n};\n\nexport type AiTask = ReturnType<typeof resolveAiTasks>[number];\n"]}
1
+ {"version":3,"file":"resolve-ai-tasks.js","sourceRoot":"","sources":["../../src/helper/resolve-ai-tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAClG,OAAO,EAA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QACL,CAAC,CACF;aACA,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE;YACrC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;gBACzB,WAAW,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;aACnC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,IAAI,CACH;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;YACnC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;SACzC,EACD,CAAC,CAAC,EAAE,EAAE;YACJ,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE;gBACzB,WAAW,EAAE,CAAC,CAAC,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;aAC7C,CAAC,CAAC;QACL,CAAC,CACF;aACA,UAAU,EAAE,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import {matter, normalizeFilePath, readMarkdown, walkFiles, writeMarkdown} from \"@gaubee/nodekit\";\nimport {str_trim_indent} from \"@gaubee/util\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport {match, P} from \"ts-pattern\";\nimport {uuidv7} from \"uuidv7\";\nimport z from \"zod\";\nimport {type JixoConfig} from \"../config.js\";\nimport {parseProgress} from \"./parse-progress.js\";\n\nconst process_runner_uuid_prefix = uuidv7();\n\n/**\n * 将 config.tasks 字段转化成具体的 ai-tasks 信息\n * @param cwd\n * @param config_tasks\n * @returns\n */\nexport const resolveAiTasks = (cwd: string, config_tasks: JixoConfig[\"tasks\"], current_job_loop_count: number) => {\n const config_tasks_arr = Array.isArray(config_tasks) ? config_tasks : [config_tasks];\n type TaskBase = {\n data: {[key: string]: any};\n content: string;\n };\n type AiTask = TaskBase &\n Readonly<{\n runner: string;\n jobName: string;\n loopCount: number;\n filepath: string;\n exitCode: number | null;\n exitReason: string;\n exit: (code: number, reason: string) => void;\n\n cwd: string;\n dirs: string[];\n agents: string[];\n model: string;\n startTime: string;\n maxTurns: number;\n otherRunners: string[];\n\n log: Readonly<{\n name: string;\n filepath: string;\n content: string;\n data: {[key: string]: any};\n createTime: string;\n preUpdateTime: string;\n preProgress: number;\n }>;\n reloadLog: () => void;\n }>;\n const tasks: AiTask[] = [];\n const addTask = (\n ai_task: TaskBase,\n options: {\n filepath?: string;\n defaultName: string;\n },\n ) => {\n const {name: inner_task_name} = ai_task.data;\n\n const task_dir = match(z.union([z.string(), z.string().array()]).safeParse(ai_task.data.dirs ?? ai_task.data.dir))\n .with({success: true}, (it) => {\n const dirList = Array.isArray(it.data) ? it.data : [it.data];\n return dirList.map((dir) => normalizeFilePath(path.resolve(cwd, dir)));\n })\n .otherwise(() => []);\n if (task_dir.length === 0) {\n task_dir.push(cwd);\n }\n\n const job_name = inner_task_name || options.defaultName;\n const useLog = ai_task.data.useLog || job_name;\n\n const log = {\n name: useLog,\n filepath: path.join(cwd, `.jixo/${useLog}.log.md`),\n content: \"\",\n data: {} as {[key: string]: any},\n get createTime(): string {\n return log.data.createTime ?? startTime;\n },\n get preUpdateTime(): string {\n return log.data.updateTime ?? startTime;\n },\n get preProgress(): number {\n return parseProgress(log.data.progress);\n },\n } satisfies AiTask[\"log\"];\n const reloadLog = () => {\n log.content = fs.existsSync(log.filepath) ? fs.readFileSync(log.filepath, \"utf-8\").trim() : \"\";\n if (log.content === \"\") {\n writeMarkdown(\n log.filepath,\n str_trim_indent(`\n ## 工作计划\n \n <!--待定-->\n\n ---\n\n ## 工作日志\n\n <!--暂无-->\n `),\n {\n title: \"_待定_\",\n createTime: new Date().toISOString(),\n updateTime: new Date().toISOString(),\n progress: \"0%\",\n },\n );\n log.content = fs.readFileSync(log.filepath, \"utf-8\");\n }\n log.data = matter(log.content).data;\n };\n reloadLog();\n const startTime = new Date().toISOString();\n const runner_id = `${job_name}-${process_runner_uuid_prefix}-${current_job_loop_count.toString().padStart(3, \"0\")}`;\n\n const task_process = {\n code: null as number | null,\n reason: \"\",\n exit(code: number, reason: string) {\n if (task_process.code) {\n return;\n }\n task_process.code = code;\n task_process.reason = reason;\n },\n };\n\n tasks.push({\n ...ai_task,\n jobName: job_name,\n loopCount: current_job_loop_count,\n runner: runner_id,\n filepath: options.filepath ?? path.join(cwd, `.jixo/${job_name}.job.md`),\n cwd: cwd,\n dirs: task_dir,\n agents: match(z.union([z.string(), z.string().array()]).safeParse(ai_task.data.agents))\n .with({success: true, data: P.select()}, (agents) => {\n return Array.isArray(agents) ? agents : agents.split(/\\s+/);\n })\n .otherwise(() => []),\n maxTurns: 40,\n otherRunners: [],\n model: match(z.string().safeParse(ai_task.data.model))\n .with({success: true, data: P.select()}, (model) => model)\n .otherwise(() => \"\"),\n startTime: startTime,\n reloadLog: reloadLog,\n log: log,\n\n get exitCode() {\n return task_process.code;\n },\n get exitReason() {\n return task_process.reason;\n },\n exit(code, reason) {\n task_process.exit(code, reason);\n },\n });\n };\n\n for (const config_task of config_tasks_arr) {\n match(config_task)\n .with(\n {\n type: \"dir\",\n dirname: P.string.select(),\n },\n (dirname) => {\n for (const entry of walkFiles(path.resolve(cwd, dirname), {\n matchFile(entry) {\n return entry.name.endsWith(\".job.md\");\n },\n })) {\n addTask(readMarkdown(entry.path), {\n filepath: entry.path,\n defaultName: entry.name.slice(0, -\".job.md\".length),\n });\n }\n },\n )\n .with(\n {\n type: \"file\",\n filename: P.string.select(\"filename\"),\n name: P.string.select(\"name\").optional(),\n },\n (m) => {\n addTask(readMarkdown(m.filename), {\n filepath: m.filename,\n defaultName: m.name ?? m.filename.slice(0, -\".job.md\".length),\n });\n },\n )\n .with(P.string.select(), (mdContent) => {\n addTask(matter(mdContent), {\n defaultName: `${tasks.length + 1}`,\n });\n })\n .with(\n {\n type: \"prompt\",\n content: P.string.select(\"content\"),\n name: P.string.select(\"name\").optional(),\n },\n (m) => {\n addTask(matter(m.content), {\n defaultName: m.name ?? `${tasks.length + 1}`,\n });\n },\n )\n .exhaustive();\n }\n return tasks;\n};\n\nexport type AiTask = ReturnType<typeof resolveAiTasks>[number];\n"]}
package/dist/prompts.json CHANGED
@@ -129,7 +129,7 @@
129
129
  "data": {
130
130
  "parent": []
131
131
  },
132
- "content": "你是一个AI工具集,叫做 JIXO,你拥有多种技能,每次开始一次任务的时候,你将被赋予“执行者”的角色称号。\r\n\r\n**你是一个基于“技能驱动与系统思考”的AI专家级长期执行者。**\r\n\r\n你的核心运作模式是作为一个智能的**任务编排器(Orchestrator)**。你拥有一个包含多个专业的技能库,每个技能都定义了一套解决特定领域问题的元标准思维链和执行协议。\r\n\r\n注意:”长期执行者“意味着你并不是要在一次任务中完成所有任务,而是会合理规划任务,将任务分成多层次多步骤,分配不同的技能来执行。从而避免上下文限制或者注意力缺失的问题。\r\n\r\n执行任务的时候,会通过 assistant-message 提供一个 Turns 的计数器,用来限制单次任务可以执行的请求次数。\r\nTurns 意味着请求的次数,本次任务最大请求数是: {{maxTurns}} 次。\r\nIF Turns == {{maxTurns}}/{{{{maxTurns}}}}(100%),意味着本次任务将不再执行,之后将开启新的上下文去做新的任务。\r\n每一次请求,意味着JIXO可以调用一些工具,做输入输出。请合理利用剩余的请求的次数,做好任务规划\r\n\r\n---\r\n\r\n**你的首要任务是:在响应用户任何请求之前,首先激活“中央调度思维链”,以最高效、最专业的方式完成任务。**\r\n\r\n以下是目前JIXO已有的技能列表:\r\n\r\n```yaml\r\n{{allSkills}}\r\n```\r\n\r\n**你可以使用`get_jixo_skill`工具来获取技能详情。**\r\n\r\n### **中央调度思维链 (Master Orchestration Chain of Thought)**\r\n\r\n**在接收到用户请求(任务)后,你必须严格遵循以下思考和行动步骤:**\r\n\r\n**第一阶段:请求解析与意图识别 (Parse & Intent Recognition)**\r\n\r\n1. **识别核心意图:** 首先,解析任务的自然语言请求,将其归类到你所拥有的一个或多个核心技能领域。\r\n\r\n - _“用户的请求‘帮我看看这段代码有什么问题’,核心意图是【代码调试】。”_\r\n - _“用户的请求‘我们要做个新功能,关于用户认证的’,核心意图可能涉及【系统设计】、【任务分解】和【代码生成】。”_\r\n\r\n2. **评估任务复杂度与范围:** 判断这是一个简单的、单一技能可以解决的问题,还是一个需要多个技能协同工作的复杂项目。\r\n\r\n**第二阶段:主技能选择与加载 (Primary Skill Selection & Loading)**\r\n\r\n3. **选择主导技能:** 根据核心意图,从你的技能库中选择一个最合适的`*.skill`文件作为本次任务的**主导技能(Primary Skill)**。这个技能的思维链将成为解决问题的主框架。\r\n\r\n - _“对于‘代码调试’请求,我将加载`code-debugging.skill`作为主导技能。”_\r\n\r\n4. **加载思维链:** 在内部“加载”并开始遵循该主导技能中定义的**元标准思维链和执行协议**。\r\n\r\n**第三阶段:跨技能协同规划 (Cross-Skill Collaboration Planning)**\r\n\r\n5. **预判辅助技能需求:** 在遵循主导技能的思维链时,主动思考并预判哪些步骤可以或应该**联动(Collaborate with)**其他辅助技能来增强效果。\r\n\r\n - _“我正在遵循`code-debugging`的思维链。在‘反思’阶段,我预判到这个问题可能源于测试缺失。因此,我规划在此处需要联动`test-generation.skill`。”_\r\n - _“我正在遵循`system-design`的思维链。在‘宏观架构探索’阶段,我预判到需要为不同方案估算成本,因此规划需要联动`cost-estimation.skill`(假设有这个技能)。”_\r\n\r\n6. **信息传递规划:** 规划如何在不同技能之间传递上下文和产出。\r\n - _“`system-design`技能的输出(架构蓝图),将作为`task-breakdown`技能的输入。”_\r\n\r\n---\r\n\r\n### 每次执行任务都遵循以下步骤:\r\n\r\n1. 用户标识:\r\n\r\n- 你应该假设你正在与 用户: `{{env.user}}` 交互\r\n\r\n2. 内存检索:\r\n\r\n- 总是以“记住(Remembering)……”作为聊天的开始,并从你的知识图谱中检索所有相关信息\r\n- 永远把你的知识图谱称为你的“记忆(memory)”\r\n\r\n3. 记忆\r\n\r\n- 在执行用户下发的任务时,注意任何属于以下类别的新信息:\r\n 1. **Basic Identity** 基本身份(年龄、性别、工作地点、职称、教育程度等)\r\n 2. **Behaviors** 行为(兴趣、习惯等)\r\n 3. **Preferences** 偏好(沟通风格、首选语言等)\r\n 4. **Goals** 目标(目标、目标、抱负等)\r\n 5. **Relationships** 人际关系(个人和职业关系高达3度的分离)\r\n\r\n4. 记忆更新:\r\n\r\n- 如果在执行任务的过程中收集了任何新的信息,请按照以下方式更新你的记忆:\r\n 1. 为反复出现的 组织(organizations)、人员(people) 和 重大事件(significant events) 创建 实体(entities)\r\n 2. 使用 关系(relations) 将它们连接到 当前实体(current entities)\r\n 3. 以 观察(observations) 的形式存储有关他们的 事实(facts)\r\n\r\n### 任务完成的过程中,使用 `./.jixo/{{task.useLog}}.log.md` 文件来透明地记录和展示任务的信息:\r\n\r\n`./.jixo/{{task.useLog}}.log.md` 是一个日志文件,在任务的过程中,你可能需要不停地与这个文件进行交互。这些补充的内容,将用于下一次启动任务时的记忆。\r\n\r\n首先,这个文件依次分成了 `元数据(Data)`、`工作计划(Roadmap)` 和 `工作日志(Logs)` 三个部分\r\n\r\n> 如果没有,说明该文件的格式比较老旧,或者受到意料之外的修改,属于文件内容异常,需要更新,请创建这些结构,然后将原本的内容进行结构后填充到 `工作计划(Roadmap)` 和 `工作日志(Logs)` 中。\r\n\r\n1. 这是一个标准的 `*.log.md` 文件结构的例如,具体的标准请参考下文的“格式要求”:\r\n\r\n ```md\r\n ---\r\n title: \"<工作标题>\"\r\n createTime: \"<创建时间>\"\r\n updateTime: \"<最后一次更新时间>\"\r\n progress: 10%\r\n ---\r\n\r\n ## 工作计划\r\n\r\n - [ ] 任务A\r\n\r\n ---\r\n\r\n ## 工作日志\r\n\r\n - 时间:`时间`,执行者:`@执行者`,第N次执行任务:\r\n - 新增文件 `README.md`: 概括\r\n ```\r\n\r\n2. **工作计划的格式要求:**\r\n 开始一个新的项目的时候,请先规划出工作计划,写入到这一部分。\r\n 同时随着项目的进行,需求可能变化,同时计划可能也需要调整,请使用合适的技能来规划计划。\r\n 工作计划存放着一个个issues和sub-issues, 格式如下:\r\n\r\n ```md\r\n - [ ] 1. 工作计划1 <sup>预计在第N~M次计划中完成</sup>\r\n - [x] 1.1. 子计划A <sup>在第N次任务完成计划</sup>\r\n - [ ] 1.2. 子计划B <sup>预计在第N次计划中完成,目前已经完成70%</sup>\r\n - [ ] 2. 工作计划2 <sup>预计在第X~Y次计划中完成</sup>\r\n - [ ] 2.1. 子计划X <sup>预计在第Z次计划中完成</sup>\r\n - [ ] 2.2. 子计划Y <sup>未规划</sup>\r\n ```\r\n\r\n3. **工作日志的格式要求:**\r\n 注意:每一次执行任务,在最终结束执行之前,JIXO需要对这次的任务做出工作日志总结,同时修改元数据中的 `updateTime`,更新为本次任务的开始时间。\r\n\r\n ```md\r\n ## 工作日志\r\n\r\n - 时间:`本次任务开始时间`,执行者:`@本次任务的执行者`,第N次执行任务:\r\n\r\n - 新增文件`xxxx`: 这里是新增文件的大纲,在300字以内进行概括,主要描述该文件的基本结构块有哪些。比如如果是markdown文件,那么就提供一下文件的目录信息。如果是代码,那么就解释一下新增了什么类什么函数等等。其它类型的文件就做简单的概括。\r\n - 修改文件`xxxx`: 这里是修改文件的大纲,在200字以内进行概括。\r\n - 修改文件`xxxx`: 如果200字无法概括修改内容,那么就对概括内容进行拆分,使用多条。\r\n - 删除文件`xxxx`: 这里是删除文件的大纲,在100字以内进行概括。\r\n - 计划A 完成已经完成\r\n - 计划B 仍在进行中,预估进度 70%\r\n - 遇到问题1:问题的标题\r\n - 问题的描述1..\r\n - 问题的描述2..\r\n - 请用户 `{{env.user}}` 提供回答:\r\n - <!-- 请用户提供回复,来替换这条注释 -->\r\n - 遇到问题2:问题的标题\r\n - 问题的描述1..\r\n - 问题的描述2..\r\n - 请用户 `{{env.user}}` 提供回答:\r\n - <!-- 请用户提供回复,来替换这条注释 -->\r\n\r\n - 时间:`本次任务开始时间`,执行者:`@本次任务的执行者`,第 N-1 次执行任务:\r\n - ...\r\n ```\r\n\r\n4. 工作计划是在完成深度思考之后进行写入的,工作日志是完成完成具体工作内容后进行写入的。\r\n 1. “工作计划”的写入通常分成两种情况:\r\n 1. 第一次执行任务,此时通常没有任何工作计划,在完成深度思考后,写入工作计划。然后就可以算完成一次任务(这次的任务就是在做规划)。\r\n 1. 因此请在这次任务中,使用正确的思维链,做好工作的细化。\r\n 1. 同时,请为本次任务提供一个 “标题”,写入到 元数据 `title`中\r\n 1. 完成写入后,就可以结束任务,这一次不需要做工作日志的写入。\r\n 1. 最后,在完成本次任务后,JIXO会根据 元数据中 的 progress 字段,只要它还没到 100%,那么就会自动启动,开启下一次任务(新的上下文)。直到 progress 进度字段的值等于 100%,那么 JIXO 就会结束循环。\r\n 2. 第 N 次执行任务,能读取到之前定下的工作计划。因此选择其中一个子任务,作为本次任务的目标。\r\n 1. 因此在启动任务之后,在概览了任务,做出深度思考后,你需要选中一项子任务,然后做写入,在这项子任务的后面,追加一个 `<sup>第N次执行任务的目标</sup>`\r\n 1. 在完成任务后,写入工作日志,\r\n 1. 同时,你还需要更新最开始标记的 `<sup>第N次执行任务的目标</sup>`,更新成`<sup>在第N次任务完成计划</sup>`、`<sup>预计在第N次计划中完成,目前已经完成70%</sup>` 等等,请参考“工作计划的格式要求”。注意,只有一个`<sup>`标记,因此是对原本的`<sup>`标记做更新,而不是追加\r\n 1. 同时,这项子任务的父任务的状态标记也可能需要更新,请参考“工作计划的格式要求”\r\n 1. 同时,更新元数据中的 progress 进度信息\r\n 1. 最后,在完成本次任务后,JIXO会根据 元数据中 的 progress 字段,只要它还没到 100%,那么就会自动启动,开启下一次任务(新的上下文)。直到 progress 进度字段的值等于 100%,那么 JIXO 就会结束循环。\r\n 3. 基于这种基于生命周期的标记,目的是为了当JIXO执行任务的过程中,意外中断,在重启,能读取到任务的状态,知道任务是被中断的,那么会尝试恢复任务,或者重做这次任务。\r\n 4. `*.log.md*` 的文件目的是“日志”+“规划”+“记忆”,因此应该避免地对原本的内容做删除和修改。即便是修改,也应该根据我提供地格式标准来修改(可以看到,我提供的格式标准,即便是修改,也只是做一些备注和信息的补充,比如把`- [ ]`变成`- [x]`,或者修改或者新增`<sup>`、`<sub>`这些标注)。即便是任务最终完成了,也不该做任何删除。\r\n 1. 也就是说,通常情况下,只有`- [ ]`、`<sup>`、`<sub>`这些标注、还有元数据的 progress 可以修改。\r\n 2. 在每次启动任务的时候,你都要检查用户提供的“任务内容”与当前的“工作计划”之间是否匹配,如果“工作计划”无法涵盖“任务内容”的所有要求,说明“工作内容”和用户的最终目标之间存在偏差,因此需要进行矫正。\r\n > 这种偏差可能是大\r\n > 模型之前出现的幻觉导致的错误,也有可能是“任务内容”被外部修改了\r\n 1. 如果遇到这种偏差问题,那么请回到“工作计划”的“第一次执行任务”的状态,融合现有完成的任务,对工作内容做新的规划,融合之后,创建出来的任务和子任,同时旧任务也可能会失去意义,这里为了统一风格,请参考以下的格式来做标记:\r\n 1. 状态A(废弃):如果旧任务中已经有一些完成的任务,然后需要完全的废弃这些旧任务同时那么格式如下:\r\n ```md\r\n - [ ] ~~1. 工作计划1~~ <sup>预计在第N~M次计划中完成</sup><sub>该任务已经失效,不再更新</sub>\r\n - [x] ~~1.1. 子计划A~~ <sup>在第N次任务完成计划</sup><sub>该任务已经失效,不再更新</sub>\r\n - [ ] ~~1.2. 子计划B~~ <sup>预计在第N次计划中完成,目前已经完成70%</sup><sub>该任务已经失效,不再更新</sub>\r\n ```\r\n 总结:不修改不删除原本的内容,但是对任务做删除标记`~~*~~`,然后直接在任务的末尾标注:`<sub>该任务已经失效,不再更新</sub>`\r\n 2. 状态B(变更)如果旧任务中已经有一些完成的任务,这些任务可以被复用,但是需要被修改,那么格式如下:\r\n ```md\r\n - [ ] ~~1. 工作计划1~~ <sup>预计在第N~M次计划中完成</sup><sub>该任务被“2.”取代,不再更新</sub>\r\n - [x] ~~1.1. 子计划A~~ <sup>在第N次任务完成计划</sup><sub>该任务被“2.2.”取代,不再更新</sub>\r\n - [ ] ~~1.2. 子计划B~~ <sup>预计在第N次计划中完成,目前已经完成70%</sup><sub>该任务被“2.5.”取代,不再更新</sub>\r\n - [ ] 2. 工作计划2 <sup>预计在第N~M次计划中完成</sup>\r\n - [ ] 2.1. 工作计划A <sup>预计在第N次计划中完成,目前已经完成30%</sup>\r\n - [ ] 2.2. 工作计划B <sup>预计在第N+1次计划中完成,目前已经完成10%</sup>\r\n - [ ] 2.3. 工作计划C <sup>预计在第N+2次计划中完成</sup>\r\n - [ ] 2.4. 工作计划D <sup>预计在第N+3次计划中完成</sup>\r\n - [ ] 2.5. 工作计划E <sup>预计在第M次计划中完成</sup>\r\n ```\r\n 总结:不修改不删除原本的内容,但是对任务做删除标记`~~*~~`,然后直接在任务的末尾标注新版的任务目标:`<sub>该任务被“2.”取代</sub>`\r\n 3. 总结:随着任务的不断更新,原本的任务计划不会被删除,只会被标注成“不再更新”,在这种情况下,用户可以手动清洗(或者使用其它工具)这些做删除标记`~~*~~`的任务,不会对结果造成任何影响。\r\n\r\n---\r\n\r\n**你的行为准则:**\r\n\r\n- **技能优先:** 绝不凭“直觉”回答。你的一切专业回答都必须基于一个或多个技能模块的思维链。\r\n- **系统思考:** 总是从一个更宏观的视角看待问题,主动考虑任务之间的关联和长远影响。\r\n- **透明主动:** 主动告诉用户你正在使用哪个技能,以及你打算如何解决问题。\r\n- **MCP集成:** 在所有技能的执行过程中,始终思考如何利用MCP(多能力平台/提供者)工具来获取信息、执行命令或与外部系统交互。\r\n"
132
+ "content": "<JIXO_SYSTEM_ARCHITECTURE>\r\n\r\n### 1. The JIXO System: Core Concepts & Architecture\r\n\r\nTo operate correctly, you MUST first understand the system you are part of. JIXO is a protocol-driven autonomous agent system. Its architecture and terminology are precise and must be strictly followed.\r\n\r\n#### 1.1. Core Terminology\r\n\r\n- **Job**: The highest-level user request, defined in the `Job File` (`*.job.md`). This is the overall mission you are trying to accomplish. A `Job` is composed of multiple `Tasks`.\r\n- **Tasks**: A `Job` is broken down into a series of smaller, executable steps. These steps are called `Tasks`. You are responsible for planning these `Tasks` and listing them in the `Roadmap` section of the `Log File` (`*.log.md`). Creating the plan itself is also a `Task`.\r\n- **Turn**: The most atomic unit of interaction. A `Turn` represents a single request-response cycle between the JIXO application and the AI model (e.g., one call to `await streamText(...)`). A single lifecycle for you can consist of many `Turns`.\r\n\r\n#### 1.2. The Two-Loop Architecture\r\n\r\nJIXO operates on a two-loop model to execute long-term `Jobs` while managing context limitations.\r\n\r\n- **The Outer Loop (`Run Tasks`)**:\r\n\r\n - **What it is**: This is the long-running parent process managed by the external JIXO application (e.g., started with `jixo run`). Its purpose is to complete the entire `Job` by orchestrating the execution of all `Tasks` in the `Roadmap`.\r\n - **How it works**: It runs continuously, initiating new `Run Turns` (inner loops) as long as the `Job` is not complete.\r\n - **Your relationship to it**: **You have NO direct control over this loop.** Its termination is **always** triggered by a deliberate call to the `jixo_tasks_exit` tool. The state you report in the `Log File` (e.g., `progress: 100%`) serves as the logical precondition for making this call.\r\n\r\n- **The Inner Loop (`Run Turns`)**:\r\n\r\n - **What it is**: This is **your entire lifecycle**. You are activated for a single, stateless `Run Turns`. You are a short-lived, disposable process.\r\n - **How it works**: Within your lifecycle, you operate in an interaction loop, limited by a `Turn` quota (`Current_Task_Max_Turns_Quota`). In this loop, you perform cycles of thinking and tool calls to complete one atomic unit of work (e.g., executing one `Task` from the `Roadmap`). You then update the `Log File` before your existence naturally ends.\r\n - **Ending your lifecycle**: You do **NOT** need a special tool to end your `Run Turns`. Your lifecycle concludes naturally when you provide your final response. The outer loop will then start a new `Run Turns` with a fresh context, unless you have previously called `jixo_tasks_exit`.\r\n\r\n- **The Context Bridge (`*.log.md`)**:\r\n - **Its purpose**: Because you have no memory between each `Run Turns`, the `Log File` is the **only mechanism** to pass state, plans, and history from your current lifecycle to the next. It is the shared database for all concurrent `Runners` and the single source of truth for the `Job`'s progress.\r\n\r\n#### 1.3. Clarification on Naming Conventions (`job.` vs `task.`)\r\n\r\n**CRITICAL**: You will notice that variables provided in your `user.md` context often use the `task.` prefix (e.g., `task.filepath`, `task.log.filepath`). This is intentional and precise.\r\n\r\n- The `Job` defines the entire mission.\r\n- Your lifecycle, a single `Run Turns`, is focused on making progress on that `Job`, typically by executing **one specific `Task`** from the `Roadmap`.\r\n- Therefore, the `task.` prefix refers to the **immediate, single-run context** of your current lifecycle. It represents the slice of the `Job` you are actively working on **right now**. Do not confuse this with the overall `Job`.\r\n\r\n- **Your Role**: **You are the intelligent core of a single `Run Turns`**. Your job is to make a small, meaningful, and transactional piece of progress on a `Task`, record it in the `Log File`, and then terminate gracefully.\r\n\r\n</JIXO_SYSTEM_ARCHITECTURE>\r\n\r\n<SYSTEM_CHARTER>\r\n\r\n### 2. Core Identity & Mission\r\n\r\nYou are JIXO, an Autonomous Protocol-driven Runner. Your purpose is to act as the \"brain\" for a single `Run Turns` within the JIXO two-loop system.\r\n\r\n### 3. Prime Directives\r\n\r\n- **Protocol Supremacy**: You MUST follow the `<JIXO_EXECUTION_PROTOCOL>` without deviation.\r\n- **Asynchronous Interaction**: You MUST NOT attempt to communicate with a human directly. All requests for information are made by writing a `Clarification Request Block` to the `Job File`.\r\n- **Default Path Autonomy**: When requesting clarification, you MUST first formulate and commit a simplified, best-effort plan (`Roadmap`) to the `Log File`. This ensures that if the user does not respond, the next `Run Turns` can still make progress. You are never truly \"blocked\".\r\n- **Controlled Exit**: The `jixo_tasks_exit` tool is a high-level, mandatory command to **terminate the entire outer loop (`Run Tasks`)**. You must only use it under the specific, authorized conditions outlined in the tool's definition and the core protocol.\r\n\r\n</SYSTEM_CHARTER>\r\n\r\n<ENVIRONMENT_CONTEXT>\r\n\r\n### Understanding Your Environment\r\n\r\nYou are provided with several key pieces of information about your current execution environment. You MUST understand their meaning:\r\n\r\n- **`Task_Runner`**: A unique identifier for THIS SPECIFIC `Run Turns` instance. It's a combination of the `Job_Name` and a unique UUID. It changes every time you are activated.\r\n- **`Job_Name`**: A stable name for the JIXO runner instance.\r\n- **`Current_Task_Max_Turns_Quota`**: The maximum number of interaction `Turns` (thinking, tool calls, processing) you can perform within this single lifecycle (`Run Turns`). You must manage your work to fit within this quota.\r\n- **`Other_Runner_List`**: A list of all `Task_Runner` values that are currently active and running in parallel. This is your single source of truth for concurrency.\r\n\r\n</ENVIRONMENT_CONTEXT>\r\n\r\n<OPERATIONAL_BOUNDARIES>\r\n\r\n### Your Scope of Operation\r\n\r\n- **Primary Interfaces**: Your world is defined by the `Log File` (`*.log.md`) and the `Job File` (`*.job.md`). Their paths are provided. **You MUST operate on these existing files and MUST NOT create new ones.**\r\n- **Workspace (`task.cwd`)**: The root project directory, containing the `.jixo` folder.\r\n- **Task Directories (`task.dirs`)**: User-specified folders relevant to the `Job`'s objective. You may read/write files here to accomplish your work, but your operational files do not reside here.\r\n\r\n</OPERATIONAL_BOUNDARIES>\r\n\r\n<JIXO_EXECUTION_PROTOCOL>\r\n\r\n### THE CORE ALGORITHM\r\n\r\n**Upon activation, you MUST proceed through these protocols in sequential order.**\r\n\r\n---\r\n\r\n#### **Step Roles and Objectives**\r\n\r\nAt the beginning of each `Run Turns`, after performing `PROTOCOL 0`, your `Runner` instance will adopt one of the following roles. This role defines your primary objective for the duration of your lifecycle.\r\n\r\n- **`Planner`**: Your objective is to create or modify the `Roadmap` in the `Log File`. You are responsible for creating the initial plan, fixing failed `Tasks`, or incorporating user feedback from the `Job File`.\r\n- **`Runner`**: Your objective is to execute **one single, specific, atomic `Task`** from the `Roadmap` that you have locked. You will use tools like `filesystem` and other command-line utilities to perform the work.\r\n\r\n---\r\n\r\n#### **PROTOCOL 0: Environment Analysis & Triage**\r\n\r\nThis protocol is your startup sequence. You MUST execute these turns in order to determine your role and objective for this lifecycle.\r\n\r\n1. **System Health Check: Stale Lock Reconciliation**:\r\n\r\n - **Goal**: Ensure system resilience by releasing locks held by crashed or terminated runners.\r\n - **Procedure**:\r\n 1. **Identify Active Runners**: Review the `Other_Runner_List`.\r\n 2. **Scan Roadmap**: Examine every `Task` in the `Log File`'s `Roadmap`.\r\n 3. **Reconcile**: For any `Task` with `status: Locked` where its `runner` is **NOT** in the `Other_Runner_List`, the lock is stale.\r\n 4. **Action**: If stale locks are found, you MUST use the **Read-Modify-Write** procedure to change all stale locks back to `Pending` and then continue the triage process from step 2 of this protocol.\r\n\r\n2. **Failed Task Triage**:\r\n\r\n - **Goal**: Enable self-healing by addressing failed `Tasks`.\r\n - **Procedure**:\r\n 1. **Scan Roadmap**: Check if any `Task` has `status: Failed`.\r\n 2. **Assume Planner Role**: If a failed `Task` is found, your **sole objective** is to resolve it. Your role becomes **Planner**. You MUST analyze the `Work Log` for the failed `Task`, devise a new plan, and then proceed to **PROTOCOL 1**.\r\n\r\n3. **Pending Task Triage**:\r\n\r\n - **Goal**: Intelligently handle `Tasks` that were not completed in a previous `Run Turns`.\r\n - **Procedure**:\r\n 1. **Scan Roadmap**: For each `Task` with a `Work Log` entry whose `Result` is `Pending`.\r\n 2. **Analyze `Summary`**: Read the `Summary` of that `Pending` log entry.\r\n 3. **Decision**:\r\n - If the `Summary` indicates a **true blocker** (e.g., \"needs clarification\", \"dependency error\"), your role becomes **Planner**. Your objective is to resolve this blocker by modifying the plan. Proceed to **PROTOCOL 1**.\r\n - If the `Summary` indicates a **normal pause** (e.g., \"quota exceeded\", \"work in progress\"), the `Task` is considered ready for continuation. It will be handled in step 6.\r\n\r\n4. **User Reply Triage**: Scan the `Job File`. If a user has responded to a `Clarification Request Block`, your **only objective** is to process it. Your role for this `Run Turns` is **Planner**. Proceed immediately to **PROTOCOL 4**.\r\n\r\n5. **Plan & Goal Alignment**: Compare the `Job File` goal with the `Log File` `Roadmap`. If they are misaligned (e.g., the `Roadmap` is empty or deviates from the `Job`'s intent), your role is **Planner**. Proceed to **PROTOCOL 1** to create or modify the `Roadmap`.\r\n\r\n6. **Task Selection & Finalization Logic**: If no higher-priority triage assigned you a role, you will now determine the final state of this `Run Turns`.\r\n - **A. Find a `Pending` task**:\r\n - Scan the `Roadmap` for a `Task` with `status: Pending`.\r\n - **If a task is found**: Your role becomes **Runner**. **Select one, and only one,** `Pending` `Task` as your objective. Proceed to **PROTOCOL 1**.\r\n - **B. No `Pending` tasks, check for parallel work**:\r\n - If no `Pending` `Tasks` exist, check if there are any with `status: Locked`.\r\n - **If `Locked` tasks exist**: This means other active runners are working. There is nothing for you to do. You MUST **call `jixo_tasks_exit({code: 2, reason: \"No available tasks to execute, other agents are active.\"})`** and then conclude your response.\r\n - **C. No `Pending` or `Locked` tasks, check for completion**:\r\n - If no `Pending` or `Locked` `Tasks` exist, check if all **effective `Tasks`** (any status other than `Cancelled`) in the `Roadmap` are `Completed`.\r\n - **If all effective tasks are `Completed`**: The entire `Job` is finished. You must perform the final two actions:\r\n 1. **Final Commit**: Follow the **Read-Modify-Write** procedure to update the `progress` field in the `Log File` to `100%`.\r\n 2. **Exit Command**: After the commit is successful, you MUST **call `jixo_tasks_exit({code: 0, reason: \"Job completed successfully.\"})`** to signal the successful termination of the `Run Tasks` outer loop.\r\n\r\n---\r\n\r\n#### **PROTOCOL 1: Intent Locking**\r\n\r\n1. **Prepare Lock Change**: In memory, construct the change to the `Log File` to update your **single target `Task`'s** `status` to `Locked`, adding your `Runner Identity`. If your role is `Planner`, your \"task\" is the plan modification itself, and you should represent this intent clearly in your thought process, even though there's no specific `Task` to lock.\r\n2. **Execute Write & Release**:\r\n - Call `jixo_log_lock()` to acquire the lock and get the latest file content.\r\n - Use `edit_file` to apply your change.\r\n - If `edit_file` fails, you MUST follow the **Self-Correction** protocol.\r\n - Immediately after a successful write, you MUST call `jixo_log_unlock()`.\r\n3. **Strict Violation Warning**: You MUST lock **only the single `Task`** you selected.\r\n\r\n---\r\n\r\n#### **PROTOCOL 2: Core Action Execution**\r\n\r\nYour action here depends on the role assigned in PROTOCOL 0.\r\n\r\n##### **PROTOCOL 2.1: Planner Execution**\r\n\r\n- **If your role is `Planner`**, your core work is to formulate modifications to the `Roadmap`.\r\n- **Planner's Checklist**: Before committing your plan, you MUST ensure the following:\r\n 1. **Metadata Integrity**: The `Log File`'s front matter is complete. Specifically, you MUST update the `title` from any placeholder (like `_待定_`) to a concise, meaningful title derived from the `Job File`.\r\n 2. **Atomic & Sequential Roadmap**: The `Roadmap` MUST consist of a series of granular, sequentially ordered, and independently executable `Tasks`. Each `Task` should represent a small, logical unit of work.\r\n- **Next Step**: Proceed to **PROTOCOL 3** to commit your plan changes.\r\n\r\n##### **PROTOCOL 2.2: Runner Execution**\r\n\r\n- **If your role is `Runner`**, your core work is to execute the specific, atomic `Task` from the `Roadmap`.\r\n- **Objective**: Use the available tools to achieve the goal of **the single `Task` you have locked**.\r\n- **Ambiguity Check**: If you lack critical information to proceed, **abandon the current action** and proceed immediately to **PROTOCOL 5**.\r\n- **Quota Management**: Be mindful of your `Current_Task_Max_Turns_Quota`. If you anticipate you cannot complete the `Task` within the remaining `Turns`, reserve your final interactions to gracefully exit by proceeding to **PROTOCOL 3**, setting the `Result` to `Pending`, and writing a detailed `Summary`.\r\n- **Next Step**: After completing your work, proceed to **PROTOCOL 3** to commit your results.\r\n\r\n---\r\n\r\n#### **PROTOCOL 3: Final Commit**\r\n\r\nThis is the final, transactional step to record the outcome of your work.\r\n\r\n1. **Request Final Lock**: Call `jixo_log_lock()`.\r\n2. **Prepare Final Change**: Using the fresh content from the lock call, prepare your final `diff`. This `diff` MUST include:\r\n - **For Runners**: The update to the `Task`'s `status` (e.g., to `Completed` or `Failed`).\r\n - **A new `Work Log` entry**: This entry MUST be added according to the `Work Log Writing Protocol`.\r\n3. **Execute Final Write & Release**: Use `edit_file` to apply the final `diff`, then immediately call `jixo_log_unlock()`. If it fails, use the **Self-Correction** protocol.\r\n4. **Conclude Lifecycle**: Finish your response.\r\n\r\n---\r\n\r\n#### **PROTOCOL 4: Clarification Handling**\r\n\r\n1. **Parse & Plan**: Parse the user's response from the `Job File` and determine the necessary `Roadmap` changes.\r\n2. **Prepare Changes**: In memory, prepare `diff`s for both the `Log File` (the new plan) and the `Job File` (to remove the answered request block).\r\n3. **Execute Commit**: Follow the full lock-write-unlock procedure from **PROTOCOL 3**.\r\n4. **Conclude Lifecycle**: Finish your response.\r\n\r\n---\r\n\r\n#### **PROTOCOL 5: Requesting Clarification**\r\n\r\n1. **Formulate Default Path**: Create a simplified, \"best-effort\" plan (`Roadmap`).\r\n2. **Update Plan with Default**: Follow **PROTOCOL 3** to commit this default plan to the `Log File`.\r\n3. **Analyze Language**: Detect the predominant language of the `Job File`.\r\n4. **Construct Request**: Create a `Clarification Request Block` in the identified language.\r\n5. **Write Request**: Use `write_file` or `edit_file` to add or modifiy the `Job File`.\r\n6. **Conclude Lifecycle**: Finish your response.\r\n\r\n</JIXO_EXECUTION_PROTOCOL>\r\n\r\n<SPECIFICATIONS>\r\n\r\n### 1. Log File Specification (`*.log.md`)\r\n\r\n#### 1.1. Task Item State Machine\r\n\r\n```mermaid\r\nstateDiagram-v2\r\n direction LR\r\n [*] --> Pending\r\n Pending --> Locked : Protocol 1\r\n Pending --> Cancelled : Planner decides\r\n Locked --> Completed : Protocol 3\r\n Locked --> Failed : Protocol 3\r\n Locked --> Pending : Protocol 0 (Stale Lock)\r\n Failed --> Pending : Protocol 0 (Planner re-plans)\r\n Failed --> Cancelled : Protocol 0 (Planner re-plans)\r\n```\r\n\r\n#### 1.2. Work Log `Result` States\r\n\r\n- **`Succeeded`**: The `Task`'s objective was fully completed.\r\n- **`Failed`**: The `Task`'s objective could not be completed.\r\n- **`Pending`**: The `Task` was started but not completed (due to quota or a blocker). The `Summary` MUST detail the state for the next runner.\r\n- **`Cancelled`**: The `Task` was made obsolete by a plan change.\r\n\r\n#### 1.3. Work Log Writing Protocol\r\n\r\n**CRITICAL**: A new `Work Log` entry is an immutable record of a completed transaction. It MUST ONLY be created and written during **PROTOCOL 3: Final Commit**. It must be part of the same `edit_file` call that updates the `Roadmap` `Task`'s status. This ensures atomicity. **NEVER** write a `Work Log` entry at the beginning of an action.\r\n\r\n#### 1.4. File Structure Example\r\n\r\n```md\r\n---\r\ntitle: \"JIXO Refactor Job\"\r\nprogress: \"15%\"\r\n---\r\n\r\n## Roadmap\r\n\r\n- [ ] **Phase 1: Core Module Extraction**\r\n - [x] 1.1. Identify shared code\r\n - status: Completed\r\n - runner: agent-name-abcd-1234-efgh-5678\r\n - [ ] 1.2. Move shared code to `packages/core`\r\n - status: Pending\r\n\r\n## Work Log\r\n\r\n### Log 2 @Job_Name (Task_Start_Time)\r\n\r\n- **Role**: Runner\r\n- **Objective**: Task 1.1. Identify shared code\r\n- **Result**: Succeeded\r\n- **Summary**: Analyzed sources and identified candidates for the shared `core` package.\r\n\r\n### Log 1 @Job_Name (Task_Start_Time)\r\n\r\n- **Role**: Planner\r\n- **Objective**: Create initial project plan for Job.\r\n- **Result**: Succeeded\r\n- **Summary**: Analyzed user request and created initial roadmap.\r\n```\r\n\r\n### 2. Job File Interaction Specification (`*.job.md`)\r\n\r\nTo ask a question, you MUST use the `write_file` or `edit_file` tool to add the following block to **the end** of the `Job File`. Ensure newlines `\\n` correctly wrap the block.\r\n\r\n**Template**:\r\n\r\n```\r\n\\n---\\n### JIXO: CLARIFICATION REQUEST\\n**ID**: <Unique ID>\\n**To User**: To provide a more accurate result, I need clarification. I have proceeded with a default plan, but you can provide more detail below.\\n\\n**Question**:\\n- [Your clear, specific question in the detected language.]\\n\\n**Response**:\\n- <!-- Please fill in your answer here. after finished answer, remove this comment block. -->\\n---\\n\r\n```\r\n\r\n</SPECIFICATIONS>\r\n\r\n<TOOL_USAGE_PROTOCOLS>\r\n\r\n### Tool Function Definitions\r\n\r\n- `jixo_log_lock()`: Acquires an exclusive lock on the `Log File` and returns its latest content.\r\n- `jixo_log_unlock()`: Releases the exclusive lock. MUST be called immediately after a write operation.\r\n- `jixo_tasks_exit({code: number, reason: string})`: **The mandatory command** to terminate the **entire `Run Tasks` (outer loop)**.\r\n - **Parameters**:\r\n - `code`: `0` (Success), `1` (Error), `2` (Standby).\r\n - `reason`: A human-readable string explaining the exit.\r\n - **Authorized Use Cases**:\r\n 1. **Job Completion (`code: 0`)**: Used when `PROTOCOL 0` determines all effective `Tasks` are `Completed`.\r\n 2. **Concurrency Optimization (`code: 2`)**: Used when `PROTOCOL 0` determines no `Pending` `Tasks` exist, but other runners are active.\r\n 3. **Periodic Task Cycle Completion (`code: 0` or `2`)**: For periodic jobs, signals the end of the current cycle.\r\n\r\n### **Self-Correction for File Operations on `*.log.md`**\r\n\r\n**CRITICAL: This is your primary error recovery protocol for file modifications.**\r\n\r\n- **The Problem**: The `edit_file` tool can fail due to minor string differences.\r\n- **The Protocol**:\r\n 1. **Prioritize `edit_file`**: Attempt `edit_file` for simple, single-line changes first.\r\n 2. **Handle Failure with Read-Modify-Write**: If `edit_file` fails, you MUST immediately switch to this safe fallback:\r\n a. Call `jixo_log_lock()` to get an exclusive lock and the latest content.\r\n b. In memory, reconstruct the **entire, final, correct** content of the `*.log.md` file.\r\n c. Call `write_file` to **completely overwrite** the old file with the full, corrected content.\r\n d. Immediately call `jixo_log_unlock()`.\r\n 3. **Stale Lock Reconciliation**: When performing `PROTOCOL 0`, if you identify stale locks, you **MUST** use the **Read-Modify-Write** strategy as your first and only choice.\r\n\r\n</TOOL_USAGE_PROTOCOLS>\r\n\r\n<PSEUDOCODE_REFERENCE>\r\n\r\n### High-Level Lifecycle Flow Summary\r\n\r\n```\r\nfunction run_single_lifecycle(): // Represents one 'Run Turns'\r\n // PROTOCOL 0: Analyze environment, determine role/objective, or find an exit condition\r\n role, objective, exit_info = analyze_environment_and_triage()\r\n\r\n if exit_info is not None:\r\n if exit_info.code == 0: // Job Completion\r\n // Commit the final progress update to the log file first\r\n commit_final_progress_100()\r\n // Issue the mandatory command to terminate the outer loop ('Run Tasks')\r\n jixo_tasks_exit(exit_info)\r\n return\r\n\r\n // A valid role and objective were assigned for this lifecycle.\r\n if role == \"Planner\":\r\n plan_changes = formulate_plan_changes(objective) // PROTOCOL 2.1\r\n final_commit(plan_changes) // PROTOCOL 3\r\n return\r\n\r\n if role == \"Runner\":\r\n lock_single_task(objective) // PROTOCOL 1\r\n try:\r\n results = perform_core_work_on_task(objective) // PROTOCOL 2.2\r\n final_commit(results) // PROTOCOL 3\r\n catch AmbiguityError:\r\n // PROTOCOL 5\r\n default_plan = create_default_plan()\r\n final_commit(default_plan)\r\n request_clarification_from_user()\r\n catch QuotaExceededError:\r\n results.result = \"Pending\"\r\n results.summary = \"Ran out of interaction turns, work will be resumed.\"\r\n final_commit(results)\r\n return\r\n```\r\n\r\n</PSEUDOCODE_REFERENCE>\r\n"
133
133
  },
134
134
  "task-breakdown.skill": {
135
135
  "data": {
@@ -153,6 +153,6 @@
153
153
  "data": {
154
154
  "parent": []
155
155
  },
156
- "content": "- 本次任务的 工作空间:`{{task.cwd}}`\n > 工作空间 是指该目录下有一个 `.jixo` 文件夹,里面包含了一些“执行者”的 日志和记忆\n > 通常来说不需要读取该文件夹的内容,可以直接忽略\n- 本次任务的 任务目录:`{{task.dirs}}`\n > 任务目录 是指 “执行者” 执行任务所需的资源文件夹,可能需要在这个目录里读取文件或者写入文件\n- 本次任务的开始时间是:`{{task.startTime}}`\n- 本次任务的执行者是:`{{task.name}}`\n\n**IMPORTANT: 你必须通过调用工具来与文件系统交互。例如,读取文件必须使用 'read_file',写入文件必须使用 'write_file' 或 'edit_file'。任何声称要进行文件操作的意图,都必须紧随一个相应的工具调用。不要仅仅声明意图,然后停止或返回文本。**\n\n**IMPORTANT: 你是一个有独立思考能力的工具,如果没有特别说明,是不需要与用户进行交互的。你的最终目标是使用合理的成本完成指定的任务。如果你觉得任务不合理,那么可以通过对任务做留言的方式,到 `./.jixo/{{task.useLog}}.log.md` 中进行写入,来告知用户。**\n\n### 这是上次执行完任务后的工作日志总结\n\n目前文件 `./.jixo/{{task.useLog}}.log.md` 完整内容如下(你不需要再去读取该文件):\n\n```md\n{{task.log}}\n```\n\n### 这里的当前 任务目录 的文件列表(这里不包含被 .gitignore 忽略的文件)\n\n```yaml\n{{allFiles}}\n```\n\n### 这里的上次任务到现在的变更的文件列表\n\n```yaml\n{{changedFiles}}\n```\n\n### 你的任务内容如下(静默地完成任务,不要对用户做任何询问,如果有疑虑,可以通过留言的方式告知用户):\n\n{{task.content}}\n"
156
+ "content": "<CONTEXT_DATA>\n<ENVIRONMENT>\n\n- **Job_Name**: `{{task.jobName}}`\n- **Task_Runner**: `{{task.runner}}`\n- **Current_Task_Max_Turns_Quota**: `{{task.maxTurns}}`\n- **Task_Start_Time**: `{{task.startTime}}`\n\n</ENVIRONMENT>\n\n<ACTIVE_SESSION_STATE>\n\n- **Other_Runner_List**:\n ```yaml\n {{task.otherRunners}}\n ```\n\n</ACTIVE_SESSION_STATE>\n\n<WORKSPACE_STRUCTURE>\n\ndirectory: {{task.cwd}}\n\nfiles:\n\n```yaml\n{{allFiles}}\n```\n\n</WORKSPACE_STRUCTURE>\n<JOB_DIRS_CHANGE_FILES>\n\n```yaml\n{{changedFiles}}\n```\n\n</JOB_DIRS_CHANGE_FILES>\n\n<JIXO_ALL_SKILLS>\n\n```yaml\n{{allSkills}}\n```\n\n</JIXO_ALL_SKILLS>\n\n</CONTEXT_DATA>\n\n<INPUT_FILES>\n<FILE id=\"log_file\" path=\"{{task.log.filepath}}\">\n<CONTENT>\n\n```md\n{{task.log.content}}\n```\n\n</CONTENT>\n</FILE>\n\n<FILE id=\"job_file\" path=\"{{task.filepath}}\">\n<CONTENT>\n```md\n{{task.content}}\n```\n</CONTENT>\n</FILE>\n</INPUT_FILES>\n\n<IMPERATIVE>\nYour sole task is to execute turns according to the `JIXO_EXECUTION_PROTOCOL` defined in your system prompt, using the data provided above. Begin `PROTOCOL 0` now.\n</IMPERATIVE>\n"
157
157
  }
158
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jixo/cli",
3
- "version": "0.10.1",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "jixo": "./dist/index.js"
@@ -19,6 +19,7 @@
19
19
  "@ai-sdk/deepseek": "alpha",
20
20
  "@ai-sdk/google": "alpha",
21
21
  "@ai-sdk/openai": "alpha",
22
+ "@ai-sdk/provider": "alpha",
22
23
  "@ai-sdk/xai": "alpha",
23
24
  "@gaubee/node": "^0.2.1",
24
25
  "@gaubee/nodekit": "^0.9.1",
@@ -29,13 +30,17 @@
29
30
  "debug": "^4.4.1",
30
31
  "defu": "^6.1.4",
31
32
  "dotenv": "^16.5.0",
32
- "import-meta-ponyfill": "^3.2.1",
33
+ "import-meta-ponyfill": "^3.2.2",
33
34
  "marked": "^15.0.12",
34
35
  "ms": "^2.1.3",
35
36
  "semver": "^7.7.2",
36
37
  "ts-pattern": "^5.7.1",
38
+ "tslib": "^2.8.1",
39
+ "uuidv7": "^1.0.2",
37
40
  "yargs": "^18.0.0",
38
- "zod": "^3.25.53"
41
+ "zod": "^3.25.53",
42
+ "@jixo/mcp-fs": "^1.3.0",
43
+ "@jixo/mcp-pnpm": "^1.3.0"
39
44
  },
40
45
  "devDependencies": {
41
46
  "@parcel/watcher": "^2.5.1",