codexmate 0.1.30 → 0.1.32

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 (77) hide show
  1. package/README.md +98 -7
  2. package/README.vi.md +98 -7
  3. package/README.zh.md +99 -7
  4. package/cli/agents-files.js +18 -4
  5. package/cli/config-bootstrap.js +25 -11
  6. package/cli/plugin-config.js +64 -0
  7. package/cli/prompt-history.js +17 -4
  8. package/cli/system-prompt-files.js +7 -2
  9. package/cli.js +396 -46
  10. package/lib/cli-config-engine.js +266 -0
  11. package/lib/cli-utils.js +2 -1
  12. package/lib/cli-webhook.js +1 -1
  13. package/lib/handoff-mcp.js +282 -0
  14. package/lib/http-access-control.js +335 -0
  15. package/lib/session-context-health.js +82 -0
  16. package/lib/session-context-records.js +153 -0
  17. package/lib/thread-handoff.js +130 -0
  18. package/lib/web-startup-auth.js +53 -0
  19. package/lib/workflow-engine.js +92 -21
  20. package/lib/workflow-runner.js +261 -0
  21. package/package.json +1 -1
  22. package/plugins/prompt-templates/computed.mjs +3 -3
  23. package/plugins/prompt-templates/invocation.mjs +73 -0
  24. package/plugins/prompt-templates/methods.mjs +48 -3
  25. package/plugins/prompt-templates/overview.mjs +2 -0
  26. package/web-ui/app.js +48 -2
  27. package/web-ui/index.html +1 -0
  28. package/web-ui/logic.context-health.mjs +144 -0
  29. package/web-ui/modules/access-token.mjs +33 -0
  30. package/web-ui/modules/api.mjs +2 -1
  31. package/web-ui/modules/app.computed.prompts.mjs +11 -0
  32. package/web-ui/modules/app.methods.agents.mjs +20 -3
  33. package/web-ui/modules/app.methods.index.mjs +6 -0
  34. package/web-ui/modules/app.methods.navigation.mjs +17 -3
  35. package/web-ui/modules/app.methods.prompts-editor.mjs +7 -0
  36. package/web-ui/modules/app.methods.providers.mjs +2 -2
  37. package/web-ui/modules/app.methods.runtime.mjs +3 -2
  38. package/web-ui/modules/app.methods.session-actions.mjs +3 -0
  39. package/web-ui/modules/app.methods.session-browser.mjs +6 -2
  40. package/web-ui/modules/app.methods.system-prompt.mjs +17 -2
  41. package/web-ui/modules/app.methods.workflows.mjs +41 -0
  42. package/web-ui/modules/context-health.methods.mjs +70 -0
  43. package/web-ui/modules/i18n/locales/en.mjs +70 -2
  44. package/web-ui/modules/i18n/locales/ja.mjs +70 -2
  45. package/web-ui/modules/i18n/locales/vi.mjs +70 -2
  46. package/web-ui/modules/i18n/locales/zh-tw.mjs +70 -2
  47. package/web-ui/modules/i18n/locales/zh.mjs +70 -2
  48. package/web-ui/modules/plugins.methods.mjs +2 -0
  49. package/web-ui/modules/prompt-ecosystem.methods.mjs +136 -0
  50. package/web-ui/modules/sessions-filters-url.mjs +3 -0
  51. package/web-ui/modules/skills.methods.mjs +6 -5
  52. package/web-ui/modules/thread-handoff.mjs +142 -0
  53. package/web-ui/partials/index/context-health.html +45 -0
  54. package/web-ui/partials/index/modal-prompt-invocation.html +17 -0
  55. package/web-ui/partials/index/panel-config-claude.html +2 -0
  56. package/web-ui/partials/index/panel-config-codex.html +2 -0
  57. package/web-ui/partials/index/panel-config-kilocode.html +3 -1
  58. package/web-ui/partials/index/panel-config-openclaw.html +2 -0
  59. package/web-ui/partials/index/panel-config-opencode.html +3 -1
  60. package/web-ui/partials/index/panel-config-pi.html +2 -0
  61. package/web-ui/partials/index/panel-dashboard.html +59 -0
  62. package/web-ui/partials/index/panel-plugins.html +37 -9
  63. package/web-ui/partials/index/panel-prompts.html +46 -18
  64. package/web-ui/partials/index/panel-sessions.html +35 -44
  65. package/web-ui/partials/index/thread-handoff.html +59 -0
  66. package/web-ui/res/web-ui-render.precompiled.js +1289 -177
  67. package/web-ui/styles/context-health.css +107 -0
  68. package/web-ui/styles/controls-forms.css +9 -0
  69. package/web-ui/styles/dashboard.css +51 -0
  70. package/web-ui/styles/modals-core.css +87 -0
  71. package/web-ui/styles/navigation-panels.css +1 -1
  72. package/web-ui/styles/plugins-panel.css +62 -0
  73. package/web-ui/styles/prompts-editor.css +34 -4
  74. package/web-ui/styles/responsive.css +19 -10
  75. package/web-ui/styles/sessions-preview.css +206 -111
  76. package/web-ui/styles/sub-tabs.css +181 -0
  77. package/web-ui/styles.css +2 -0
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ const crypto = require('crypto');
4
+ const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
5
+ const CONFIG_VERSION = 1;
6
+ const MAX_CONFIG_BYTES = 2 * 1024 * 1024;
7
+ const HISTORY_BUCKET = 'plugin_prompt_templates';
8
+ const TEMPLATE_FIELDS = ['id', 'name', 'description', 'template', 'createdAt', 'updatedAt', 'createdBy'];
9
+
10
+ function normalizeTemplates(input) {
11
+ if (!Array.isArray(input)) throw new Error('模板配置必须是数组');
12
+ const ids = new Set();
13
+ return input.filter((item) => item && item.isBuiltin !== true).map((item) => {
14
+ if (typeof item.id !== 'string' || !item.id || typeof item.name !== 'string' || !item.name.trim()
15
+ || typeof item.template !== 'string' || ids.has(item.id)) throw new Error('模板配置条目无效');
16
+ ids.add(item.id);
17
+ const entry = Object.fromEntries(TEMPLATE_FIELDS.map((field) => [field, typeof item[field] === 'string' ? item[field] : '']));
18
+ entry.isBuiltin = false;
19
+ entry.maintainers = Array.isArray(item.maintainers) ? item.maintainers.filter((name) => typeof name === 'string') : [];
20
+ return entry;
21
+ });
22
+ }
23
+
24
+ function serializeTemplates(templates) {
25
+ const content = JSON.stringify({ version: CONFIG_VERSION, templates: normalizeTemplates(templates) }, null, 2) + '\n';
26
+ if (Buffer.byteLength(content, 'utf8') > MAX_CONFIG_BYTES) throw new Error('模板配置超过 2MB');
27
+ return content;
28
+ }
29
+
30
+ function createPluginConfigController({ fs, path, CONFIG_DIR, backupPromptBeforeWrite }) {
31
+ const filePath = path.join(CONFIG_DIR, 'codexmate-plugin-config.json');
32
+ function getPluginConfig() {
33
+ try {
34
+ const exists = fs.existsSync(filePath);
35
+ const raw = exists ? fs.readFileSync(filePath, 'utf8') : '';
36
+ const parsed = exists ? JSON.parse(raw) : { version: CONFIG_VERSION, templates: [] };
37
+ if (parsed.version !== CONFIG_VERSION) throw new Error('模板配置版本无效');
38
+ return {
39
+ exists, templates: normalizeTemplates(parsed.templates), historyBucket: HISTORY_BUCKET,
40
+ hash: crypto.createHash('sha256').update(raw).digest('hex')
41
+ };
42
+ } catch (error) { return { error: error.message }; }
43
+ }
44
+ function applyPluginConfig(params = {}) {
45
+ try {
46
+ const content = serializeTemplates(params.templates);
47
+ const current = getPluginConfig();
48
+ if (current.error) return current;
49
+ if (typeof params.baseHash !== 'string' || params.baseHash !== current.hash) {
50
+ return { error: '模板配置已被修改,请重新加载后再保存' };
51
+ }
52
+ if (!current.exists && Array.isArray(params.legacyTemplates) && params.legacyTemplates.length) {
53
+ writeTextAtomicWithBackup(filePath, serializeTemplates(params.legacyTemplates), { fs });
54
+ }
55
+ const backup = backupPromptBeforeWrite(HISTORY_BUCKET, filePath);
56
+ if (backup && backup.error) return { error: backup.error };
57
+ writeTextAtomicWithBackup(filePath, content, { fs });
58
+ return getPluginConfig();
59
+ } catch (error) { return { error: error.message }; }
60
+ }
61
+ return { getPluginConfig, applyPluginConfig };
62
+ }
63
+
64
+ module.exports = { createPluginConfigController };
@@ -1,11 +1,15 @@
1
1
  'use strict';
