gipity 1.1.42 → 1.1.44

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.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * changelog.ts - what's new in Gipity, read from the server's GET /changelog
3
+ * (platform/CHANGELOG.md), plus the small machine-level memory of what this
4
+ * user has already seen (~/.gipity/changelog.json):
5
+ *
6
+ * { "baselineCli": "1.1.42", CLI version when this file was first written;
7
+ * `--newer` starts here until something is seen
8
+ * "seenEntry": "2026-11-18-scoped-api-keys",
9
+ * "seenDate": "2026-11-18", newest entry the user (or their agent) viewed
10
+ * "noticedCli": "1.1.42" } last CLI version the update notice ran on
11
+ *
12
+ * `gipity changelog --newer` lists entries above the seen one, and after the
13
+ * CLI auto-updates the first interactive command prints one line saying how
14
+ * many there are.
15
+ */
16
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
17
+ import { join } from 'path';
18
+ import { GIPITY_DIR } from './updater/state.js';
19
+ import { compareSemver } from './updater/check.js';
20
+ import { publicRequest } from './api.js';
21
+ import { muted, brand } from './colors.js';
22
+ const STATE_FILE = () => join(GIPITY_DIR, 'changelog.json');
23
+ export function readChangelogState() {
24
+ if (!existsSync(STATE_FILE()))
25
+ return null;
26
+ try {
27
+ const parsed = JSON.parse(readFileSync(STATE_FILE(), 'utf-8'));
28
+ return parsed && typeof parsed === 'object' ? parsed : null;
29
+ }
30
+ catch {
31
+ return null; // a corrupt file is rebuilt; it only remembers what was seen
32
+ }
33
+ }
34
+ export function writeChangelogState(state) {
35
+ mkdirSync(GIPITY_DIR, { recursive: true });
36
+ writeFileSync(STATE_FILE(), JSON.stringify(state, null, 2) + '\n');
37
+ }
38
+ /** Read the state, creating it with this CLI version as the baseline. */
39
+ export function ensureChangelogState(currentCli) {
40
+ const existing = readChangelogState();
41
+ if (existing)
42
+ return existing;
43
+ const fresh = { baselineCli: currentCli, noticedCli: currentCli };
44
+ writeChangelogState(fresh);
45
+ return fresh;
46
+ }
47
+ export async function fetchChangelog(query, timeoutMs) {
48
+ const params = new URLSearchParams();
49
+ if (query.since)
50
+ params.set('since', query.since);
51
+ if (query.last !== undefined)
52
+ params.set('last', String(query.last));
53
+ const res = await publicRequest('GET', `/changelog?${params}`, undefined, undefined, timeoutMs);
54
+ return res.data.entries;
55
+ }
56
+ /** Entries the user hasn't seen: above the seen entry, or (nothing seen yet)
57
+ * everything that shipped after the CLI version they started from. */
58
+ export async function fetchNewer(state, currentCli, timeoutMs) {
59
+ if (state.seenEntry && state.seenDate) {
60
+ const entries = await fetchChangelog({ since: state.seenDate }, timeoutMs);
61
+ const at = entries.findIndex((e) => e.id === state.seenEntry);
62
+ return at === -1 ? entries.filter((e) => e.date > state.seenDate) : entries.slice(0, at);
63
+ }
64
+ return fetchChangelog({ since: `cli:${state.baselineCli ?? currentCli}` }, timeoutMs);
65
+ }
66
+ /** Every filter returns entries from the newest down, so the first one shown
67
+ * is the newest the user has now seen. */
68
+ export function markSeen(state, shown) {
69
+ if (shown.length === 0)
70
+ return state;
71
+ const next = { ...state, seenEntry: shown[0].id, seenDate: shown[0].date };
72
+ writeChangelogState(next);
73
+ return next;
74
+ }
75
+ /** `gipity changelog --newer` in one line, or null when there's nothing new. */
76
+ export function updateNoticeLine(count) {
77
+ if (count <= 0)
78
+ return null;
79
+ return `${muted(`${count} update${count === 1 ? '' : 's'} since you last looked:`)} ${brand('gipity changelog --newer')}`;
80
+ }
81
+ /**
82
+ * Called before every command. Records the baseline on first run. On the first
83
+ * interactive (TTY, non-JSON) command after the CLI's version went up (the
84
+ * auto-updater installed a new one), prints one line with the number of unseen
85
+ * entries, once. Never prints off a TTY or with --json, and never delays a
86
+ * command by more than the short fetch timeout; a failed fetch prints nothing
87
+ * (the notice is a hint, and `gipity changelog --newer` reports real errors).
88
+ */
89
+ export async function maybePrintUpdateNotice(currentCli, opts) {
90
+ const state = ensureChangelogState(currentCli);
91
+ if (!opts.interactive)
92
+ return;
93
+ if (state.noticedCli && compareSemver(currentCli, state.noticedCli) <= 0)
94
+ return;
95
+ writeChangelogState({ ...state, noticedCli: currentCli });
96
+ let count;
97
+ try {
98
+ count = (await fetchNewer(state, currentCli, opts.timeoutMs ?? 2000)).length;
99
+ }
100
+ catch {
101
+ return;
102
+ }
103
+ const line = updateNoticeLine(count);
104
+ if (line)
105
+ (opts.print ?? console.log)(line);
106
+ }
107
+ //# sourceMappingURL=changelog.js.map
@@ -16,7 +16,7 @@ import { resolveProjectContext, getConfigPath } from '../config.js';
16
16
  import { sync } from '../sync.js';
