@seavideo/cli 0.0.0-stage → 0.3.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.
Files changed (111) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +153 -2
  3. package/README.publish.md +154 -0
  4. package/dist/bin/seavideo.js +11 -0
  5. package/dist/src/atomic-write.js +14 -0
  6. package/dist/src/canvas/api.js +172 -0
  7. package/dist/src/canvas/browser.js +40 -0
  8. package/dist/src/canvas/chrome-binary.js +109 -0
  9. package/dist/src/canvas/daemon.js +264 -0
  10. package/dist/src/canvas/engine-install.js +46 -0
  11. package/dist/src/canvas/engine-log.js +9 -0
  12. package/dist/src/canvas/engine.js +99 -0
  13. package/dist/src/canvas/entry.js +16 -0
  14. package/dist/src/canvas/env-lock.js +164 -0
  15. package/dist/src/canvas/launch.js +97 -0
  16. package/dist/src/canvas/lifecycle.js +65 -0
  17. package/dist/src/canvas/names.js +61 -0
  18. package/dist/src/canvas/params.js +38 -0
  19. package/dist/src/canvas/puppeteer.js +153 -0
  20. package/dist/src/canvas/screenshot.js +23 -0
  21. package/dist/src/canvas/session-record.js +77 -0
  22. package/dist/src/canvas/team.js +97 -0
  23. package/dist/src/canvas/tool-args.js +47 -0
  24. package/dist/src/canvas/tool-session.js +165 -0
  25. package/dist/src/canvas/tool-specs.js +54 -0
  26. package/dist/src/canvas/url.js +38 -0
  27. package/dist/src/cli/args.js +16 -0
  28. package/dist/src/cli/commands/auth.js +51 -0
  29. package/dist/src/cli/commands/canvas/common.js +31 -0
  30. package/dist/src/cli/commands/canvas/engine-choice.js +41 -0
  31. package/dist/src/cli/commands/canvas/index.js +5 -0
  32. package/dist/src/cli/commands/canvas/item.js +233 -0
  33. package/dist/src/cli/commands/canvas/list.js +168 -0
  34. package/dist/src/cli/commands/canvas/register.js +106 -0
  35. package/dist/src/cli/commands/canvas/render.js +229 -0
  36. package/dist/src/cli/commands/canvas/screenshot.js +52 -0
  37. package/dist/src/cli/commands/canvas/session.js +249 -0
  38. package/dist/src/cli/commands/canvas/teams.js +142 -0
  39. package/dist/src/cli/commands/config.js +74 -0
  40. package/dist/src/cli/commands/doctor.js +261 -0
  41. package/dist/src/cli/commands/engine.js +96 -0
  42. package/dist/src/cli/commands/env/create.js +160 -0
  43. package/dist/src/cli/commands/env/fields.js +26 -0
  44. package/dist/src/cli/commands/env/index.js +4 -0
  45. package/dist/src/cli/commands/env/list.js +44 -0
  46. package/dist/src/cli/commands/env/mutate.js +118 -0
  47. package/dist/src/cli/commands/login/flow-token.js +41 -0
  48. package/dist/src/cli/commands/login/index.js +12 -0
  49. package/dist/src/cli/commands/login/oauth.js +69 -0
  50. package/dist/src/cli/commands/login/save.js +26 -0
  51. package/dist/src/cli/commands/logout.js +92 -0
  52. package/dist/src/cli/commands/skill.js +185 -0
  53. package/dist/src/cli/commands/tool.js +279 -0
  54. package/dist/src/cli/commands/update.js +117 -0
  55. package/dist/src/cli/commands/wallet.js +69 -0
  56. package/dist/src/cli/commands/whoami.js +147 -0
  57. package/dist/src/cli/context.js +41 -0
  58. package/dist/src/cli/credential.js +93 -0
  59. package/dist/src/cli/elapsed.js +25 -0
  60. package/dist/src/cli/failure-screenshot.js +24 -0
  61. package/dist/src/cli/flags.js +1 -0
  62. package/dist/src/cli/hints.js +7 -0
  63. package/dist/src/cli/main.js +44 -0
  64. package/dist/src/cli/output-error.js +23 -0
  65. package/dist/src/cli/output.js +47 -0
  66. package/dist/src/cli/program.js +261 -0
  67. package/dist/src/cli/run.js +11 -0
  68. package/dist/src/cli/session.js +63 -0
  69. package/dist/src/config/base-url.js +26 -0
  70. package/dist/src/config/credential-vault.js +115 -0
  71. package/dist/src/config/dotenv.js +59 -0
  72. package/dist/src/config/envname.js +41 -0
  73. package/dist/src/config/paths.js +22 -0
  74. package/dist/src/config/preset-schema.js +67 -0
  75. package/dist/src/config/presets.js +132 -0
  76. package/dist/src/config/resolve.js +41 -0
  77. package/dist/src/config/secret-key.js +63 -0
  78. package/dist/src/config/store-schema.js +143 -0
  79. package/dist/src/config/store.js +273 -0
  80. package/dist/src/config/vault-crypto.js +44 -0
  81. package/dist/src/deps.js +191 -0
  82. package/dist/src/deps.types.js +1 -0
  83. package/dist/src/errors.js +24 -0
  84. package/dist/src/fs-retry.js +34 -0
  85. package/dist/src/i18n.js +1214 -0
  86. package/dist/src/loopback.js +134 -0
  87. package/dist/src/sdk/auth.js +20 -0
  88. package/dist/src/sdk/credential-expiry.js +67 -0
  89. package/dist/src/sdk/discovery.js +90 -0
  90. package/dist/src/sdk/http.js +98 -0
  91. package/dist/src/sdk/identity.js +17 -0
  92. package/dist/src/sdk/jwks.js +119 -0
  93. package/dist/src/sdk/oauth-protocol.js +226 -0
  94. package/dist/src/sdk/oauth.js +179 -0
  95. package/dist/src/sdk/provider/cn.js +34 -0
  96. package/dist/src/sdk/provider/index.js +16 -0
  97. package/dist/src/sdk/provider/oversea.js +41 -0
  98. package/dist/src/sdk/provider/types.js +1 -0
  99. package/dist/src/sdk/refresh.js +66 -0
  100. package/dist/src/semver.js +89 -0
  101. package/dist/src/skill/api.js +176 -0
  102. package/dist/src/text.js +3 -0
  103. package/dist/src/types.js +1 -0
  104. package/dist/src/update/check-cache.js +56 -0
  105. package/dist/src/update/install-layout.js +79 -0
  106. package/dist/src/update/notify.js +15 -0
  107. package/dist/src/update/npm-install.js +64 -0
  108. package/dist/src/update/passive.js +53 -0
  109. package/dist/src/update/registry.js +59 -0
  110. package/dist/src/wallet/api.js +107 -0
  111. package/package.json +59 -4
