tinker-agent 1.0.65 → 1.2.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 (208) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +6 -0
  4. package/README.md +90 -9
  5. package/bin/tinker.js +39 -0
  6. package/node_modules/ansi-regex/index.d.ts +33 -0
  7. package/node_modules/ansi-regex/index.js +14 -0
  8. package/node_modules/ansi-regex/license +9 -0
  9. package/node_modules/ansi-regex/package.json +61 -0
  10. package/node_modules/ansi-regex/readme.md +66 -0
  11. package/node_modules/ansi-styles/index.d.ts +236 -0
  12. package/node_modules/ansi-styles/index.js +223 -0
  13. package/node_modules/ansi-styles/license +9 -0
  14. package/node_modules/ansi-styles/package.json +54 -0
  15. package/node_modules/ansi-styles/readme.md +173 -0
  16. package/node_modules/chalk/license +9 -0
  17. package/node_modules/chalk/package.json +83 -0
  18. package/node_modules/chalk/readme.md +297 -0
  19. package/node_modules/chalk/source/index.d.ts +325 -0
  20. package/node_modules/chalk/source/index.js +225 -0
  21. package/node_modules/chalk/source/utilities.js +33 -0
  22. package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
  23. package/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
  24. package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
  25. package/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
  26. package/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
  27. package/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
  28. package/node_modules/character-entities/index.d.ts +6 -0
  29. package/node_modules/character-entities/index.js +2132 -0
  30. package/node_modules/character-entities/license +22 -0
  31. package/node_modules/character-entities/package.json +78 -0
  32. package/node_modules/character-entities/readme.md +152 -0
  33. package/node_modules/decode-named-character-reference/index.d.ts +13 -0
  34. package/node_modules/decode-named-character-reference/index.d.ts.map +1 -0
  35. package/node_modules/decode-named-character-reference/index.dom.d.ts +6 -0
  36. package/node_modules/decode-named-character-reference/index.dom.d.ts.map +1 -0
  37. package/node_modules/decode-named-character-reference/index.dom.js +32 -0
  38. package/node_modules/decode-named-character-reference/index.js +19 -0
  39. package/node_modules/decode-named-character-reference/license +22 -0
  40. package/node_modules/decode-named-character-reference/package.json +90 -0
  41. package/node_modules/decode-named-character-reference/readme.md +136 -0
  42. package/node_modules/get-east-asian-width/index.d.ts +60 -0
  43. package/node_modules/get-east-asian-width/index.js +30 -0
  44. package/node_modules/get-east-asian-width/license +9 -0
  45. package/node_modules/get-east-asian-width/lookup-data.js +21 -0
  46. package/node_modules/get-east-asian-width/lookup.js +138 -0
  47. package/node_modules/get-east-asian-width/package.json +71 -0
  48. package/node_modules/get-east-asian-width/readme.md +65 -0
  49. package/node_modules/get-east-asian-width/utilities.js +24 -0
  50. package/node_modules/has-flag/index.d.ts +39 -0
  51. package/node_modules/has-flag/index.js +8 -0
  52. package/node_modules/has-flag/license +9 -0
  53. package/node_modules/has-flag/package.json +49 -0
  54. package/node_modules/has-flag/readme.md +74 -0
  55. package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
  56. package/node_modules/is-fullwidth-code-point/index.js +12 -0
  57. package/node_modules/is-fullwidth-code-point/license +9 -0
  58. package/node_modules/is-fullwidth-code-point/package.json +53 -0
  59. package/node_modules/is-fullwidth-code-point/readme.md +31 -0
  60. package/node_modules/markdansi/LICENSE +21 -0
  61. package/node_modules/markdansi/README.md +167 -0
  62. package/node_modules/markdansi/dist/ast.d.ts +99 -0
  63. package/node_modules/markdansi/dist/ast.js +1 -0
  64. package/node_modules/markdansi/dist/cli.d.ts +17 -0
  65. package/node_modules/markdansi/dist/cli.js +208 -0
  66. package/node_modules/markdansi/dist/hyperlink.d.ts +9 -0
  67. package/node_modules/markdansi/dist/hyperlink.js +26 -0
  68. package/node_modules/markdansi/dist/index.d.ts +10 -0
  69. package/node_modules/markdansi/dist/index.js +16 -0
  70. package/node_modules/markdansi/dist/parser.d.ts +2 -0
  71. package/node_modules/markdansi/dist/parser.js +205 -0
  72. package/node_modules/markdansi/dist/render.d.ts +9 -0
  73. package/node_modules/markdansi/dist/render.js +680 -0
  74. package/node_modules/markdansi/dist/stream.d.ts +39 -0
  75. package/node_modules/markdansi/dist/stream.js +192 -0
  76. package/node_modules/markdansi/dist/theme.d.ts +18 -0
  77. package/node_modules/markdansi/dist/theme.js +105 -0
  78. package/node_modules/markdansi/dist/types.d.ts +58 -0
  79. package/node_modules/markdansi/dist/types.js +1 -0
  80. package/node_modules/markdansi/dist/wrap.d.ts +10 -0
  81. package/node_modules/markdansi/dist/wrap.js +73 -0
  82. package/node_modules/markdansi/docs/spec.md +110 -0
  83. package/node_modules/markdansi/package.json +78 -0
  84. package/node_modules/markdansi/tsconfig.json +18 -0
  85. package/node_modules/marked/LICENSE +44 -0
  86. package/node_modules/marked/README.md +115 -0
  87. package/node_modules/marked/bin/main.js +284 -0
  88. package/node_modules/marked/bin/marked.js +16 -0
  89. package/node_modules/marked/lib/marked.d.ts +760 -0
  90. package/node_modules/marked/lib/marked.esm.js +77 -0
  91. package/node_modules/marked/lib/marked.esm.js.map +7 -0
  92. package/node_modules/marked/lib/marked.umd.js +79 -0
  93. package/node_modules/marked/lib/marked.umd.js.map +7 -0
  94. package/node_modules/marked/man/marked.1 +113 -0
  95. package/node_modules/marked/man/marked.1.md +93 -0
  96. package/node_modules/marked/package.json +103 -0
  97. package/node_modules/slice-ansi/index.d.ts +19 -0
  98. package/node_modules/slice-ansi/index.js +317 -0
  99. package/node_modules/slice-ansi/license +10 -0
  100. package/node_modules/slice-ansi/package.json +59 -0
  101. package/node_modules/slice-ansi/readme.md +55 -0
  102. package/node_modules/slice-ansi/tokenize-ansi.js +752 -0
  103. package/node_modules/string-width/index.d.ts +39 -0
  104. package/node_modules/string-width/index.js +203 -0
  105. package/node_modules/string-width/license +9 -0
  106. package/node_modules/string-width/package.json +65 -0
  107. package/node_modules/string-width/readme.md +66 -0
  108. package/node_modules/strip-ansi/index.d.ts +15 -0
  109. package/node_modules/strip-ansi/index.js +19 -0
  110. package/node_modules/strip-ansi/license +9 -0
  111. package/node_modules/strip-ansi/package.json +59 -0
  112. package/node_modules/strip-ansi/readme.md +37 -0
  113. package/node_modules/supports-color/browser.d.ts +1 -0
  114. package/node_modules/supports-color/browser.js +35 -0
  115. package/node_modules/supports-color/index.d.ts +55 -0
  116. package/node_modules/supports-color/index.js +202 -0
  117. package/node_modules/supports-color/license +9 -0
  118. package/node_modules/supports-color/package.json +64 -0
  119. package/node_modules/supports-color/readme.md +75 -0
  120. package/node_modules/supports-hyperlinks/browser.js +10 -0
  121. package/node_modules/supports-hyperlinks/index.d.ts +25 -0
  122. package/node_modules/supports-hyperlinks/index.js +163 -0
  123. package/node_modules/supports-hyperlinks/license +10 -0
  124. package/node_modules/supports-hyperlinks/package.json +47 -0
  125. package/node_modules/supports-hyperlinks/readme.md +45 -0
  126. package/package.json +41 -10
  127. package/patches/markdansi@0.3.2.patch +22 -2
  128. package/src/agent/context-builder.ts +24 -10
  129. package/src/agent/context-meter.ts +89 -5
  130. package/src/agent/loop.ts +107 -10
  131. package/src/agent/runtime-session.ts +1437 -82
  132. package/src/agent/session-ledger.ts +169 -29
  133. package/src/agent/types.ts +12 -1
  134. package/src/agent/user-prompt-projection.ts +62 -0
  135. package/src/cli/config.ts +57 -14
  136. package/src/cli/model-profiles.ts +124 -0
  137. package/src/cli/run-runner.ts +4 -1
  138. package/src/cli/tui-runner.tsx +68 -30
  139. package/src/context/compiled-context-hash.ts +1 -1
  140. package/src/context/compiled-context-validator.ts +92 -15
  141. package/src/context/context-automation-policy.ts +121 -0
  142. package/src/context/context-manager.ts +390 -11
  143. package/src/context/context-policy.ts +8 -0
  144. package/src/context/context-protocol-validator.ts +11 -1
  145. package/src/context/context-revision-compiler.ts +190 -27
  146. package/src/context/context-revision.ts +105 -19
  147. package/src/context/context-surface.ts +329 -0
  148. package/src/context/prefix-retirement-planner.ts +570 -0
  149. package/src/context/protocol-frame.ts +30 -3
  150. package/src/context/recall-retirement-contract.ts +27 -0
  151. package/src/context/swap-planner.ts +34 -10
  152. package/src/events/observation-text-log.ts +3 -3
  153. package/src/events/stdout-event-printer.ts +39 -3
  154. package/src/events/types.ts +172 -35
  155. package/src/ids/runtime-id.ts +6 -0
  156. package/src/ids/uuid-v7.ts +7 -0
  157. package/src/image/image-asset-store.ts +319 -0
  158. package/src/image/image-input-policy.ts +14 -0
  159. package/src/image/image-probe.ts +233 -0
  160. package/src/image/image-types.ts +262 -0
  161. package/src/instructions/project-instructions.ts +4 -1
  162. package/src/mcp/mcp-manager.ts +83 -19
  163. package/src/model/fake-model-client.ts +9 -1
  164. package/src/model/input-token-estimator.ts +25 -0
  165. package/src/model/model-client.ts +60 -0
  166. package/src/model/model-request-preflight.ts +1 -0
  167. package/src/model/moonshot-input-token-estimator.ts +107 -0
  168. package/src/model/openai-chat-mapping.ts +77 -1
  169. package/src/model/openai-chat-model-client.ts +389 -59
  170. package/src/model/openai-chat-stream.ts +272 -0
  171. package/src/model/prompt-prefix-hash.ts +2 -4
  172. package/src/model/token-estimator.ts +4 -0
  173. package/src/observation/observation-builder.ts +29 -0
  174. package/src/session/resume-projection.ts +94 -34
  175. package/src/session/session-catalog.ts +4 -4
  176. package/src/session/session-errors.ts +1 -1
  177. package/src/session/session-history-reader.ts +151 -4
  178. package/src/session/session-last-response-reader.ts +189 -0
  179. package/src/session/session-schema.ts +349 -35
  180. package/src/session/session-store.ts +3266 -255
  181. package/src/session/sqlite-session-ledger.ts +9 -4
  182. package/src/skills/skill-catalog.ts +182 -0
  183. package/src/skills/skill-context.ts +364 -0
  184. package/src/skills/skill-loader.ts +779 -0
  185. package/src/skills/skill-tool.ts +297 -0
  186. package/src/tools/edit.ts +51 -64
  187. package/src/tools/ensure-parent-directory.ts +6 -0
  188. package/src/tools/read.ts +2 -2
  189. package/src/tools/recall.ts +43 -40
  190. package/src/tools/registry.ts +24 -3
  191. package/src/tools/ripgrep.ts +3 -2
  192. package/src/tools/types.ts +43 -4
  193. package/src/tools/write.ts +20 -31
  194. package/src/tui/app.tsx +333 -96
  195. package/src/tui/clipboard.ts +5 -0
  196. package/src/tui/components/mcp-panel.tsx +28 -0
  197. package/src/tui/components/prompt-input.tsx +790 -257
  198. package/src/tui/components/skills-panel.tsx +31 -0
  199. package/src/tui/components/timeline.tsx +30 -1
  200. package/src/tui/event-store.ts +85 -2
  201. package/src/tui/file-mention.ts +234 -0
  202. package/src/tui/line-editor.ts +1 -0
  203. package/src/tui/project-slash-commands.ts +229 -0
  204. package/src/tui/prompt-draft.ts +510 -0
  205. package/src/tui/prompt-history.ts +294 -22
  206. package/src/tui/slash-commands.ts +46 -2
  207. package/src/tui/tui-session-controller.ts +110 -48
  208. package/src/tui/workspace-file-search.ts +94 -0
