claude-coder 1.8.2 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +167 -167
  2. package/bin/cli.js +172 -172
  3. package/package.json +53 -52
  4. package/recipes/_shared/roles/developer.md +11 -0
  5. package/recipes/_shared/roles/product.md +12 -0
  6. package/recipes/_shared/roles/tester.md +12 -0
  7. package/recipes/_shared/test/report-format.md +86 -0
  8. package/recipes/backend/base.md +27 -0
  9. package/recipes/backend/components/auth.md +18 -0
  10. package/recipes/backend/components/crud-api.md +18 -0
  11. package/recipes/backend/components/file-service.md +15 -0
  12. package/recipes/backend/manifest.json +20 -0
  13. package/recipes/backend/test/api-test.md +25 -0
  14. package/recipes/console/base.md +37 -0
  15. package/recipes/console/components/modal-form.md +20 -0
  16. package/recipes/console/components/pagination.md +17 -0
  17. package/recipes/console/components/search.md +17 -0
  18. package/recipes/console/components/table-list.md +18 -0
  19. package/recipes/console/components/tabs.md +14 -0
  20. package/recipes/console/components/tree.md +15 -0
  21. package/recipes/console/components/upload.md +15 -0
  22. package/recipes/console/manifest.json +24 -0
  23. package/recipes/console/test/crud-e2e.md +47 -0
  24. package/recipes/h5/base.md +26 -0
  25. package/recipes/h5/components/animation.md +11 -0
  26. package/recipes/h5/components/countdown.md +11 -0
  27. package/recipes/h5/components/share.md +11 -0
  28. package/recipes/h5/components/swiper.md +11 -0
  29. package/recipes/h5/manifest.json +21 -0
  30. package/recipes/h5/test/h5-e2e.md +20 -0
  31. package/src/commands/auth.js +290 -240
  32. package/src/commands/setup-modules/helpers.js +99 -99
  33. package/src/commands/setup-modules/index.js +25 -25
  34. package/src/commands/setup-modules/mcp.js +94 -94
  35. package/src/commands/setup-modules/provider.js +260 -260
  36. package/src/commands/setup-modules/safety.js +61 -61
  37. package/src/commands/setup-modules/simplify.js +52 -52
  38. package/src/commands/setup.js +172 -172
  39. package/src/common/assets.js +236 -236
  40. package/src/common/config.js +125 -125
  41. package/src/common/constants.js +55 -55
  42. package/src/common/indicator.js +222 -222
  43. package/src/common/interaction.js +170 -170
  44. package/src/common/logging.js +77 -77
  45. package/src/common/sdk.js +50 -50
  46. package/src/common/tasks.js +88 -88
  47. package/src/common/utils.js +161 -161
  48. package/src/core/coding.js +55 -55
  49. package/src/core/context.js +117 -117
  50. package/src/core/go.js +310 -310
  51. package/src/core/harness.js +484 -484
  52. package/src/core/hooks.js +533 -533
  53. package/src/core/init.js +171 -171
  54. package/src/core/plan.js +325 -325
  55. package/src/core/prompts.js +227 -227
  56. package/src/core/query.js +49 -49
  57. package/src/core/repair.js +46 -46
  58. package/src/core/runner.js +195 -195
  59. package/src/core/scan.js +89 -89
  60. package/src/core/session.js +56 -56
  61. package/src/core/simplify.js +53 -52
  62. package/templates/bash-process.md +12 -12
  63. package/templates/codingSystem.md +65 -65
  64. package/templates/codingUser.md +17 -17
  65. package/templates/coreProtocol.md +29 -29
  66. package/templates/goSystem.md +130 -130
  67. package/templates/guidance.json +52 -52
  68. package/templates/planSystem.md +78 -78
  69. package/templates/planUser.md +8 -8
  70. package/templates/playwright.md +16 -16
  71. package/templates/requirements.example.md +57 -57
  72. package/templates/scanSystem.md +120 -120
  73. package/templates/scanUser.md +10 -10
  74. package/templates/test_rule.md +194 -194
