@crewx/dreaming 0.1.0-rc.171 → 0.1.0-rc.173

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/cli.d.ts CHANGED
@@ -4,4 +4,4 @@ import type { TaskLogEntry } from '@crewx/sdk/repository';
4
4
  export declare const DEFAULT_ACTIVITY_LOG_BUDGET = 8000;
5
5
  export declare function readCanonicalTaskLogs(taskRepo: Pick<TaskRepository, 'readLogs'>, taskId: string): TaskLogEntry[];
6
6
  export declare function main(inputArgs?: string[]): Promise<void>;
7
- //# sourceMappingURL=cli.d.ts.map
7
+
package/dist/cli.js CHANGED
@@ -1,101 +1,6 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.DEFAULT_ACTIVITY_LOG_BUDGET = void 0;
38
- exports.readCanonicalTaskLogs = readCanonicalTaskLogs;
39
- exports.main = main;
40
- const sdk_1 = require("@crewx/sdk");
41
- const fs = __importStar(require("fs"));
42
- const path = __importStar(require("path"));
43
- const analyzer_js_1 = require("./src/analyzer.js");
44
- const scrub_js_1 = require("./src/scrub.js");
45
- const renderer_js_1 = require("./src/renderer.js");
46
- exports.DEFAULT_ACTIVITY_LOG_BUDGET = 8000;
47
- const DEFAULT_TASK_TIMELINE = 60;
48
- const CONTINUE_LATEST_TIMELINE = 30;
49
- function parseFlags(argv) {
50
- const flags = {
51
- task: null,
52
- thread: null,
53
- agent: null,
54
- days: 1,
55
- recent: null,
56
- json: false,
57
- all: false,
58
- continue: false,
59
- full: false,
60
- lookback: 3,
61
- activityLog: false,
62
- };
63
- for (const a of argv) {
64
- if (a === '--json')
65
- flags.json = true;
66
- else if (a === '--all')
67
- flags.all = true;
68
- else if (a === '--full')
69
- flags.full = true;
70
- else if (a === '--continue')
71
- flags.continue = true;
72
- else if (a === '--activity-log')
73
- flags.activityLog = true;
74
- else if (a.startsWith('--task='))
75
- flags.task = a.slice('--task='.length);
76
- else if (a.startsWith('--thread='))
77
- flags.thread = a.slice('--thread='.length);
78
- else if (a.startsWith('--agent='))
79
- flags.agent = a.slice('--agent='.length);
80
- else if (a.startsWith('--days='))
81
- flags.days = parseInt(a.slice('--days='.length), 10);
82
- else if (a.startsWith('--recent='))
83
- flags.recent = parseInt(a.slice('--recent='.length), 10);
84
- else if (a.startsWith('--lookback='))
85
- flags.lookback = parseInt(a.slice('--lookback='.length), 10);
86
- else if (a === '--help' || a === '-h') {
87
- printUsage();
88
- process.exit(0);
89
- }
90
- else if (a.startsWith('--')) {
91
- console.error(`Unknown option: ${a}\nRun with --help for usage.`);
92
- process.exit(1);
93
- }
94
- }
95
- return flags;
96
- }
97
- function printUsage() {
98
- console.log(`crewx dreaming — Selective reflection skill
2
+ "use strict";var j=exports&&exports.__createBinding||(Object.create?(function(r,t,e,n){if(n===void 0)n=e;var s=Object.getOwnPropertyDescriptor(t,e);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[e]}}}Object.defineProperty(r,n,s)}):(function(r,t,e,n){if(n===void 0)n=e;r[n]=t[e]}));var E=exports&&exports.__setModuleDefault||(Object.create?(function(r,t){Object.defineProperty(r,"default",{enumerable:true,value:t})}):function(r,t){r["default"]=t});var T=exports&&exports.__importStar||(function(){var r=function(t){r=Object.getOwnPropertyNames||function(e){var n=[];for(var s in e)if(Object.prototype.hasOwnProperty.call(e,s))n[n.length]=s;return n};return r(t)};return function(t){if(t&&t.__esModule)return t;var e={};if(t!=null){for(var n=r(t),s=0;s<n.length;s++)if(n[s]!=="default")j(e,t,n[s])}E(e,t);return e}})();Object.defineProperty(exports,"__esModule",{value:true});exports.DEFAULT_ACTIVITY_LOG_BUDGET=void 0;exports.readCanonicalTaskLogs=D;exports.main=A;const b=require("@crewx/sdk");const I=T(require("fs"));const L=T(require("path"));const k=require("./src/analyzer.js");const N=require("./src/scrub.js");const d=require("./src/renderer.js");exports.DEFAULT_ACTIVITY_LOG_BUDGET=8e3;const O=60;const S=30;function C(r){const t={task:null,thread:null,agent:null,days:1,recent:null,json:false,all:false,continue:false,full:false,lookback:3,activityLog:false};for(const e of r){if(e==="--json")t.json=true;else if(e==="--all")t.all=true;else if(e==="--full")t.full=true;else if(e==="--continue")t.continue=true;else if(e==="--activity-log")t.activityLog=true;else if(e.startsWith("--task="))t.task=e.slice("--task=".length);else if(e.startsWith("--thread="))t.thread=e.slice("--thread=".length);else if(e.startsWith("--agent="))t.agent=e.slice("--agent=".length);else if(e.startsWith("--days="))t.days=parseInt(e.slice("--days=".length),10);else if(e.startsWith("--recent="))t.recent=parseInt(e.slice("--recent=".length),10);else if(e.startsWith("--lookback="))t.lookback=parseInt(e.slice("--lookback=".length),10);else if(e==="--help"||e==="-h"){y();process.exit(0)}else if(e.startsWith("--")){console.error(`Unknown option: ${e}
3
+ Run with --help for usage.`);process.exit(1)}}return t}function y(){console.log(`crewx dreaming \u2014 Selective reflection skill
99
4
 
100
5
  A first-class reflection tool agents call before/after work or during retries to recover context.
101
6
  Use it proactively alongside memory/doc/search when the situation calls for it.
@@ -130,203 +35,4 @@ Examples:
130
35
  crewx dreaming --thread=thd_xyz789 --recent=5
131
36
  crewx dreaming --thread=thd_xyz789 --agent=core_lead --continue
132
37
  crewx dreaming --thread=thd_xyz789 --agent=core_lead --activity-log --lookback=2
133
- `);
134
- }
135
- function showDetailedUsage() {
136
- const skillMd = path.join(__dirname, '..', 'SKILL.md');
137
- if (fs.existsSync(skillMd)) {
138
- process.stdout.write(fs.readFileSync(skillMd, 'utf-8'));
139
- }
140
- else {
141
- printUsage();
142
- }
143
- }
144
- function resolveAgent(agent) {
145
- if (agent !== 'self')
146
- return agent;
147
- const envAgent = process.env.CREWX_AGENT_ID;
148
- if (!envAgent) {
149
- console.error('Error: --agent=self requires CREWX_AGENT_ID in the environment.\n' +
150
- 'Pass an explicit agent id instead, e.g. --agent=core_lead.');
151
- process.exit(1);
152
- }
153
- return envAgent;
154
- }
155
- function jsonSafeAnalysis(a, full) {
156
- if (full)
157
- return a;
158
- return {
159
- ...a,
160
- timeline: a.timeline.map((e) => {
161
- const { input: _input, resultPreview: _resultPreview, ...rest } = e;
162
- return rest;
163
- }),
164
- };
165
- }
166
- function writeJson(obj) {
167
- process.stdout.write(JSON.stringify((0, scrub_js_1.scrubSecrets)(obj), null, 2) + '\n');
168
- }
169
- function topLevelByThread(taskRepo, threadId) {
170
- return taskRepo
171
- .findTasksByThread(threadId)
172
- .filter((t) => !t.parent_task_id)
173
- .sort((a, b) => (b.started_at > a.started_at ? 1 : -1));
174
- }
175
- function readCanonicalTaskLogs(taskRepo, taskId) {
176
- try {
177
- return taskRepo.readLogs(taskId)?.entries ?? [];
178
- }
179
- catch {
180
- return [];
181
- }
182
- }
183
- function analyzeCanonicalTask(taskRepo, spanRepo, row) {
184
- return (0, analyzer_js_1.analyzeTask)(row, spanRepo.findByTaskId(row.id), readCanonicalTaskLogs(taskRepo, row.id));
185
- }
186
- async function main(inputArgs) {
187
- const args = inputArgs ?? process.argv.slice(2);
188
- if (args[0] === 'usage') {
189
- showDetailedUsage();
190
- return;
191
- }
192
- if (!args.length || args[0] === '--help' || args[0] === '-h') {
193
- printUsage();
194
- return;
195
- }
196
- const flags = parseFlags(args);
197
- const agent = resolveAgent(flags.agent);
198
- if (!flags.task && !flags.thread) {
199
- console.error('Error: --task=<id> or --thread=<id> is required.\nRun crewx dreaming --help for usage.');
200
- process.exit(1);
201
- }
202
- const taskRepo = new sdk_1.TaskRepository();
203
- const spanRepo = new sdk_1.SpanRepository();
204
- if (flags.task) {
205
- const row = taskRepo.getTask(flags.task);
206
- if (!row) {
207
- console.log(`No task found: ${flags.task}`);
208
- return;
209
- }
210
- const result = analyzeCanonicalTask(taskRepo, spanRepo, row);
211
- if (flags.json) {
212
- writeJson(jsonSafeAnalysis(result, flags.full));
213
- return;
214
- }
215
- const detail = (0, renderer_js_1.renderTaskFull)(result, {
216
- maxTimeline: flags.full ? null : DEFAULT_TASK_TIMELINE,
217
- });
218
- const actions = [];
219
- if (!flags.full) {
220
- actions.push({ label: 'Full activity log', cmd: `crewx dreaming --task=${result.taskId} --full` });
221
- }
222
- actions.push({ label: 'Detailed task log JSON', cmd: `crewx dreaming --task=${result.taskId} --json` });
223
- console.log(detail + '\n' + (0, renderer_js_1.buildCalFooter)(actions));
224
- return;
225
- }
226
- if (flags.thread && flags.activityLog) {
227
- if (!agent) {
228
- console.error('Error: --activity-log requires --agent=<id> (or --agent=self).');
229
- process.exit(1);
230
- }
231
- const lookback = flags.lookback;
232
- if (lookback === 0) {
233
- if (flags.json) {
234
- writeJson({ mode: 'activity-log', lookback: 0, entries: [], truncated: false, xml: '' });
235
- }
236
- else {
237
- process.stdout.write('');
238
- }
239
- return;
240
- }
241
- const rows = topLevelByThread(taskRepo, flags.thread)
242
- .filter((t) => t.agent_id === agent)
243
- .slice(0, Math.min(lookback, 5));
244
- const analyses = rows.map((t) => analyzeCanonicalTask(taskRepo, spanRepo, t));
245
- const log = (0, analyzer_js_1.buildActivityLog)(analyses, flags.thread, agent, lookback, exports.DEFAULT_ACTIVITY_LOG_BUDGET);
246
- if (flags.json) {
247
- writeJson({ mode: 'activity-log', ...log, xml: (0, renderer_js_1.renderActivityLogXml)(log) });
248
- return;
249
- }
250
- process.stdout.write((0, renderer_js_1.renderActivityLogXml)(log) + '\n');
251
- return;
252
- }
253
- if (flags.thread && flags.continue) {
254
- if (!agent) {
255
- console.error('Error: --continue requires --agent=<id> (or --agent=self).');
256
- process.exit(1);
257
- }
258
- const recent = flags.recent ?? 3;
259
- const rows = topLevelByThread(taskRepo, flags.thread).filter((t) => t.agent_id === agent).slice(0, recent + 1);
260
- const analyses = rows.map((t) => analyzeCanonicalTask(taskRepo, spanRepo, t));
261
- const latest = analyses[0] ?? null;
262
- const previous = analyses.slice(1).map(analyzer_js_1.summarizeAnalysis);
263
- const result = {
264
- mode: 'continue',
265
- thread: flags.thread,
266
- agent,
267
- latest,
268
- previous,
269
- };
270
- if (flags.json) {
271
- writeJson({
272
- ...result,
273
- latest: latest ? jsonSafeAnalysis(latest, flags.full) : null,
274
- });
275
- return;
276
- }
277
- const body = (0, renderer_js_1.renderContinue)(result, {
278
- maxTimeline: flags.full ? null : CONTINUE_LATEST_TIMELINE,
279
- });
280
- const actions = [];
281
- const drill = previous[0]?.taskId ?? latest?.taskId;
282
- if (drill) {
283
- actions.push({ label: 'Full activity log', cmd: `crewx dreaming --task=${drill} --full` });
284
- actions.push({ label: 'Detailed task log JSON', cmd: `crewx dreaming --task=${drill} --json` });
285
- }
286
- actions.push({
287
- label: 'Task list for this conversation',
288
- cmd: `crewx dreaming --thread=${flags.thread} --agent=${agent}`,
289
- });
290
- console.log(body + (actions.length ? '\n' + (0, renderer_js_1.buildCalFooter)(actions) : ''));
291
- return;
292
- }
293
- if (flags.thread) {
294
- const recent = flags.recent ?? 5;
295
- let topLevel = topLevelByThread(taskRepo, flags.thread);
296
- if (agent)
297
- topLevel = topLevel.filter((t) => t.agent_id === agent);
298
- topLevel = topLevel.slice(0, recent);
299
- const summaryRows = topLevel.map((t) => ({
300
- taskId: t.id,
301
- agentId: t.agent_id,
302
- status: t.status,
303
- promptSummary: t.prompt ? t.prompt.split('\n')[0].slice(0, 100) : null,
304
- startedAt: t.started_at,
305
- duration: t.duration_ms != null ? Math.round(t.duration_ms / 1000) : null,
306
- }));
307
- if (flags.json) {
308
- writeJson(summaryRows);
309
- return;
310
- }
311
- const list = (0, renderer_js_1.renderThreadTaskList)(summaryRows, flags.thread, recent);
312
- const actions = [];
313
- const first = summaryRows[0];
314
- if (first) {
315
- const agentArg = agent ?? first.agentId;
316
- actions.push({
317
- label: 'Continue previous work',
318
- cmd: `crewx dreaming --thread=${flags.thread} --agent=${agentArg} --continue`,
319
- });
320
- actions.push({ label: 'Task drilldown', cmd: `crewx dreaming --task=${first.taskId} --full` });
321
- }
322
- console.log(list + (actions.length ? '\n' + (0, renderer_js_1.buildCalFooter)(actions) : ''));
323
- return;
324
- }
325
- }
326
- if (require.main === module) {
327
- main().catch((e) => {
328
- console.error(e.message);
329
- process.exit(1);
330
- });
331
- }
332
- //# sourceMappingURL=cli.js.map
38
+ `)}function R(){const r=L.join(__dirname,"..","SKILL.md");if(I.existsSync(r)){process.stdout.write(I.readFileSync(r,"utf-8"))}else{y()}}function U(r){if(r!=="self")return r;const t=process.env.CREWX_AGENT_ID;if(!t){console.error("Error: --agent=self requires CREWX_AGENT_ID in the environment.\nPass an explicit agent id instead, e.g. --agent=core_lead.");process.exit(1)}return t}function x(r,t){if(t)return r;return{...r,timeline:r.timeline.map(e=>{const{input:n,resultPreview:s,...g}=e;return g})}}function p(r){process.stdout.write(JSON.stringify((0,N.scrubSecrets)(r),null,2)+"\n")}function v(r,t){return r.findTasksByThread(t).filter(e=>!e.parent_task_id).sort((e,n)=>n.started_at>e.started_at?1:-1)}function D(r,t){try{return r.readLogs(t)?.entries??[]}catch{return[]}}function w(r,t,e){return(0,k.analyzeTask)(e,t.findByTaskId(e.id),D(r,e.id))}async function A(r){const t=r??process.argv.slice(2);if(t[0]==="usage"){R();return}if(!t.length||t[0]==="--help"||t[0]==="-h"){y();return}const e=C(t);const n=U(e.agent);if(!e.task&&!e.thread){console.error("Error: --task=<id> or --thread=<id> is required.\nRun crewx dreaming --help for usage.");process.exit(1)}const s=new b.TaskRepository;const g=new b.SpanRepository;if(e.task){const l=s.getTask(e.task);if(!l){console.log(`No task found: ${e.task}`);return}const a=w(s,g,l);if(e.json){p(x(a,e.full));return}const u=(0,d.renderTaskFull)(a,{maxTimeline:e.full?null:O});const i=[];if(!e.full){i.push({label:"Full activity log",cmd:`crewx dreaming --task=${a.taskId} --full`})}i.push({label:"Detailed task log JSON",cmd:`crewx dreaming --task=${a.taskId} --json`});console.log(u+"\n"+(0,d.buildCalFooter)(i));return}if(e.thread&&e.activityLog){if(!n){console.error("Error: --activity-log requires --agent=<id> (or --agent=self).");process.exit(1)}const l=e.lookback;if(l===0){if(e.json){p({mode:"activity-log",lookback:0,entries:[],truncated:false,xml:""})}else{process.stdout.write("")}return}const a=v(s,e.thread).filter(c=>c.agent_id===n).slice(0,Math.min(l,5));const u=a.map(c=>w(s,g,c));const i=(0,k.buildActivityLog)(u,e.thread,n,l,exports.DEFAULT_ACTIVITY_LOG_BUDGET);if(e.json){p({mode:"activity-log",...i,xml:(0,d.renderActivityLogXml)(i)});return}process.stdout.write((0,d.renderActivityLogXml)(i)+"\n");return}if(e.thread&&e.continue){if(!n){console.error("Error: --continue requires --agent=<id> (or --agent=self).");process.exit(1)}const l=e.recent??3;const a=v(s,e.thread).filter(_=>_.agent_id===n).slice(0,l+1);const u=a.map(_=>w(s,g,_));const i=u[0]??null;const c=u.slice(1).map(k.summarizeAnalysis);const f={mode:"continue",thread:e.thread,agent:n,latest:i,previous:c};if(e.json){p({...f,latest:i?x(i,e.full):null});return}const o=(0,d.renderContinue)(f,{maxTimeline:e.full?null:S});const h=[];const m=c[0]?.taskId??i?.taskId;if(m){h.push({label:"Full activity log",cmd:`crewx dreaming --task=${m} --full`});h.push({label:"Detailed task log JSON",cmd:`crewx dreaming --task=${m} --json`})}h.push({label:"Task list for this conversation",cmd:`crewx dreaming --thread=${e.thread} --agent=${n}`});console.log(o+(h.length?"\n"+(0,d.buildCalFooter)(h):""));return}if(e.thread){const l=e.recent??5;let a=v(s,e.thread);if(n)a=a.filter(o=>o.agent_id===n);a=a.slice(0,l);const u=a.map(o=>({taskId:o.id,agentId:o.agent_id,status:o.status,promptSummary:o.prompt?o.prompt.split("\n")[0].slice(0,100):null,startedAt:o.started_at,duration:o.duration_ms!=null?Math.round(o.duration_ms/1e3):null}));if(e.json){p(u);return}const i=(0,d.renderThreadTaskList)(u,e.thread,l);const c=[];const f=u[0];if(f){const o=n??f.agentId;c.push({label:"Continue previous work",cmd:`crewx dreaming --thread=${e.thread} --agent=${o} --continue`});c.push({label:"Task drilldown",cmd:`crewx dreaming --task=${f.taskId} --full`})}console.log(i+(c.length?"\n"+(0,d.buildCalFooter)(c):""));return}}if(require.main===module){A().catch(r=>{console.error(r.message);process.exit(1)})}
@@ -18,4 +18,4 @@ export declare function extractActivityLogEntries(analyses: TaskAnalysis[]): Act
18
18
  export declare function buildActivityLog(analyses: TaskAnalysis[], threadId: string, agentId: string, lookback: number, tokenBudget: number): ActivityLog;
19
19
  export declare function summarizeAnalysis(a: TaskAnalysis): TaskActivitySummary;
20
20
  export {};
21
- //# sourceMappingURL=analyzer.d.ts.map
21
+