17
17
  import { createProgressReporter } from '../progress.js';
18
18
  import { bold, muted, success } from '../colors.js';
19
- import { run } from '../helpers/index.js';
19
+ import { run, PROJECT_OPTION } from '../helpers/index.js';
20
20
  const ACCENT_SOURCE_LABEL = {
21
21
  theme: " (from the app's own theme --primary)",
22
22
  derived: ' (derived from project)',
@@ -47,7 +47,7 @@ and are versioned like any other file - rollback restores previous ones.`);
47
47
  brandCommand
48
48
  .command('show', { isDefault: true })
49
49
  .description('Show the stored brand and the resolved render spec')
50
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
50
+ .option(...PROJECT_OPTION)
51
51
  .option('--json', 'Output raw JSON')
52
52
  .action((opts) => run('Brand', async () => {
53
53
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -70,7 +70,7 @@ brandCommand
70
70
  .option('--tagline <text>', 'One-line subtitle on the share card (max 120 chars)')
71
71
  .option('--fix-head', 'Also splice the share/SEO head block into src/index.html (for apps installed before templates shipped it)')
72
72
  .option('--no-regenerate', 'Store the fields without re-rendering assets')
73
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
73
+ .option(...PROJECT_OPTION)
74
74
  .option('--json', 'Output raw JSON')
75
75
  .action((opts) => run('Brand', async () => {
76
76
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -106,7 +106,7 @@ brandCommand
106
106
  .command('apply')
107
107
  .description('Re-render all brand assets from the stored brand (no field changes)')
108
108
  .option('--fix-head', 'Also splice the share/SEO head block into src/index.html (for apps installed before templates shipped it)')
109
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
109
+ .option(...PROJECT_OPTION)
110
110
  .option('--json', 'Output raw JSON')
111
111
  .action((opts) => run('Brand', async () => {
112
112
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -0,0 +1,74 @@
1
+ import { Command } from 'commander';
2
+ import { readFileSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { PKG_ROOT } from '../updater/state.js';
5
+ import { run } from '../helpers/command.js';
6
+ import { bold, brand, muted, warning } from '../colors.js';
7
+ import { ensureChangelogState, fetchChangelog, fetchNewer, markSeen, } from '../changelog.js';
8
+ /** Without --newer or --since, show this many of the newest entries. */
9
+ const DEFAULT_LAST = 10;
10
+ function cliVersion() {
11
+ return JSON.parse(readFileSync(join(PKG_ROOT, 'package.json'), 'utf-8')).version;
12
+ }
13
+ /** Markdown code spans read fine in a terminal without the backticks. */
14
+ const plain = (s) => s.replace(/`([^`]+)`/g, '$1');
15
+ export function formatEntries(entries) {
16
+ const blocks = entries.map((e) => {
17
+ const versions = [e.server ? `server ${e.server}` : '', e.cli ? `CLI ${e.cli}` : ''].filter(Boolean);
18
+ const lines = [
19
+ brand(bold(e.title)),
20
+ muted([e.date, ...versions].join(', ')),
21
+ ...e.bullets.map((b) => `- ${plain(b)}`),
22
+ ];
23
+ if (e.breaking.length) {
24
+ lines.push(warning('Breaking:'));
25
+ lines.push(...e.breaking.map((b) => `- ${plain(b)}`));
26
+ }
27
+ if (e.skills.length) {
28
+ lines.push(muted(`Docs: ${e.skills.map((s) => `gipity skill read ${s}`).join(', ')}`));
29
+ }
30
+ return lines.join('\n');
31
+ });
32
+ return blocks.join('\n\n');
33
+ }
34
+ export const changelogCommand = new Command('changelog')
35
+ .description("What's new in Gipity (--newer: since you last looked)")
36
+ .option('--newer', 'Only what shipped since you (or your agent) last looked')
37
+ .option('--since <date|version>', 'What shipped since a date (yyyy-mm-dd, that day included) or after a version (1.1.40, cli:1.1.40, server:9.14.781)')
38
+ .option('--last <n>', `Only the newest n entries (default ${DEFAULT_LAST} without --newer or --since)`)
39
+ .option('--json', 'Output the entries as JSON')
40
+ .addHelpText('after', '\nAgents: run `gipity changelog --newer --json` to pull what changed since your docs into context.\n')
41
+ .action((opts) => run('Changelog', async () => {
42
+ if (opts.newer && opts.since)
43
+ throw new Error('use --newer or --since, not both');
44
+ let last;
45
+ if (opts.last !== undefined) {
46
+ last = Number(opts.last);
47
+ if (!Number.isInteger(last) || last < 1)
48
+ throw new Error('--last must be a whole number of 1 or more');
49
+ }
50
+ const current = cliVersion();
51
+ const state = ensureChangelogState(current);
52
+ let entries;
53
+ if (opts.newer) {
54
+ entries = await fetchNewer(state, current);
55
+ if (last !== undefined)
56
+ entries = entries.slice(0, last);
57
+ }
58
+ else {
59
+ entries = await fetchChangelog({ since: opts.since, last: last ?? (opts.since ? undefined : DEFAULT_LAST) });
60
+ }
61
+ markSeen(state, entries);
62
+ if (opts.json) {
63
+ console.log(JSON.stringify({ entries }, null, 2));
64
+ return;
65
+ }
66
+ if (entries.length === 0) {
67
+ console.log(opts.newer ? 'Nothing new since you last looked.' : 'No changelog entries match.');
68
+ return;
69
+ }
70
+ if (opts.newer)
71
+ console.log(muted(`${entries.length} update${entries.length === 1 ? '' : 's'} since you last looked`) + '\n');
72
+ console.log(formatEntries(entries));
73
+ }));
74
+ //# sourceMappingURL=changelog.js.map
@@ -2,7 +2,7 @@ import { Command, Option } from 'commander';
2
2
  import { get, post } from '../api.js';
3
3
  import { resolveProjectContext } from '../config.js';
4
4
  import { success, bold, muted, warning } from '../colors.js';
5
- import { run } from '../helpers/index.js';
5
+ import { run, PROJECT_OPTION } from '../helpers/index.js';
6
6
  // `email` is a command GROUP for the deployed app's email() service:
7
7
  // `email test` sends through it, `email log` lists recent sends.
8
8
  export const emailCommand = new Command('email')
@@ -18,7 +18,7 @@ emailCommand
18
18
  .option('--text <text>', 'Body text', 'This is a test email sent through your app\'s email() service. ✉️')
19
19
  .option('--reply-to <email>', 'Reply-To address')
20
20
  .option('--from-name <name>', 'Sender display name (address stays gipity@gipity.ai)')
21
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
21
+ .option(...PROJECT_OPTION)
22
22
  .option('--json', 'Output raw JSON')
23
23
  .action((to, opts) => run('Email', async () => {
24
24
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -50,7 +50,7 @@ emailCommand
50
50
  .description('Recent email() sends and skipped attempts from your app')
51
51
  .addOption(new Option('--range <range>', 'Time range').choices(['1h', '24h', '7d', '30d', '1y']).default('7d'))
52
52
  .option('--limit <n>', 'Max rows', '50')
53
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
53
+ .option(...PROJECT_OPTION)
54
54
  .option('--json', 'Output raw JSON')
55
55
  .action((opts) => run('Email', async () => {
56
56
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -1,8 +1,7 @@
1
1
  import { Command, Option } from 'commander';
2
2
  import { get, post, del } from '../api.js';
3
- import { resolveProjectContext } from '../config.js';
4
3
  import { bold, muted, success, warning } from '../colors.js';
5
- import { run, printList } from '../helpers/index.js';
4
+ import { run, printList, PROJECT_OPTION, projectGuidFor } from '../helpers/index.js';
6
5
  /**
7
6
  * Project API keys - the revocable secret a script, cron, or agent sends as
8
7
  * `X-Api-Key` (or `Authorization: Bearer`) to write to YOUR app without a
@@ -95,11 +94,6 @@ export function describeScopes(scopes) {
95
94
  parts.push(`ip: ${scopes.ip.join(',')}`);
96
95
  return parts.join(' ');
97
96
  }
98
- const projectOpt = ['--project <guid-or-slug>', 'Target a specific project instead of cwd / Home'];
99
- async function projectGuid(opts) {
100
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
101
- return config.projectGuid;
102
- }
103
97
  keyCommand
104
98
  .command('create <name>')
105
99
  .description('Mint a project API key (shown once). Give it a name you will recognize later')
@@ -110,7 +104,7 @@ keyCommand
110
104
  .addOption(new Option('--files <access>', 'Scope: app files access').choices(['read', 'write']))
111
105
  .addOption(new Option('--approvals <access>', 'Scope: read and consume passkey approvals').choices(['read']))
112
106
  .option('--ip <list>', 'Scope: only from these IPs / CIDR ranges (comma-separated)')
113
- .option(...projectOpt)
107
+ .option(...PROJECT_OPTION)
114
108
  .option('--json', 'Output as JSON')
115
109
  .action((name, opts) => run('Create', async () => {
116
110
  const body = { name, role: opts.role };
@@ -123,7 +117,7 @@ keyCommand
123
117
  throw new Error('--expires-days must be a positive number of days');
124
118
  body.expires_in_days = days;
125
119
  }
126
- const res = await post(`/projects/${await projectGuid(opts)}/api-keys`, body);
120
+ const res = await post(`/projects/${await projectGuidFor(opts)}/api-keys`, body);
127
121
  const k = res.data;
128
122
  if (opts.json) {
129
123
  console.log(JSON.stringify(k));
@@ -146,20 +140,20 @@ keyCommand
146
140
  .command('list')
147
141
  .alias('ls')
148
142
  .description('List this project\'s API keys (values are never shown again)')
149
- .option(...projectOpt)
143
+ .option(...PROJECT_OPTION)
150
144
  .option('--json', 'Output as JSON')
151
145
  .action((opts) => run('List', async () => {
152
- const res = await get(`/projects/${await projectGuid(opts)}/api-keys`);
146
+ const res = await get(`/projects/${await projectGuidFor(opts)}/api-keys`);
153
147
  printList(res.data, opts, 'No API keys. Mint one with: gipity key create "my script" --role editor', (k) => `${bold(k.short_guid)} ${k.name} ${muted(`${k.role} ${describeScopes(k.scopes)} ${k.prefix}... last used ${fmtDate(k.last_used_at)} expires ${fmtDate(k.expires_at)}`)}`);
154
148
  }));
155
149
  keyCommand
156
150
  .command('revoke <short_guid>')
157
151
  .alias('rm')
158
152
  .description('Revoke a project API key (instant, irreversible)')
159
- .option(...projectOpt)
153
+ .option(...PROJECT_OPTION)
160
154
  .option('--json', 'Output as JSON')
161
155
  .action((shortGuid, opts) => run('Revoke', async () => {
162
- await del(`/projects/${await projectGuid(opts)}/api-keys/${encodeURIComponent(shortGuid)}`);
156
+ await del(`/projects/${await projectGuidFor(opts)}/api-keys/${encodeURIComponent(shortGuid)}`);
163
157
  if (opts.json) {
164
158
  console.log(JSON.stringify({ short_guid: shortGuid, revoked: true }));
165
159
  return;
@@ -1,9 +1,8 @@
1
1
  import { Command } from 'commander';
2
2
  import { readFileSync } from 'fs';
3
3
  import { get, post, put, del } from '../api.js';
4
- import { resolveProjectContext } from '../config.js';
5
4
  import { bold, muted, success, warning } from '../colors.js';
6
- import { run } from '../helpers/index.js';
5
+ import { run, PROJECT_OPTION, projectGuidFor } from '../helpers/index.js';
7
6
  export const notifyCommand = new Command('notify')
8
7
  .description('Push notifications (web and native iOS)')
9
8
  .addHelpText('after', '\nGipity Notify: send a test notification, inspect subscriptions, or set up iOS push (notify apns).');
@@ -14,15 +13,15 @@ notifyCommand
14
13
  .option('--title <text>', 'Notification title', 'Test notification')
15
14
  .option('--body <text>', 'Notification body', 'Hello from Gipity Notify 👋')
16
15
  .option('--url <url>', 'URL to open when the notification is clicked')
17
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
16
+ .option(...PROJECT_OPTION)
18
17
  .option('--json', 'Output raw JSON')
19
18
  .action((opts) => run('Notify', async () => {
20
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
19
+ const projectGuid = await projectGuidFor(opts);
21
20
  const to = opts.to === 'all' ? 'all' : (opts.to.includes(',') ? opts.to.split(',').map((s) => s.trim()) : opts.to);
22
21
  const notification = { title: opts.title, body: opts.body };
23
22
  if (opts.url)
24
23
  notification.url = opts.url;
25
- const res = await post(`/api/${config.projectGuid}/services/notify/send`, { to, notification });
24
+ const res = await post(`/api/${projectGuid}/services/notify/send`, { to, notification });
26
25
  if (opts.json) {
27
26
  console.log(JSON.stringify(res.data));
28
27
  return;
@@ -50,11 +49,11 @@ notifyCommand
50
49
  notifyCommand
51
50
  .command('subs')
52
51
  .description('Show how many push subscriptions this app has, per user')
53
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
52
+ .option(...PROJECT_OPTION)
54
53
  .option('--json', 'Output raw JSON')
55
54
  .action((opts) => run('Notify', async () => {
56
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
57
- const res = await get(`/api/${config.projectGuid}/services/notify/subs`);
55
+ const projectGuid = await projectGuidFor(opts);
56
+ const res = await get(`/api/${projectGuid}/services/notify/subs`);
58
57
  if (opts.json) {
59
58
  console.log(JSON.stringify(res.data));
60
59
  return;
@@ -70,11 +69,11 @@ notifyCommand
70
69
  .command('rm')
71
70
  .description("Remove a user's push subscriptions and iOS devices (e.g. on account deletion)")
72
71
  .requiredOption('--user <guid>', 'User guid whose subscriptions to remove')
73
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
72
+ .option(...PROJECT_OPTION)
74
73
  .option('--json', 'Output raw JSON')
75
74
  .action((opts) => run('Notify', async () => {
76
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
77
- const res = await post(`/api/${config.projectGuid}/services/notify/remove`, { user_guid: opts.user });
75
+ const projectGuid = await projectGuidFor(opts);
76
+ const res = await post(`/api/${projectGuid}/services/notify/remove`, { user_guid: opts.user });
78
77
  if (opts.json) {
79
78
  console.log(JSON.stringify(res.data));
80
79
  return;
@@ -111,10 +110,10 @@ apnsCommand
111
110
  .requiredOption('--p8 <file>', 'Path to the AuthKey_<KEYID>.p8 file')
112
111
  .requiredOption('--bundle-id <id>', 'Your app bundle id, e.g. com.example.myapp')
113
112
  .option('--sandbox', 'Devices that register without an environment use the sandbox (development builds)')
114
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
113
+ .option(...PROJECT_OPTION)
115
114
  .option('--json', 'Output raw JSON')
116
115
  .action((opts) => run('Notify', async () => {
117
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
116
+ const projectGuid = await projectGuidFor(opts);
118
117
  let p8;
119
118
  try {
120
119
  p8 = readFileSync(opts.p8, 'utf-8');
@@ -122,7 +121,7 @@ apnsCommand
122
121
  catch {
123
122
  throw new Error(`Can't read ${opts.p8}. Pass the path to the AuthKey_<KEYID>.p8 file from Apple.`);
124
123
  }
125
- const res = await put(`/api/${config.projectGuid}/services/notify/apns`, {
124
+ const res = await put(`/api/${projectGuid}/services/notify/apns`, {
126
125
  team_id: opts.teamId, key_id: opts.keyId, bundle_id: opts.bundleId, p8, sandbox: !!opts.sandbox,
127
126
  });
128
127
  if (opts.json) {
@@ -135,11 +134,11 @@ apnsCommand
135
134
  apnsCommand
136
135
  .command('show')
137
136
  .description('Show the APNs setup for this app (never the key itself)')
138
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
137
+ .option(...PROJECT_OPTION)
139
138
  .option('--json', 'Output raw JSON')
140
139
  .action((opts) => run('Notify', async () => {
141
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
142
- const res = await get(`/api/${config.projectGuid}/services/notify/apns`);
140
+ const projectGuid = await projectGuidFor(opts);
141
+ const res = await get(`/api/${projectGuid}/services/notify/apns`);
143
142
  if (opts.json) {
144
143
  console.log(JSON.stringify(res.data));
145
144
  return;
@@ -149,11 +148,11 @@ apnsCommand
149
148
  apnsCommand
150
149
  .command('rm')
151
150
  .description('Remove the APNs key (iOS devices stop receiving notifications)')
152
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
151
+ .option(...PROJECT_OPTION)
153
152
  .option('--json', 'Output raw JSON')
154
153
  .action((opts) => run('Notify', async () => {
155
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
156
- const res = await del(`/api/${config.projectGuid}/services/notify/apns`);
154
+ const projectGuid = await projectGuidFor(opts);
155
+ const res = await del(`/api/${projectGuid}/services/notify/apns`);
157
156
  if (opts.json) {
158
157
  console.log(JSON.stringify(res.data));
159
158
  return;
@@ -2,7 +2,7 @@ import { Command } from 'commander';
2
2
  import { get, put, del } from '../api.js';
3
3
  import { resolveProjectContext } from '../config.js';
4
4
  import { bold, muted, success } from '../colors.js';
5
- import { run } from '../helpers/index.js';
5
+ import { run, PROJECT_OPTION } from '../helpers/index.js';
6
6
  /** Build the query string for a scope. Account scope is project-independent;
7
7
  * project scope needs the linked app's guid. */
8
8
  async function scopeQuery(opts) {
@@ -19,7 +19,7 @@ secretsCommand
19
19
  .alias('ls')
20
20
  .description('List secret names (never values). Project secrets by default; --account for account-wide')
21
21
  .option('--account', 'Account-wide secrets shared across all your projects')
22
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
22
+ .option(...PROJECT_OPTION)
23
23
  .option('--json', 'Output raw JSON')
24
24
  .action((opts) => run('Secrets', async () => {
25
25
  const res = await get(`/secrets?${await scopeQuery(opts)}`);
@@ -46,7 +46,7 @@ secretsCommand
46
46
  .command('get <name>')
47
47
  .description('Secret values are write-only: confirms the secret exists, never prints its value')
48
48
  .option('--account', 'Look in account-wide secrets')
49
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
49
+ .option(...PROJECT_OPTION)
50
50
  .option('--json', 'Output raw JSON')
51
51
  .action((name, opts) => run('Secrets', async () => {
52
52
  const res = await get(`/secrets?${await scopeQuery(opts)}`);
@@ -63,7 +63,7 @@ secretsCommand
63
63
  .command('set <name> <value>')
64
64
  .description('Create or update a secret (UPPER_SNAKE_CASE name). Encrypted at rest; never echoed back')
65
65
  .option('--account', 'Store account-wide (shared across all your projects)')
66
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
66
+ .option(...PROJECT_OPTION)
67
67
  .option('--json', 'Output raw JSON')
68
68
  .action((name, value, opts) => run('Secrets', async () => {
69
69
  const res = await put(`/secrets?${await scopeQuery(opts)}`, { name, value });
@@ -79,7 +79,7 @@ secretsCommand
79
79
  .alias('delete')
80
80
  .description('Delete a secret')
81
81
  .option('--account', 'Delete from account-wide secrets')
82
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
82
+ .option(...PROJECT_OPTION)
83
83
  .option('--json', 'Output raw JSON')
84
84
  .action((name, opts) => run('Secrets', async () => {
85
85
  const res = await del(`/secrets/${encodeURIComponent(name)}?${await scopeQuery(opts)}`);
@@ -6,4 +6,5 @@ export { printOutput, printList, printResult, pluckField, emitField } from './ou
6
6
  export { syncBeforeAction, syncAfterAction } from './sync.js';
7
7
  export { resolveJsonBody, resolveBody, resolveFormBody } from './body.js';
8
8
  export { parseDuration } from './duration.js';
9
+ export { PROJECT_OPTION, projectGuidFor } from './project.js';
9
10
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ import { resolveProjectContext } from '../config.js';
2
+ /** The `--project` option every project-scoped command takes: `.option(...PROJECT_OPTION)`. */
3
+ export const PROJECT_OPTION = ['--project <guid-or-slug>', 'Target a specific project instead of cwd / Home'];
4
+ /** The project guid a command acts on: `--project`, else the linked cwd / Home. */
5
+ export async function projectGuidFor(opts) {
6
+ const { config } = await resolveProjectContext({ projectOverride: opts.project });
7
+ return config.projectGuid;
8
+ }
9
+ //# sourceMappingURL=project.js.map