claude-coder 1.8.2 → 1.8.3

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 (47) hide show
  1. package/README.md +167 -167
  2. package/bin/cli.js +172 -172
  3. package/package.json +52 -52
  4. package/src/commands/auth.js +290 -240
  5. package/src/commands/setup-modules/helpers.js +99 -99
  6. package/src/commands/setup-modules/index.js +25 -25
  7. package/src/commands/setup-modules/mcp.js +94 -94
  8. package/src/commands/setup-modules/provider.js +260 -260
  9. package/src/commands/setup-modules/safety.js +61 -61
  10. package/src/commands/setup-modules/simplify.js +52 -52
  11. package/src/commands/setup.js +172 -172
  12. package/src/common/assets.js +236 -236
  13. package/src/common/config.js +125 -125
  14. package/src/common/constants.js +55 -55
  15. package/src/common/indicator.js +222 -222
  16. package/src/common/interaction.js +170 -170
  17. package/src/common/logging.js +77 -77
  18. package/src/common/sdk.js +50 -50
  19. package/src/common/tasks.js +88 -88
  20. package/src/common/utils.js +161 -161
  21. package/src/core/coding.js +55 -55
  22. package/src/core/context.js +117 -117
  23. package/src/core/go.js +310 -310
  24. package/src/core/harness.js +484 -484
  25. package/src/core/hooks.js +533 -533
  26. package/src/core/init.js +171 -171
  27. package/src/core/plan.js +325 -325
  28. package/src/core/prompts.js +227 -227
  29. package/src/core/query.js +49 -49
  30. package/src/core/repair.js +46 -46
  31. package/src/core/runner.js +195 -195
  32. package/src/core/scan.js +89 -89
  33. package/src/core/session.js +56 -56
  34. package/src/core/simplify.js +53 -52
  35. package/templates/bash-process.md +12 -12
  36. package/templates/codingSystem.md +65 -65
  37. package/templates/codingUser.md +17 -17
  38. package/templates/coreProtocol.md +29 -29
  39. package/templates/goSystem.md +130 -130
  40. package/templates/guidance.json +52 -52
  41. package/templates/planSystem.md +78 -78
  42. package/templates/planUser.md +8 -8
  43. package/templates/playwright.md +16 -16
  44. package/templates/requirements.example.md +57 -57
  45. package/templates/scanSystem.md +120 -120
  46. package/templates/scanUser.md +10 -10
  47. 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 };