@giftsofprometheus/cli 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +77 -3
- package/dist/skill-files.js +44 -3
- package/package.json +1 -1
- package/skills/giftsofprometheus/SKILL.md +22 -3
- package/skills/history.json +10 -0
package/dist/index.js
CHANGED
|
@@ -3,12 +3,12 @@ import { z } from 'zod';
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { chmod, lstat, mkdir, readFile, realpath, rename, stat, writeFile, unlink } from 'node:fs/promises';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
|
-
import { isAbsolute, join } from 'node:path';
|
|
6
|
+
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
7
7
|
import { spawn } from 'node:child_process';
|
|
8
8
|
import { randomUUID } from 'node:crypto';
|
|
9
9
|
import { createRequire } from 'node:module';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
|
-
import { mergeSkill, newerVersion, skillHash } from './skill-files.js';
|
|
11
|
+
import { mergeSkill, newerVersion, personalDescription, skillDescription, skillHash, tailTopics } from './skill-files.js';
|
|
12
12
|
const { version } = z.object({ version: z.string() }).parse(createRequire(import.meta.url)('../package.json'));
|
|
13
13
|
const program = new Command();
|
|
14
14
|
const base = (process.env.GIFTSOFPROMETHEUS_URL || 'https://giftsofprometheus.com').replace(/\/$/, '');
|
|
@@ -85,7 +85,7 @@ async function readState(file, schema) {
|
|
|
85
85
|
}
|
|
86
86
|
async function request(path, method = 'GET', body, authenticated = true) {
|
|
87
87
|
if (!path.startsWith('/') || path.includes('\\'))
|
|
88
|
-
throw new ApiError(
|
|
88
|
+
throw new ApiError(`Invalid API path: pass a full path starting with ${publicApi.join(', ')}, e.g. /api/knowledge/profile`);
|
|
89
89
|
const target = new URL(base + path);
|
|
90
90
|
// Checked after URL normalization, so `..` cannot leave the public API
|
|
91
91
|
if (target.origin !== new URL(base).origin || !publicApi.some(prefix => target.pathname.startsWith(prefix)))
|
|
@@ -527,6 +527,17 @@ talks
|
|
|
527
527
|
console.error(`Next: open one with ${launcher} talks content <slug> --rec-id ${result.recId}`);
|
|
528
528
|
return result;
|
|
529
529
|
}));
|
|
530
|
+
const reactionTypes = { like: 'like', dislike: 'dislike', 'not-interested': 'not_interested', clear: 'clear_reaction' };
|
|
531
|
+
talks
|
|
532
|
+
.command('react')
|
|
533
|
+
.description('Record what the user said about a talk: like, dislike, not-interested or clear')
|
|
534
|
+
.argument('<slug-or-id>')
|
|
535
|
+
.argument('<reaction>', Object.keys(reactionTypes).join(' | '))
|
|
536
|
+
.option('--rec-id <recId>', 'recId of the list the talk came from')
|
|
537
|
+
.action(run(async (id, reaction, options) => {
|
|
538
|
+
const type = z.enum(['like', 'dislike', 'not-interested', 'clear']).parse(reaction);
|
|
539
|
+
return event(id, reactionTypes[type], options.recId);
|
|
540
|
+
}));
|
|
530
541
|
const favorites = program.command('favorites').description('Manage bookmarks');
|
|
531
542
|
favorites
|
|
532
543
|
.command('list')
|
|
@@ -707,6 +718,69 @@ skill
|
|
|
707
718
|
.description('Replace installed copies of the skill that are older than this CLI; a custom description is kept')
|
|
708
719
|
.option('--force', 'also replace copies that were edited by hand')
|
|
709
720
|
.action(run((options) => updateSkills(Boolean(options.force))));
|
|
721
|
+
const profileTopics = z.object({
|
|
722
|
+
interests: z.array(z.object({ topic: z.string().optional(), level: z.enum(['high', 'interested', 'not_interested']) })),
|
|
723
|
+
topics: z.array(z.object({ slug: z.string(), title: z.string(), section: z.string().nullable() })),
|
|
724
|
+
});
|
|
725
|
+
/** Titles of the user's topics for the skill tail: strong interests first, subtopics before whole sections */
|
|
726
|
+
async function personalTopics() {
|
|
727
|
+
const profile = profileTopics.parse(await request('/api/knowledge/profile'));
|
|
728
|
+
const bySlug = new Map(profile.topics.map(t => [t.slug, t]));
|
|
729
|
+
return profile.interests
|
|
730
|
+
.flatMap(i => {
|
|
731
|
+
const topic = i.topic === undefined ? undefined : bySlug.get(i.topic);
|
|
732
|
+
return topic && i.level !== 'not_interested' ? [{ title: topic.title, order: (i.level === 'high' ? 0 : 2) + (topic.section ? 0 : 1) }] : [];
|
|
733
|
+
})
|
|
734
|
+
.sort((a, b) => a.order - b.order)
|
|
735
|
+
.map(t => t.title);
|
|
736
|
+
}
|
|
737
|
+
// A command the user can paste into their own terminal, where the file may be writable
|
|
738
|
+
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
739
|
+
/**
|
|
740
|
+
* Adds the user's topics to the description of the skill copy the agent loaded, so the agent reaches for it on them too.
|
|
741
|
+
* Only a SKILL.md of this skill is changed; a copy that cannot be written is reported with a command for the user.
|
|
742
|
+
*/
|
|
743
|
+
async function personalizeSkill(o) {
|
|
744
|
+
const given = resolve(o.file);
|
|
745
|
+
const file = basename(given) === 'SKILL.md' ? given : join(given, 'SKILL.md');
|
|
746
|
+
let text;
|
|
747
|
+
try {
|
|
748
|
+
text = await readFile(file, 'utf8');
|
|
749
|
+
}
|
|
750
|
+
catch {
|
|
751
|
+
throw new ApiError(`No skill file at ${file}`);
|
|
752
|
+
}
|
|
753
|
+
if (!/^---\r?\nname: giftsofprometheus\r?\n/.test(text))
|
|
754
|
+
throw new ApiError(`${file} is not the giftsofprometheus skill`);
|
|
755
|
+
const line = skillDescription(text);
|
|
756
|
+
if (!line)
|
|
757
|
+
throw new ApiError(`${file} has no description line`);
|
|
758
|
+
const topics = tailTopics(await personalTopics());
|
|
759
|
+
const next = personalDescription(line, topics);
|
|
760
|
+
if (next === line)
|
|
761
|
+
return { personalized: true, changed: false, path: file, topics };
|
|
762
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
763
|
+
try {
|
|
764
|
+
await writeFile(temporary, text.replace(/\r\n/g, '\n').replace(line, () => next), { mode: (await stat(file)).mode & 0o777, flag: 'wx' });
|
|
765
|
+
await rename(temporary, file);
|
|
766
|
+
}
|
|
767
|
+
catch (e) {
|
|
768
|
+
await unlink(temporary).catch(() => { });
|
|
769
|
+
return {
|
|
770
|
+
personalized: false,
|
|
771
|
+
path: file,
|
|
772
|
+
topics,
|
|
773
|
+
reason: e instanceof Error ? e.message : 'Write failed',
|
|
774
|
+
command: `${launcher} skill personalize --file ${shellQuote(file)}`,
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
return { personalized: true, changed: true, path: file, topics };
|
|
778
|
+
}
|
|
779
|
+
skill
|
|
780
|
+
.command('personalize')
|
|
781
|
+
.description("Add the user's topics (ten words at most) to the description of the skill copy at --file; requires login")
|
|
782
|
+
.requiredOption('--file <path>', 'SKILL.md of the loaded skill, or its folder')
|
|
783
|
+
.action(run(personalizeSkill));
|
|
710
784
|
// The daily check runs after the command, so it never delays or breaks its output; doctor and skill report the same state themselves
|
|
711
785
|
let skipNotice = false;
|
|
712
786
|
program.hook('preAction', (_, action) => {
|
package/dist/skill-files.js
CHANGED
|
@@ -15,12 +15,20 @@ export function skillHash(text) {
|
|
|
15
15
|
.trim();
|
|
16
16
|
return createHash('sha256').update(body).digest('hex').slice(0, 16);
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The bundled skill with the installed description kept, unless that description is one the CLI shipped.
|
|
20
|
+
* A shipped description with a personal tail becomes the new shipped description with the same tail.
|
|
21
|
+
*/
|
|
19
22
|
export function mergeSkill(bundled, installed, stockDescriptions) {
|
|
20
23
|
const own = skillDescription(installed);
|
|
21
|
-
|
|
24
|
+
const text = bundled.replace(/\r\n/g, '\n');
|
|
25
|
+
if (!own)
|
|
22
26
|
return bundled;
|
|
23
|
-
|
|
27
|
+
if (stockDescriptions.includes(baseDescription(own))) {
|
|
28
|
+
const fresh = skillDescription(text);
|
|
29
|
+
return fresh ? text.replace(DESCRIPTION, () => `${fresh}${personalTail(own)}`) : bundled;
|
|
30
|
+
}
|
|
31
|
+
return text.replace(DESCRIPTION, () => own);
|
|
24
32
|
}
|
|
25
33
|
export function newerVersion(latest, current) {
|
|
26
34
|
const parse = (value) => value.split('-')[0]?.split('.').map(Number) ?? [];
|
|
@@ -34,3 +42,36 @@ export function newerVersion(latest, current) {
|
|
|
34
42
|
}
|
|
35
43
|
return false;
|
|
36
44
|
}
|
|
45
|
+
// A personal tail: up to ten words in all, naming the user's topics, so the agent also reaches for the skill on them
|
|
46
|
+
const TAIL_PREFIX = ' Also good for ';
|
|
47
|
+
const TAIL = / Also good for [^\n]*$/;
|
|
48
|
+
const TAIL_WORDS = 10;
|
|
49
|
+
/** Topic titles that fit the tail, in the given order; characters YAML or the line could trip on are dropped */
|
|
50
|
+
export function tailTopics(titles) {
|
|
51
|
+
const chosen = [];
|
|
52
|
+
let words = TAIL_PREFIX.trim().split(/\s+/).length;
|
|
53
|
+
for (const raw of titles) {
|
|
54
|
+
const title = raw
|
|
55
|
+
.replace(/[:#"'`\n\r;]/g, ' ')
|
|
56
|
+
.replace(/\s+/g, ' ')
|
|
57
|
+
.trim();
|
|
58
|
+
const count = title ? title.split(' ').length : 0;
|
|
59
|
+
if (!count || chosen.includes(title) || words + count > TAIL_WORDS)
|
|
60
|
+
continue;
|
|
61
|
+
chosen.push(title);
|
|
62
|
+
words += count;
|
|
63
|
+
}
|
|
64
|
+
return chosen;
|
|
65
|
+
}
|
|
66
|
+
/** The description line without a personal tail */
|
|
67
|
+
export function baseDescription(line) {
|
|
68
|
+
return line.replace(TAIL, '');
|
|
69
|
+
}
|
|
70
|
+
/** The description line with a tail for these topics, or without one when there are none */
|
|
71
|
+
export function personalDescription(line, topics) {
|
|
72
|
+
const base = baseDescription(line);
|
|
73
|
+
return topics.length ? `${base}${TAIL_PREFIX}${topics.join('; ')}.` : base;
|
|
74
|
+
}
|
|
75
|
+
export function personalTail(line) {
|
|
76
|
+
return line.match(TAIL)?.[0] ?? '';
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -47,9 +47,9 @@ giftsofprometheus --json profile get # interests and curre
|
|
|
47
47
|
- Lists are paginated: check `totalPages` and pass `--page`.
|
|
48
48
|
- Search and use the returned `slug` or `id` for exact reads.
|
|
49
49
|
- A transcript is in the talk's original language. Segment timecodes are in milliseconds from the start of the talk. When a talk is a part of a longer recording, `sourceRange` gives its bounds in that recording. A talk without a transcript returns an empty array.
|
|
50
|
-
- `request <path>` makes a read-only GET to a path under `/api/knowledge/` or `/api/account/` that no command covers.
|
|
50
|
+
- `request <path>` makes a read-only GET to a full path under `/api/knowledge/` or `/api/account/` that no command covers, for example `request /api/knowledge/talks/<slug>/state` for the user's current reaction and bookmark on a talk.
|
|
51
51
|
- Reading never needs the user's confirmation: search, open talks and transcripts as the task requires.
|
|
52
|
-
- A list with a `recId` (feed, search, similar)
|
|
52
|
+
- A list with a `recId` (feed, search, similar, `ask`) returns it at the top of the response. When you open a talk from that list, pass it on: `talks content <slug> --rec-id <recId>`, and `favorites add <slug> --rec-id <recId>` when the user saves it.
|
|
53
53
|
|
|
54
54
|
## Next steps
|
|
55
55
|
|
|
@@ -61,6 +61,25 @@ After answering, offer one next step in a short line, matched to where the user
|
|
|
61
61
|
|
|
62
62
|
Commands print the suggested next command on stderr. It is a hint for you; do not run a change without the user.
|
|
63
63
|
|
|
64
|
+
## Feedback
|
|
65
|
+
|
|
66
|
+
Once per conversation, when the user is signed in and you opened two or more transcripts for them (from any list, including `ask`), ask in one message how the talks landed, as a natural continuation: "Of these, which hit the mark and which missed?" with the titles as a short numbered list. Ask when their question is answered, not in the middle of their work, and never again in the same conversation.
|
|
67
|
+
|
|
68
|
+
Record only what the user said, one command per talk, with the `recId` of the list the talk came from:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
giftsofprometheus --json talks react <slug-or-id> like|dislike|not-interested|clear --rec-id <recId>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
"Useful", "great" → `like`; "missed", "too basic" → `dislike`; "not my topic" → `not-interested`; talks they did not mention stay unjudged. Then say in one line that the feed takes it into account. If they ignore the question, drop it.
|
|
75
|
+
|
|
76
|
+
## Personal topics
|
|
77
|
+
|
|
78
|
+
After `onboarding finish` or a `profile update` that changed interests, run `giftsofprometheus --json skill personalize --file <path of this SKILL.md>` with the path you loaded this skill from. It adds the user's topics, ten words at most, to this skill's description, so the next conversations reach for talks on those topics too. Do not ask first; it changes only this skill file.
|
|
79
|
+
|
|
80
|
+
- `personalized: true`: tell the user in two or three words, for example "Skill tuned to your topics." Say nothing when `changed` is `false`.
|
|
81
|
+
- `personalized: false`: the file could not be written. Tell the user in one line and give them `command` from the output to run in their terminal.
|
|
82
|
+
|
|
64
83
|
## Onboarding
|
|
65
84
|
|
|
66
85
|
Run it when the user asks for onboarding. Offer it when `profile get` returns `needsOnboarding: true`, or when the user is not signed in and asks what to watch. It takes a minute and needs no account until the last step; the user fills in nothing, they answer in the chat.
|
|
@@ -89,7 +108,7 @@ giftsofprometheus --json favorites remove <slug-or-id>
|
|
|
89
108
|
giftsofprometheus --json profile update --interest agents=high --remove-interest rag --query-text 'evaluate coding agents'
|
|
90
109
|
```
|
|
91
110
|
|
|
92
|
-
`profile update` changes only the fields you pass: `--interest <topic>=high|interested|not_interested` and `--remove-interest <topic>` (both repeatable; topic slugs are in `profile get`) and `--query-text <text>`. Pass only values the user gave or confirmed; never put file contents, secrets or environment values into an argument. Reading, searching or opening a transcript is never approval to save a talk, react to it or change interests.
|
|
111
|
+
`profile update` changes only the fields you pass: `--interest <topic>=high|interested|not_interested` and `--remove-interest <topic>` (both repeatable; topic slugs are in `profile get`) and `--query-text <text>`. Pass only values the user gave or confirmed; never put file contents, secrets or environment values into an argument. Reading, searching or opening a transcript is never approval to save a talk, react to it or change interests. Reactions follow Feedback: only the user's own words about a talk.
|
|
93
112
|
|
|
94
113
|
## Errors
|
|
95
114
|
|
package/skills/history.json
CHANGED
|
@@ -43,5 +43,15 @@
|
|
|
43
43
|
"version": "0.4.0",
|
|
44
44
|
"hash": "2beae7a9ece869e0",
|
|
45
45
|
"description": "description: Find AI conference talks (AI Engineer, BAAI, Apsara and others) with Russian summaries, read their full transcripts, and manage the signed-in user's favorites, interests and personal feed through the giftsofprometheus CLI, and build a starting profile in the chat. Use when the user asks for talks, speakers or transcripts on an AI engineering topic, or wants to save, list or remove favorites on Gifts of Prometheus."
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"version": "0.5.0",
|
|
49
|
+
"hash": "d67f041ffd94e30e",
|
|
50
|
+
"description": "description: Find AI conference talks (AI Engineer, BAAI, Apsara and others) with Russian summaries, read their full transcripts, and manage the signed-in user's favorites, interests and personal feed through the giftsofprometheus CLI, and build a starting profile in the chat. Use when the user asks for talks, speakers or transcripts on an AI engineering topic, or wants to save, list or remove favorites on Gifts of Prometheus."
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"version": "0.5.1",
|
|
54
|
+
"hash": "a5decd76f9054068",
|
|
55
|
+
"description": "description: Find AI conference talks (AI Engineer, BAAI, Apsara and others) with Russian summaries, read their full transcripts, and manage the signed-in user's favorites, interests and personal feed through the giftsofprometheus CLI, and build a starting profile in the chat. Use when the user asks for talks, speakers or transcripts on an AI engineering topic, or wants to save, list or remove favorites on Gifts of Prometheus."
|
|
46
56
|
}
|
|
47
57
|
]
|