@quadient/skillshare 1.12.0 → 1.13.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/README.md +21 -0
- package/dist/agents-detect.js +9 -3
- package/dist/agents-service-path.js +52 -0
- package/dist/agents-service.js +32 -1
- package/dist/agents.js +3 -2
- package/dist/help.js +9 -4
- package/dist/index.js +6 -1
- package/dist/output.js +1 -0
- package/dist/pages-comments.js +152 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -341,6 +341,27 @@ printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN
|
|
|
341
341
|
skillshare pages secrets delete my-app API_TOKEN
|
|
342
342
|
```
|
|
343
343
|
|
|
344
|
+
## Page comments (1.13.0+)
|
|
345
|
+
|
|
346
|
+
Every Page is also served at `/pa/<slug>/` with an **Annotations** button. Signed-in
|
|
347
|
+
users highlight text, place pins or add page notes there; comments are stored in
|
|
348
|
+
SkillShare with their author and time. The owner can show the button on the regular
|
|
349
|
+
`/p/<slug>/` address too. The CLI reads and answers comments:
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
skillshare pages comments enable my-app # also on /p/my-app/ (owner or admin)
|
|
353
|
+
skillshare pages comments list my-app --author mine
|
|
354
|
+
skillshare pages comments list my-app --path docs/ --resolved
|
|
355
|
+
skillshare pages comments add my-app "Please add a changelog section" --path index.html
|
|
356
|
+
skillshare pages comments reply my-app 12 "Fixed in revision 4"
|
|
357
|
+
skillshare pages comments resolve my-app 12
|
|
358
|
+
skillshare pages comments delete my-app 12
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
`--author` accepts `mine` or a user id and keeps threads that person started or
|
|
362
|
+
replied to. Each thread is listed with a link that opens the Page on `/pa/` with that
|
|
363
|
+
thread selected; the **Copy link** action in the browser panel creates the same link. Text without an argument, or `-`, is read from stdin.
|
|
364
|
+
|
|
344
365
|
## Local Pages development (1.6.0+)
|
|
345
366
|
|
|
346
367
|
Run a celld application without a SkillShare server, repository checkout, Docker,
|
package/dist/agents-detect.js
CHANGED
|
@@ -15,10 +15,10 @@ export function profilesPath(home = homedir()) {
|
|
|
15
15
|
export async function detectAgents(options = {}) {
|
|
16
16
|
const home = options.home ?? homedir();
|
|
17
17
|
const env = options.env ?? process.env;
|
|
18
|
-
const version = options.version ?? commandVersion;
|
|
19
18
|
const read = options.read ?? readOptional;
|
|
20
19
|
const agents = [];
|
|
21
20
|
const problems = [];
|
|
21
|
+
const version = options.version ?? (command => commandVersion(command, env, problem => problems.push(problem)));
|
|
22
22
|
const claudeVersion = await version('claude');
|
|
23
23
|
if (claudeVersion !== null) {
|
|
24
24
|
const settings = parseJson(await read(join(env.CLAUDE_CONFIG_DIR ?? join(home, '.claude'), 'settings.json')));
|
|
@@ -45,6 +45,8 @@ export async function detectAgents(options = {}) {
|
|
|
45
45
|
for (const profile of profiles)
|
|
46
46
|
if (!agents.some(agent => agent.kind === profile.agent))
|
|
47
47
|
problems.push(`Profile "${profile.name}" uses ${profile.agent}, which is not installed.`);
|
|
48
|
+
if (agents.length === 0)
|
|
49
|
+
problems.push(`Could not run claude --version or codex --version. Check that an agent is installed and runnable on PATH: ${env.PATH ?? env.Path ?? ''}. For a service, check skillshare agents service status and reinstall from a fresh terminal if needed.`);
|
|
48
50
|
return {
|
|
49
51
|
capabilities: { agents, profiles: profiles.map(p => ({ name: p.name, agent: p.agent, model: p.model, reasoning: p.reasoning,
|
|
50
52
|
workdir: p.workdir ? basename(p.workdir) : undefined, ...(p.sandbox ? { sandbox: true } : {}) })) },
|
|
@@ -202,8 +204,12 @@ async function readOptional(path) {
|
|
|
202
204
|
return null;
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
|
-
function commandVersion(command) {
|
|
207
|
+
function commandVersion(command, env, report) {
|
|
206
208
|
return new Promise(resolvePromise => {
|
|
207
|
-
execFile(command, ['--version'], { timeout: 15_000, windowsHide: true, shell: process.platform === 'win32' }, (error, stdout) =>
|
|
209
|
+
execFile(command, ['--version'], { env, timeout: 15_000, windowsHide: true, shell: process.platform === 'win32' }, (error, stdout) => {
|
|
210
|
+
if (error)
|
|
211
|
+
report(`${command} --version failed (${error.killed ? 'timeout or terminated' : error.code ?? 'unknown error'}). Check the executable and PATH.`);
|
|
212
|
+
resolvePromise(error ? null : stdout.toString());
|
|
213
|
+
});
|
|
208
214
|
});
|
|
209
215
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const readRegistry = (command, args) => new Promise((resolve, reject) => {
|
|
4
|
+
execFile(command, args, { timeout: 10_000, windowsHide: true }, (error, stdout, stderr) => {
|
|
5
|
+
if (error)
|
|
6
|
+
reject(error);
|
|
7
|
+
else
|
|
8
|
+
resolve({ code: 0, stdout, stderr });
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
export function mergeWindowsPath(...paths) {
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
return paths.flatMap(path => path.split(';')).map(part => part.trim()).filter(part => {
|
|
14
|
+
const key = part.replace(/[\\/]+$/, '').toLowerCase();
|
|
15
|
+
if (!part || /(?:^|[\\/])node_modules[\\/]\.bin(?:[\\/]|$)/i.test(part) || seen.has(key))
|
|
16
|
+
return false;
|
|
17
|
+
seen.add(key);
|
|
18
|
+
return true;
|
|
19
|
+
}).join(';');
|
|
20
|
+
}
|
|
21
|
+
/** Refresh before every service detection, including in services installed by older CLIs. */
|
|
22
|
+
export async function refreshServicePath(env = process.env, platform = process.platform, run = readRegistry) {
|
|
23
|
+
if (platform !== 'win32')
|
|
24
|
+
return [];
|
|
25
|
+
const script = `$ErrorActionPreference = 'Stop'
|
|
26
|
+
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
|
27
|
+
foreach ($scope in @('Machine', 'User')) {
|
|
28
|
+
$vars = [Environment]::GetEnvironmentVariables($scope)
|
|
29
|
+
foreach ($key in $vars.Keys) { if ($key -ne 'Path') { [Environment]::SetEnvironmentVariable($key, [Environment]::ExpandEnvironmentVariables($vars[$key]), 'Process') } }
|
|
30
|
+
}
|
|
31
|
+
$machine = [Environment]::GetEnvironmentVariable('Path', 'Machine')
|
|
32
|
+
[Environment]::SetEnvironmentVariable('Path', [Environment]::ExpandEnvironmentVariables($machine), 'Process')
|
|
33
|
+
$user = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
34
|
+
[Environment]::ExpandEnvironmentVariables($machine + ';' + $user)`;
|
|
35
|
+
const pathKeys = Object.keys(env).filter(key => key.toLowerCase() === 'path');
|
|
36
|
+
const snapshot = pathKeys.map(key => env[key] ?? '').join(';');
|
|
37
|
+
let current = '';
|
|
38
|
+
const warnings = [];
|
|
39
|
+
try {
|
|
40
|
+
const result = await run(join(env.SystemRoot ?? env.SYSTEMROOT ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'), ['-NoProfile', '-NonInteractive', '-Command', script]);
|
|
41
|
+
if (result.code !== 0)
|
|
42
|
+
throw new Error('registry read failed');
|
|
43
|
+
current = result.stdout.trim();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
warnings.push('Could not read current Windows PATH from the registry; using the saved service PATH. Reinstall from a fresh terminal if agents are missing.');
|
|
47
|
+
}
|
|
48
|
+
for (const key of pathKeys)
|
|
49
|
+
delete env[key];
|
|
50
|
+
env.PATH = mergeWindowsPath(current, snapshot);
|
|
51
|
+
return warnings;
|
|
52
|
+
}
|
package/dist/agents-service.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { detectAgents } from './agents-detect.js';
|
|
2
|
+
import { refreshServicePath } from './agents-service-path.js';
|
|
1
3
|
import { existsSync } from 'node:fs';
|
|
2
4
|
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
5
|
import { homedir } from 'node:os';
|
|
@@ -18,6 +20,7 @@ export function defaultServiceEnvironment(appDir) {
|
|
|
18
20
|
export function servicePaths(appDir) {
|
|
19
21
|
return {
|
|
20
22
|
config: join(appDir, 'agents-service.json'),
|
|
23
|
+
detection: join(appDir, 'agents-service-detection.json'),
|
|
21
24
|
launcher: join(appDir, 'agents-service.mjs'),
|
|
22
25
|
log: join(appDir, 'logs', 'agents.log'),
|
|
23
26
|
// What the service manager catches before the listener's own log opens, such as a launcher that cannot start.
|
|
@@ -286,6 +289,20 @@ export async function uninstallService(environment) {
|
|
|
286
289
|
await environment.run('systemctl', ['--user', 'daemon-reload']);
|
|
287
290
|
return existed || wasRunning;
|
|
288
291
|
}
|
|
292
|
+
export async function detectServiceAgents(appDir) {
|
|
293
|
+
const warnings = await refreshServicePath();
|
|
294
|
+
const detected = await detectAgents();
|
|
295
|
+
detected.problems.unshift(...warnings);
|
|
296
|
+
const report = {
|
|
297
|
+
checkedAt: new Date().toISOString(), path: process.env.PATH ?? '',
|
|
298
|
+
agents: detected.capabilities.agents.map(agent => `${agent.kind} ${agent.version ?? ''}`.trim()),
|
|
299
|
+
problems: detected.problems,
|
|
300
|
+
};
|
|
301
|
+
await writeFile(servicePaths(appDir).detection, JSON.stringify(report, null, 2));
|
|
302
|
+
for (const problem of report.problems)
|
|
303
|
+
console.warn(problem);
|
|
304
|
+
return detected;
|
|
305
|
+
}
|
|
289
306
|
export async function serviceStatus(environment) {
|
|
290
307
|
let config;
|
|
291
308
|
try {
|
|
@@ -294,8 +311,15 @@ export async function serviceStatus(environment) {
|
|
|
294
311
|
catch { }
|
|
295
312
|
const lock = await readListenerLock(environment.appDir);
|
|
296
313
|
const running = lock?.service === true;
|
|
314
|
+
let detection;
|
|
315
|
+
try {
|
|
316
|
+
const report = JSON.parse(await readFile(servicePaths(environment.appDir).detection, 'utf8'));
|
|
317
|
+
if (running && report.checkedAt >= lock.startedAt)
|
|
318
|
+
detection = report;
|
|
319
|
+
}
|
|
320
|
+
catch { }
|
|
297
321
|
return {
|
|
298
|
-
installed: config !== undefined && existsSync(definitionPath(environment)), config, running,
|
|
322
|
+
installed: config !== undefined && existsSync(definitionPath(environment)), config, running, detection,
|
|
299
323
|
pid: running ? lock.pid : undefined, version: running ? lock.version : undefined, since: running ? lock.startedAt : undefined,
|
|
300
324
|
};
|
|
301
325
|
}
|
|
@@ -313,6 +337,13 @@ export function renderServiceStatus(status, appDir) {
|
|
|
313
337
|
];
|
|
314
338
|
if (status.config.args.length)
|
|
315
339
|
lines.push(`Options: ${status.config.args.join(' ')}`);
|
|
340
|
+
if (status.detection) {
|
|
341
|
+
lines.push(`Service agent detection (${status.detection.checkedAt}): ${status.detection.agents.join(', ') || 'No supported agent found.'}`);
|
|
342
|
+
lines.push(`Service PATH: ${status.detection.path}`);
|
|
343
|
+
lines.push(...status.detection.problems);
|
|
344
|
+
}
|
|
345
|
+
else
|
|
346
|
+
lines.push('Service agent detection is not available yet. Check service logs; reinstall with the updated CLI if needed.');
|
|
316
347
|
lines.push(`Log: ${servicePaths(appDir).log}`);
|
|
317
348
|
return lines.join('\n');
|
|
318
349
|
}
|
package/dist/agents.js
CHANGED
|
@@ -4,7 +4,7 @@ import { hostname, platform, tmpdir } from 'node:os';
|
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
6
|
import { createClaudeDriver } from './agents-claude.js';
|
|
7
|
-
import { defaultServiceEnvironment, installService, renderServiceStatus, serviceLogs, serviceStatus, uninstallService, } from './agents-service.js';
|
|
7
|
+
import { defaultServiceEnvironment, detectServiceAgents, installService, renderServiceStatus, serviceLogs, serviceStatus, uninstallService, } from './agents-service.js';
|
|
8
8
|
import { createCodexDriver } from './agents-codex.js';
|
|
9
9
|
import { detectAgents, expandHome, profilesPath } from './agents-detect.js';
|
|
10
10
|
import { SessionRunner, errorMessage, } from './agents-session.js';
|
|
@@ -135,6 +135,7 @@ export async function runAgentsCommand(client, args, flags, appDirectory, teamsW
|
|
|
135
135
|
try {
|
|
136
136
|
result = await listen({
|
|
137
137
|
client, listenerId, name: flags.name, workdir, maxConcurrency: max, sandbox, signal: abort.signal, onProgress: console.log, service,
|
|
138
|
+
detect: service ? () => detectServiceAgents(appDirectory) : undefined,
|
|
138
139
|
updater: worker ? { currentVersion: readCliVersion(), prepare: version => installVersion(appDirectory, version) } : undefined,
|
|
139
140
|
});
|
|
140
141
|
}
|
|
@@ -183,7 +184,7 @@ export async function runServiceCommand(action, flags, appDirectory, server) {
|
|
|
183
184
|
await installService(environment, { server, workdir, args: serviceListenArgs(flags), version });
|
|
184
185
|
// The service manager starts it right away; it takes a moment to sign in and report.
|
|
185
186
|
let status = await serviceStatus(environment);
|
|
186
|
-
for (let attempt = 0; attempt <
|
|
187
|
+
for (let attempt = 0; attempt < 60 && (!status.running || !status.detection); attempt++) {
|
|
187
188
|
await delay(500);
|
|
188
189
|
status = await serviceStatus(environment);
|
|
189
190
|
}
|
package/dist/help.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
export const GLOBAL_FLAGS = ['token', 'server', 'help'];
|
|
3
|
-
export const BOOLEAN_FLAGS = new Set(['dry-run', 'force', 'headless', 'help', 'json', 'no-teams-watch', 'no-update', 'sandbox']);
|
|
3
|
+
export const BOOLEAN_FLAGS = new Set(['dry-run', 'force', 'headless', 'help', 'json', 'no-teams-watch', 'no-update', 'resolved', 'sandbox']);
|
|
4
4
|
export const COMMANDS = [
|
|
5
5
|
{
|
|
6
6
|
name: 'login',
|
|
@@ -90,12 +90,17 @@ export const COMMANDS = [
|
|
|
90
90
|
'pages secrets list <slug> [--json]',
|
|
91
91
|
'pages secrets set <slug> <name> [--json]',
|
|
92
92
|
'pages secrets delete <slug> <name> [--json]',
|
|
93
|
+
'pages comments list <slug> [--path <path>] [--author mine|<user id>] [--resolved] [--json]',
|
|
94
|
+
'pages comments add <slug> [text] [--path <path>] [--json]',
|
|
95
|
+
'pages comments reply|edit <slug> <id> [text] [--json]',
|
|
96
|
+
'pages comments resolve|reopen|delete <slug> <id> [--json]',
|
|
97
|
+
'pages comments enable|disable <slug> [--json]',
|
|
93
98
|
'pages dev [directory] [--slug <slug>] [--port <port>] [--build <command> --watch-dir <sources>]',
|
|
94
99
|
' [--celld <executable>] [--user-id <id>] [--user-name <name>] [--user-email <email>]',
|
|
95
100
|
],
|
|
96
|
-
description: 'An upload replaces all content of the page. Without --slug the directory name is used; build output folders such as dist need an explicit --slug. Pages owned by someone else are refused unless you are an admin. pages secrets manages the write-only secrets an app reads through SKILLSHARE_SECRETS (owner or admin only, at most 32 per page, 16 KiB each); set reads the value from piped stdin or a masked prompt, never from the command line.',
|
|
97
|
-
examples: ['skillshare pages upload ./site --slug release-notes', 'skillshare pages dev . --slug my-app', 'skillshare pages secrets set my-app API_TOKEN', 'printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN'],
|
|
98
|
-
flags: ['slug', 'json'],
|
|
101
|
+
description: 'An upload replaces all content of the page. Without --slug the directory name is used; build output folders such as dist need an explicit --slug. Pages owned by someone else are refused unless you are an admin. pages secrets manages the write-only secrets an app reads through SKILLSHARE_SECRETS (owner or admin only, at most 32 per page, 16 KiB each); set reads the value from piped stdin or a masked prompt, never from the command line. pages comments reads and writes the annotations reviewers leave on a Page at /pa/<slug>/ (enable and disable decide whether the regular /p/<slug>/ address shows them too); add creates a page note, text without an argument (or -) is read from stdin, and list hides resolved threads unless --resolved is given.',
|
|
102
|
+
examples: ['skillshare pages upload ./site --slug release-notes', 'skillshare pages dev . --slug my-app', 'skillshare pages secrets set my-app API_TOKEN', 'printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN', 'skillshare pages comments list my-app --author mine', 'skillshare pages comments reply my-app 12 "Fixed in revision 4"'],
|
|
103
|
+
flags: ['slug', 'path', 'author', 'resolved', 'json'],
|
|
99
104
|
},
|
|
100
105
|
{
|
|
101
106
|
name: 'teams',
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { inspectInstallTarget, installFilesAtomically } from './install-files.js
|
|
|
8
8
|
import { preparePageFiles, resolvePageSlug } from './pages.js';
|
|
9
9
|
import { formatByteSize, formatDateTime, pageUrl, plural, renderPageDetail, renderPageList, renderPageRuntime, renderSkillDetail, renderSkillList, renderSkillVersion, renderUser, } from './output.js';
|
|
10
10
|
import { runPageDev } from './pages-dev.js';
|
|
11
|
+
import { runPageCommentsCommand } from './pages-comments.js';
|
|
11
12
|
import { runPageSecretsCommand } from './pages-secrets.js';
|
|
12
13
|
import { createServer } from 'node:http';
|
|
13
14
|
import { createHash, randomBytes } from 'node:crypto';
|
|
@@ -391,7 +392,11 @@ async function main() {
|
|
|
391
392
|
await runPageSecretsCommand(client, options.positionals.slice(1), print);
|
|
392
393
|
return;
|
|
393
394
|
}
|
|
394
|
-
|
|
395
|
+
if (action === 'comments') {
|
|
396
|
+
await runPageCommentsCommand(client, options.positionals.slice(1), options.flags, print);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
throw new Error(`Unknown pages command '${action}'. Use list, show, runtime, upload, secrets, or comments.`);
|
|
395
400
|
}
|
|
396
401
|
}
|
|
397
402
|
return;
|
package/dist/output.js
CHANGED
|
@@ -122,6 +122,7 @@ export function renderPageDetail(page, baseUrl, now = new Date()) {
|
|
|
122
122
|
`${page.slug} (${page.kind === 'celld' ? 'application' : 'static site'})`,
|
|
123
123
|
...fields([
|
|
124
124
|
['URL', pageUrl(baseUrl, page.slug)],
|
|
125
|
+
['Annotate', `${baseUrl.replace(/\/+$/, '')}/pa/${encodeURIComponent(page.slug)}/`],
|
|
125
126
|
['Owner', page.ownerDisplayName],
|
|
126
127
|
['Revision', `${page.contentRevision}, updated ${formatDateTime(page.updated)}`],
|
|
127
128
|
['Users this month', page.monthlyUsage.find((usage) => usage.month === month)?.uniqueUsers ?? 0],
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { formatDateTime } from './output.js';
|
|
2
|
+
/** Opens the Page on /pa/ with the panel focused on the thread; the browser script reads the parameter. */
|
|
3
|
+
export function pageCommentLink(baseUrl, slug, comment) {
|
|
4
|
+
return `${baseUrl.replace(/\/+$/, '')}/pa/${encodeURIComponent(slug)}/${comment.path}?skillshare-annotation=${comment.threadId}`;
|
|
5
|
+
}
|
|
6
|
+
const ACTIONS = ['list', 'add', 'reply', 'edit', 'resolve', 'reopen', 'delete', 'enable', 'disable'];
|
|
7
|
+
/** Keeps threads where the author (`mine` or a user id) wrote the first comment or any reply. */
|
|
8
|
+
export function filterPageComments(list, filter) {
|
|
9
|
+
const authorId = filter.author === 'mine' ? list.currentUserId : filter.author ? Number(filter.author) : undefined;
|
|
10
|
+
if (filter.author && filter.author !== 'mine' && !Number.isInteger(authorId)) {
|
|
11
|
+
throw new Error('--author must be "mine" or a user id.');
|
|
12
|
+
}
|
|
13
|
+
const threads = list.annotations.filter((comment) => comment.threadId === comment.id);
|
|
14
|
+
return threads.filter((thread) => {
|
|
15
|
+
if (!filter.resolved && thread.resolved)
|
|
16
|
+
return false;
|
|
17
|
+
if (authorId === undefined)
|
|
18
|
+
return true;
|
|
19
|
+
return list.annotations.some((comment) => comment.threadId === thread.id && comment.authorUserId === authorId);
|
|
20
|
+
}).flatMap((thread) => list.annotations.filter((comment) => comment.threadId === thread.id));
|
|
21
|
+
}
|
|
22
|
+
function quote(comment) {
|
|
23
|
+
if (comment.kind !== 'text')
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const anchor = JSON.parse(comment.anchor);
|
|
27
|
+
return anchor.quote ? anchor.quote.replace(/\s+/g, ' ').slice(0, 120) : null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function renderPageComments(slug, list, comments, baseUrl) {
|
|
34
|
+
const header = list.enabled ? [] : [`/p/${slug}/ hides annotations; comment on /pa/${slug}/.`, ''];
|
|
35
|
+
if (comments.length === 0)
|
|
36
|
+
return [...header, `/p/${slug}/ has no matching comments.`].join('\n');
|
|
37
|
+
const lines = [...header];
|
|
38
|
+
let path = null;
|
|
39
|
+
for (const comment of comments) {
|
|
40
|
+
const isThread = comment.threadId === comment.id;
|
|
41
|
+
if (isThread && comment.path !== path) {
|
|
42
|
+
path = comment.path;
|
|
43
|
+
if (lines.length > header.length)
|
|
44
|
+
lines.push('');
|
|
45
|
+
lines.push(`/p/${slug}/${path}`);
|
|
46
|
+
}
|
|
47
|
+
const indent = isThread ? ' ' : ' ';
|
|
48
|
+
const status = isThread ? ` [${comment.kind}${comment.resolved ? `, resolved by ${comment.resolvedByDisplayName}` : ''}]` : '';
|
|
49
|
+
lines.push(`${indent}#${comment.id}${status} ${comment.authorDisplayName} · ${formatDateTime(comment.created)}`);
|
|
50
|
+
if (isThread && baseUrl)
|
|
51
|
+
lines.push(`${indent} ${pageCommentLink(baseUrl, slug, comment)}`);
|
|
52
|
+
const quoted = quote(comment);
|
|
53
|
+
if (quoted)
|
|
54
|
+
lines.push(`${indent} > ${quoted}`);
|
|
55
|
+
for (const line of comment.body.split('\n'))
|
|
56
|
+
lines.push(`${indent} ${line}`);
|
|
57
|
+
}
|
|
58
|
+
return lines.join('\n');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reads and writes a Page's annotation comments. /pa/<slug>/ always shows them; enable and disable
|
|
62
|
+
* only decide whether the regular /p/<slug>/ address shows them too. The CLI adds page notes and replies;
|
|
63
|
+
* text highlights and pins are placed in the browser where their position is known.
|
|
64
|
+
*/
|
|
65
|
+
export async function runPageCommentsCommand(client, positionals, flags, print, readText = readStdin) {
|
|
66
|
+
const [action = 'list', slug, ...rest] = positionals;
|
|
67
|
+
if (!ACTIONS.includes(action)) {
|
|
68
|
+
throw new Error(`Unknown pages comments command '${action}'. Use ${ACTIONS.join(', ')}.`);
|
|
69
|
+
}
|
|
70
|
+
if (!slug)
|
|
71
|
+
throw new Error(`pages comments ${action} requires <slug>`);
|
|
72
|
+
const base = `/api/pages/${encodeURIComponent(slug)}/annotations`;
|
|
73
|
+
if (action === 'list') {
|
|
74
|
+
const query = flags.path !== undefined ? `?path=${encodeURIComponent(flags.path)}` : '';
|
|
75
|
+
const list = await expectJson(slug, await client.request(base + query, { method: 'GET' }));
|
|
76
|
+
const comments = filterPageComments(list, { path: flags.path, author: flags.author, resolved: flags.resolved === 'true' });
|
|
77
|
+
const output = client.baseUrl
|
|
78
|
+
? comments.map((comment) => ({ ...comment, link: pageCommentLink(client.baseUrl, slug, comment) }))
|
|
79
|
+
: comments;
|
|
80
|
+
print(output, () => renderPageComments(slug, list, comments, client.baseUrl));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (action === 'enable' || action === 'disable') {
|
|
84
|
+
await expectJson(slug, await client.request(`${base}/settings`, json('PUT', { enabled: action === 'enable' })));
|
|
85
|
+
print({ enabled: action === 'enable' }, () => action === 'enable'
|
|
86
|
+
? `/p/${slug}/ now shows the Annotations button too. Reload the Page to see it.`
|
|
87
|
+
: `/p/${slug}/ no longer shows annotations. They stay available on /pa/${slug}/.`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (action === 'add') {
|
|
91
|
+
const body = await commentText(rest, readText);
|
|
92
|
+
const created = await expectJson(slug, await client.request(base, json('POST', { path: normalizePath(flags.path), kind: 'note', anchor: '', body })));
|
|
93
|
+
print(created, () => `Added page note #${created.id} to /p/${slug}/${created.path}.`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const [idText, ...text] = rest;
|
|
97
|
+
const id = Number(idText);
|
|
98
|
+
if (!idText || !Number.isInteger(id) || id <= 0)
|
|
99
|
+
throw new Error(`pages comments ${action} requires <slug> <comment id>`);
|
|
100
|
+
if (action === 'delete') {
|
|
101
|
+
await expectJson(slug, await client.request(`${base}/${id}`, { method: 'DELETE' }), id);
|
|
102
|
+
print({ deleted: id }, () => `Deleted comment #${id} and its replies.`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (action === 'reply') {
|
|
106
|
+
const created = await expectJson(slug, await client.request(base, json('POST', { threadId: id, body: await commentText(text, readText) })), id);
|
|
107
|
+
print(created, () => `Added reply #${created.id} to #${id}.`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const change = action === 'edit' ? { body: await commentText(text, readText) } : { resolved: action === 'resolve' };
|
|
111
|
+
const updated = await expectJson(slug, await client.request(`${base}/${id}`, json('PATCH', change)), id);
|
|
112
|
+
print(updated, () => action === 'edit' ? `Updated comment #${id}.` : `${action === 'resolve' ? 'Resolved' : 'Reopened'} #${id}.`);
|
|
113
|
+
}
|
|
114
|
+
function json(method, body) {
|
|
115
|
+
return { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) };
|
|
116
|
+
}
|
|
117
|
+
function normalizePath(path) {
|
|
118
|
+
return (path ?? '').replace(/^\/+/, '');
|
|
119
|
+
}
|
|
120
|
+
async function commentText(words, readText) {
|
|
121
|
+
const text = (words.length > 0 && words.join(' ') !== '-' ? words.join(' ') : await readText()).trim();
|
|
122
|
+
if (!text)
|
|
123
|
+
throw new Error('The comment is empty. Pass it as an argument or pipe it to stdin.');
|
|
124
|
+
return text;
|
|
125
|
+
}
|
|
126
|
+
async function expectJson(slug, response, id) {
|
|
127
|
+
if (response.status === 204)
|
|
128
|
+
return undefined;
|
|
129
|
+
if (response.ok)
|
|
130
|
+
return await response.json();
|
|
131
|
+
if (response.status === 403) {
|
|
132
|
+
throw new Error(id
|
|
133
|
+
? `Only the comment's author, the owner of /p/${slug}/ or an administrator can change #${id}.`
|
|
134
|
+
: `Only the owner of /p/${slug}/ or an administrator can change its annotation settings.`);
|
|
135
|
+
}
|
|
136
|
+
if (response.status === 404)
|
|
137
|
+
throw new Error(id ? `Comment #${id} on /p/${slug}/ was not found.` : `Page /p/${slug}/ was not found.`);
|
|
138
|
+
let error = {};
|
|
139
|
+
try {
|
|
140
|
+
error = await response.json();
|
|
141
|
+
}
|
|
142
|
+
catch { }
|
|
143
|
+
throw new Error(error.error ?? `Skillshare returned HTTP ${response.status} for the Page comments.`);
|
|
144
|
+
}
|
|
145
|
+
async function readStdin() {
|
|
146
|
+
if (process.stdin.isTTY)
|
|
147
|
+
return '';
|
|
148
|
+
const chunks = [];
|
|
149
|
+
for await (const chunk of process.stdin)
|
|
150
|
+
chunks.push(Buffer.from(chunk));
|
|
151
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadient/skillshare",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "Skillshare CLI for installing and publishing Quadient skills",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
17
17
|
"start": "node ./dist/index.js",
|
|
18
18
|
"prepublishOnly": "npm run build",
|
|
19
|
-
"test": "tsx --test cli-args.test.ts install-files.test.ts output.test.ts pages.test.ts pages-secrets.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-update.test.ts"
|
|
19
|
+
"test": "tsx --test cli-args.test.ts install-files.test.ts output.test.ts pages.test.ts pages-secrets.test.ts pages-comments.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-update.test.ts"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|