goals-cli 0.0.0-stage → 0.1.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +125 -2
  3. package/dist/args.js +96 -0
  4. package/dist/auth/command.js +16 -0
  5. package/dist/auth/help.js +82 -0
  6. package/dist/auth/list.js +41 -0
  7. package/dist/auth/login.js +203 -0
  8. package/dist/auth/logout.js +25 -0
  9. package/dist/auth/select.js +30 -0
  10. package/dist/auth/status.js +43 -0
  11. package/dist/auth/use.js +10 -0
  12. package/dist/cli.js +112 -0
  13. package/dist/commands/export-help.js +49 -0
  14. package/dist/commands/export.js +194 -0
  15. package/dist/commands/goal-flags.js +111 -0
  16. package/dist/commands/goal-format.js +95 -0
  17. package/dist/commands/goal-help.js +214 -0
  18. package/dist/commands/goal-read.js +80 -0
  19. package/dist/commands/goal-write.js +186 -0
  20. package/dist/commands/goal.js +15 -0
  21. package/dist/commands/initiative-help.js +38 -0
  22. package/dist/commands/initiative.js +81 -0
  23. package/dist/commands/list-output.js +13 -0
  24. package/dist/commands/skill-help.js +18 -0
  25. package/dist/commands/skill.js +36 -0
  26. package/dist/credentials.js +270 -0
  27. package/dist/deps.js +46 -0
  28. package/dist/dispatch.js +16 -0
  29. package/dist/endpoints.js +82 -0
  30. package/dist/errors.js +29 -0
  31. package/dist/help.js +105 -0
  32. package/dist/http.js +199 -0
  33. package/dist/iso-week.js +18 -0
  34. package/dist/open-browser.js +47 -0
  35. package/dist/output.js +29 -0
  36. package/dist/vendor/cli-contract/index.js +26 -0
  37. package/dist/vendor/quarterly-markdown/dateFormat.js +101 -0
  38. package/dist/vendor/quarterly-markdown/generate.js +450 -0
  39. package/dist/vendor/quarterly-markdown/htmlToPlainText.js +101 -0
  40. package/dist/vendor/quarterly-markdown/index.js +4 -0
  41. package/dist/vendor/quarterly-markdown/types.js +1 -0
  42. package/dist/vendor/quarterly-markdown/year.js +45 -0
  43. package/dist/version.js +9 -0
  44. package/package.json +37 -4
  45. package/skills/goals-cli/REFERENCE.md +212 -0
  46. package/skills/goals-cli/SKILL.md +12 -0
