@artis-lab/cli 0.7.0 → 0.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artis-lab/cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Agent-first CLI for publishing, reviewing, and revising self-contained HTML artifacts on an Artis server.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/lib/cli.js CHANGED
@@ -13,6 +13,7 @@ function isRootAnnotation(annotation) {
13
13
  return annotation.motivation === 'commenting';
14
14
  }
15
15
  import { ARTIS_DEFAULT_HOST, findProfileForHost, getConfigPath, normalizeHost, readCliConfig, saveDefaultProfile, } from './config.js';
16
+ import { getRememberedBase, rememberBase } from './revision-bases.js';
16
17
  import { installSkillFromCli } from './skill-install.js';
17
18
  import { artisCliVersion } from './version.js';
18
19
  import { collectFlagValues, hasFlag, parseFlagValue } from './args.js';
@@ -414,7 +415,7 @@ Options:
414
415
  --kind <value> Artifact kind. Defaults to custom-html.
415
416
  --author <name> Artifact author/agent name. Defaults to Artis CLI.
416
417
  --summary <text> Revision summary. Write one change per line; they render as a list.
417
- --base <revision-id> Revision the file was edited from (printed by publish and artifact html). Refuses the revise if someone revised since.
418
+ --base <revision-id> Revision the file was edited from. Defaults to the revision this machine last published, read (artifact html), or revised. Refuses the revise if someone revised since.
418
419
  --resolve <annotation-id> Mark an annotation resolved when revising. Repeatable.
419
420
  --comment <text> Annotation or reply comment text (annotate, reply).
420
421
  --requested-change <text> Structured change request for the artifact author (annotate).