@@ -1,117 +1,117 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { loadConfig, buildEnvVars, log } = require('../common/config');
6
- const { Indicator } = require('../common/indicator');
7
- const { logMessage: baseLogMessage } = require('../common/logging');
8
- const { createHooks } = require('./hooks');
9
- const { assets } = require('../common/assets');
10
-
11
- class SessionContext {
12
- constructor(type, opts = {}) {
13
- this.type = type;
14
- this.opts = opts;
15
- assets.init(opts.projectRoot || process.cwd());
16
- this.config = loadConfig();
17
- this._applyEnvConfig();
18
- this.indicator = new Indicator();
19
- this.logStream = null;
20
- this.logFile = null;
21
- this.hooks = null;
22
- this.cleanup = null;
23
- this._isStalled = () => false;
24
- this.abortController = new AbortController();
25
- this._lastStatusKey = '';
26
- }
27
-
28
- _applyEnvConfig() {
29
- Object.assign(process.env, buildEnvVars(this.config));
30
- }
31
-
32
- initLogging(logFileName, externalLogStream) {
33
- if (externalLogStream) {
34
- this.logStream = externalLogStream;
35
- this._externalLogStream = true;
36
- } else {
37
- const logsDir = assets.dir('logs');
38
- this.logFile = path.join(logsDir, logFileName);
39
- this.logStream = fs.createWriteStream(this.logFile, { flags: 'a' });
40
- this._externalLogStream = false;
41
- }
42
- }
43
-
44
- initHooks(hookType) {
45
- const stallTimeoutMs = this.config.stallTimeout * 1000;
46
- const completionTimeoutMs = this.config.completionTimeout * 1000;
47
- const result = createHooks(hookType, this.indicator, this.logStream, {
48
- stallTimeoutMs,
49
- abortController: this.abortController,
50
- editThreshold: this.config.editThreshold,
51
- completionTimeoutMs,
52
- });
53
- this.hooks = result.hooks;
54
- this.cleanup = result.cleanup;
55
- this._isStalled = result.isStalled;
56
- return Math.floor(stallTimeoutMs / 60000);
57
- }
58
-
59
- startIndicator(sessionNum, stallTimeoutMin) {
60
- this.indicator.start(sessionNum, stallTimeoutMin);
61
- }
62
-
63
- isStalled() {
64
- return this._isStalled();
65
- }
66
-
67
- async runQuery(sdk, prompt, queryOpts) {
68
- const collected = [];
69
- const session = sdk.query({ prompt, options: queryOpts });
70
-
71
- for await (const message of session) {
72
- if (this._isStalled()) {
73
- log('warn', '停顿超时,中断消息循环');
74
- break;
75
- }
76
- collected.push(message);
77
- this._logMessage(message);
78
- }
79
-
80
- return collected;
81
- }
82
-
83
- _logMessage(message) {
84
- const hasText = message.type === 'assistant'
85
- && message.message?.content?.some(b => b.type === 'text' && b.text);
86
-
87
- if (hasText && this.indicator) {
88
- this.indicator.pauseRendering();
89
- process.stderr.write('\r\x1b[K');
90
- }
91
-
92
- baseLogMessage(message, this.logStream, this.indicator);
93
-
94
- if (hasText && this.indicator) {
95
- const contentKey = `${this.indicator.phase}|${this.indicator.step}|${this.indicator.toolTarget}`;
96
- if (contentKey !== this._lastStatusKey) {
97
- this._lastStatusKey = contentKey;
98
- const statusLine = this.indicator.getStatusLine();
99
- if (statusLine) process.stderr.write(statusLine + '\n');
100
- }
101
- this.indicator.resumeRendering();
102
- }
103
- }
104
-
105
- finish() {
106
- if (this.cleanup) this.cleanup();
107
- if (this.logStream && !this._externalLogStream) this.logStream.end();
108
- this.indicator.stop();
109
- }
110
-
111
- errorFinish(err) {
112
- this.finish();
113
- log('error', err.message);
114
- }
115
- }
116
-
117
- module.exports = { SessionContext };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { loadConfig, buildEnvVars, log } = require('../common/config');
6
+ const { Indicator } = require('../common/indicator');
7
+ const { logMessage: baseLogMessage } = require('../common/logging');
8
+ const { createHooks } = require('./hooks');
9
+ const { assets } = require('../common/assets');
10
+
11
+ class SessionContext {
12
+ constructor(type, opts = {}) {
13
+ this.type = type;
14
+ this.opts = opts;
15
+ assets.init(opts.projectRoot || process.cwd());
16
+ this.config = loadConfig();
17
+ this._applyEnvConfig();
18
+ this.indicator = new Indicator();
19
+ this.logStream = null;
20
+ this.logFile = null;
21
+ this.hooks = null;
22
+ this.cleanup = null;
23
+ this._isStalled = () => false;
24
+ this.abortController = new AbortController();
25
+ this._lastStatusKey = '';
26
+ }
27
+
28
+ _applyEnvConfig() {
29
+ Object.assign(process.env, buildEnvVars(this.config));
30
+ }
31
+
32
+ initLogging(logFileName, externalLogStream) {
33
+ if (externalLogStream) {
34
+ this.logStream = externalLogStream;
35
+ this._externalLogStream = true;
36
+ } else {
37
+ const logsDir = assets.dir('logs');
38
+ this.logFile = path.join(logsDir, logFileName);
39
+ this.logStream = fs.createWriteStream(this.logFile, { flags: 'a' });
40
+ this._externalLogStream = false;
41
+ }
42
+ }
43
+
44
+ initHooks(hookType) {
45
+ const stallTimeoutMs = this.config.stallTimeout * 1000;
46
+ const completionTimeoutMs = this.config.completionTimeout * 1000;
47
+ const result = createHooks(hookType, this.indicator, this.logStream, {
48
+ stallTimeoutMs,
49
+ abortController: this.abortController,
50
+ editThreshold: this.config.editThreshold,
51
+ completionTimeoutMs,
52
+ });
53
+ this.hooks = result.hooks;
54
+ this.cleanup = result.cleanup;
55
+ this._isStalled = result.isStalled;
56
+ return Math.floor(stallTimeoutMs / 60000);
57
+ }
58
+
59
+ startIndicator(sessionNum, stallTimeoutMin) {
60
+ this.indicator.start(sessionNum, stallTimeoutMin);
61
+ }
62
+
63
+ isStalled() {
64
+ return this._isStalled();
65
+ }
66
+
67
+ async runQuery(sdk, prompt, queryOpts) {
68
+ const collected = [];
69
+ const session = sdk.query({ prompt, options: queryOpts });
70
+
71
+ for await (const message of session) {
72
+ if (this._isStalled()) {
73
+ log('warn', '停顿超时,中断消息循环');
74
+ break;
75
+ }
76
+ collected.push(message);
77
+ this._logMessage(message);
78
+ }
79
+
80
+ return collected;
81
+ }
82
+
83
+ _logMessage(message) {
84
+ const hasText = message.type === 'assistant'
85
+ && message.message?.content?.some(b => b.type === 'text' && b.text);
86
+
87
+ if (hasText && this.indicator) {
88
+ this.indicator.pauseRendering();
89
+ process.stderr.write('\r\x1b[K');
90
+ }
91
+
92
+ baseLogMessage(message, this.logStream, this.indicator);
93
+
94
+ if (hasText && this.indicator) {
95
+ const contentKey = `${this.indicator.phase}|${this.indicator.step}|${this.indicator.toolTarget}`;
96
+ if (contentKey !== this._lastStatusKey) {
97
+ this._lastStatusKey = contentKey;
98
+ const statusLine = this.indicator.getStatusLine();
99
+ if (statusLine) process.stderr.write(statusLine + '\n');
100
+ }
101
+ this.indicator.resumeRendering();
102
+ }
103
+ }
104
+
105
+ finish() {
106
+ if (this.cleanup) this.cleanup();
107
+ if (this.logStream && !this._externalLogStream) this.logStream.end();
108
+ this.indicator.stop();
109
+ }
110
+
111
+ errorFinish(err) {
112
+ this.finish();
113
+ log('error', err.message);
114
+ }
115
+ }
116
+
117
+ module.exports = { SessionContext };