@@ -0,0 +1,214 @@
1
+ /** Help data for the `goal` family; the text is pinned by `src/__views__/goal-*-help.txt`. */
2
+ export const goalHelp = {
3
+ name: 'goal',
4
+ summary: 'Read and change your goals.',
5
+ actions: {
6
+ list: {
7
+ summary: 'List goals in one scope for a year (quarterly by default).',
8
+ usage: 'goals goal list [--scope <scope>] --year <year> [--quarter <n>] [--week <n>] [--initiative <id>] [--limit <n>] [--json] [--as <label>]',
9
+ options: [
10
+ { syntax: '--scope <scope>', description: 'quarterly (default), weekly, daily or adhoc.' },
11
+ {
12
+ syntax: '--year <year>',
13
+ description: 'Calendar year, 2000-2100; required for every scope.',
14
+ },
15
+ {
16
+ syntax: '--quarter <n>',
17
+ description: 'Quarter 1-4; required for quarterly, weekly and daily goals.',
18
+ },
19
+ {
20
+ syntax: '--week <n>',
21
+ description: 'ISO week 1-53; required for weekly and daily goals, optional for adhoc.',
22
+ },
23
+ {
24
+ syntax: '--initiative <id>',
25
+ description: 'Only goals tagged with this initiative; IDs come from `goals initiative list`.',
26
+ },
27
+ { syntax: '--limit <n>', description: 'Maximum rows, 1-500 (default: 200).' },
28
+ { syntax: '--json', description: 'Print a JSON array instead of a table.' },
29
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
30
+ ],
31
+ examples: [
32
+ 'goals goal list --year 2026 --quarter 3',
33
+ 'goals goal list --scope weekly --year 2026 --quarter 3 --week 31',
34
+ 'goals goal list --scope adhoc --year 2026 --json',
35
+ ],
36
+ notes: [
37
+ 'Default scope is quarterly; quarterly needs --year and --quarter and rejects --week.',
38
+ 'Weekly and daily need --year, --quarter and --week; adhoc needs --year and rejects --quarter.',
39
+ 'An empty list prints `No goals found.`; --json prints a bare array.',
40
+ 'The default cap is 200 (--limit max 500); a truncation note goes to stderr.',
41
+ ],
42
+ },
43
+ get: {
44
+ summary: 'Show one goal with its parent, children, details and due date.',
45
+ usage: 'goals goal get <id> [--json] [--as <label>]',
46
+ options: [
47
+ {
48
+ syntax: '<id>',
49
+ description: 'Goal ID from `goals goal list` (use --json for scripts).',
50
+ },
51
+ { syntax: '--json', description: 'Print one JSON object instead of text.' },
52
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
53
+ ],
54
+ examples: ['goals goal get goal_123', 'goals goal get goal_123 --json'],
55
+ notes: [
56
+ 'IDs come from `goals goal list` (use --json for scripts).',
57
+ 'Details are rich text and are printed as plain text.',
58
+ ],
59
+ },
60
+ create: {
61
+ summary: 'Create one quarterly, weekly, daily or adhoc goal.',
62
+ usage: 'goals goal create --scope <scope> --title <text> [--details <text>] [--year <year>] [--quarter <n>] [--week <n>] [--parent <id>] [--day <day>] [--domain <id>] [--initiative <id>] [--as <label>]',
63
+ options: [
64
+ {
65
+ syntax: '--scope <scope>',
66
+ description: 'quarterly, weekly, daily or adhoc; required.',
67
+ },
68
+ { syntax: '--title <text>', description: 'Goal title, trimmed; required.' },
69
+ {
70
+ syntax: '--details <text>',
71
+ description: 'Rich-text details; printed as plain text by `goals goal get`.',
72
+ },
73
+ {
74
+ syntax: '--year <year>',
75
+ description: 'Calendar year 2000-2100; required for quarterly, defaults for adhoc.',
76
+ },
77
+ {
78
+ syntax: '--quarter <n>',
79
+ description: 'Quarter 1-4; required for quarterly, optional for weekly and daily.',
80
+ },
81
+ {
82
+ syntax: '--week <n>',
83
+ description: 'ISO week 1-53; defaults to the current ISO week for weekly, daily and adhoc.',
84
+ },
85
+ {
86
+ syntax: '--parent <id>',
87
+ description: 'Parent ID: a quarterly goal for weekly, a weekly goal for daily, an adhoc goal for adhoc; from `goals goal list --scope <same scope>`.',
88
+ },
89
+ {
90
+ syntax: '--day <day>',
91
+ description: 'Day for daily goals: 1-7 or mon..sun (Monday is 1).',
92
+ },
93
+ {
94
+ syntax: '--domain <id>',
95
+ description: 'Domain ID (shown as `domainId` in `goals goal get <id> --json`); adhoc only.',
96
+ },
97
+ {
98
+ syntax: '--initiative <id>',
99
+ description: 'Initiative ID from `goals initiative list`.',
100
+ },
101
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
102
+ ],
103
+ examples: [
104
+ 'goals goal create --scope quarterly --year 2026 --quarter 3 --title "Ship the beta"',
105
+ 'goals goal create --scope weekly --parent goal_1 --title "Draft the launch"',
106
+ 'goals goal create --scope daily --parent goal_2 --day tue --title "Call the printer"',
107
+ 'goals goal create --scope adhoc --title "Book the venue" --domain domain_1',
108
+ ],
109
+ notes: [
110
+ 'Quarterly needs --year and --quarter and rejects --parent, --day and --domain.',
111
+ 'Weekly needs --parent (a quarterly goal) and rejects --day and --domain.',
112
+ 'Daily needs --parent (a weekly goal) and --day, and rejects --domain.',
113
+ 'Adhoc rejects --quarter and --day; --parent must be an adhoc goal.',
114
+ 'Weekly and daily default --week to the current ISO week.',
115
+ 'Adhoc defaults --year and --week to the current ISO year and week; another --year needs --week.',
116
+ 'Quarterly without --week uses the first week of the quarter (server default).',
117
+ 'IDs come from `goals goal list` (use --json for scripts); initiative IDs from `goals initiative list`.',
118
+ ],
119
+ },
120
+ rename: {
121
+ summary: 'Rename one goal.',
122
+ usage: 'goals goal rename <id> --title <text> [--as <label>]',
123
+ options: [
124
+ {
125
+ syntax: '<id>',
126
+ description: 'Goal ID from `goals goal list` (use --json for scripts).',
127
+ },
128
+ { syntax: '--title <text>', description: 'New title, trimmed; must not be empty.' },
129
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
130
+ ],
131
+ examples: ['goals goal rename goal_123 --title "Ship the beta"'],
132
+ notes: ['IDs come from `goals goal list` (use --json for scripts).'],
133
+ },
134
+ complete: {
135
+ summary: 'Mark one goal complete.',
136
+ usage: 'goals goal complete <id> [--week <n>] [--include-children] [--as <label>]',
137
+ options: [
138
+ {
139
+ syntax: '<id>',
140
+ description: 'Goal ID from `goals goal list` (use --json for scripts).',
141
+ },
142
+ {
143
+ syntax: '--week <n>',
144
+ description: 'ISO week 1-53; required for weekly and daily goals.',
145
+ },
146
+ {
147
+ syntax: '--include-children',
148
+ description: 'Also mark child goals complete (off by default).',
149
+ },
150
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
151
+ ],
152
+ examples: [
153
+ 'goals goal complete goal_123 --week 31',
154
+ 'goals goal complete goal_123 --include-children',
155
+ ],
156
+ notes: [
157
+ '--week is required for weekly and daily goals; the error names the current ISO week.',
158
+ "Quarterly goals default to the quarter's first week server-side.",
159
+ '--include-children also applies to child goals; it is off by default.',
160
+ "Use `goals goal get <id>` to see a goal's scope.",
161
+ 'IDs come from `goals goal list` (use --json for scripts).',
162
+ ],
163
+ },
164
+ reopen: {
165
+ summary: 'Mark one goal incomplete again.',
166
+ usage: 'goals goal reopen <id> [--week <n>] [--include-children] [--as <label>]',
167
+ options: [
168
+ {
169
+ syntax: '<id>',
170
+ description: 'Goal ID from `goals goal list` (use --json for scripts).',
171
+ },
172
+ {
173
+ syntax: '--week <n>',
174
+ description: 'ISO week 1-53; required for weekly and daily goals.',
175
+ },
176
+ {
177
+ syntax: '--include-children',
178
+ description: 'Also mark child goals incomplete (off by default).',
179
+ },
180
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
181
+ ],
182
+ examples: [
183
+ 'goals goal reopen goal_123 --week 31',
184
+ 'goals goal reopen goal_123 --include-children',
185
+ ],
186
+ notes: [
187
+ '--week is required for weekly and daily goals; the error names the current ISO week.',
188
+ "Quarterly goals default to the quarter's first week server-side.",
189
+ '--include-children also applies to child goals; it is off by default.',
190
+ "Use `goals goal get <id>` to see a goal's scope.",
191
+ 'IDs come from `goals goal list` (use --json for scripts).',
192
+ ],
193
+ },
194
+ delete: {
195
+ summary: 'Delete one goal and all of its child goals.',
196
+ usage: 'goals goal delete <id> --yes [--as <label>]',
197
+ options: [
198
+ {
199
+ syntax: '<id>',
200
+ description: 'Goal ID from `goals goal list` (use --json for scripts).',
201
+ },
202
+ { syntax: '--yes', description: 'Confirm the deletion; nothing is sent without it.' },
203
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
204
+ ],
205
+ examples: ['goals goal delete goal_123 --yes'],
206
+ notes: [
207
+ 'Deletes this goal and all of its child goals.',
208
+ '--yes is required and nothing is sent without it.',
209
+ 'Goal log history is kept.',
210
+ 'IDs come from `goals goal list` (use --json for scripts).',
211
+ ],
212
+ },
213
+ },
214
+ };
@@ -0,0 +1,80 @@
1
+ import { booleanFlag, parseFlags, usageFailure } from '../args.js';
2
+ import { callAsIdentity } from '../auth/select.js';
3
+ import { toJson } from '../output.js';
4
+ import { intFlag, omitUndefined, optionalText, requiredInt, scopeFlag } from './goal-flags.js';
5
+ import { formatGoalDetail, formatGoalTable, truncationNote } from './goal-format.js';
6
+ import { writeBoundedList } from './list-output.js';
7
+ const LIST_HINT = 'goals goal list --help';
8
+ const GET_HINT = 'goals goal get --help';
9
+ const LIST_FLAGS = {
10
+ scope: { type: 'string' },
11
+ year: { type: 'string' },
12
+ quarter: { type: 'string' },
13
+ week: { type: 'string' },
14
+ initiative: { type: 'string' },
15
+ limit: { type: 'string' },
16
+ json: { type: 'boolean' },
17
+ as: { type: 'string' },
18
+ };
19
+ const GET_FLAGS = {
20
+ json: { type: 'boolean' },
21
+ as: { type: 'string' },
22
+ };
23
+ const ONE_ID = { min: 1, max: 1, name: '<id>' };
24
+ /** Rejects a flag the scope does not accept; the value itself is still range-checked. */
25
+ function rejectFlag(parsed, name, message) {
26
+ if (intFlag(parsed, name, LIST_HINT) !== undefined)
27
+ throw usageFailure(message, LIST_HINT);
28
+ }
29
+ function quarterlyPeriod(parsed) {
30
+ const year = requiredInt(parsed, 'year', 'for quarterly goals', LIST_HINT);
31
+ const quarter = requiredInt(parsed, 'quarter', 'for quarterly goals', LIST_HINT);
32
+ rejectFlag(parsed, 'week', '--week is not supported for quarterly goals');
33
+ return { year, quarter };
34
+ }
35
+ function adhocPeriod(parsed) {
36
+ const year = requiredInt(parsed, 'year', 'for adhoc goals', LIST_HINT);
37
+ rejectFlag(parsed, 'quarter', '--quarter is not supported for adhoc goals');
38
+ return { year, week: intFlag(parsed, 'week', LIST_HINT) };
39
+ }
40
+ function weekPeriod(parsed) {
41
+ return {
42
+ year: requiredInt(parsed, 'year', 'for weekly and daily goals', LIST_HINT),
43
+ quarter: requiredInt(parsed, 'quarter', 'for weekly and daily goals', LIST_HINT),
44
+ week: requiredInt(parsed, 'week', 'for weekly and daily goals', LIST_HINT),
45
+ };
46
+ }
47
+ /** `--year` plus the per-scope quarter/week rules from `goalRead.ts`; runs before any I/O. */
48
+ function listPeriod(parsed, scope) {
49
+ if (scope === 'quarterly')
50
+ return quarterlyPeriod(parsed);
51
+ if (scope === 'adhoc')
52
+ return adhocPeriod(parsed);
53
+ return weekPeriod(parsed);
54
+ }
55
+ function writeTruncation(ctx, truncated, shown) {
56
+ if (truncated)
57
+ ctx.deps.stderr.write(truncationNote('goals', shown));
58
+ }
59
+ /** `goals goal list` — a bounded list of goals in one scope. */
60
+ export async function runGoalList(args, ctx) {
61
+ const parsed = parseFlags(args, LIST_FLAGS, LIST_HINT);
62
+ const scope = scopeFlag(parsed, LIST_HINT, 'quarterly');
63
+ const period = listPeriod(parsed, scope);
64
+ const request = omitUndefined({
65
+ scope,
66
+ ...period,
67
+ initiativeId: optionalText(parsed, 'initiative', LIST_HINT),
68
+ limit: intFlag(parsed, 'limit', LIST_HINT),
69
+ });
70
+ const result = await callAsIdentity(ctx, parsed, 'goal.list', request);
71
+ writeTruncation(ctx, result.truncated, result.items.length);
72
+ writeBoundedList(ctx, parsed, result, 'No goals found.\n', formatGoalTable);
73
+ }
74
+ /** `goals goal get` — one goal with parent, children, details and due date. */
75
+ export async function runGoalGet(args, ctx) {
76
+ const parsed = parseFlags(args, GET_FLAGS, GET_HINT, ONE_ID);
77
+ const [id = ''] = parsed.positionals;
78
+ const detail = await callAsIdentity(ctx, parsed, 'goal.get', { id });
79
+ ctx.deps.stdout.write(booleanFlag(parsed, 'json') ? toJson(detail) : formatGoalDetail(detail));
80
+ }
@@ -0,0 +1,186 @@
1
+ import { booleanFlag, parseFlags, usageFailure } from '../args.js';
2
+ import { callAsIdentity, selectIdentity } from '../auth/select.js';
3
+ import { isoWeekOf } from '../iso-week.js';
4
+ import { dayFlag, intFlag, omitUndefined, optionalText, requiredText, scopeFlag, } from './goal-flags.js';
5
+ const CREATE_HINT = 'goals goal create --help';
6
+ const RENAME_HINT = 'goals goal rename --help';
7
+ const DELETE_HINT = 'goals goal delete --help';
8
+ const CREATE_FLAGS = {
9
+ scope: { type: 'string' },
10
+ title: { type: 'string' },
11
+ details: { type: 'string' },
12
+ year: { type: 'string' },
13
+ quarter: { type: 'string' },
14
+ week: { type: 'string' },
15
+ parent: { type: 'string' },
16
+ day: { type: 'string' },
17
+ domain: { type: 'string' },
18
+ initiative: { type: 'string' },
19
+ as: { type: 'string' },
20
+ };
21
+ const RENAME_FLAGS = {
22
+ title: { type: 'string' },
23
+ as: { type: 'string' },
24
+ };
25
+ const COMPLETE_FLAGS = {
26
+ week: { type: 'string' },
27
+ 'include-children': { type: 'boolean' },
28
+ as: { type: 'string' },
29
+ };
30
+ const DELETE_FLAGS = {
31
+ yes: { type: 'boolean' },
32
+ as: { type: 'string' },
33
+ };
34
+ const ONE_ID = { min: 1, max: 1, name: '<id>' };
35
+ function rejectPresent(value, message) {
36
+ if (value !== undefined)
37
+ throw usageFailure(message, CREATE_HINT);
38
+ }
39
+ function requirePresent(value, message) {
40
+ if (value === undefined)
41
+ throw usageFailure(message, CREATE_HINT);
42
+ return value;
43
+ }
44
+ /** Applies the quarterly column of the create matrix. */
45
+ function quarterlyInput(input) {
46
+ rejectPresent(input.parentId, '--parent is not supported for quarterly goals');
47
+ rejectPresent(input.dayOfWeek, '--day is not supported for quarterly goals');
48
+ rejectPresent(input.domainId, '--domain is not supported for quarterly goals');
49
+ return {
50
+ ...input,
51
+ year: requirePresent(input.year, '--year is required for quarterly goals'),
52
+ quarter: requirePresent(input.quarter, '--quarter is required for quarterly goals'),
53
+ };
54
+ }
55
+ /** Weekly and daily share the `--parent` requirement and current-week default. */
56
+ function childInput(input, week) {
57
+ rejectPresent(input.domainId, `--domain is not supported for ${input.scope} goals`);
58
+ const parentId = requirePresent(input.parentId, `--parent is required for ${input.scope} goals`);
59
+ if (input.scope === 'weekly') {
60
+ rejectPresent(input.dayOfWeek, '--day is not supported for weekly goals');
61
+ return { ...input, parentId, week: input.week ?? week };
62
+ }
63
+ const dayOfWeek = requirePresent(input.dayOfWeek, '--day is required for daily goals');
64
+ return { ...input, parentId, week: input.week ?? week, dayOfWeek };
65
+ }
66
+ /** Applies the adhoc column, including the cross-year `--week` rule. */
67
+ function adhocInput(input, currentYear, currentWeek) {
68
+ rejectPresent(input.quarter, '--quarter is not supported for adhoc goals');
69
+ rejectPresent(input.dayOfWeek, '--day is not supported for adhoc goals');
70
+ const year = input.year ?? currentYear;
71
+ return {
72
+ ...input,
73
+ year,
74
+ week: input.week ?? requireAdhocWeek(year, currentYear, currentWeek),
75
+ };
76
+ }
77
+ function requireAdhocWeek(year, currentYear, currentWeek) {
78
+ if (year !== currentYear) {
79
+ throw usageFailure('--week is required for adhoc goals when --year is not the current ISO year', CREATE_HINT);
80
+ }
81
+ return currentWeek;
82
+ }
83
+ /** Fills in defaults and enforces the per-scope matrix before any credential read. */
84
+ function createInput(input, now) {
85
+ if (input.scope === 'quarterly')
86
+ return quarterlyInput(input);
87
+ const current = isoWeekOf(now);
88
+ if (input.scope === 'adhoc')
89
+ return adhocInput(input, current.year, current.week);
90
+ return childInput(input, current.week);
91
+ }
92
+ function createRequest(parsed, now) {
93
+ const input = createInput({
94
+ scope: scopeFlag(parsed, CREATE_HINT),
95
+ title: requiredText(parsed, 'title', CREATE_HINT),
96
+ details: optionalText(parsed, 'details', CREATE_HINT),
97
+ year: intFlag(parsed, 'year', CREATE_HINT),
98
+ quarter: intFlag(parsed, 'quarter', CREATE_HINT),
99
+ week: intFlag(parsed, 'week', CREATE_HINT),
100
+ parentId: optionalText(parsed, 'parent', CREATE_HINT),
101
+ dayOfWeek: dayFlag(parsed, CREATE_HINT),
102
+ domainId: optionalText(parsed, 'domain', CREATE_HINT),
103
+ initiativeId: optionalText(parsed, 'initiative', CREATE_HINT),
104
+ }, now);
105
+ return omitUndefined({
106
+ scope: input.scope,
107
+ title: input.title,
108
+ details: input.details,
109
+ year: input.year,
110
+ quarter: input.quarter,
111
+ week: input.week,
112
+ parentId: input.parentId,
113
+ dayOfWeek: input.dayOfWeek,
114
+ domainId: input.domainId,
115
+ initiativeId: input.initiativeId,
116
+ });
117
+ }
118
+ /** `goals goal create` — one goal in the requested family. */
119
+ export async function runGoalCreate(args, ctx) {
120
+ const parsed = parseFlags(args, CREATE_FLAGS, CREATE_HINT);
121
+ const request = createRequest(parsed, ctx.deps.now());
122
+ const result = await callAsIdentity(ctx, parsed, 'goal.create', request);
123
+ ctx.deps.stdout.write(`Created ${request.scope} goal ${result.id}.\n`);
124
+ }
125
+ /** `goals goal rename` — retitles one goal in place. */
126
+ export async function runGoalRename(args, ctx) {
127
+ const parsed = parseFlags(args, RENAME_FLAGS, RENAME_HINT, ONE_ID);
128
+ const [id = ''] = parsed.positionals;
129
+ const title = requiredText(parsed, 'title', RENAME_HINT);
130
+ const result = await callAsIdentity(ctx, parsed, 'goal.rename', { id, title });
131
+ ctx.deps.stdout.write(`Renamed goal ${result.id}.\n`);
132
+ }
133
+ /** The current ISO week, named in the error when a weekly/daily goal arrives without --week. */
134
+ function missingWeek(verb, scope, now, hint) {
135
+ const week = isoWeekOf(now).week;
136
+ throw usageFailure(`--week is required to ${verb} a ${scope} goal (the current ISO week is ${week})`, hint);
137
+ }
138
+ /**
139
+ * Confirms the already-validated `--week`, or for weekly and daily goals reports a usage error
140
+ * after the one `goal.get` that discovers the scope. Quarterly (and adhoc) need no week.
141
+ */
142
+ async function completionWeek(ctx, credential, flaggedWeek, id, verb, hint) {
143
+ if (flaggedWeek !== undefined)
144
+ return flaggedWeek;
145
+ const detail = await ctx.api.call(credential, 'goal.get', { id });
146
+ if (detail.scope === 'weekly' || detail.scope === 'daily') {
147
+ missingWeek(verb, detail.scope, ctx.deps.now(), hint);
148
+ }
149
+ return undefined;
150
+ }
151
+ async function runSetComplete(args, ctx, isComplete) {
152
+ const verb = isComplete ? 'complete' : 'reopen';
153
+ const hint = `goals goal ${verb} --help`;
154
+ const parsed = parseFlags(args, COMPLETE_FLAGS, hint, ONE_ID);
155
+ const [id = ''] = parsed.positionals;
156
+ // Validate every flag before the credential lookup so usage errors never depend on login.
157
+ const week = intFlag(parsed, 'week', hint);
158
+ const { credential } = await selectIdentity(parsed, ctx);
159
+ const completion = await completionWeek(ctx, credential, week, id, verb, hint);
160
+ const includeChildren = booleanFlag(parsed, 'include-children');
161
+ const result = await ctx.api.call(credential, 'goal.setComplete', omitUndefined({
162
+ id,
163
+ isComplete,
164
+ week: completion,
165
+ includeChildren: includeChildren ? true : undefined,
166
+ }));
167
+ ctx.deps.stdout.write(`Goal ${result.id} is now ${result.isComplete ? 'complete' : 'incomplete'}.\n`);
168
+ }
169
+ /** `goals goal complete` — marks a goal (and optionally its children) complete. */
170
+ export async function runGoalComplete(args, ctx) {
171
+ await runSetComplete(args, ctx, true);
172
+ }
173
+ /** `goals goal reopen` — marks a goal (and optionally its children) incomplete. */
174
+ export async function runGoalReopen(args, ctx) {
175
+ await runSetComplete(args, ctx, false);
176
+ }
177
+ /** `goals goal delete` — deletes one goal and all of its child goals; `--yes` is mandatory. */
178
+ export async function runGoalDelete(args, ctx) {
179
+ const parsed = parseFlags(args, DELETE_FLAGS, DELETE_HINT, ONE_ID);
180
+ const [id = ''] = parsed.positionals;
181
+ if (!booleanFlag(parsed, 'yes')) {
182
+ throw usageFailure(`refusing to delete goal ${id} without --yes: this deletes the goal and all of its child goals`, DELETE_HINT);
183
+ }
184
+ const result = await callAsIdentity(ctx, parsed, 'goal.delete', { id });
185
+ ctx.deps.stdout.write(`Deleted goal ${result.id} and all of its child goals.\n`);
186
+ }
@@ -0,0 +1,15 @@
1
+ import { runFamilyAction } from '../dispatch.js';
2
+ import { runGoalGet, runGoalList } from './goal-read.js';
3
+ import { runGoalComplete, runGoalCreate, runGoalDelete, runGoalRename, runGoalReopen, } from './goal-write.js';
4
+ const ACTIONS = {
5
+ list: runGoalList,
6
+ get: runGoalGet,
7
+ create: runGoalCreate,
8
+ rename: runGoalRename,
9
+ complete: runGoalComplete,
10
+ reopen: runGoalReopen,
11
+ delete: runGoalDelete,
12
+ };
13
+ export async function runGoalCommand(args, ctx) {
14
+ await runFamilyAction('goal', ACTIONS, args, ctx);
15
+ }
@@ -0,0 +1,38 @@
1
+ /** Help data for the `initiative` family; pinned by `src/__views__/initiative-*-help.txt`. */
2
+ export const initiativeHelp = {
3
+ name: 'initiative',
4
+ summary: 'Read your initiatives.',
5
+ actions: {
6
+ list: {
7
+ summary: 'List initiatives.',
8
+ usage: 'goals initiative list [--limit <n>] [--json] [--as <label>]',
9
+ options: [
10
+ { syntax: '--limit <n>', description: 'Maximum rows, 1-500 (default: 200).' },
11
+ { syntax: '--json', description: 'Print a JSON array instead of a table.' },
12
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
13
+ ],
14
+ examples: ['goals initiative list', 'goals initiative list --json'],
15
+ notes: [
16
+ 'An empty list prints `No initiatives found.`; --json prints a bare array.',
17
+ 'The default cap is 200 (--limit max 500); a truncation note goes to stderr.',
18
+ ],
19
+ },
20
+ get: {
21
+ summary: 'Show one initiative and the goals tagged with it.',
22
+ usage: 'goals initiative get <id> [--json] [--as <label>]',
23
+ options: [
24
+ {
25
+ syntax: '<id>',
26
+ description: 'Initiative ID from `goals initiative list` (use --json for scripts).',
27
+ },
28
+ { syntax: '--json', description: 'Print one JSON object instead of text.' },
29
+ { syntax: '--as <label>', description: 'Identity to use (default: the default identity).' },
30
+ ],
31
+ examples: ['goals initiative get init_123', 'goals initiative get init_123 --json'],
32
+ notes: [
33
+ 'IDs come from `goals initiative list` (use --json for scripts).',
34
+ 'The goals table lists goals tagged with the initiative, quarterly first.',
35
+ ],
36
+ },
37
+ },
38
+ };
@@ -0,0 +1,81 @@
1
+ import { booleanFlag, parseFlags } from '../args.js';
2
+ import { callAsIdentity } from '../auth/select.js';
3
+ import { runFamilyAction } from '../dispatch.js';
4
+ import { formatKeyValues, formatTable, toJson } from '../output.js';
5
+ import { intFlag, omitUndefined } from './goal-flags.js';
6
+ import { formatGoalTable, isoDate, plainTextBlock, truncationNote } from './goal-format.js';
7
+ import { writeBoundedList } from './list-output.js';
8
+ const LIST_HINT = 'goals initiative list --help';
9
+ const GET_HINT = 'goals initiative get --help';
10
+ const LIST_FLAGS = {
11
+ limit: { type: 'string' },
12
+ json: { type: 'boolean' },
13
+ as: { type: 'string' },
14
+ };
15
+ const GET_FLAGS = {
16
+ json: { type: 'boolean' },
17
+ as: { type: 'string' },
18
+ };
19
+ const ONE_ID = { min: 1, max: 1, name: '<id>' };
20
+ const HEADERS = ['ID', 'START', 'END', 'TITLE'];
21
+ function initiativeRow(initiative) {
22
+ return [
23
+ initiative.id,
24
+ isoDate(initiative.startDate),
25
+ initiative.endDate === undefined ? '-' : isoDate(initiative.endDate),
26
+ initiative.title,
27
+ ];
28
+ }
29
+ /** `goals initiative list` — a bounded list of initiatives. */
30
+ async function runInitiativeList(args, ctx) {
31
+ const parsed = parseFlags(args, LIST_FLAGS, LIST_HINT);
32
+ const request = omitUndefined({ limit: intFlag(parsed, 'limit', LIST_HINT) });
33
+ const result = await callAsIdentity(ctx, parsed, 'initiative.list', request);
34
+ if (result.truncated)
35
+ ctx.deps.stderr.write(truncationNote('initiatives', result.items.length));
36
+ writeBoundedList(ctx, parsed, result, 'No initiatives found.\n', (items) => formatTable(HEADERS, items.map(initiativeRow), []));
37
+ }
38
+ function initiativeRows(initiative) {
39
+ const rows = [
40
+ ['ID', initiative.id],
41
+ ['Title', initiative.title],
42
+ ['Start', isoDate(initiative.startDate)],
43
+ ];
44
+ if (initiative.endDate !== undefined)
45
+ rows.push(['End', isoDate(initiative.endDate)]);
46
+ return rows;
47
+ }
48
+ /** The text page: key/values, plain-text description, then the goals table or an empty note. */
49
+ function formatInitiativeDetail(result) {
50
+ const goals = result.goals.items;
51
+ const blocks = [
52
+ formatKeyValues(initiativeRows(result.initiative)).trimEnd(),
53
+ ...plainTextBlock('Description:', result.initiative.description ?? ''),
54
+ '',
55
+ 'Goals:',
56
+ goals.length === 0 ? 'No goals found.' : formatGoalTable(goals).trimEnd(),
57
+ ];
58
+ return `${blocks.join('\n')}\n`;
59
+ }
60
+ /** `goals initiative get` — one initiative plus its goals table. */
61
+ async function runInitiativeGet(args, ctx) {
62
+ const parsed = parseFlags(args, GET_FLAGS, GET_HINT, ONE_ID);
63
+ const [id = ''] = parsed.positionals;
64
+ const result = await callAsIdentity(ctx, parsed, 'initiative.get', { id });
65
+ // Diagnostics go to stderr in both modes; stdout carries only the requested result.
66
+ if (result.goals.truncated) {
67
+ ctx.deps.stderr.write(truncationNote('goals', result.goals.items.length));
68
+ }
69
+ if (booleanFlag(parsed, 'json')) {
70
+ ctx.deps.stdout.write(toJson({ initiative: result.initiative, goals: result.goals.items }));
71
+ return;
72
+ }
73
+ ctx.deps.stdout.write(formatInitiativeDetail(result));
74
+ }
75
+ const ACTIONS = {
76
+ list: runInitiativeList,
77
+ get: runInitiativeGet,
78
+ };
79
+ export async function runInitiativeCommand(args, ctx) {
80
+ await runFamilyAction('initiative', ACTIONS, args, ctx);
81
+ }
@@ -0,0 +1,13 @@
1
+ import { booleanFlag } from '../args.js';
2
+ import { toJson } from '../output.js';
3
+ /**
4
+ * Writes a bounded list: a bare JSON array with `--json`, else the caller's text table or the
5
+ * command's empty message. stdout carries only the list; truncation notes go to stderr.
6
+ */
7
+ export function writeBoundedList(ctx, parsed, result, empty, format) {
8
+ if (booleanFlag(parsed, 'json')) {
9
+ ctx.deps.stdout.write(toJson(result.items));
10
+ return;
11
+ }
12
+ ctx.deps.stdout.write(result.items.length === 0 ? empty : format(result.items));
13
+ }
@@ -0,0 +1,18 @@
1
+ /** Help data for the `skill` family; pinned by `src/__views__/skill-*-help.txt`. */
2
+ export const skillHelp = {
3
+ name: 'skill',
4
+ summary: 'Print the agent skill that explains this CLI.',
5
+ actions: {
6
+ activate: {
7
+ summary: 'Print the install guidance, the skill stub and the full command reference.',
8
+ usage: 'goals skill activate',
9
+ options: [{ syntax: '--help, -h', description: 'Show this help.' }],
10
+ examples: ['goals skill activate'],
11
+ notes: [
12
+ 'Prints to stdout and writes no files.',
13
+ 'Makes no network call and works when you are logged out.',
14
+ 'Save the printed stub as a skill named goals-cli so your agent can find it.',
15
+ ],
16
+ },
17
+ },
18
+ };