2
2
 
3
+ const crypto = require('crypto');
4
+ const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
5
+
3
6
  function createPromptHistoryController(deps = {}) {
4
7
  const {
5
8
  fs,
6
9
  path,
7
10
  CONFIG_DIR,
8
- MAX_HISTORY = 20
11
+ MAX_HISTORY = 20,
12
+ now = Date.now
9
13
  } = deps;
10
14
 
11
15
  if (!fs) throw new Error('createPromptHistoryController 缺少 fs');
@@ -61,10 +65,19 @@ function createPromptHistoryController(deps = {}) {
61
65
  return { backedUp: false, error: '读取当前文件失败: ' + e.message };
62
66
  }
63
67
  ensureDirSync(dir);
64
- const stamp = buildTimestamp();
65
- const dest = path.join(dir, stamp + '.bak');
68
+ let time = now();
69
+ let stamp = buildTimestamp(new Date(time));
70
+ let dest = path.join(dir, stamp + '.bak');
71
+ while (fs.existsSync(dest)) {
72
+ time += 1;
73
+ stamp = buildTimestamp(new Date(time));
74
+ dest = path.join(dir, stamp + '.bak');
75
+ }
66
76
  try {
67
- fs.writeFileSync(dest, raw, 'utf-8');
77
+ writeTextAtomicWithBackup(dest, raw, { fs });
78
+ const sourceHash = crypto.createHash('sha256').update(Buffer.from(raw, 'utf8')).digest('hex');
79
+ const backupHash = crypto.createHash('sha256').update(fs.readFileSync(dest)).digest('hex');
80
+ if (sourceHash !== backupHash) throw new Error('历史备份校验失败');
68
81
  } catch (e) {
69
82
  return { backedUp: false, error: '写入备份失败: ' + e.message };
70
83
  }
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { writeTextAtomicWithBackup } = require('../lib/cli-config-engine');
4
+
3
5
  function createSystemPromptFileController(deps = {}) {
4
6
  const {
5
7
  fs,
@@ -120,11 +122,12 @@ function createSystemPromptFileController(deps = {}) {
120
122
  const bucket = 'system_' + target.scope + '_' + (target.scope === 'project'
121
123
  ? sanitizeSystemHistoryId(path.dirname(target.path))
122
124
  : 'global');
123
- backupPromptBeforeWrite(bucket, target.path);
125
+ const backup = backupPromptBeforeWrite(bucket, target.path);
126
+ if (backup && backup.error) return { error: backup.error };
124
127
  sysHistoryBucket = bucket;
125
128
  }
126
129
  const finalContent = content.endsWith('\n') ? content : content + '\n';
127
- fs.writeFileSync(target.path, finalContent, { encoding: 'utf8', mode: 0o600 });
130
+ writeTextAtomicWithBackup(target.path, finalContent, { fs });
128
131
  try { fs.chmodSync(target.path, 0o600); } catch (_) {}
129
132
  } catch (e) {
130
133
  return { error: '写入 system prompt 失败: ' + e.message };
@@ -146,6 +149,8 @@ function createSystemPromptFileController(deps = {}) {
146
149
  }
147
150
  return {
148
151
  ...resolved,
152
+ historyBucket: 'system_' + resolved.scope + '_' + (resolved.scope === 'project'
153
+ ? sanitizeSystemHistoryId(path.dirname(resolved.path)) : 'global'),
149
154
  exists,
150
155
  content,
151
156
  hash: hashContent(content)