@@ -0,0 +1,168 @@
1
+ import { CliError, errorMessage } from "../../../errors.js";
2
+ import { createTeamApi } from "../../../canvas/team.js";
3
+ import { collectNames } from "../../../canvas/names.js";
4
+ import { requireSpace } from "../../../canvas/entry.js";
5
+ import { PAGE_SIZE_LIMIT } from "../../../canvas/params.js";
6
+ import { parsePositiveInt } from "../../args.js";
7
+ import { formatTimestamp } from "../../elapsed.js";
8
+ import { renderTable, style } from "../../output.js";
9
+ import { hint } from "../../hints.js";
10
+ import { renderList, renderTeamList } from "./render.js";
11
+ import { sanitizeText } from "../../../text.js";
12
+ import { t } from "../../../i18n.js";
13
+ import { accountOf, apiOf, assertSpace, MAX_ALL_PAGES, requireAccountCredential, } from "./common.js";
14
+ async function teamOverview(ctx, config, flowToken) {
15
+ const credential = config.credential;
16
+ let result;
17
+ if (credential === null) {
18
+ result = {
19
+ teams: [],
20
+ error: t('canvas.teamsNoAccountCredential', { env: config.env }, ctx.deps.env),
21
+ };
22
+ }
23
+ else {
24
+ try {
25
+ const teams = await createTeamApi(ctx.deps, config, credential, flowToken).teams();
26
+ result = { teams, error: null };
27
+ }
28
+ catch (err) {
29
+ result = { teams: [], error: errorMessage(err) };
30
+ }
31
+ }
32
+ return result;
33
+ }
34
+ async function listAllPages(api, params) {
35
+ const items = [];
36
+ let total = 0;
37
+ for (let page = 1; page <= MAX_ALL_PAGES; page += 1) {
38
+ const chunk = await api.list({ ...params, page, pageSize: PAGE_SIZE_LIMIT });
39
+ total = chunk.total;
40
+ items.push(...chunk.items);
41
+ if (chunk.items.length < PAGE_SIZE_LIMIT || items.length >= total)
42
+ break;
43
+ }
44
+ return { items, total };
45
+ }
46
+ export async function canvasListCommand(ctx, options) {
47
+ const { deps } = ctx;
48
+ assertSpace(ctx, options.project !== undefined ? options.project : options.team);
49
+ if (options.team !== undefined && options.project !== undefined) {
50
+ throw new CliError('usage', t('canvas.teamWithProject', {}, deps.env));
51
+ }
52
+ const { api, config, flowToken } = await apiOf(ctx);
53
+ const pageSize = options.pageSize === undefined
54
+ ? 20
55
+ : parsePositiveInt(options.pageSize, '--page-size', deps.env);
56
+ if (pageSize > PAGE_SIZE_LIMIT) {
57
+ throw new CliError('usage', t('canvas.pageSizeTooLarge', { value: pageSize, limit: PAGE_SIZE_LIMIT }, deps.env));
58
+ }
59
+ let result;
60
+ if (options.team !== undefined) {
61
+ result = await listTeam(ctx, config, flowToken, options, pageSize);
62
+ }
63
+ else {
64
+ const base = { projectId: options.project, keyword: options.keyword };
65
+ const last = await ctx.store.readLastCanvas(config.env);
66
+ const now = deps.clock();
67
+ const lookup = async (rows) => {
68
+ const names = await collectNames(deps, config, api, rows, accountOf(config, flowToken));
69
+ if (names.error !== null) {
70
+ deps.stderr(`${style.warn('!')} ${t('canvas.namesUnavailable', { error: names.error }, deps.env)}\n`);
71
+ }
72
+ else {
73
+ }
74
+ return names.names;
75
+ };
76
+ if (options.all === true) {
77
+ const { items, total } = await listAllPages(api, base);
78
+ result = await renderList(ctx, items, await lookup(items), { total, page: 1, pageSize: Math.max(1, items.length) }, options.json === true, options.project === undefined && options.keyword === undefined
79
+ ? await teamOverview(ctx, config, flowToken)
80
+ : null, last, now);
81
+ }
82
+ else {
83
+ const page = options.page === undefined ? 1 : parsePositiveInt(options.page, '--page', deps.env);
84
+ const pageResult = await api.list({ ...base, page, pageSize });
85
+ const overview = page === 1 && options.project === undefined && options.keyword === undefined
86
+ ? await teamOverview(ctx, config, flowToken)
87
+ : null;
88
+ result = await renderList(ctx, pageResult.items, await lookup(pageResult.items), { total: pageResult.total, page, pageSize }, options.json === true, overview, last, now);
89
+ }
90
+ }
91
+ return result;
92
+ }
93
+ async function listTeam(ctx, config, flowToken, options, pageSize) {
94
+ const { deps } = ctx;
95
+ const credential = requireAccountCredential(config, deps.env);
96
+ const teamApi = createTeamApi(deps, config, credential, flowToken);
97
+ const teamId = options.team;
98
+ const collected = [];
99
+ const projectNames = new Map();
100
+ let projectCount = 0;
101
+ for (let p = 1; p <= MAX_ALL_PAGES; p += 1) {
102
+ const chunk = await teamApi.canvases(teamId, p, PAGE_SIZE_LIMIT);
103
+ collected.push(...chunk.canvases);
104
+ projectCount += chunk.projects.length;
105
+ for (const project of chunk.projects)
106
+ projectNames.set(project.id, project.name);
107
+ if (p >= chunk.pages)
108
+ break;
109
+ }
110
+ const page = options.page === undefined ? 1 : parsePositiveInt(options.page, '--page', deps.env);
111
+ const total = collected.length;
112
+ const pages = Math.max(1, Math.ceil(total / pageSize));
113
+ const visible = options.all === true ? collected : collected.slice((page - 1) * pageSize, page * pageSize);
114
+ let teamName = null;
115
+ try {
116
+ teamName = (await teamApi.teams()).find((x) => x.id === teamId)?.name ?? null;
117
+ }
118
+ catch {
119
+ teamName = null;
120
+ }
121
+ return renderTeamList(ctx, visible, {
122
+ total,
123
+ page: options.all === true ? 1 : page,
124
+ pages: options.all === true ? 1 : pages,
125
+ projectCount,
126
+ }, teamId, teamName, options.json === true, options.all === true, await ctx.store.readLastCanvas(config.env), deps.clock());
127
+ }
128
+ export async function canvasFolderListCommand(ctx, options) {
129
+ const { deps } = ctx;
130
+ requireSpace(ctx.entry, 'personal', deps.env);
131
+ const { api } = await apiOf(ctx);
132
+ const folders = await api.folders();
133
+ let result;
134
+ if (options.json === true) {
135
+ deps.stdout(`${JSON.stringify({ total: folders.length, items: folders }, null, 2)}\n`);
136
+ result = 0;
137
+ }
138
+ else if (folders.length === 0) {
139
+ deps.stdout(`${style.dim(t('canvas.folderEmpty', {}, deps.env))}\n`);
140
+ deps.stdout(`${style.dim(` ${t('canvas.folderEmptyHint', {}, deps.env)}`)}\n`);
141
+ result = 0;
142
+ }
143
+ else {
144
+ const hasCount = folders.some((f) => f.canvasCount !== null);
145
+ const columns = [
146
+ ['id', 'canvas.col.id'],
147
+ ['name', 'canvas.col.name'],
148
+ ['createdAt', 'canvas.col.createdAt'],
149
+ ];
150
+ const header = columns.map(([, key]) => t(key, {}, deps.env));
151
+ if (hasCount) {
152
+ header.push(t('canvas.col.canvases', {}, deps.env));
153
+ }
154
+ else {
155
+ }
156
+ const cells = folders.map((f) => [
157
+ f.id,
158
+ f.name === '' ? style.dim(t('canvas.unnamed', {}, deps.env)) : sanitizeText(f.name),
159
+ f.createdAt === null ? '' : formatTimestamp(f.createdAt),
160
+ ...(hasCount ? [f.canvasCount === null ? '' : String(f.canvasCount)] : []),
161
+ ]);
162
+ deps.stdout(`${style.bold(header.join(' '))}\n`);
163
+ deps.stdout(`${renderTable(cells)}\n`);
164
+ deps.stdout(`${style.dim(` ${t('canvas.folderCount', { count: folders.length }, deps.env)} · ${hint(ctx, 'canvas.folderHint', `canvas create <name> --folder <id>`)}`)}\n`);
165
+ result = 0;
166
+ }
167
+ return result;
168
+ }
@@ -0,0 +1,106 @@
1
+ import { t } from "../../../i18n.js";
2
+ import { runCommand } from "../../run.js";
3
+ import { canvasCloseCommand, canvasCreateCommand, canvasDeleteCommand, canvasFolderListCommand, canvasGetCommand, canvasListCommand, canvasProjectListCommand, canvasScreenshotCommand, canvasTeamListCommand, canvasUrlCommand, canvasUseCommand, } from "./index.js";
4
+ export function registerCanvas(program, deps, ctx) {
5
+ const canvas = program.command('canvas').description(t('cmd.canvas'));
6
+ addCanvasBrowse(canvas, deps, ctx);
7
+ addCanvasItem(canvas, deps, ctx);
8
+ }
9
+ function addCanvasBrowse(canvas, deps, ctx) {
10
+ canvas
11
+ .command('list')
12
+ .description(t('cmd.canvas.list'))
13
+ .option('--project <id>', t('opt.projectId'))
14
+ .option('--team <id>', t('opt.teamId'))
15
+ .option('--keyword <text>', t('opt.keyword'))
16
+ .option('--page <n>', t('opt.page'))
17
+ .option('--page-size <n>', t('opt.pageSize'))
18
+ .option('--all', t('opt.allPages'))
19
+ .option('--json', t('opt.json'))
20
+ .action(async (options) => {
21
+ process.exitCode = await runCommand(() => canvasListCommand(ctx(), options), deps);
22
+ });
23
+ const folder = canvas.command('folder').description(t('cmd.canvas.folder'));
24
+ folder
25
+ .command('list')
26
+ .description(t('cmd.canvas.folderList'))
27
+ .option('--json', t('opt.json'))
28
+ .action(async (options) => {
29
+ process.exitCode = await runCommand(() => canvasFolderListCommand(ctx(), options), deps);
30
+ });
31
+ const project = canvas.command('project').description(t('cmd.canvas.project'));
32
+ project
33
+ .command('list')
34
+ .description(t('cmd.canvas.projectList'))
35
+ .option('--team <id>', t('opt.teamId'))
36
+ .option('--json', t('opt.json'))
37
+ .action(async (options) => {
38
+ process.exitCode = await runCommand(() => canvasProjectListCommand(ctx(), options), deps);
39
+ });
40
+ const team = canvas.command('team').description(t('cmd.canvas.team'));
41
+ team
42
+ .command('list')
43
+ .description(t('cmd.canvas.teamList'))
44
+ .option('--json', t('opt.json'))
45
+ .action(async (options) => {
46
+ process.exitCode = await runCommand(() => canvasTeamListCommand(ctx(), options), deps);
47
+ });
48
+ }
49
+ function addCanvasItem(canvas, deps, ctx) {
50
+ canvas
51
+ .command('create <name>')
52
+ .description(t('cmd.canvas.create'))
53
+ .option('--project <id>', t('opt.projectId'))
54
+ .option('--folder <id>', t('opt.folderId'))
55
+ .option('--use', t('opt.useCanvas'))
56
+ .option('--json', t('opt.json'))
57
+ .action(async (name, options) => {
58
+ process.exitCode = await runCommand(() => canvasCreateCommand(ctx(), name, options), deps);
59
+ });
60
+ canvas
61
+ .command('get <id>')
62
+ .description(t('cmd.canvas.get'))
63
+ .option('--json', t('opt.json'))
64
+ .action(async (id, options) => {
65
+ process.exitCode = await runCommand(() => canvasGetCommand(ctx(), id, options), deps);
66
+ });
67
+ canvas
68
+ .command('use <id>')
69
+ .description(t('cmd.canvas.use'))
70
+ .option('--show', t('opt.canvasShow'))
71
+ .option('--json', t('opt.json'))
72
+ .action(async (id, options) => {
73
+ process.exitCode = await runCommand(() => canvasUseCommand(ctx(), id, options), deps);
74
+ });
75
+ canvas
76
+ .command('close')
77
+ .description(t('cmd.canvas.close'))
78
+ .option('--json', t('opt.json'))
79
+ .action(async (options) => {
80
+ process.exitCode = await runCommand(() => canvasCloseCommand(ctx(), options), deps);
81
+ });
82
+ canvas
83
+ .command('screenshot')
84
+ .description(t('cmd.canvas.screenshot'))
85
+ .option('--out <path>', t('opt.screenshotOut'))
86
+ .option('--json', t('opt.json'))
87
+ .action(async (options) => {
88
+ process.exitCode = await runCommand(() => canvasScreenshotCommand(ctx(), options), deps);
89
+ });
90
+ canvas
91
+ .command('url <id>')
92
+ .description(t('cmd.canvas.url'))
93
+ .option('--raw', t('opt.raw'))
94
+ .option('--json', t('opt.json'))
95
+ .action(async (id, options) => {
96
+ process.exitCode = await runCommand(() => canvasUrlCommand(ctx(), id, options), deps);
97
+ });
98
+ canvas
99
+ .command('delete <ids...>')
100
+ .description(t('cmd.canvas.delete'))
101
+ .option('--hard', t('opt.hardDelete'))
102
+ .option('--json', t('opt.json'))
103
+ .action(async (ids, options) => {
104
+ process.exitCode = await runCommand(() => canvasDeleteCommand(ctx(), ids, options), deps);
105
+ });
106
+ }
@@ -0,0 +1,229 @@
1
+ import { t } from "../../../i18n.js";
2
+ import { renderTable, style } from "../../output.js";
3
+ import { cmdPrefix } from "../../hints.js";
4
+ import { sanitizeText } from "../../../text.js";
5
+ import { elapsedSince } from "../../elapsed.js";
6
+ import { pageInfoOf } from "../../args.js";
7
+ const COLUMNS = [
8
+ ['id', 'canvas.col.id'],
9
+ ['name', 'canvas.col.name'],
10
+ ['teamId', 'canvas.col.teamId'],
11
+ ['teamName', 'canvas.col.teamName'],
12
+ ['projectId', 'canvas.col.projectId'],
13
+ ['projectName', 'canvas.col.projectName'],
14
+ ['folderId', 'canvas.col.folderId'],
15
+ ['folderName', 'canvas.col.folderName'],
16
+ ];
17
+ const ALWAYS_SHOWN = new Set(['id', 'name']);
18
+ function renderRows(ctx, rows, last, now) {
19
+ const { deps } = ctx;
20
+ const visible = COLUMNS.filter(([key]) => ALWAYS_SHOWN.has(key) || rows.some((row) => has(row[key])));
21
+ const header = visible.map(([, key]) => t(key, {}, deps.env));
22
+ const body = rows.map((row) => visible.map(([key], i) => {
23
+ const text = cellText(row, key, deps.env);
24
+ return i === visible.length - 1 ? text + lastUsedLabel(row.id, last, now, deps.env) : text;
25
+ }));
26
+ deps.stdout(`${style.bold(header.join(' '))}\n`);
27
+ deps.stdout(`${renderTable(body)}\n`);
28
+ }
29
+ function has(value) {
30
+ return value !== null && value !== '';
31
+ }
32
+ export function nameOf(table, id) {
33
+ let result;
34
+ if (id === null) {
35
+ result = null;
36
+ }
37
+ else {
38
+ result = table.get(id) ?? null;
39
+ }
40
+ return result;
41
+ }
42
+ function cellText(row, key, envMap) {
43
+ let result;
44
+ if (key === 'name' && row.name === '') {
45
+ result = style.dim(t('canvas.unnamed', {}, envMap));
46
+ }
47
+ else {
48
+ const value = row[key];
49
+ result = value === null ? '' : sanitizeText(value);
50
+ }
51
+ return result;
52
+ }
53
+ function lastUsedLabel(id, last, now, envMap) {
54
+ let result;
55
+ if (last === null || last.id !== id) {
56
+ result = '';
57
+ }
58
+ else {
59
+ result = ` ${style.dim(t('canvas.lastUsedTag', { ago: agoText(last.at, now, envMap) }, envMap))}`;
60
+ }
61
+ return result;
62
+ }
63
+ export function agoText(at, now, envMap) {
64
+ const e = elapsedSince(at, now);
65
+ const key = `canvas.ago.${e.unit}`;
66
+ return e.value === 0 ? t('canvas.ago.justNow', {}, envMap) : t(key, { n: e.value }, envMap);
67
+ }
68
+ export function renderTeamList(ctx, items, meta, teamId, teamName, json, all, last, now) {
69
+ const { deps } = ctx;
70
+ let result;
71
+ if (json) {
72
+ deps.stdout(`${JSON.stringify({
73
+ team: teamId,
74
+ teamName,
75
+ total: meta.total,
76
+ projectCount: meta.projectCount,
77
+ page: meta.page,
78
+ pages: meta.pages,
79
+ items: items.map((g) => ({
80
+ id: g.id,
81
+ name: g.name,
82
+ teamId,
83
+ teamName,
84
+ projectId: g.projectId,
85
+ projectName: g.projectName,
86
+ folderId: null,
87
+ folderName: null,
88
+ ...(last !== null && last.id === g.id ? { lastUsedAt: last.at } : {}),
89
+ })),
90
+ }, null, 2)}\n`);
91
+ result = 0;
92
+ }
93
+ else if (items.length === 0) {
94
+ deps.stdout(`${style.dim(t('canvas.listEmpty', {}, deps.env))}\n`);
95
+ deps.stdout(`${style.dim(` ${t('canvas.teamProjectCount', { count: meta.projectCount }, deps.env)}`)}\n`);
96
+ result = 0;
97
+ }
98
+ else {
99
+ const rows = items.map((g) => ({
100
+ id: g.id,
101
+ name: g.name,
102
+ teamId,
103
+ teamName,
104
+ projectId: g.projectId,
105
+ projectName: g.projectName,
106
+ folderId: null,
107
+ folderName: null,
108
+ }));
109
+ renderRows(ctx, rows, last, now);
110
+ const parts = [
111
+ t('canvas.total', { total: meta.total }, deps.env),
112
+ t('canvas.teamProjectCount', { count: meta.projectCount }, deps.env),
113
+ ...(all ? [] : [t('canvas.pageOf', { page: meta.page, pages: meta.pages }, deps.env)]),
114
+ ];
115
+ deps.stdout(`${style.dim(` ${parts.join(' · ')}`)}\n`);
116
+ if (!all && meta.page < meta.pages) {
117
+ deps.stdout(`${style.dim(` ${t('canvas.nextPage', { page: meta.page + 1 }, deps.env)}: ${cmdPrefix(ctx)}canvas list --team ${teamId} --page ${meta.page + 1}`)}\n`);
118
+ }
119
+ else {
120
+ }
121
+ result = 0;
122
+ }
123
+ return result;
124
+ }
125
+ export function renderList(ctx, items, names, meta, json, overview, last, now) {
126
+ const { deps } = ctx;
127
+ const info = pageInfoOf(meta.total, meta.page, meta.pageSize);
128
+ let result;
129
+ if (json) {
130
+ deps.stdout(`${JSON.stringify({
131
+ total: info.total,
132
+ page: info.page,
133
+ pageSize: info.pageSize,
134
+ pages: info.pages,
135
+ next: info.next,
136
+ items: items.map((g) => ({
137
+ ...serializeItem(g),
138
+ teamName: nameOf(names.teams, g.teamId),
139
+ projectName: nameOf(names.projects, g.projectId),
140
+ folderName: nameOf(names.folders, g.folderId),
141
+ ...(last !== null && last.id === g.id ? { lastUsedAt: last.at } : {}),
142
+ })),
143
+ ...(overview === null
144
+ ? {}
145
+ : {
146
+ teams: overview.teams.map((x) => ({
147
+ id: x.id,
148
+ name: x.name,
149
+ role: x.role,
150
+ projectCount: x.projectCount,
151
+ canvasCount: x.canvasCount,
152
+ })),
153
+ ...(overview.error === null ? {} : { teamsError: overview.error }),
154
+ }),
155
+ }, null, 2)}\n`);
156
+ result = 0;
157
+ }
158
+ else if (items.length === 0) {
159
+ deps.stdout(`${style.dim(t('canvas.listEmpty', {}, deps.env))}\n`);
160
+ deps.stdout(`${style.dim(` ${t('canvas.total', { total: info.total }, deps.env)} · ${t('canvas.pageOf', { page: info.page, pages: info.pages }, deps.env)}`)}\n`);
161
+ if (overview !== null) {
162
+ printTeamHint(ctx, overview);
163
+ }
164
+ else {
165
+ }
166
+ result = 0;
167
+ }
168
+ else {
169
+ const rows = items.map((g) => ({
170
+ id: g.id,
171
+ name: g.name,
172
+ teamId: g.teamId,
173
+ teamName: nameOf(names.teams, g.teamId),
174
+ projectId: g.projectId,
175
+ projectName: nameOf(names.projects, g.projectId),
176
+ folderId: g.folderId,
177
+ folderName: nameOf(names.folders, g.folderId),
178
+ }));
179
+ renderRows(ctx, rows, last, now);
180
+ const parts = [
181
+ t('canvas.total', { total: info.total }, deps.env),
182
+ t('canvas.pageOf', { page: info.page, pages: info.pages }, deps.env),
183
+ ];
184
+ deps.stdout(`${style.dim(` ${parts.join(' · ')}`)}\n`);
185
+ if (info.next !== null) {
186
+ deps.stdout(`${style.dim(` ${t('canvas.nextPage', { page: info.next }, deps.env)}: ${cmdPrefix(ctx)}canvas list --page ${info.next}`)}\n`);
187
+ }
188
+ else {
189
+ }
190
+ if (overview !== null) {
191
+ printTeamHint(ctx, overview);
192
+ }
193
+ else {
194
+ }
195
+ result = 0;
196
+ }
197
+ return result;
198
+ }
199
+ function printTeamHint(ctx, overview) {
200
+ const { deps } = ctx;
201
+ if (overview.error !== null) {
202
+ deps.stdout(`${style.dim(` ${t('canvas.teamsUnavailable', { error: overview.error }, deps.env)}`)}\n`);
203
+ }
204
+ else if (overview.teams.length > 0) {
205
+ deps.stdout(`${style.bold(t('canvas.teamsHeader', {}, deps.env))}\n`);
206
+ const rows = overview.teams.map((x) => [
207
+ x.id,
208
+ x.name === '' ? style.dim(t('canvas.unnamed', {}, deps.env)) : sanitizeText(x.name),
209
+ ]);
210
+ deps.stdout(`${renderTable(rows)}\n`);
211
+ deps.stdout(`${style.dim(` ${t('canvas.teamsHint', {}, deps.env)}: ${cmdPrefix(ctx)}canvas list --team <id>`)}\n`);
212
+ deps.stdout(`${style.dim(` ${t('canvas.teamsMoreHint', {}, deps.env)}: ${cmdPrefix(ctx)}canvas team list`)}\n`);
213
+ }
214
+ else {
215
+ }
216
+ }
217
+ export function serializeItem(g) {
218
+ return {
219
+ id: g.id,
220
+ name: g.name,
221
+ type: g.graphType,
222
+ projectId: g.projectId,
223
+ teamId: g.teamId,
224
+ folderId: g.folderId,
225
+ createdAt: g.createdAt,
226
+ updatedAt: g.updatedAt,
227
+ deletedAt: g.deletedAt,
228
+ };
229
+ }
@@ -0,0 +1,52 @@
1
+ import { CliError, errorMessage } from "../../../errors.js";
2
+ import { saveScreenshot } from "../../../canvas/screenshot.js";
3
+ import { resolveEnvName } from "../../../config/resolve.js";
4
+ import { connectSession, touchSession } from "../../session.js";
5
+ import { style } from "../../output.js";
6
+ import { t } from "../../../i18n.js";
7
+ const MANUAL_SCREENSHOT_REASON = 'manual';
8
+ export async function canvasScreenshotCommand(ctx, options) {
9
+ const { deps } = ctx;
10
+ const opened = await connectSession(ctx);
11
+ try {
12
+ const png = await opened.browser.screenshot();
13
+ if (png === null) {
14
+ throw new CliError('config', t('canvas.notOpened', {}, deps.env));
15
+ }
16
+ const path = await writeShot(ctx, opened.id, png, options.out);
17
+ await touchSession(ctx, opened);
18
+ if (options.json === true) {
19
+ deps.stdout(`${JSON.stringify({ id: opened.id, path, bytes: png.length }, null, 2)}\n`);
20
+ }
21
+ else {
22
+ deps.stdout(`${style.ok('✓')} ${t('canvas.shotSaved', { path }, deps.env)}\n`);
23
+ }
24
+ return 0;
25
+ }
26
+ finally {
27
+ await opened.browser.close();
28
+ }
29
+ }
30
+ async function writeShot(ctx, canvasId, png, out) {
31
+ let result;
32
+ if (out === undefined) {
33
+ const env = await resolveEnvName(ctx.envFlag, ctx.deps, ctx.paths);
34
+ const saved = await saveScreenshot({ fs: ctx.deps.fs, clock: ctx.deps.clock, dir: ctx.paths.screenshotsDir(env) }, { canvasId, reason: MANUAL_SCREENSHOT_REASON, png });
35
+ if (saved === null) {
36
+ throw new CliError('config', t('canvas.shotWriteFailed', {}, ctx.deps.env));
37
+ }
38
+ result = saved;
39
+ }
40
+ else {
41
+ try {
42
+ await ctx.deps.fs.writeFile(out, png, { mode: 0o600 });
43
+ }
44
+ catch (err) {
45
+ throw new CliError('config', t('canvas.shotWriteFailed', {}, ctx.deps.env), {
46
+ detail: err.code ?? errorMessage(err),
47
+ });
48
+ }
49
+ result = out;
50
+ }
51
+ return result;
52
+ }