@@ -480,6 +481,7 @@ export function publishArtifactFromCli(args) {
480
481
  if (!(result === null || result === void 0 ? void 0 : result.result)) {
481
482
  throw new Error('Publish response did not include artifact details.');
482
483
  }
484
+ yield rememberBase(options.baseUrl, [result.result.artifactId, result.result.slug], result.result.revisionId);
483
485
  return {
484
486
  artifactId: result.result.artifactId,
485
487
  revisionId: result.result.revisionId,
@@ -591,6 +593,11 @@ export function getArtifactHtmlFromCli(args) {
591
593
  ? `?revisionId=${encodeURIComponent(revisionId)}`
592
594
  : '';
593
595
  const result = yield apiFetchOptional(target, `/api/artifacts/${encodeURIComponent(artifactId)}/html${query}`);
596
+ // Whatever was read is what an edit of it builds on: `revise` sends it as
597
+ // the base, so a revision landing in between is refused, not overwritten.
598
+ if (result === null || result === void 0 ? void 0 : result.revisionId) {
599
+ yield rememberBase(target.baseUrl, [artifactId, result.artifactId], result.revisionId);
600
+ }
594
601
  if (hasFlag(args, '--json')) {
595
602
  console.log(JSON.stringify(result, null, 2));
596
603
  return;
@@ -698,17 +705,22 @@ export function reviseArtifactFromCli(args) {
698
705
  if (!html.toLowerCase().includes('<html')) {
699
706
  throw new Error('Revision file must be self-contained HTML including <html>.');
700
707
  }
708
+ const explicitBase = parseFlagValue(args, '--base');
709
+ const baseRevisionId = explicitBase !== null && explicitBase !== void 0 ? explicitBase : (yield getRememberedBase(credentials.baseUrl, artifactId));
701
710
  const result = yield apiFetch(credentials, `/api/artifacts/${encodeURIComponent(artifactId)}/revisions`, {
702
711
  method: 'POST',
703
712
  body: JSON.stringify({
704
713
  authorName: (_a = parseFlagValue(args, '--author')) !== null && _a !== void 0 ? _a : 'Artis CLI',
705
714
  html,
706
- baseRevisionId: parseFlagValue(args, '--base'),
715
+ baseRevisionId,
707
716
  resolvedAnnotationIds: collectFlagValues(args, '--resolve'),
708
717
  source: 'cli',
709
718
  summary,
710
719
  }),
711
720
  });
721
+ if (result === null || result === void 0 ? void 0 : result.revision) {
722
+ yield rememberBase(credentials.baseUrl, [artifactId], result.revision.id, baseRevisionId);
723
+ }
712
724
  if (hasFlag(args, '--json')) {
713
725
  console.log(JSON.stringify(result, null, 2));
714
726
  return;
@@ -718,6 +730,12 @@ export function reviseArtifactFromCli(args) {
718
730
  }
719
731
  console.log(`Revision ${result.revision.id}`);
720
732
  console.log(`Version ${result.revision.version}`);
733
+ if (baseRevisionId && !explicitBase) {
734
+ console.log(`Base ${baseRevisionId} (remembered from this machine)`);
735
+ }
736
+ else if (!baseRevisionId) {
737
+ console.log('No base revision: pass --base, or read the artifact with publish or artifact html first, so a concurrent revision is refused instead of overwritten.');
738
+ }
721
739
  });
722
740
  }
723
741
  export function createAnnotationFromCli(args) {
@@ -0,0 +1,10 @@
1
+ export declare function getRevisionBasesPath(): string;
2
+ export declare function getRememberedBase(host: string, artifactIdOrSlug: string): Promise<string | undefined>;
3
+ /**
4
+ * Remember `revisionId` as the base for every name in `artifactKeys`. When
5
+ * `supersedes` is given (a revise built on that revision), entries for this
6
+ * host still pointing at it move forward too — the artifact may have been
7
+ * pulled by id and revised by slug. Best-effort: bookkeeping must never fail
8
+ * the command that produced it.
9
+ */
10
+ export declare function rememberBase(host: string, artifactKeys: Array<string | undefined>, revisionId: string, supersedes?: string): Promise<void>;
@@ -0,0 +1,75 @@
1
+ import { __awaiter } from "tslib";
2
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
+ import { dirname, join } from 'node:path';
4
+ import { getConfigPath, normalizeHost } from './config.js';
5
+ /** Oldest entries are dropped past this, so the file cannot grow unbounded. */
6
+ const MAX_ENTRIES = 500;
7
+ export function getRevisionBasesPath() {
8
+ return join(dirname(getConfigPath()), 'revision-bases.json');
9
+ }
10
+ /** Keyed by host + the id or slug, since either can name an artifact. */
11
+ function entryKey(host, artifactIdOrSlug) {
12
+ return `${normalizeHost(host)} ${artifactIdOrSlug}`;
13
+ }
14
+ function readBases() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ var _a;
17
+ try {
18
+ const parsed = JSON.parse(yield readFile(getRevisionBasesPath(), 'utf8'));
19
+ return { bases: (_a = parsed.bases) !== null && _a !== void 0 ? _a : {} };
20
+ }
21
+ catch (_b) {
22
+ return { bases: {} };
23
+ }
24
+ });
25
+ }
26
+ function writeBases(file) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const entries = Object.entries(file.bases)
29
+ .sort(([, a], [, b]) => b.recordedAt.localeCompare(a.recordedAt))
30
+ .slice(0, MAX_ENTRIES);
31
+ const path = getRevisionBasesPath();
32
+ yield mkdir(dirname(path), { mode: 0o700, recursive: true });
33
+ yield writeFile(path, `${JSON.stringify({ bases: Object.fromEntries(entries) }, null, 2)}\n`, { mode: 0o600 });
34
+ });
35
+ }
36
+ export function getRememberedBase(host, artifactIdOrSlug) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ var _a;
39
+ const file = yield readBases();
40
+ return (_a = file.bases[entryKey(host, artifactIdOrSlug)]) === null || _a === void 0 ? void 0 : _a.revisionId;
41
+ });
42
+ }
43
+ /**
44
+ * Remember `revisionId` as the base for every name in `artifactKeys`. When
45
+ * `supersedes` is given (a revise built on that revision), entries for this
46
+ * host still pointing at it move forward too — the artifact may have been
47
+ * pulled by id and revised by slug. Best-effort: bookkeeping must never fail
48
+ * the command that produced it.
49
+ */
50
+ export function rememberBase(host, artifactKeys, revisionId, supersedes) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ const file = yield readBases();
54
+ const recordedAt = new Date().toISOString();
55
+ const hostPrefix = `${normalizeHost(host)} `;
56
+ if (supersedes) {
57
+ for (const [key, entry] of Object.entries(file.bases)) {
58
+ if (key.startsWith(hostPrefix) && entry.revisionId === supersedes) {
59
+ file.bases[key] = { revisionId, recordedAt };
60
+ }
61
+ }
62
+ }
63
+ for (const artifactKey of artifactKeys) {
64
+ if (artifactKey) {
65
+ file.bases[entryKey(host, artifactKey)] = { revisionId, recordedAt };
66
+ }
67
+ }
68
+ yield writeBases(file);
69
+ }
70
+ catch (_a) {
71
+ // Without a remembered base, revise still works; the agent passes --base.
72
+ }
73
+ });
74
+ }
75
+ //# sourceMappingURL=revision-bases.js.map
@@ -1,10 +1,12 @@
1
1
  /**
2
- * The agent skill installed by `artis install-skill`: a compact guide to the
3
- * publish → review → revise loop using this CLI. Keep roughly in sync with
4
- * `getCliHelp()` and the server-side agent guidance in
5
- * `apps/app/src/worker/lib/skills.ts`.
2
+ * The agent skill installed by `artis install-skill`. Deliberately a router:
3
+ * it decides when to use Artis and which workflow applies, and defers every
4
+ * authoring rule and command detail to `artis guidelines`, which reads the
5
+ * server's current guidelines (`packages/sdk/src/lib/guidelines.ts`). An
6
+ * installed skill is never updated in place, so anything that changes over
7
+ * time belongs in the guidelines, not here.
6
8
  */
