@winning-sales/nexo 0.3.0 → 0.5.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.
- package/README.md +88 -4
- package/assets/docs/pages.json +1 -1
- package/assets/skills/nexo-automations/SKILL.md +12 -0
- package/dist/commands/artifacts.js +118 -0
- package/dist/commands/brain.js +217 -0
- package/dist/commands/document-negotiation.js +60 -0
- package/dist/commands/document-templates.js +76 -0
- package/dist/commands/documents.js +215 -0
- package/dist/commands/logout.js +14 -3
- package/dist/commands/skills.js +130 -10
- package/dist/commands/templates.js +279 -0
- package/dist/commands/whoami.js +5 -6
- package/dist/documents/answers-file.js +91 -0
- package/dist/documents/journey-api.js +110 -0
- package/dist/documents/journey.types.js +1 -0
- package/dist/documents/summary.js +102 -0
- package/dist/documents/transfer.js +42 -0
- package/dist/http/problem.js +32 -2
- package/dist/input/confirm.js +21 -0
- package/dist/program-artifacts.js +37 -0
- package/dist/program-brain.js +111 -0
- package/dist/program-documents.js +150 -0
- package/dist/program-templates.js +97 -0
- package/dist/program.js +25 -9
- package/dist/skills/bundled-freshness.js +39 -0
- package/dist/skills/remote-skills.js +45 -0
- package/dist/skills/sync-skills.js +50 -0
- package/dist/skills/targets.js +1 -4
- package/dist/skills/user-skills.js +145 -0
- package/dist/tools/tool-manifest.js +211 -0
- package/package.json +2 -2
- package/reference.json +1318 -5
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { printJson, printLine, printNotice, sessionOf } from '../context.js';
|
|
2
|
+
import { CliError, usageError } from '../errors.js';
|
|
3
|
+
import { EXIT_CODES } from '../exit-codes.types.js';
|
|
4
|
+
import { answersFileOf, changedAnswers, readAnswersFile, readJsonFile, writeAnswersFile } from '../documents/answers-file.js';
|
|
5
|
+
import { agentOf, call, documentOf, failureOf, statusLabel, timeoutOf, versionOf, waitForVersion } from '../documents/journey-api.js';
|
|
6
|
+
import { describeDocument, describeQuestionnaire, documentRow } from '../documents/summary.js';
|
|
7
|
+
import { download, readText, targetOf } from '../documents/transfer.js';
|
|
8
|
+
function needsTemplate(templateId) {
|
|
9
|
+
if (templateId === null) {
|
|
10
|
+
throw usageError('Diga o modelo com --template <id>.', 'Veja os modelos com `nexo documents templates --agent proposal|contract`.');
|
|
11
|
+
}
|
|
12
|
+
return templateId;
|
|
13
|
+
}
|
|
14
|
+
function firstOf(...values) {
|
|
15
|
+
return values.find((value) => value !== null && value !== undefined) ?? null;
|
|
16
|
+
}
|
|
17
|
+
function newStart(options, file) {
|
|
18
|
+
return {
|
|
19
|
+
agent: agentOf(firstOf(options.agent, file?.agent)),
|
|
20
|
+
dealId: firstOf(options.deal, file?.dealId),
|
|
21
|
+
templateId: needsTemplate(firstOf(options.template, file?.templateId)),
|
|
22
|
+
proposalDocumentId: firstOf(options.proposal, file?.proposalDocumentId),
|
|
23
|
+
documentId: null
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async function revisionStart(context, session, documentId, options) {
|
|
27
|
+
const document = await documentOf(context, session, documentId);
|
|
28
|
+
return {
|
|
29
|
+
agent: document.agent,
|
|
30
|
+
dealId: document.dealId,
|
|
31
|
+
templateId: options.template ?? null,
|
|
32
|
+
proposalDocumentId: null,
|
|
33
|
+
documentId: document.id
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function questionnaireOf(context, session, start, dealReading) {
|
|
37
|
+
const { agent, ...body } = start;
|
|
38
|
+
return (await call(context, session, 'POST', `/${agent}/questionnaire`, { ...body, dealReading }));
|
|
39
|
+
}
|
|
40
|
+
async function answeredOf(context, session, start, file) {
|
|
41
|
+
if (file === null) {
|
|
42
|
+
return { answers: [], groups: [] };
|
|
43
|
+
}
|
|
44
|
+
const baseline = await questionnaireOf(context, session, start, false);
|
|
45
|
+
return {
|
|
46
|
+
answers: changedAnswers(file, baseline.questionnaire),
|
|
47
|
+
groups: file.groups,
|
|
48
|
+
...(file.notes === null || file.notes.trim() === '' ? {} : { notes: file.notes })
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function writtenOf(options) {
|
|
52
|
+
if (options.document === undefined) {
|
|
53
|
+
if (options.adaptations !== undefined) {
|
|
54
|
+
throw usageError('--adaptations só vale com --document, o documento já escrito.');
|
|
55
|
+
}
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
const html = readText(options.document);
|
|
59
|
+
if (html.trim() === '') {
|
|
60
|
+
throw usageError(`${options.document} está vazio.`);
|
|
61
|
+
}
|
|
62
|
+
return { html, ...(options.adaptations === undefined ? {} : { adaptations: readJsonFile(options.adaptations) }) };
|
|
63
|
+
}
|
|
64
|
+
function fileOf(options) {
|
|
65
|
+
return options.answers === undefined ? null : readAnswersFile(options.answers);
|
|
66
|
+
}
|
|
67
|
+
export async function documentsList(context, options) {
|
|
68
|
+
const query = new URLSearchParams();
|
|
69
|
+
if (options.agent !== undefined) {
|
|
70
|
+
query.set('agent', agentOf(options.agent));
|
|
71
|
+
}
|
|
72
|
+
if (options.deal !== undefined) {
|
|
73
|
+
query.set('dealId', options.deal);
|
|
74
|
+
}
|
|
75
|
+
const body = (await call(context, sessionOf(context, options), 'GET', `/documents${query.size === 0 ? '' : `?${query.toString()}`}`));
|
|
76
|
+
if (options.json === true) {
|
|
77
|
+
printJson(context, body);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (body.items.length === 0) {
|
|
81
|
+
printLine(context, 'Nenhum documento.');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
body.items.forEach((document) => {
|
|
85
|
+
printLine(context, documentRow(document));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export async function documentsGet(context, documentId, options) {
|
|
89
|
+
const document = await documentOf(context, sessionOf(context, options), documentId);
|
|
90
|
+
if (options.json === true) {
|
|
91
|
+
printJson(context, document);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
describeDocument(document).forEach((line) => {
|
|
95
|
+
printLine(context, line);
|
|
96
|
+
});
|
|
97
|
+
if (document.current?.status === 'failed') {
|
|
98
|
+
failureOf(document.current).forEach((line) => {
|
|
99
|
+
printLine(context, line);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export async function documentsQuestionnaire(context, options) {
|
|
104
|
+
const session = sessionOf(context, options);
|
|
105
|
+
const start = options.revising === undefined ? newStart(options, null) : await revisionStart(context, session, options.revising, options);
|
|
106
|
+
const response = await questionnaireOf(context, session, start, options.reading !== false);
|
|
107
|
+
if (options.output !== undefined) {
|
|
108
|
+
writeAnswersFile(options.output, answersFileOf(response.questionnaire));
|
|
109
|
+
}
|
|
110
|
+
if (options.json === true) {
|
|
111
|
+
printJson(context, response);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
describeQuestionnaire(response).forEach((line) => {
|
|
115
|
+
printLine(context, line);
|
|
116
|
+
});
|
|
117
|
+
if (options.output !== undefined) {
|
|
118
|
+
printNotice(context, `Respostas em ${options.output}: edite o "text" de cada resposta e mande com --answers ${options.output}.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function reportReceipt(context, receipt, version, options) {
|
|
122
|
+
if (options.json === true) {
|
|
123
|
+
printJson(context, {
|
|
124
|
+
...receipt,
|
|
125
|
+
...(version === null
|
|
126
|
+
? {}
|
|
127
|
+
: {
|
|
128
|
+
status: version.status,
|
|
129
|
+
failureReason: version.failureReason,
|
|
130
|
+
findings: [...version.valueFindings, ...version.checkFindings],
|
|
131
|
+
changeSummary: version.changeSummary
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const status = statusLabel(version?.status ?? receipt.status);
|
|
137
|
+
printLine(context, `${receipt.documentId} ${receipt.number ?? '—'} versão ${String(receipt.version)} ${status} ${receipt.title}`);
|
|
138
|
+
if (version?.changeSummary !== null && version?.changeSummary !== undefined) {
|
|
139
|
+
printLine(context, `O que mudou: ${version.changeSummary}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function failed(context, version) {
|
|
143
|
+
const [headline, ...findings] = failureOf(version);
|
|
144
|
+
findings.forEach((line) => {
|
|
145
|
+
printNotice(context, line);
|
|
146
|
+
});
|
|
147
|
+
return new CliError(headline ?? 'A versão não saiu.', EXIT_CODES.failure, 'Corrija a resposta e peça uma versão nova com `nexo documents revise`.');
|
|
148
|
+
}
|
|
149
|
+
async function followReceipt(context, session, receipt, options) {
|
|
150
|
+
if (receipt.status === 'ready') {
|
|
151
|
+
reportReceipt(context, receipt, null, options);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (options.wait === false) {
|
|
155
|
+
reportReceipt(context, receipt, null, options);
|
|
156
|
+
printNotice(context, `Acompanhe com \`nexo documents get ${receipt.documentId}\`.`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const version = await waitForVersion(context, session, receipt, timeoutOf(options.timeout));
|
|
160
|
+
reportReceipt(context, receipt, version, options);
|
|
161
|
+
if (version.status === 'failed') {
|
|
162
|
+
throw failed(context, version);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export async function documentsCreate(context, options) {
|
|
166
|
+
const session = sessionOf(context, options);
|
|
167
|
+
const file = fileOf(options);
|
|
168
|
+
const written = writtenOf(options);
|
|
169
|
+
const start = newStart(options, file);
|
|
170
|
+
const { agent, documentId: _none, ...body } = start;
|
|
171
|
+
const receipt = (await call(context, session, 'POST', `/${agent}/documents${written.html === undefined ? '' : '/written'}`, {
|
|
172
|
+
...body,
|
|
173
|
+
...(await answeredOf(context, session, start, file)),
|
|
174
|
+
...written
|
|
175
|
+
}));
|
|
176
|
+
await followReceipt(context, session, receipt, options);
|
|
177
|
+
}
|
|
178
|
+
export async function documentsRevise(context, documentId, options) {
|
|
179
|
+
const request = (options.request ?? '').trim();
|
|
180
|
+
const file = fileOf(options);
|
|
181
|
+
const written = writtenOf(options);
|
|
182
|
+
if (request === '' && file === null && written.html === undefined) {
|
|
183
|
+
throw usageError('Diga o que muda: --request "o pedido", --answers com as respostas que mudaram, ou --document com a versão já escrita.');
|
|
184
|
+
}
|
|
185
|
+
const session = sessionOf(context, options);
|
|
186
|
+
const answered = file === null
|
|
187
|
+
? { answers: [], groups: [] }
|
|
188
|
+
: await answeredOf(context, session, await revisionStart(context, session, documentId, options), file);
|
|
189
|
+
const receipt = (await call(context, session, 'POST', `/documents/${encodeURIComponent(documentId)}/versions${written.html === undefined ? '' : '/written'}`, { templateId: options.template ?? null, request: request === '' ? null : request, ...answered, ...written }));
|
|
190
|
+
await followReceipt(context, session, receipt, options);
|
|
191
|
+
}
|
|
192
|
+
export async function documentsAccept(context, documentId, options) {
|
|
193
|
+
const session = sessionOf(context, options);
|
|
194
|
+
const version = versionOf(await documentOf(context, session, documentId), options.versionNumber);
|
|
195
|
+
const accepted = await call(context, session, 'POST', `/documents/${encodeURIComponent(documentId)}/versions/${version.id}/acceptance`);
|
|
196
|
+
if (options.json === true) {
|
|
197
|
+
printJson(context, accepted);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
printLine(context, `Versão ${String(version.version)} aceita: a proposta deixou de ser rascunho.`);
|
|
201
|
+
printNotice(context, `Baixe com \`nexo documents pdf ${documentId}\` ou comece a negociação com \`nexo documents negotiate ${documentId}\`.`);
|
|
202
|
+
}
|
|
203
|
+
export async function documentsFile(context, kind, documentId, options) {
|
|
204
|
+
const session = sessionOf(context, options);
|
|
205
|
+
const document = await documentOf(context, session, documentId);
|
|
206
|
+
const version = versionOf(document, options.versionNumber);
|
|
207
|
+
const link = (await call(context, session, 'POST', `/documents/${encodeURIComponent(documentId)}/versions/${version.id}/${kind}`));
|
|
208
|
+
const target = targetOf(options.output, link.fileName, `${document.number ?? document.id}-v${String(version.version)}.${kind}`);
|
|
209
|
+
await download(context, link.url, target);
|
|
210
|
+
if (options.json === true) {
|
|
211
|
+
printJson(context, { documentId, versionId: version.id, version: version.version, path: target });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
printLine(context, target);
|
|
215
|
+
}
|
package/dist/commands/logout.js
CHANGED
|
@@ -2,6 +2,7 @@ import { revokeToken } from '../auth/oauth.js';
|
|
|
2
2
|
import { profileName } from '../config/session.js';
|
|
3
3
|
import { printJson, printLine, printNotice } from '../context.js';
|
|
4
4
|
import { CliError } from '../errors.js';
|
|
5
|
+
import { homeOf, removeUserSkills } from '../skills/user-skills.js';
|
|
5
6
|
async function revoke(context, stored) {
|
|
6
7
|
if (stored?.kind !== 'oauth') {
|
|
7
8
|
return 'not_applicable';
|
|
@@ -21,10 +22,10 @@ function notices(context, stored, revocation) {
|
|
|
21
22
|
printNotice(context, 'O acesso da CLI foi revogado no Nexo.');
|
|
22
23
|
}
|
|
23
24
|
if (revocation === 'failed') {
|
|
24
|
-
printNotice(context, 'Não consegui revogar no Nexo; desconecte a "Nexo CLI" em Configurações ›
|
|
25
|
+
printNotice(context, 'Não consegui revogar no Nexo; desconecte a "Nexo CLI" em Configurações › Conexões › IA e API.');
|
|
25
26
|
}
|
|
26
27
|
if (stored?.kind === 'pat') {
|
|
27
|
-
printNotice(context, 'O token continua valendo até você revogá-lo no Nexo, em Configurações ›
|
|
28
|
+
printNotice(context, 'O token continua valendo até você revogá-lo no Nexo, em Configurações › Conexões › IA e API.');
|
|
28
29
|
}
|
|
29
30
|
if ((context.env.NEXO_TOKEN ?? '') !== '') {
|
|
30
31
|
printNotice(context, 'NEXO_TOKEN ainda está definido no ambiente e continua sendo usado.');
|
|
@@ -35,10 +36,20 @@ export async function logout(context, options) {
|
|
|
35
36
|
const stored = context.store.profile(profile);
|
|
36
37
|
const revocation = await revoke(context, stored);
|
|
37
38
|
const removed = context.store.remove(profile);
|
|
39
|
+
const clientSkills = removeUserSkills(homeOf(context.env), profile);
|
|
38
40
|
if (options.json === true) {
|
|
39
|
-
printJson(context, {
|
|
41
|
+
printJson(context, {
|
|
42
|
+
profile,
|
|
43
|
+
removed,
|
|
44
|
+
revocation,
|
|
45
|
+
clientSkillsRemoved: clientSkills.length,
|
|
46
|
+
envTokenStillSet: (context.env.NEXO_TOKEN ?? '') !== ''
|
|
47
|
+
});
|
|
40
48
|
return;
|
|
41
49
|
}
|
|
42
50
|
printLine(context, removed ? `Perfil ${profile} removido desta máquina.` : `Nenhum perfil ${profile} salvo nesta máquina.`);
|
|
51
|
+
if (clientSkills.length > 0) {
|
|
52
|
+
printLine(context, `${String(clientSkills.length)} skills da empresa saíram da sua pasta (as de produto do projeto ficam).`);
|
|
53
|
+
}
|
|
43
54
|
notices(context, stored, revocation);
|
|
44
55
|
}
|
package/dist/commands/skills.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { join, relative, resolve } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { currentSession, profileName } from '../config/session.js';
|
|
4
|
+
import { clientOf, printJson, printLine, printNotice } from '../context.js';
|
|
5
|
+
import { CliError, usageError } from '../errors.js';
|
|
6
|
+
import { NexoApiError } from '../http/problem.js';
|
|
7
|
+
import { LEVEL_LABELS, clientLevelOnly, remoteIndex, remoteSkill } from '../skills/remote-skills.js';
|
|
8
|
+
import { staleBundledSkills, staleNotice } from '../skills/bundled-freshness.js';
|
|
5
9
|
import { bundledSkills } from '../skills/skill-files.js';
|
|
6
10
|
import { SKILL_TARGETS } from '../skills/skill-targets.types.js';
|
|
7
11
|
import { detectedTargets, installSkills } from '../skills/targets.js';
|
|
12
|
+
import { homeOf, installedUserTools, syncUserSkills, userToolsFor } from '../skills/user-skills.js';
|
|
8
13
|
function chosenTargets(options, directory) {
|
|
9
14
|
if (options.all === true) {
|
|
10
15
|
return SKILL_TARGETS;
|
|
@@ -19,42 +24,157 @@ function chosenTargets(options, directory) {
|
|
|
19
24
|
}
|
|
20
25
|
return detected;
|
|
21
26
|
}
|
|
22
|
-
|
|
27
|
+
function reasonOf(error) {
|
|
28
|
+
if (error instanceof NexoApiError || error instanceof CliError || error instanceof Error) {
|
|
29
|
+
return error.message;
|
|
30
|
+
}
|
|
31
|
+
return String(error);
|
|
32
|
+
}
|
|
33
|
+
/** The skills of the four levels, read with the token at the time of use; with no token or no network the CLI says why and goes on. */
|
|
34
|
+
async function remoteState(context, options) {
|
|
35
|
+
const session = currentSession(context.store, profileName(options.profile, context.env), context.env);
|
|
36
|
+
if (session === null) {
|
|
37
|
+
return { kind: 'logged-out' };
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
return { kind: 'ok', session, entries: await remoteIndex(clientOf(context, session)) };
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return { kind: 'failed', reason: reasonOf(error) };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** With network, compares the skills that came with the CLI against the ones the Nexo serves, and warns when they are old. */
|
|
47
|
+
async function staleSkillsNotice(context) {
|
|
48
|
+
const stale = await staleBundledSkills(context.fetchFn);
|
|
49
|
+
if (stale !== null && stale.length > 0) {
|
|
50
|
+
printNotice(context, staleNotice(stale));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function remoteNotice(context, state) {
|
|
54
|
+
if (state.kind === 'logged-out') {
|
|
55
|
+
printNotice(context, 'Sem login: só as skills de produto, que vêm com a CLI. Rode `nexo login` para ter também as da sua empresa, área e time.');
|
|
56
|
+
}
|
|
57
|
+
if (state.kind === 'failed') {
|
|
58
|
+
printNotice(context, `Não consegui ler as skills da empresa (${state.reason}). Ficam as de produto, que vêm com a CLI.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function installClientSkills(context, state, targets) {
|
|
62
|
+
if (state.kind !== 'ok') {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const client = clientOf(context, state.session);
|
|
67
|
+
const entries = clientLevelOnly(state.entries);
|
|
68
|
+
const home = homeOf(context.env);
|
|
69
|
+
const tools = userToolsFor(home, targets);
|
|
70
|
+
const sync = await syncUserSkills(home, tools, state.session.profile, entries, (entry) => remoteSkill(client, entry.name));
|
|
71
|
+
return { tools, skills: entries.map((entry) => entry.name), sync };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
printNotice(context, `Não consegui baixar as skills da empresa (${reasonOf(error)}); as que já estavam na sua pasta ficaram como estavam.`);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function clientSummary(client) {
|
|
79
|
+
const { written, upToDate, removed } = client.sync;
|
|
80
|
+
const parts = [
|
|
81
|
+
`${String(client.skills.length - upToDate.length)} novas ou atualizadas`,
|
|
82
|
+
`${String(upToDate.length)} já em dia`,
|
|
83
|
+
`${String(removed.length)} removidas`
|
|
84
|
+
];
|
|
85
|
+
return `${String(client.skills.length)} skills da sua empresa, área e time na sua pasta (${client.tools.join(', ')}), fora do projeto: ${parts.join(', ')}.${written.length === 0 && removed.length === 0 ? ' Nada mudou desde o último install.' : ''}`;
|
|
86
|
+
}
|
|
87
|
+
export async function skillsInstall(context, options) {
|
|
23
88
|
const directory = resolve(options.dir ?? '.');
|
|
24
89
|
const skills = bundledSkills();
|
|
25
90
|
const targets = chosenTargets(options, directory);
|
|
26
91
|
const written = targets.flatMap((target) => installSkills(directory, target, skills));
|
|
92
|
+
const state = await remoteState(context, options);
|
|
93
|
+
const client = await installClientSkills(context, state, targets);
|
|
27
94
|
if (options.json === true) {
|
|
28
|
-
printJson(context, {
|
|
95
|
+
printJson(context, {
|
|
96
|
+
directory,
|
|
97
|
+
targets,
|
|
98
|
+
skills: skills.map((skill) => skill.name),
|
|
99
|
+
files: written,
|
|
100
|
+
clientSkills: client === null ? [] : client.skills,
|
|
101
|
+
clientTools: client === null ? [] : client.tools,
|
|
102
|
+
clientFiles: client === null ? [] : client.sync.written,
|
|
103
|
+
clientUpToDate: client === null ? [] : client.sync.upToDate,
|
|
104
|
+
clientRemoved: client === null ? [] : client.sync.removed
|
|
105
|
+
});
|
|
29
106
|
return;
|
|
30
107
|
}
|
|
31
108
|
for (const file of written) {
|
|
32
109
|
printLine(context, ` ${relative(directory, file)}`);
|
|
33
110
|
}
|
|
34
111
|
printLine(context, `${String(skills.length)} skills do Nexo em ${targets.join(', ')}. Rode de novo depois de atualizar a CLI.`);
|
|
112
|
+
if (client !== null) {
|
|
113
|
+
printLine(context, clientSummary(client));
|
|
114
|
+
}
|
|
115
|
+
remoteNotice(context, state);
|
|
116
|
+
await staleSkillsNotice(context);
|
|
35
117
|
}
|
|
36
118
|
function installedIn(directory, skill) {
|
|
37
119
|
const paths = {
|
|
38
120
|
claude: join(directory, '.claude', 'skills', skill.name, 'SKILL.md'),
|
|
39
|
-
cursor: join(directory, '.cursor', '
|
|
121
|
+
cursor: join(directory, '.cursor', 'skills', skill.name, 'SKILL.md'),
|
|
40
122
|
agents: join(directory, '.nexo', 'skills', `${skill.name}.md`)
|
|
41
123
|
};
|
|
42
124
|
return SKILL_TARGETS.filter((target) => existsSync(paths[target]));
|
|
43
125
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const skills = bundledSkills();
|
|
47
|
-
const rows = skills.map((skill) => ({
|
|
126
|
+
function productRows(directory) {
|
|
127
|
+
return bundledSkills().map((skill) => ({
|
|
48
128
|
name: skill.name,
|
|
129
|
+
level: LEVEL_LABELS.product,
|
|
49
130
|
description: skill.description,
|
|
50
131
|
installed: installedIn(directory, skill)
|
|
51
132
|
}));
|
|
133
|
+
}
|
|
134
|
+
function clientRows(context, state) {
|
|
135
|
+
if (state.kind !== 'ok') {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
const home = homeOf(context.env);
|
|
139
|
+
return clientLevelOnly(state.entries).map((entry) => ({
|
|
140
|
+
name: entry.name,
|
|
141
|
+
level: entry.status === 'tentative' ? `${LEVEL_LABELS[entry.level]}, em teste` : LEVEL_LABELS[entry.level],
|
|
142
|
+
description: entry.description,
|
|
143
|
+
installed: installedUserTools(home, state.session.profile, entry)
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
export async function skillsList(context, options) {
|
|
147
|
+
const directory = resolve(options.dir ?? '.');
|
|
148
|
+
const state = await remoteState(context, options);
|
|
149
|
+
const rows = [...productRows(directory), ...clientRows(context, state)];
|
|
52
150
|
if (options.json === true) {
|
|
53
151
|
printJson(context, rows);
|
|
54
152
|
return;
|
|
55
153
|
}
|
|
56
154
|
for (const row of rows) {
|
|
57
155
|
const where = row.installed.length === 0 ? 'não instalada aqui' : `instalada: ${row.installed.join(', ')}`;
|
|
58
|
-
printLine(context, `${row.name} (${where})\n ${row.description}`);
|
|
156
|
+
printLine(context, `${row.name} [${row.level}] (${where})\n ${row.description}`);
|
|
157
|
+
}
|
|
158
|
+
remoteNotice(context, state);
|
|
159
|
+
await staleSkillsNotice(context);
|
|
160
|
+
}
|
|
161
|
+
function bundledNamed(name) {
|
|
162
|
+
return bundledSkills().find((skill) => skill.name === name);
|
|
163
|
+
}
|
|
164
|
+
/** Prints one skill and writes nothing: the body of a skill of the client is read with the token at the time of use. */
|
|
165
|
+
export async function skillsShow(context, name, options) {
|
|
166
|
+
const state = await remoteState(context, options);
|
|
167
|
+
const bundled = bundledNamed(name);
|
|
168
|
+
const entry = state.kind === 'ok' ? state.entries.find((each) => each.name === name) : undefined;
|
|
169
|
+
if (state.kind === 'ok' && entry !== undefined && entry.level !== 'product') {
|
|
170
|
+
const skill = await remoteSkill(clientOf(context, state.session), name);
|
|
171
|
+
printLine(context, options.json === true ? JSON.stringify(skill, null, 2) : skill.body);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (bundled === undefined) {
|
|
175
|
+
remoteNotice(context, state);
|
|
176
|
+
throw usageError(`Não achei a skill ${name}.`, 'Veja os nomes com `nexo skills list`.');
|
|
59
177
|
}
|
|
178
|
+
printLine(context, options.json === true ? JSON.stringify({ name, level: 'product', body: bundled.body }, null, 2) : bundled.content);
|
|
179
|
+
remoteNotice(context, state);
|
|
60
180
|
}
|