autocrew 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autocrew",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "One-person content studio powered by AI — from trending topics to published posts",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/cli/index.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * CLI command router — parses argv and dispatches to the matching command.
3
3
  */
4
+ import { createRequire } from "node:module";
4
5
  import { commands } from "./commands/index.js";
5
6
  import { showBanner } from "./banner.js";
6
7
  import type { ToolRunner } from "../runtime/tool-runner.js";
7
8
  import type { ToolContext } from "../runtime/context.js";
8
9
  import type { EventBus } from "../runtime/events.js";
9
10
 
10
- const VERSION = "0.1.0";
11
+ const require = createRequire(import.meta.url);
12
+ const { version: VERSION } = require("../../package.json");
11
13
 
12
14
  export async function run(argv: string[], runner: ToolRunner, ctx: ToolContext, eventBus: EventBus): Promise<void> {
13
15
  const subcommand = argv[0];
@@ -665,21 +665,87 @@ export async function startProject(
665
665
  dataDir?: string,
666
666
  ): Promise<string> {
667
667
  await initPipeline(dataDir);
668
- const topicsDir = stagePath("topics", dataDir);
668
+ const pipelineTopicsDir = stagePath("topics", dataDir);
669
669
 
670
- // Find the topic file
671
- const files = await fs.readdir(topicsDir);
672
- const topicFile = files.find(
673
- (f) => f.endsWith(".md") && f.includes(topicSlug),
674
- );
675
- if (!topicFile) throw new Error(`Topic not found: ${topicSlug}`);
670
+ // Strategy 1: Find in pipeline topics (markdown files in pipeline/topics/)
671
+ let topicTitle = "";
672
+ let topicDomain = "";
673
+ let topicFormats: string[] = [];
674
+ let topicIntelRefs: string[] = [];
675
+ let topicFile = "";
676
676
 
677
- const content = await fs.readFile(
678
- path.join(topicsDir, topicFile),
679
- "utf-8",
680
- );
681
- const topic = parseTopicFile(content);
682
- const projectName = slugify(topic.title);
677
+ try {
678
+ const files = await fs.readdir(pipelineTopicsDir);
679
+ const found = files.find(
680
+ (f) => f.endsWith(".md") && f.includes(topicSlug),
681
+ );
682
+ if (found) {
683
+ topicFile = found;
684
+ const content = await fs.readFile(
685
+ path.join(pipelineTopicsDir, found),
686
+ "utf-8",
687
+ );
688
+ const topic = parseTopicFile(content);
689
+ topicTitle = topic.title;
690
+ topicDomain = topic.domain;
691
+ topicFormats = topic.formats;
692
+ topicIntelRefs = topic.intelRefs;
693
+ }
694
+ } catch {
695
+ // Pipeline topics dir may not exist
696
+ }
697
+
698
+ // Strategy 2: Fallback to legacy local-store topics (JSON files in topics/)
699
+ if (!topicTitle) {
700
+ const effectiveDataDir = dataDir || path.join(process.env.HOME ?? ".", ".autocrew");
701
+ const legacyTopicsDir = path.join(effectiveDataDir, "topics");
702
+ try {
703
+ const files = await fs.readdir(legacyTopicsDir);
704
+ for (const f of files) {
705
+ if (!f.endsWith(".json")) continue;
706
+ // Match by ID (topic-xxx) or by slug in filename
707
+ if (f.includes(topicSlug) || f === `${topicSlug}.json`) {
708
+ const raw = JSON.parse(
709
+ await fs.readFile(path.join(legacyTopicsDir, f), "utf-8"),
710
+ );
711
+ topicTitle = raw.title || topicSlug;
712
+ topicDomain = raw.domain || "";
713
+ topicFormats = raw.formats || [];
714
+ topicIntelRefs = [];
715
+ topicFile = f;
716
+ break;
717
+ }
718
+ }
719
+ // If still not found, try matching topic title against the slug
720
+ if (!topicTitle) {
721
+ for (const f of files) {
722
+ if (!f.endsWith(".json")) continue;
723
+ const raw = JSON.parse(
724
+ await fs.readFile(path.join(legacyTopicsDir, f), "utf-8"),
725
+ );
726
+ if (raw.title && slugify(raw.title).includes(topicSlug)) {
727
+ topicTitle = raw.title;
728
+ topicDomain = raw.domain || "";
729
+ topicFormats = raw.formats || [];
730
+ topicIntelRefs = [];
731
+ topicFile = f;
732
+ break;
733
+ }
734
+ }
735
+ }
736
+ } catch {
737
+ // Legacy topics dir may not exist
738
+ }
739
+ }
740
+
741
+ if (!topicTitle) {
742
+ throw new Error(
743
+ `Topic not found: "${topicSlug}". Searched in pipeline/topics/ (markdown) ` +
744
+ `and topics/ (JSON). Use autocrew_topic action="list" to see available topics.`,
745
+ );
746
+ }
747
+
748
+ const projectName = slugify(topicTitle);
683
749
 
684
750
  const projectDir = path.join(stagePath("drafting", dataDir), projectName);
685
751
  await fs.mkdir(projectDir, { recursive: true });
@@ -691,12 +757,12 @@ export async function startProject(
691
757
  // draft-v{N}.md = immutable snapshots of content that has been REPLACED by a revision.
692
758
  // On initial create there are no snapshots yet — only draft.md exists.
693
759
  const meta: ProjectMeta = {
694
- title: topic.title,
695
- domain: topic.domain,
696
- format: topic.formats[0] ?? "article",
760
+ title: topicTitle,
761
+ domain: topicDomain,
762
+ format: topicFormats[0] ?? "article",
697
763
  createdAt: now,
698
764
  sourceTopic: topicFile,
699
- intelRefs: topic.intelRefs,
765
+ intelRefs: topicIntelRefs,
700
766
  versions: [],
701
767
  current: "draft.md",
702
768
  history: [{ stage: "drafting", entered: now }],
@@ -706,12 +772,18 @@ export async function startProject(
706
772
  await writeMeta(projectDir, meta);
707
773
  await fs.writeFile(
708
774
  path.join(projectDir, "draft.md"),
709
- `# ${topic.title}\n\n`,
775
+ `# ${topicTitle}\n\n`,
710
776
  "utf-8",
711
777
  );
712
778
 
713
- // Remove topic file
714
- await fs.unlink(path.join(topicsDir, topicFile));
779
+ // Remove topic file from pipeline topics (if it came from there)
780
+ if (topicFile.endsWith(".md")) {
781
+ try {
782
+ await fs.unlink(path.join(pipelineTopicsDir, topicFile));
783
+ } catch {
784
+ // May not exist in pipeline topics dir
785
+ }
786
+ }
715
787
 
716
788
  return projectDir;
717
789
  }
@@ -84,7 +84,30 @@ export async function executeContentSave(params: Record<string, unknown>) {
84
84
 
85
85
  if (action === "list") {
86
86
  const contents = await listContents(dataDir);
87
- return { ok: true, contents };
87
+
88
+ // Also list pipeline drafting projects (these may not exist in legacy contents/)
89
+ const pipelineProjects: Array<{ slug: string; title: string; stage: string; current: string }> = [];
90
+ try {
91
+ const { listProjects, getProjectMeta, stagePath } = await import("../storage/pipeline-store.js");
92
+ for (const stage of ["drafting", "production", "published"] as const) {
93
+ const slugs = await listProjects(stage, dataDir);
94
+ for (const slug of slugs) {
95
+ const meta = await getProjectMeta(slug, dataDir);
96
+ if (meta) {
97
+ pipelineProjects.push({
98
+ slug,
99
+ title: meta.title,
100
+ stage,
101
+ current: meta.current,
102
+ });
103
+ }
104
+ }
105
+ }
106
+ } catch {
107
+ // Pipeline store may not be initialized
108
+ }
109
+
110
+ return { ok: true, contents, pipelineProjects };
88
111
  }
89
112
 
90
113
  if (action === "get") {
@@ -235,13 +235,26 @@ async function runDiscovery(params: Record<string, unknown>) {
235
235
  }
236
236
 
237
237
  if (items.length === 0) {
238
- items = Array.from({ length: topicCount }).map((_, index) => ({
239
- title: `${keyword} 选题方向 ${index + 1}`,
240
- summary: "手动降级模式生成,请后续结合真实平台反馈再筛一次。",
238
+ // All sources failed. Instead of returning useless placeholders,
239
+ // tell the caller to use the intel pipeline which has working
240
+ // web search + RSS + trends collectors.
241
+ return {
242
+ ok: false,
243
+ mode: "failed",
241
244
  platform,
242
- source: "manual",
243
- }));
244
- sourcesUsed.push("manual");
245
+ keyword,
246
+ industry: industry || null,
247
+ sourcesUsed,
248
+ error:
249
+ "所有调研源都未返回结果(browser/API/free engine)。" +
250
+ "建议使用 autocrew_intel action='pull' 进行内容调研," +
251
+ "它支持 web search + RSS + 趋势热榜,不依赖浏览器登录态。",
252
+ suggestion: {
253
+ tool: "autocrew_intel",
254
+ action: "pull",
255
+ keywords: [keyword],
256
+ },
257
+ };
245
258
  }
246
259
 
247
260
  const topics = items.slice(0, topicCount).map((item) => ({