7
- export declare const ARTIS_SKILL_MD = "---\nname: artis\ndescription: >-\n Publish, review, and revise self-contained HTML artifacts on an Artis server\n with the artis CLI. Use when the deliverable should be an interactive page\n humans open in a browser (dashboards, timelines, prototypes, reports) rather\n than a markdown dump.\n---\n\n# Artis\n\nHost, share, and revise **self-contained HTML artifacts** at stable URLs.\n\n**Loop:** publish \u2192 get feedback \u2192 revise (optionally resolving annotations).\n\n## Setup\n\n npm install -g @artis-lab/cli\n artis login --host <url> # required before publishing\n artis whoami # verify credentials\n\n`artis login` opens a browser approval flow and stores the API key in `~/.artis/config.json`; never ask the user for a password. Hosts default to https://artis.xiispace.eu.org. Override with `--host`, `ARTIS_URL`, or a saved login \u2014 a self-hosted user never wants the default.\n\n## Commands\n\n artis publish artifact.html [--visibility unlisted|public|private] [--kind <kind>] [--title <t>] [--author <name>]\n artis artifact get <id-or-slug> [--json]\n artis artifact feedback <id-or-slug> [--json] [--revision <id>]\n artis artifact html <id-or-slug> [--output <path>] [--revision <id>]\n artis revise <id-or-slug> revised.html --summary \"...\" --base <revision-id> [--resolve <annotation-id>]...\n artis guidelines [section]\n artis annotate <id-or-slug> --comment \"...\" [--quote \"...\"] [--requested-change \"...\"] [--status open|needs-revision|resolved]\n artis reply <annotation-id> --comment \"...\"\n artis annotation edit <annotation-id> [--comment \"...\"] [--title \"...\"] [--requested-change \"...\"]\n artis annotation retract <annotation-id>\n artis share <id-or-slug> --email a@b.com --role viewer|commenter [--remove]\n\nRun `artis help` for the full flag reference.\n\n## Workflow\n\n1. Publish with the default `unlisted` visibility unless the user asks for public or private. Return the artifact URL and a short summary.\n2. Gather feedback with `artis artifact feedback <id>`; the printed prompt lists open annotations with their ids.\n3. Revise with a complete replacement document, passing `--base <revision-id>` (the revision you edited, printed by `publish` and `artifact html`) and `--resolve <annotation-id>` for each addressed annotation. If the file is no longer on disk, pull the current source first: `artis artifact html <id> --output revised.html`, edit it, then `artis revise`. A conflict means someone revised since: pull the current revision, reapply your changes, and retry with its id. Write the `--summary` one change per line.\n4. For authoring rules beyond this file, run `artis guidelines` (index) and `artis guidelines <section>`.\n\n## Authoring rules\n\n- Self-contained HTML with inline CSS and small scripts; avoid external dependencies unless asked.\n- Prefer visual structure (cards, timelines, diagrams) over long prose; semantic, responsive markup.\n- Theme via `prefers-color-scheme`; interactive artifacts should offer copy/export so users can paste changes back to you.\n- On failure, show the HTTP status and response body once; do not retry blindly.\n";
9
+ export declare const ARTIS_SKILL_MD = "---\nname: artis\ndescription: >-\n Use for any Artis task: whenever the user mentions Artis, shares an Artis\n artifact link, or asks about an Artis artifact's feedback, annotations,\n revisions, or sharing; and to publish a deliverable that is better as an\n interactive page humans open in a browser (report, dashboard, timeline,\n postmortem, plan, prototype, review) than as a markdown dump.\n---\n\n# Artis\n\nArtis hosts self-contained HTML artifacts at stable URLs for a publish \u2192 review \u2192 revise loop. Use the `artis` CLI for every Artis action. If Artis MCP tools are already available in this session, you may use them instead; they share the same server and guidelines.\n\n## First rule: read the guidelines before authoring\n\nBefore writing, publishing, or revising an artifact in a session, run:\n\n artis guidelines # index of sections\n artis guidelines authoring # what a good artifact looks like\n artis guidelines revising # before any revise\n\nTreat that output as the source of truth for authoring rules and command syntax; it is served by the Artis server and stays current, while this file does not. `artis guidelines cli` and `artis help` give the full command reference.\n\n## Workflows\n\n### Someone shares an Artis link or names an artifact\n\nDo not curl or web-fetch the page: it is an app shell, and private artifacts are served only through signed URLs. Use the CLI with the id or slug from the link (`/artifacts/<slug>`):\n\n1. `artis artifact get <id-or-slug>` for metadata and revisions; `artis artifact feedback <id-or-slug>` for open review threads.\n2. `artis artifact html <id-or-slug> --output <file>` when you need the source.\n3. Do what was asked, then report the result or URL.\n\n### New deliverable\n\n1. Read `artis guidelines authoring` if you have not in this session.\n2. Write one self-contained HTML file and save it locally.\n3. `artis publish <file>` \u2014 `unlisted` unless the user asks for public or private.\n4. Return the printed URL with a one-line summary.\n\n### Revising an existing artifact\n\nRevise it; never publish a second artifact for the same work.\n\n1. Read `artis guidelines revising` if you have not in this session.\n2. `artis artifact feedback <id-or-slug>` for the open annotations and their ids.\n3. If the current source is not on disk, `artis artifact html <id-or-slug> --output <file>`.\n4. Edit the file, then `artis revise <id-or-slug> <file> --summary \"...\" --resolve <annotation-id>` (one change per summary line). The CLI sends the revision it last saw as the base; a conflict means someone revised since \u2014 pull the current source, reapply your changes, and revise again.\n\n## When not to publish\n\nDo not publish to Artis if the user asks for Markdown, plain text, a PDF, an answer in chat, or another destination. You may still use the CLI to read an Artis artifact they mention.\n\n## Setup and auth\n\n npm install -g @artis-lab/cli\n artis login --host <url> # browser approval; stores an API key\n artis whoami\n\nNever ask the user for a password. Hosts default to https://artis.xiispace.eu.org; pass `--host` or set `ARTIS_URL` for a self-hosted server. If a command reports missing or invalid credentials, run `artis login` and retry once; if login cannot complete here, say so and ask the user to authenticate. On any other failure, show the HTTP status and error once; do not retry blindly.\n";
8
10
  export interface SkillHarnessDefinition {
9
11
  /** Canonical id accepted by `--harness` and printed by `--list`. */
10
12
  id: string;
@@ -7,63 +7,74 @@ import { collectFlagValues, hasFlag, parseFlagValue } from './args.js';
7
7
  /** Directory the skill installs under, inside each harness's skills dir. */
8
8
  const SKILL_DIR_NAME = 'artis';
9
9
  /**
10
- * The agent skill installed by `artis install-skill`: a compact guide to the
11
- * publish → review → revise loop using this CLI. Keep roughly in sync with
12
- * `getCliHelp()` and the server-side agent guidance in
13
- * `apps/app/src/worker/lib/skills.ts`.
10
+ * The agent skill installed by `artis install-skill`. Deliberately a router:
11
+ * it decides when to use Artis and which workflow applies, and defers every
12
+ * authoring rule and command detail to `artis guidelines`, which reads the
13
+ * server's current guidelines (`packages/sdk/src/lib/guidelines.ts`). An
14
+ * installed skill is never updated in place, so anything that changes over
15
+ * time belongs in the guidelines, not here.
14
16
  */
15
17
  export const ARTIS_SKILL_MD = `---
16
18
  name: artis
17
19
  description: >-
18
- Publish, review, and revise self-contained HTML artifacts on an Artis server
19
- with the artis CLI. Use when the deliverable should be an interactive page
20
- humans open in a browser (dashboards, timelines, prototypes, reports) rather
21
- than a markdown dump.
20
+ Use for any Artis task: whenever the user mentions Artis, shares an Artis
21
+ artifact link, or asks about an Artis artifact's feedback, annotations,
22
+ revisions, or sharing; and to publish a deliverable that is better as an
23
+ interactive page humans open in a browser (report, dashboard, timeline,
24
+ postmortem, plan, prototype, review) than as a markdown dump.
22
25
  ---
23
26
 
24
27
  # Artis
25
28
 
26
- Host, share, and revise **self-contained HTML artifacts** at stable URLs.
29
+ Artis hosts self-contained HTML artifacts at stable URLs for a publish → review → revise loop. Use the \`artis\` CLI for every Artis action. If Artis MCP tools are already available in this session, you may use them instead; they share the same server and guidelines.
27
30
 
28
- **Loop:** publish → get feedback → revise (optionally resolving annotations).
31
+ ## First rule: read the guidelines before authoring
29
32
 
30
- ## Setup
33
+ Before writing, publishing, or revising an artifact in a session, run:
31
34
 
32
- npm install -g @artis-lab/cli
33
- artis login --host <url> # required before publishing
34
- artis whoami # verify credentials
35
+ artis guidelines # index of sections
36
+ artis guidelines authoring # what a good artifact looks like
37
+ artis guidelines revising # before any revise
38
+
39
+ Treat that output as the source of truth for authoring rules and command syntax; it is served by the Artis server and stays current, while this file does not. \`artis guidelines cli\` and \`artis help\` give the full command reference.
40
+
41
+ ## Workflows
42
+
43
+ ### Someone shares an Artis link or names an artifact
44
+
45
+ Do not curl or web-fetch the page: it is an app shell, and private artifacts are served only through signed URLs. Use the CLI with the id or slug from the link (\`/artifacts/<slug>\`):
35
46
 
36
- \`artis login\` opens a browser approval flow and stores the API key in \`~/.artis/config.json\`; never ask the user for a password. Hosts default to https://artis.xiispace.eu.org. Override with \`--host\`, \`ARTIS_URL\`, or a saved login — a self-hosted user never wants the default.
47
+ 1. \`artis artifact get <id-or-slug>\` for metadata and revisions; \`artis artifact feedback <id-or-slug>\` for open review threads.
48
+ 2. \`artis artifact html <id-or-slug> --output <file>\` when you need the source.
49
+ 3. Do what was asked, then report the result or URL.
37
50
 
38
- ## Commands
51
+ ### New deliverable
39
52
 
40
- artis publish artifact.html [--visibility unlisted|public|private] [--kind <kind>] [--title <t>] [--author <name>]
41
- artis artifact get <id-or-slug> [--json]
42
- artis artifact feedback <id-or-slug> [--json] [--revision <id>]
43
- artis artifact html <id-or-slug> [--output <path>] [--revision <id>]
44
- artis revise <id-or-slug> revised.html --summary "..." --base <revision-id> [--resolve <annotation-id>]...
45
- artis guidelines [section]
46
- artis annotate <id-or-slug> --comment "..." [--quote "..."] [--requested-change "..."] [--status open|needs-revision|resolved]
47
- artis reply <annotation-id> --comment "..."
48
- artis annotation edit <annotation-id> [--comment "..."] [--title "..."] [--requested-change "..."]
49
- artis annotation retract <annotation-id>
50
- artis share <id-or-slug> --email a@b.com --role viewer|commenter [--remove]
53
+ 1. Read \`artis guidelines authoring\` if you have not in this session.
54
+ 2. Write one self-contained HTML file and save it locally.
55
+ 3. \`artis publish <file>\` — \`unlisted\` unless the user asks for public or private.
56
+ 4. Return the printed URL with a one-line summary.
51
57
 
52
- Run \`artis help\` for the full flag reference.
58
+ ### Revising an existing artifact
53
59
 
54
- ## Workflow
60
+ Revise it; never publish a second artifact for the same work.
55
61
 
56
- 1. Publish with the default \`unlisted\` visibility unless the user asks for public or private. Return the artifact URL and a short summary.
57
- 2. Gather feedback with \`artis artifact feedback <id>\`; the printed prompt lists open annotations with their ids.
58
- 3. Revise with a complete replacement document, passing \`--base <revision-id>\` (the revision you edited, printed by \`publish\` and \`artifact html\`) and \`--resolve <annotation-id>\` for each addressed annotation. If the file is no longer on disk, pull the current source first: \`artis artifact html <id> --output revised.html\`, edit it, then \`artis revise\`. A conflict means someone revised since: pull the current revision, reapply your changes, and retry with its id. Write the \`--summary\` one change per line.
59
- 4. For authoring rules beyond this file, run \`artis guidelines\` (index) and \`artis guidelines <section>\`.
62
+ 1. Read \`artis guidelines revising\` if you have not in this session.
63
+ 2. \`artis artifact feedback <id-or-slug>\` for the open annotations and their ids.
64
+ 3. If the current source is not on disk, \`artis artifact html <id-or-slug> --output <file>\`.
65
+ 4. Edit the file, then \`artis revise <id-or-slug> <file> --summary "..." --resolve <annotation-id>\` (one change per summary line). The CLI sends the revision it last saw as the base; a conflict means someone revised since — pull the current source, reapply your changes, and revise again.
60
66
 
61
- ## Authoring rules
67
+ ## When not to publish
68
+
69
+ Do not publish to Artis if the user asks for Markdown, plain text, a PDF, an answer in chat, or another destination. You may still use the CLI to read an Artis artifact they mention.
70
+
71
+ ## Setup and auth
72
+
73
+ npm install -g @artis-lab/cli
74
+ artis login --host <url> # browser approval; stores an API key
75
+ artis whoami
62
76
 
63
- - Self-contained HTML with inline CSS and small scripts; avoid external dependencies unless asked.
64
- - Prefer visual structure (cards, timelines, diagrams) over long prose; semantic, responsive markup.
65
- - Theme via \`prefers-color-scheme\`; interactive artifacts should offer copy/export so users can paste changes back to you.
66
- - On failure, show the HTTP status and response body once; do not retry blindly.
77
+ Never ask the user for a password. Hosts default to https://artis.xiispace.eu.org; pass \`--host\` or set \`ARTIS_URL\` for a self-hosted server. If a command reports missing or invalid credentials, run \`artis login\` and retry once; if login cannot complete here, say so and ask the user to authenticate. On any other failure, show the HTTP status and error once; do not retry blindly.
67
78
  `;
68
79
  /** Hermes keeps its config under $HERMES_HOME when set, otherwise
69
80
  * `%LOCALAPPDATA%\hermes` on Windows and `~/.hermes` elsewhere — mirroring