@xihe-lab/tapd-cli 2.0.0-rc.1
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.
- package/LICENSE +190 -0
- package/dist/bin/tapd.d.ts +3 -0
- package/dist/bin/tapd.d.ts.map +1 -0
- package/dist/bin/tapd.js +4 -0
- package/dist/bin/tapd.js.map +1 -0
- package/dist/commands/advisor.d.ts +4 -0
- package/dist/commands/advisor.d.ts.map +1 -0
- package/dist/commands/advisor.js +29 -0
- package/dist/commands/advisor.js.map +1 -0
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +28 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +69 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/stub.d.ts +2 -0
- package/dist/commands/stub.d.ts.map +1 -0
- package/dist/commands/stub.js +8 -0
- package/dist/commands/stub.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -0
- package/dist/exit-codes.d.ts +6 -0
- package/dist/exit-codes.d.ts.map +1 -0
- package/dist/exit-codes.js +6 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/flags.d.ts +9 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.js +133 -0
- package/dist/flags.js.map +1 -0
- package/dist/flags.test.d.ts +2 -0
- package/dist/flags.test.d.ts.map +1 -0
- package/dist/flags.test.js +56 -0
- package/dist/flags.test.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/output/formatter.d.ts +12 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +97 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/formatter.test.d.ts +2 -0
- package/dist/output/formatter.test.d.ts.map +1 -0
- package/dist/output/formatter.test.js +170 -0
- package/dist/output/formatter.test.js.map +1 -0
- package/dist/output/table.d.ts +6 -0
- package/dist/output/table.d.ts.map +1 -0
- package/dist/output/table.js +48 -0
- package/dist/output/table.js.map +1 -0
- package/dist/program.d.ts +4 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +84 -0
- package/dist/program.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 xihe-lab
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tapd.d.ts","sourceRoot":"","sources":["../../src/bin/tapd.ts"],"names":[],"mappings":""}
|
package/dist/bin/tapd.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tapd.js","sourceRoot":"","sources":["../../src/bin/tapd.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,MAAM,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advisor.d.ts","sourceRoot":"","sources":["../../src/commands/advisor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAMxD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAwBrF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { buildAdvisorIndex, recommend } from '@xihe-lab/tapd-core';
|
|
2
|
+
import { renderTable } from '../output/table.js';
|
|
3
|
+
const DEFAULT_LIMIT = 10;
|
|
4
|
+
export function registerAdvisorCommand(program, registry) {
|
|
5
|
+
const advisor = program.command('advisor').description('自然语言命令推荐(规则召回,零 LLM)');
|
|
6
|
+
advisor
|
|
7
|
+
.argument('<query...>', '想完成的操作描述,中英文均可')
|
|
8
|
+
.option('--json', '以 JSON 输出推荐结果')
|
|
9
|
+
.action((queryParts, options) => {
|
|
10
|
+
const query = queryParts.join(' ').trim();
|
|
11
|
+
const index = buildAdvisorIndex(registry);
|
|
12
|
+
const hits = recommend(query, index, DEFAULT_LIMIT);
|
|
13
|
+
if (hits.length === 0) {
|
|
14
|
+
process.stderr.write(`advisor: 未找到与「${query}」相关的命令,可尝试英文关键词(如 story list、status update)\n`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (options.json) {
|
|
18
|
+
process.stdout.write(JSON.stringify(hits, null, 2) + '\n');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const rows = hits.map(hit => ({
|
|
22
|
+
COMMAND: hit.command,
|
|
23
|
+
WRITE: hit.write ? '✓' : '',
|
|
24
|
+
DESCRIPTION: hit.description,
|
|
25
|
+
}));
|
|
26
|
+
process.stdout.write(renderTable(rows, ['COMMAND', 'WRITE', 'DESCRIPTION']) + '\n');
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=advisor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advisor.js","sourceRoot":"","sources":["../../src/commands/advisor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB,MAAM,UAAU,sBAAsB,CAAC,OAAgB,EAAE,QAAsB;IAC7E,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC;IAC/E,OAAO;SACJ,QAAQ,CAAC,YAAY,EAAE,gBAAgB,CAAC;SACxC,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC;SACjC,MAAM,CAAC,CAAC,UAAoB,EAAE,OAA2B,EAAE,EAAE;QAC5D,MAAM,KA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AG,IAAI,CAYvF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { loadConfig, maskSecret, resolveConfig } from '@xihe-lab/tapd-core';
|
|
2
|
+
function sourceTag(source) {
|
|
3
|
+
return source ?? 'default';
|
|
4
|
+
}
|
|
5
|
+
function credentialSummary(resolved) {
|
|
6
|
+
const parts = [];
|
|
7
|
+
if (resolved.access_token) {
|
|
8
|
+
parts.push(`access_token ${maskSecret(resolved.access_token)} (${sourceTag(resolved.sources.access_token)})`);
|
|
9
|
+
}
|
|
10
|
+
if (resolved.api_user) {
|
|
11
|
+
parts.push(`api_user ${maskSecret(resolved.api_user)} (${sourceTag(resolved.sources.api_user)})`);
|
|
12
|
+
}
|
|
13
|
+
return parts.length > 0 ? parts.join('; ') : '(missing)';
|
|
14
|
+
}
|
|
15
|
+
export function registerAuthCommand(ensureResource) {
|
|
16
|
+
const auth = ensureResource('auth');
|
|
17
|
+
auth.command('status').description('查看认证状态').action(() => {
|
|
18
|
+
const resolved = resolveConfig({}, loadConfig());
|
|
19
|
+
const lines = [
|
|
20
|
+
`auth_mode: ${resolved.auth_mode} (${sourceTag(resolved.sources.auth_mode)})`,
|
|
21
|
+
`credentials: ${credentialSummary(resolved)}`,
|
|
22
|
+
`workspace_id: ${resolved.workspace_id ?? '(unset)'} (${sourceTag(resolved.sources.workspace_id)})`,
|
|
23
|
+
`read_only: ${resolved.readOnly} (${sourceTag(resolved.sources.read_only)})`,
|
|
24
|
+
];
|
|
25
|
+
process.stdout.write(lines.join('\n') + '\n');
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAA0C,MAAM,qBAAqB,CAAC;AAEpH,SAAS,SAAS,CAAC,MAAgC;IACjD,OAAO,M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,KAAK,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG;SAC7E,CAAC;QACF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6CzC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAuC5D"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { allTools, CONFIG_KEYS, configPath, exportSchemas, loadConfig, maskSecret, parseConfigSet, resolveConfig, saveConfig, } from '@xihe-lab/tapd-core';
|
|
3
|
+
import { CliError } from '../errors.js';
|
|
4
|
+
const SECRET_KEYS = new Set(['access_token', 'api_password']);
|
|
5
|
+
function sourceTag(source) {
|
|
6
|
+
return source ?? 'default';
|
|
7
|
+
}
|
|
8
|
+
function renderValue(value) {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return '(unset)';
|
|
11
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
12
|
+
return String(value);
|
|
13
|
+
return JSON.stringify(value);
|
|
14
|
+
}
|
|
15
|
+
function renderConfig(resolved) {
|
|
16
|
+
const record = resolved;
|
|
17
|
+
const lines = [];
|
|
18
|
+
for (const key of CONFIG_KEYS) {
|
|
19
|
+
if (SECRET_KEYS.has(key)) {
|
|
20
|
+
lines.push(`${key}: ${maskSecret(record[key])} (${sourceTag(resolved.sources[key])})`);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
lines.push(`${key}: ${renderValue(record[key])} (${sourceTag(resolved.sources[key])})`);
|
|
24
|
+
}
|
|
25
|
+
lines.push(`use_sdk (effective): ${resolved.useSdk}`);
|
|
26
|
+
lines.push(`use_richtext_auto (effective): ${resolved.useRichtextAuto}`);
|
|
27
|
+
lines.push(`timeout (effective): ${resolved.timeoutMs}ms`);
|
|
28
|
+
return lines.join('\n');
|
|
29
|
+
}
|
|
30
|
+
export function registerConfigCommand(program) {
|
|
31
|
+
const config = program.command('config').description('TAPD 本地配置管理');
|
|
32
|
+
config.command('show').description('查看当前生效配置(凭证脱敏)').action(() => {
|
|
33
|
+
const resolved = resolveConfig({}, loadConfig());
|
|
34
|
+
process.stdout.write(renderConfig(resolved) + '\n');
|
|
35
|
+
});
|
|
36
|
+
config.command('set').description('设置配置项').argument('<items...>', 'key=value 列表').action((items) => {
|
|
37
|
+
let patch;
|
|
38
|
+
try {
|
|
39
|
+
patch = parseConfigSet(items);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new CliError('INVALID_ARGS', error instanceof Error ? error.message : String(error));
|
|
43
|
+
}
|
|
44
|
+
const merged = { ...loadConfig(), ...patch };
|
|
45
|
+
saveConfig(merged);
|
|
46
|
+
process.stdout.write(`saved ${Object.keys(patch).length} key(s) to ${configPath()}\n`);
|
|
47
|
+
});
|
|
48
|
+
config.command('export-schema')
|
|
49
|
+
.description('导出工具 schema(anthropic / openai 格式)')
|
|
50
|
+
.option('--format <format>', '导出格式:anthropic | openai', 'anthropic')
|
|
51
|
+
.option('--resource <resource>', '按资源过滤(如 story)')
|
|
52
|
+
.option('--out <file>', '写入文件而非 stdout')
|
|
53
|
+
.action((options) => {
|
|
54
|
+
if (options.format !== 'anthropic' && options.format !== 'openai') {
|
|
55
|
+
throw new CliError('INVALID_ARGS', `format: invalid_enum_value(预期 anthropic | openai,收到 ${options.format})`);
|
|
56
|
+
}
|
|
57
|
+
const format = options.format;
|
|
58
|
+
const exported = exportSchemas(allTools, format, { resource: options.resource });
|
|
59
|
+
const json = JSON.stringify(exported, null, 2);
|
|
60
|
+
if (options.out) {
|
|
61
|
+
writeFileSync(options.out, json + '\n');
|
|
62
|
+
process.stdout.write(`exported ${exported.length} tools to ${options.out}\n`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
process.stdout.write(json + '\n');
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EACL,QAAQ,EACR,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,cAAc,EACd,aAAa,EACb,UAAU,GAIX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;AAEnF,SAAS,SAAS,CAAC,MAAgC;IACjD,OAAO,MAAM,IAAI,SAAS,CAAC;AAC7B,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/G,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,YAAY,CAAC,QAAwB;IAC5C,MAAM,MAAM,GAAG,QAA8C,CAAC;IAC9D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAA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AC;QAC9F,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC/C,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YAChB,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;YACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,QAAQ,CAAC,MAAM,aAAa,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QAChF,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../src/commands/stub.ts"],"names":[],"mappings":"AAEA,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,IAAI,CAK3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.js","sourceRoot":"","sources":["../../src/commands/stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,IAAY;IAC7C,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,eAAe,IAAI,KAAK,CAAC,CAAC;QACtD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CliErrorCode } from '@xihe-lab/tapd-core';
|
|
2
|
+
export declare class CliError extends Error {
|
|
3
|
+
readonly code: CliErrorCode;
|
|
4
|
+
constructor(code: CliErrorCode, message: string);
|
|
5
|
+
get exitCode(): number;
|
|
6
|
+
render(): string;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD,qBAAa,QAAS,SAAQ,KAAK;aAEf,IAAI,EAAE,YAAY;gBAAlB,IAAI,EAAE,YAAY,EAClC,OAAO,EAAE,MAAM;IAKjB,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,MAAM,IAAI,MAAM;CAUjB"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EXIT } from './exit-codes.js';
|
|
2
|
+
export class CliError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
get exitCode() {
|
|
9
|
+
return this.code === 'INVALID_ARGS' ? EXIT.USAGE : EXIT.RUNTIME;
|
|
10
|
+
}
|
|
11
|
+
render() {
|
|
12
|
+
if (this.code !== 'INVALID_ARGS') {
|
|
13
|
+
return `error: ${this.code}: ${this.message}`;
|
|
14
|
+
}
|
|
15
|
+
const pretty = this.message.replace(/(^|[;\s])([a-z0-9_]+):/g, (_match, prefix, field) => `${prefix}--${field.replaceAll('_', '-')}:`);
|
|
16
|
+
return `error: ${this.code}: ${pretty}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,MAAM,OAAO,QAAS,SAAQ,KAAK;IAEf;IADlB,YACkB,IAAkB,EAClC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAc;IAIpC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IAClE,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YACjC,OAAO,UAAU,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;QAChD,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CACjC,yBAAyB,EACzB,CAAC,MAAM,EAAE,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,KAAK,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CACvF,CAAC;QACF,OAAO,UAAU,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-codes.d.ts","sourceRoot":"","sources":["../src/exit-codes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI;;;;CAIP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-codes.js","sourceRoot":"","sources":["../src/exit-codes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,CAAC;IACL,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;CACA,CAAC"}
|
package/dist/flags.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { TapdClient, type CliMeta, type ToolDef } from '@xihe-lab/tapd-core';
|
|
3
|
+
import type { OutputMode } from './output/formatter.js';
|
|
4
|
+
export declare function parseOutputMode(value: unknown): OutputMode | undefined;
|
|
5
|
+
export declare function addGlobalOptions(cmd: Command): void;
|
|
6
|
+
export declare function bindSchemaFlags(sub: Command, tool: ToolDef, meta?: CliMeta): void;
|
|
7
|
+
export declare function toArgs(tool: ToolDef, meta: CliMeta | undefined, opts: Record<string, unknown>, positional: unknown[], globals: Record<string, unknown>): Record<string, unknown>;
|
|
8
|
+
export declare function makeClientFactory(globals: Record<string, unknown>): () => TapdClient;
|
|
9
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,KAAK,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAsBxD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAKtE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAWnD;AAuCD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAiBjF;AAED,wBAAgB,MAAM,CACpB,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,UAAU,EAAE,OAAO,EAAE,EACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAezB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,UAAU,CAcpF"}
|
package/dist/flags.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TapdClient } from '@xihe-lab/tapd-core';
|
|
3
|
+
import { CliError } from './errors.js';
|
|
4
|
+
const GLOBAL_KEYS = new Set([
|
|
5
|
+
'workspaceId', 'apiKey', 'auth', 'readOnly', 'output', 'timeout', 'color', 'verbose',
|
|
6
|
+
]);
|
|
7
|
+
const kebab = (key) => key.replaceAll('_', '-');
|
|
8
|
+
const camelToSnake = (key) => key.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`);
|
|
9
|
+
function parseWorkspaceId(value) {
|
|
10
|
+
const id = parseInt(value, 10);
|
|
11
|
+
if (Number.isNaN(id))
|
|
12
|
+
throw new CliError('INVALID_ARGS', `--workspace-id must be a number, got "${value}"`);
|
|
13
|
+
return id;
|
|
14
|
+
}
|
|
15
|
+
function parseTimeout(value) {
|
|
16
|
+
const seconds = parseFloat(value);
|
|
17
|
+
if (Number.isNaN(seconds) || seconds < 0)
|
|
18
|
+
throw new CliError('INVALID_ARGS', `--timeout must be a non-negative number of seconds, got "${value}"`);
|
|
19
|
+
return Math.round(seconds * 1000);
|
|
20
|
+
}
|
|
21
|
+
export function parseOutputMode(value) {
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (value === 'text' || value === 'table' || value === 'json')
|
|
25
|
+
return value;
|
|
26
|
+
const got = typeof value === 'string' ? value : JSON.stringify(value);
|
|
27
|
+
throw new CliError('INVALID_ARGS', `--output must be one of text | table | json, got "${got}"`);
|
|
28
|
+
}
|
|
29
|
+
export function addGlobalOptions(cmd) {
|
|
30
|
+
cmd
|
|
31
|
+
.option('--workspace-id <id>', '默认项目 ID(优先级高于环境变量)', parseWorkspaceId)
|
|
32
|
+
.option('--api-key <token>', 'TAPD API Token(Access Token,覆盖环境变量)')
|
|
33
|
+
.option('--auth <mode>', '认证方式 token | basic')
|
|
34
|
+
.option('--read-only', '只读模式,拦截所有写命令')
|
|
35
|
+
.option('--no-read-only', '显式关闭只读模式(优先于配置文件)')
|
|
36
|
+
.option('--output <fmt>', '输出格式 text | table | json(缺省自动:管道 json,终端 table/text)')
|
|
37
|
+
.option('--timeout <seconds>', '单命令超时秒数', parseTimeout)
|
|
38
|
+
.option('--no-color', '关闭彩色输出')
|
|
39
|
+
.option('-v, --verbose', '打印请求/响应日志(凭证脱敏)');
|
|
40
|
+
}
|
|
41
|
+
function unwrap(field) {
|
|
42
|
+
let cur = field;
|
|
43
|
+
for (;;) {
|
|
44
|
+
if (cur instanceof z.ZodOptional || cur instanceof z.ZodNullable) {
|
|
45
|
+
cur = cur._def.innerType;
|
|
46
|
+
}
|
|
47
|
+
else if (cur instanceof z.ZodDefault) {
|
|
48
|
+
cur = cur._def.innerType;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return cur;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function shapeOf(schema) {
|
|
56
|
+
return schema instanceof z.ZodObject ? schema.shape : {};
|
|
57
|
+
}
|
|
58
|
+
function describe(field) {
|
|
59
|
+
return field.description ?? unwrap(field).description;
|
|
60
|
+
}
|
|
61
|
+
function isNumberish(field) {
|
|
62
|
+
const inner = unwrap(field);
|
|
63
|
+
if (inner instanceof z.ZodNumber)
|
|
64
|
+
return true;
|
|
65
|
+
if (!(inner instanceof z.ZodUnion))
|
|
66
|
+
return false;
|
|
67
|
+
const options = inner.options;
|
|
68
|
+
return options.some(o => o instanceof z.ZodNumber);
|
|
69
|
+
}
|
|
70
|
+
function coerceValue(value, numberish) {
|
|
71
|
+
if (numberish && typeof value === 'string' && value.trim() !== '') {
|
|
72
|
+
const num = Number(value);
|
|
73
|
+
if (!Number.isNaN(num))
|
|
74
|
+
return num;
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
export function bindSchemaFlags(sub, tool, meta) {
|
|
79
|
+
const shape = shapeOf(tool.inputSchema);
|
|
80
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
81
|
+
if (key === 'workspace_id')
|
|
82
|
+
continue;
|
|
83
|
+
const flag = `--${kebab(key)}`;
|
|
84
|
+
const inner = unwrap(field);
|
|
85
|
+
const desc = describe(field);
|
|
86
|
+
if (inner instanceof z.ZodBoolean) {
|
|
87
|
+
sub.option(flag, desc);
|
|
88
|
+
sub.option(`--no-${kebab(key)}`, desc);
|
|
89
|
+
}
|
|
90
|
+
else if (inner instanceof z.ZodArray) {
|
|
91
|
+
sub.option(`${flag} <items...>`, desc);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
sub.option(`${flag} <value>`, desc);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (meta?.positional)
|
|
98
|
+
sub.argument(`<${meta.positional}>`);
|
|
99
|
+
}
|
|
100
|
+
export function toArgs(tool, meta, opts, positional, globals) {
|
|
101
|
+
const shape = shapeOf(tool.inputSchema);
|
|
102
|
+
const args = {};
|
|
103
|
+
for (const [key, value] of Object.entries(opts)) {
|
|
104
|
+
if (value === undefined || GLOBAL_KEYS.has(key))
|
|
105
|
+
continue;
|
|
106
|
+
const snake = camelToSnake(key);
|
|
107
|
+
args[snake] = coerceValue(value, isNumberish(shape[snake]));
|
|
108
|
+
}
|
|
109
|
+
if (args.workspace_id === undefined && globals.workspaceId !== undefined) {
|
|
110
|
+
args.workspace_id = globals.workspaceId;
|
|
111
|
+
}
|
|
112
|
+
if (meta?.positional && positional.length > 0) {
|
|
113
|
+
args[meta.positional] = positional[0];
|
|
114
|
+
}
|
|
115
|
+
return { ...(meta?.defaults ?? {}), ...args };
|
|
116
|
+
}
|
|
117
|
+
export function makeClientFactory(globals) {
|
|
118
|
+
return () => {
|
|
119
|
+
if (globals.auth === 'basic') {
|
|
120
|
+
const user = process.env.TAPD_API_USER;
|
|
121
|
+
const password = process.env.TAPD_API_PASSWORD;
|
|
122
|
+
if (!user || !password) {
|
|
123
|
+
throw new Error('auth mode "basic" requires TAPD_API_USER and TAPD_API_PASSWORD environment variables');
|
|
124
|
+
}
|
|
125
|
+
return TapdClient.fromBasicAuth(user, password);
|
|
126
|
+
}
|
|
127
|
+
const apiKey = globals.apiKey;
|
|
128
|
+
if (apiKey)
|
|
129
|
+
return TapdClient.fromAccessToken(apiKey);
|
|
130
|
+
return TapdClient.fromEnv();
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAA8B,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS;CACrF,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAChE,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAEhG,SAAS,gBAAgB,CAAC,KAAa;IACrC,MAAM,EAAE,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/B,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,QAAQ,CAAC,cAAc,EAAE,yCAAyC,KAAK,GAAG,CAAC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