@@ -0,0 +1,202 @@
1
+ import process from 'node:process';
2
+ import os from 'node:os';
3
+ import tty from 'node:tty';
4
+
5
+ // From: https://github.com/sindresorhus/has-flag/blob/main/index.js
6
+ /// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
7
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
8
+ const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
9
+ const position = argv.indexOf(prefix + flag);
10
+ const terminatorPosition = argv.indexOf('--');
11
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
12
+ }
13
+
14
+ const {env} = process;
15
+
16
+ let flagForceColor;
17
+ if (
18
+ hasFlag('no-color')
19
+ || hasFlag('no-colors')
20
+ || hasFlag('color=false')
21
+ || hasFlag('color=never')
22
+ ) {
23
+ flagForceColor = 0;
24
+ } else if (
25
+ hasFlag('color')
26
+ || hasFlag('colors')
27
+ || hasFlag('color=true')
28
+ || hasFlag('color=always')
29
+ ) {
30
+ flagForceColor = 1;
31
+ }
32
+
33
+ function envForceColor() {
34
+ if (!('FORCE_COLOR' in env)) {
35
+ return;
36
+ }
37
+
38
+ if (env.FORCE_COLOR === 'true') {
39
+ return 1;
40
+ }
41
+
42
+ if (env.FORCE_COLOR === 'false') {
43
+ return 0;
44
+ }
45
+
46
+ if (env.FORCE_COLOR.length === 0) {
47
+ return 1;
48
+ }
49
+
50
+ const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
51
+
52
+ if (![0, 1, 2, 3].includes(level)) {
53
+ return;
54
+ }
55
+
56
+ return level;
57
+ }
58
+
59
+ function translateLevel(level) {
60
+ if (level === 0) {
61
+ return false;
62
+ }
63
+
64
+ return {
65
+ level,
66
+ hasBasic: true,
67
+ has256: level >= 2,
68
+ has16m: level >= 3,
69
+ };
70
+ }
71
+
72
+ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
73
+ const noFlagForceColor = envForceColor();
74
+ if (noFlagForceColor !== undefined) {
75
+ flagForceColor = noFlagForceColor;
76
+ }
77
+
78
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
79
+
80
+ if (forceColor === 0) {
81
+ return 0;
82
+ }
83
+
84
+ if (sniffFlags) {
85
+ if (hasFlag('color=16m')
86
+ || hasFlag('color=full')
87
+ || hasFlag('color=truecolor')) {
88
+ return 3;
89
+ }
90
+
91
+ if (hasFlag('color=256')) {
92
+ return 2;
93
+ }
94
+ }
95
+
96
+ // Check for Azure DevOps pipelines.
97
+ // Has to be above the `!streamIsTTY` check.
98
+ if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
99
+ return 1;
100
+ }
101
+
102
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
103
+ return 0;
104
+ }
105
+
106
+ const min = forceColor || 0;
107
+
108
+ if (env.TERM === 'dumb') {
109
+ return min;
110
+ }
111
+
112
+ if (process.platform === 'win32') {
113
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
114
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
115
+ const osRelease = os.release().split('.');
116
+ if (
117
+ Number(osRelease[0]) >= 10
118
+ && Number(osRelease[2]) >= 10_586
119
+ ) {
120
+ return Number(osRelease[2]) >= 14_931 ? 3 : 2;
121
+ }
122
+
123
+ return 1;
124
+ }
125
+
126
+ if ('CI' in env) {
127
+ if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
128
+ return 3;
129
+ }
130
+
131
+ if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
132
+ return 1;
133
+ }
134
+
135
+ return min;
136
+ }
137
+
138
+ if ('TEAMCITY_VERSION' in env) {
139
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
140
+ }
141
+
142
+ if (env.COLORTERM === 'truecolor') {
143
+ return 3;
144
+ }
145
+
146
+ if (env.TERM === 'xterm-kitty') {
147
+ return 3;
148
+ }
149
+
150
+ if (env.TERM === 'xterm-ghostty') {
151
+ return 3;
152
+ }
153
+
154
+ if (env.TERM === 'wezterm') {
155
+ return 3;
156
+ }
157
+
158
+ if ('TERM_PROGRAM' in env) {
159
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
160
+
161
+ switch (env.TERM_PROGRAM) {
162
+ case 'iTerm.app': {
163
+ return version >= 3 ? 3 : 2;
164
+ }
165
+
166
+ case 'Apple_Terminal': {
167
+ return 2;
168
+ }
169
+ // No default
170
+ }
171
+ }
172
+
173
+ if (/-256(color)?$/i.test(env.TERM)) {
174
+ return 2;
175
+ }
176
+
177
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
178
+ return 1;
179
+ }
180
+
181
+ if ('COLORTERM' in env) {
182
+ return 1;
183
+ }
184
+
185
+ return min;
186
+ }
187
+
188
+ export function createSupportsColor(stream, options = {}) {
189
+ const level = _supportsColor(stream, {
190
+ streamIsTTY: stream && stream.isTTY,
191
+ ...options,
192
+ });
193
+
194
+ return translateLevel(level);
195
+ }
196
+
197
+ const supportsColor = {
198
+ stdout: createSupportsColor({isTTY: tty.isatty(1)}),
199
+ stderr: createSupportsColor({isTTY: tty.isatty(2)}),
200
+ };
201
+
202
+ export default supportsColor;
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "supports-color",
3
+ "version": "10.2.2",
4
+ "description": "Detect whether a terminal supports color",
5
+ "license": "MIT",
6
+ "repository": "chalk/supports-color",
7
+ "funding": "https://github.com/chalk/supports-color?sponsor=1",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "sindresorhus@gmail.com",
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "node": "./index.js",
17
+ "default": "./browser.js"
18
+ },
19
+ "sideEffects": false,
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "scripts": {
24
+ "test": "xo && ava && tsd"
25
+ },
26
+ "files": [
27
+ "index.js",
28
+ "index.d.ts",
29
+ "browser.js",
30
+ "browser.d.ts"
31
+ ],
32
+ "keywords": [
33
+ "color",
34
+ "colour",
35
+ "colors",
36
+ "terminal",
37
+ "console",
38
+ "cli",
39
+ "ansi",
40
+ "styles",
41
+ "tty",
42
+ "rgb",
43
+ "256",
44
+ "shell",
45
+ "xterm",
46
+ "command-line",
47
+ "support",
48
+ "supports",
49
+ "capability",
50
+ "detect",
51
+ "truecolor",
52
+ "16m"
53
+ ],
54
+ "devDependencies": {
55
+ "@types/node": "^22.10.2",
56
+ "ava": "^6.2.0",
57
+ "tsd": "^0.31.2",
58
+ "xo": "^0.60.0"
59
+ },
60
+ "ava": {
61
+ "serial": true,
62
+ "workerThreads": false
63
+ }
64
+ }
@@ -0,0 +1,75 @@
1
+ # supports-color
2
+
3
+ > Detect whether a terminal supports color
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install supports-color
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import supportsColor from 'supports-color';
15
+
16
+ if (supportsColor.stdout) {
17
+ console.log('Terminal stdout supports color');
18
+ }
19
+
20
+ if (supportsColor.stdout.has256) {
21
+ console.log('Terminal stdout supports 256 colors');
22
+ }
23
+
24
+ if (supportsColor.stderr.has16m) {
25
+ console.log('Terminal stderr supports 16 million colors (truecolor)');
26
+ }
27
+ ```
28
+
29
+ ## API
30
+
31
+ Returns an `object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported.
32
+
33
+ The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
34
+
35
+ - `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
36
+ - `.level = 2` and `.has256 = true`: 256 color support
37
+ - `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
38
+
39
+ ### Custom instance
40
+
41
+ The package also exposes the named export `createSupportColor` function that takes an arbitrary write stream (for example, `process.stdout`) and an optional options object to (re-)evaluate color support for an arbitrary stream.
42
+
43
+ ```js
44
+ import {createSupportsColor} from 'supports-color';
45
+
46
+ const stdoutSupportsColor = createSupportsColor(process.stdout);
47
+
48
+ if (stdoutSupportsColor) {
49
+ console.log('Terminal stdout supports color');
50
+ }
51
+
52
+ // `stdoutSupportsColor` is the same as `supportsColor.stdout`
53
+ ```
54
+
55
+ The options object supports a single boolean property `sniffFlags`. By default it is `true`, which instructs the detection to sniff `process.argv` for the multitude of `--color` flags (see _Info_ below). If `false`, then `process.argv` is not considered when determining color support.
56
+
57
+ ## Info
58
+
59
+ It obeys the `--color` and `--no-color` CLI flags.
60
+
61
+ For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
62
+
63
+ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
64
+
65
+ ## Related
66
+
67
+ - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
68
+ - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
69
+ - [is-unicode-supported](https://github.com/sindresorhus/is-unicode-supported) - Detect whether the terminal supports Unicode
70
+ - [is-interactive](https://github.com/sindresorhus/is-interactive) - Check if stdout or stderr is interactive
71
+
72
+ ## Maintainers
73
+
74
+ - [Sindre Sorhus](https://github.com/sindresorhus)
75
+ - [Josh Junon](https://github.com/qix-)
@@ -0,0 +1,10 @@
1
+ export function createSupportsHyperlinks() {
2
+ return false;
3
+ }
4
+
5
+ const supportsHyperlinks = {
6
+ stdout: createSupportsHyperlinks(),
7
+ stderr: createSupportsHyperlinks(),
8
+ };
9
+
10
+ export default supportsHyperlinks;
@@ -0,0 +1,25 @@
1
+ /**
2
+ Creates a supports hyperlinks check for a given stream.
3
+
4
+ @param stream - Optional stream to check for hyperlink support.
5
+ @returns boolean indicating whether hyperlinks are supported.
6
+ */
7
+ export function createSupportsHyperlinks(stream?: {isTTY?: boolean}): boolean;
8
+
9
+ /**
10
+ Object containing hyperlink support status for stdout and stderr.
11
+ */
12
+ type SupportsHyperlinks = {
13
+ /**
14
+ Whether stdout supports hyperlinks.
15
+ */
16
+ stdout: boolean;
17
+ /**
18
+ Whether stderr supports hyperlinks.
19
+ */
20
+ stderr: boolean;
21
+ };
22
+
23
+ declare const supportsHyperlinks: SupportsHyperlinks;
24
+
25
+ export default supportsHyperlinks;
@@ -0,0 +1,163 @@
1
+ import process from 'node:process';
2
+ import {createSupportsColor} from 'supports-color';
3
+ import hasFlag from 'has-flag';
4
+
5
+ function parseVersion(versionString = '') {
6
+ if (/^\d{3,4}$/.test(versionString)) {
7
+ // Env var doesn't always use dots. example: 4601 => 46.1.0
8
+ const match = /(\d{1,2})(\d{2})/.exec(versionString) ?? [];
9
+ return {
10
+ major: 0,
11
+ minor: Number.parseInt(match[1], 10),
12
+ patch: Number.parseInt(match[2], 10),
13
+ };
14
+ }
15
+
16
+ const versions = (versionString ?? '').split('.').map(n => Number.parseInt(n, 10));
17
+ return {
18
+ major: versions[0],
19
+ minor: versions[1],
20
+ patch: versions[2],
21
+ };
22
+ }
23
+
24
+ // eslint-disable-next-line complexity
25
+ export function createSupportsHyperlinks(stream) {
26
+ const {
27
+ CI,
28
+ CURSOR_TRACE_ID,
29
+ FORCE_HYPERLINK,
30
+ NETLIFY,
31
+ TEAMCITY_VERSION,
32
+ TERM_PROGRAM,
33
+ TERM_PROGRAM_VERSION,
34
+ VTE_VERSION,
35
+ TERM,
36
+ } = process.env;
37
+
38
+ if (FORCE_HYPERLINK) {
39
+ return !(FORCE_HYPERLINK.length > 0 && Number.parseInt(FORCE_HYPERLINK, 10) === 0);
40
+ }
41
+
42
+ if (hasFlag('no-hyperlink') || hasFlag('no-hyperlinks') || hasFlag('hyperlink=false') || hasFlag('hyperlink=never')) {
43
+ return false;
44
+ }
45
+
46
+ if (hasFlag('hyperlink=true') || hasFlag('hyperlink=always')) {
47
+ return true;
48
+ }
49
+
50
+ // Netlify does not run a TTY, it does not need `supportsColor` check
51
+ if (NETLIFY) {
52
+ return true;
53
+ }
54
+
55
+ // If they specify no colors, they probably don't want hyperlinks.
56
+ if (!createSupportsColor(stream)) {
57
+ return false;
58
+ }
59
+
60
+ if (stream && !stream.isTTY) {
61
+ return false;
62
+ }
63
+
64
+ // Windows Terminal
65
+ if ('WT_SESSION' in process.env) {
66
+ return true;
67
+ }
68
+
69
+ if (process.platform === 'win32') {
70
+ return false;
71
+ }
72
+
73
+ if (CI) {
74
+ return false;
75
+ }
76
+
77
+ if (TEAMCITY_VERSION) {
78
+ return false;
79
+ }
80
+
81
+ if (TERM_PROGRAM) {
82
+ const version = parseVersion(TERM_PROGRAM_VERSION);
83
+
84
+ switch (TERM_PROGRAM) {
85
+ case 'iTerm.app': {
86
+ if (version.major === 3) {
87
+ return version.minor >= 1;
88
+ }
89
+
90
+ return version.major > 3;
91
+ }
92
+
93
+ case 'WezTerm': {
94
+ // WezTerm packaged by Nix uses their own version scheme.
95
+ if (/^0-unstable-\d{4}-\d{2}-\d{2}$/.test(TERM_PROGRAM_VERSION)) {
96
+ const date = TERM_PROGRAM_VERSION.slice('0-unstable-'.length);
97
+ return date >= '2020-06-20';
98
+ }
99
+
100
+ // This number is a date and reads better grouped as such.
101
+ // eslint-disable-next-line unicorn/numeric-separators-style
102
+ return version.major >= 2020_06_20;
103
+ }
104
+
105
+ case 'vscode': {
106
+ // Cursor forked VS Code and supports hyperlinks in 0.x.x
107
+ if (CURSOR_TRACE_ID) {
108
+ return true;
109
+ }
110
+
111
+ // eslint-disable-next-line @stylistic/no-mixed-operators
112
+ return version.major > 1 || version.major === 1 && version.minor >= 72;
113
+ }
114
+
115
+ case 'ghostty': {
116
+ return true;
117
+ }
118
+
119
+ case 'zed': {
120
+ return true;
121
+ }
122
+
123
+ case 'Orca': {
124
+ // Orca is an Electron-based terminal (xterm.js + OSC 8
125
+ // linkHandler). https://github.com/stablyai/orca
126
+ return true;
127
+ }
128
+
129
+ // No default
130
+ }
131
+ }
132
+
133
+ if (VTE_VERSION) {
134
+ // 0.50.0 was supposed to support hyperlinks, but throws a segfault
135
+ if (VTE_VERSION === '0.50.0') {
136
+ return false;
137
+ }
138
+
139
+ const version = parseVersion(VTE_VERSION);
140
+ return version.major > 0 || version.minor >= 50;
141
+ }
142
+
143
+ switch (TERM) {
144
+ case 'alacritty': {
145
+ // Support added in v0.11 (2022-10-13)
146
+ return true;
147
+ }
148
+
149
+ case 'xterm-kitty': {
150
+ return true;
151
+ }
152
+ // No default
153
+ }
154
+
155
+ return false;
156
+ }
157
+
158
+ const supportsHyperlinks = {
159
+ stdout: createSupportsHyperlinks(process.stdout),
160
+ stderr: createSupportsHyperlinks(process.stderr),
161
+ };
162
+
163
+ export default supportsHyperlinks;
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+ Copyright (c) James Talmage <james@talmage.io> (https://github.com/jamestalmage)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "supports-hyperlinks",
3
+ "version": "4.5.0",
4
+ "description": "Detect whether a terminal supports hyperlinks",
5
+ "license": "MIT",
6
+ "repository": "chalk/supports-hyperlinks",
7
+ "funding": "https://github.com/chalk/supports-hyperlinks?sponsor=1",
8
+ "type": "module",
9
+ "exports": {
10
+ "types": "./index.d.ts",
11
+ "default": "./index.js"
12
+ },
13
+ "sideEffects": false,
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "scripts": {
18
+ "test": "xo && ava && tsc --lib es2022 index.d.ts"
19
+ },
20
+ "files": [
21
+ "index.js",
22
+ "index.d.ts",
23
+ "browser.js"
24
+ ],
25
+ "browser": "browser.js",
26
+ "keywords": [
27
+ "link",
28
+ "terminal",
29
+ "hyperlink",
30
+ "cli",
31
+ "detect",
32
+ "check",
33
+ "ansi",
34
+ "escapes",
35
+ "console"
36
+ ],
37
+ "dependencies": {
38
+ "has-flag": "^5.0.1",
39
+ "supports-color": "^10.2.2"
40
+ },
41
+ "devDependencies": {
42
+ "ava": "^6.4.1",
43
+ "codecov": "^3.8.3",
44
+ "typescript": "^5.9.3",
45
+ "xo": "^1.2.3"
46
+ }
47
+ }
@@ -0,0 +1,45 @@
1
+ # supports-hyperlinks
2
+
3
+ > Detect whether a terminal supports hyperlinks
4
+
5
+ Terminal emulators are [starting to support hyperlinks](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda). While many terminals have long detected URL's and linkified them, allowing you to Command-Click or Control-Click them to open a browser, you were forced to print the long unsightly URL's on the screen. As of spring 2017 [a few terminals](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) began supporting HTML like links, where the link text and destination could be specified separately.
6
+
7
+ This module allows you to detect if hyperlinks are supported in the current Terminal.
8
+
9
+ As this is a new development, we anticipate the list of supported terminals to grow rapidly. Please open an issue or submit a PR as new terminals implement support.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install supports-hyperlinks
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ import supportsHyperlinks from 'supports-hyperlinks';
21
+
22
+ if (supportsHyperlinks.stdout) {
23
+ console.log('Terminal stdout supports hyperlinks');
24
+ }
25
+
26
+ if (supportsHyperlinks.stderr) {
27
+ console.log('Terminal stderr supports hyperlinks');
28
+ }
29
+ ```
30
+
31
+ ## API
32
+
33
+ Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is a `boolean`, indicating whether or not hyperlinks are supported.
34
+
35
+ ## Info
36
+
37
+ Obeys the `--no-hyperlinks`, `--hyperlink=always`, and `--hyperlink=never` CLI flags.
38
+
39
+ Can be overridden by the user with the flags `--hyperlinks=always` and `--no-hyperlinks`. For situations where using those flags are not possible, add the environment variable `FORCE_HYPERLINK=1` to forcefully enable hyperlinks or `FORCE_HYPERLINK=0` to forcefully disable. The use of `FORCE_HYPERLINK` overrides all other hyperlink support checks.
40
+
41
+ ## Related
42
+
43
+ - [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
44
+ - [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
45
+ - [supports-terminal-graphics](https://github.com/sindresorhus/supports-terminal-graphics) - Detect which terminal graphics protocols are supported