@tothemax/tasking 0.0.0-stage → 0.6.16
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/LICENSE +21 -0
- package/README.md +121 -2
- package/README.zh-CN.md +122 -0
- package/assets/skills/install-glab/SKILL.md +70 -0
- package/assets/skills/land/SKILL.md +63 -0
- package/assets/skills/land/land_watch.py +312 -0
- package/assets/skills/openspec-archive-change/SKILL.md +114 -0
- package/assets/skills/opsx-grill-with-docs/SKILL.md +193 -0
- package/assets/skills/opsx-implement/SKILL.md +258 -0
- package/assets/skills/opsx-propose-with-tdd/SKILL.md +271 -0
- package/assets/workflows/WORKFLOW.code-mr.en.md.example +345 -0
- package/assets/workflows/WORKFLOW.code-mr.md.example +339 -0
- package/assets/workflows/WORKFLOW.feishu-direct.en.md.example +267 -0
- package/assets/workflows/WORKFLOW.feishu-direct.md.example +258 -0
- package/assets/workflows/WORKFLOW.grill-openspec.en.md.example +362 -0
- package/assets/workflows/WORKFLOW.grill-openspec.md.example +356 -0
- package/assets/workflows/WORKFLOW.minimal.en.md.example +296 -0
- package/assets/workflows/WORKFLOW.minimal.md.example +289 -0
- package/dist/adapters/feishu/events.d.ts +55 -0
- package/dist/adapters/feishu/events.d.ts.map +1 -0
- package/dist/adapters/feishu/events.js +184 -0
- package/dist/adapters/feishu/events.js.map +1 -0
- package/dist/adapters/feishu/index.d.ts +2 -0
- package/dist/adapters/feishu/index.d.ts.map +1 -0
- package/dist/adapters/feishu/index.js +2 -0
- package/dist/adapters/feishu/index.js.map +1 -0
- package/dist/adapters/feishu/probe.d.ts +31 -0
- package/dist/adapters/feishu/probe.d.ts.map +1 -0
- package/dist/adapters/feishu/probe.js +179 -0
- package/dist/adapters/feishu/probe.js.map +1 -0
- package/dist/adapters/feishu/source.d.ts +124 -0
- package/dist/adapters/feishu/source.d.ts.map +1 -0
- package/dist/adapters/feishu/source.js +715 -0
- package/dist/adapters/feishu/source.js.map +1 -0
- package/dist/adapters/jira/index.d.ts +2 -0
- package/dist/adapters/jira/index.d.ts.map +1 -0
- package/dist/adapters/jira/index.js +2 -0
- package/dist/adapters/jira/index.js.map +1 -0
- package/dist/adapters/jira/tracker.d.ts +63 -0
- package/dist/adapters/jira/tracker.d.ts.map +1 -0
- package/dist/adapters/jira/tracker.js +402 -0
- package/dist/adapters/jira/tracker.js.map +1 -0
- package/dist/bridge/binding-store.d.ts +93 -0
- package/dist/bridge/binding-store.d.ts.map +1 -0
- package/dist/bridge/binding-store.js +365 -0
- package/dist/bridge/binding-store.js.map +1 -0
- package/dist/bridge/commands.d.ts +45 -0
- package/dist/bridge/commands.d.ts.map +1 -0
- package/dist/bridge/commands.js +197 -0
- package/dist/bridge/commands.js.map +1 -0
- package/dist/bridge/comment-bridge.d.ts +116 -0
- package/dist/bridge/comment-bridge.d.ts.map +1 -0
- package/dist/bridge/comment-bridge.js +1473 -0
- package/dist/bridge/comment-bridge.js.map +1 -0
- package/dist/cli/daemon-info.d.ts +17 -0
- package/dist/cli/daemon-info.d.ts.map +1 -0
- package/dist/cli/daemon-info.js +64 -0
- package/dist/cli/daemon-info.js.map +1 -0
- package/dist/cli/daemon.d.ts +27 -0
- package/dist/cli/daemon.d.ts.map +1 -0
- package/dist/cli/daemon.js +77 -0
- package/dist/cli/daemon.js.map +1 -0
- package/dist/cli/doctor.d.ts +7 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +156 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/event-channel.d.ts +16 -0
- package/dist/cli/event-channel.d.ts.map +1 -0
- package/dist/cli/event-channel.js +51 -0
- package/dist/cli/event-channel.js.map +1 -0
- package/dist/cli/help.d.ts +3 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +155 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +774 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +64 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +1296 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/instance-lock.d.ts +13 -0
- package/dist/cli/instance-lock.d.ts.map +1 -0
- package/dist/cli/instance-lock.js +53 -0
- package/dist/cli/instance-lock.js.map +1 -0
- package/dist/cli/prompts.d.ts +13 -0
- package/dist/cli/prompts.d.ts.map +1 -0
- package/dist/cli/prompts.js +26 -0
- package/dist/cli/prompts.js.map +1 -0
- package/dist/cli/style.d.ts +26 -0
- package/dist/cli/style.d.ts.map +1 -0
- package/dist/cli/style.js +58 -0
- package/dist/cli/style.js.map +1 -0
- package/dist/cli/tui-helpers.d.ts +5 -0
- package/dist/cli/tui-helpers.d.ts.map +1 -0
- package/dist/cli/tui-helpers.js +124 -0
- package/dist/cli/tui-helpers.js.map +1 -0
- package/dist/cli/workflow-path.d.ts +12 -0
- package/dist/cli/workflow-path.d.ts.map +1 -0
- package/dist/cli/workflow-path.js +37 -0
- package/dist/cli/workflow-path.js.map +1 -0
- package/dist/config/config-types.d.ts +180 -0
- package/dist/config/config-types.d.ts.map +1 -0
- package/dist/config/config-types.js +71 -0
- package/dist/config/config-types.js.map +1 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.d.ts.map +1 -0
- package/dist/config/dotenv.js +10 -0
- package/dist/config/dotenv.js.map +1 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +304 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/manager.d.ts +31 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +110 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/resolver.d.ts +6 -0
- package/dist/config/resolver.d.ts.map +1 -0
- package/dist/config/resolver.js +267 -0
- package/dist/config/resolver.js.map +1 -0
- package/dist/config/validator.d.ts +9 -0
- package/dist/config/validator.d.ts.map +1 -0
- package/dist/config/validator.js +70 -0
- package/dist/config/validator.js.map +1 -0
- package/dist/direct/card.d.ts +49 -0
- package/dist/direct/card.d.ts.map +1 -0
- package/dist/direct/card.js +274 -0
- package/dist/direct/card.js.map +1 -0
- package/dist/direct/command.d.ts +12 -0
- package/dist/direct/command.d.ts.map +1 -0
- package/dist/direct/command.js +23 -0
- package/dist/direct/command.js.map +1 -0
- package/dist/direct/manager.d.ts +159 -0
- package/dist/direct/manager.d.ts.map +1 -0
- package/dist/direct/manager.js +1862 -0
- package/dist/direct/manager.js.map +1 -0
- package/dist/mcp/inject.d.ts +5 -0
- package/dist/mcp/inject.d.ts.map +1 -0
- package/dist/mcp/inject.js +51 -0
- package/dist/mcp/inject.js.map +1 -0
- package/dist/mcp/jira-server.d.ts +29 -0
- package/dist/mcp/jira-server.d.ts.map +1 -0
- package/dist/mcp/jira-server.js +288 -0
- package/dist/mcp/jira-server.js.map +1 -0
- package/dist/observability/activity-store.d.ts +29 -0
- package/dist/observability/activity-store.d.ts.map +1 -0
- package/dist/observability/activity-store.js +32 -0
- package/dist/observability/activity-store.js.map +1 -0
- package/dist/observability/config-view.d.ts +19 -0
- package/dist/observability/config-view.d.ts.map +1 -0
- package/dist/observability/config-view.js +61 -0
- package/dist/observability/config-view.js.map +1 -0
- package/dist/observability/http-dashboard.d.ts +36 -0
- package/dist/observability/http-dashboard.d.ts.map +1 -0
- package/dist/observability/http-dashboard.js +297 -0
- package/dist/observability/http-dashboard.js.map +1 -0
- package/dist/observability/log-buffer.d.ts +21 -0
- package/dist/observability/log-buffer.d.ts.map +1 -0
- package/dist/observability/log-buffer.js +69 -0
- package/dist/observability/log-buffer.js.map +1 -0
- package/dist/observability/logger.d.ts +37 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +114 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/snapshot.d.ts +11 -0
- package/dist/observability/snapshot.d.ts.map +1 -0
- package/dist/observability/snapshot.js +59 -0
- package/dist/observability/snapshot.js.map +1 -0
- package/dist/observability/terminal-dashboard.d.ts +155 -0
- package/dist/observability/terminal-dashboard.d.ts.map +1 -0
- package/dist/observability/terminal-dashboard.js +1598 -0
- package/dist/observability/terminal-dashboard.js.map +1 -0
- package/dist/observability/wrap.d.ts +4 -0
- package/dist/observability/wrap.d.ts.map +1 -0
- package/dist/observability/wrap.js +80 -0
- package/dist/observability/wrap.js.map +1 -0
- package/dist/scheduler/index.d.ts +2 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +52 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/scheduler.js +535 -0
- package/dist/scheduler/scheduler.js.map +1 -0
- package/dist/shared/agent-resolver.d.ts +11 -0
- package/dist/shared/agent-resolver.d.ts.map +1 -0
- package/dist/shared/agent-resolver.js +20 -0
- package/dist/shared/agent-resolver.js.map +1 -0
- package/dist/shared/errors.d.ts +14 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/errors.js +24 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/info-card.d.ts +24 -0
- package/dist/shared/info-card.d.ts.map +1 -0
- package/dist/shared/info-card.js +46 -0
- package/dist/shared/info-card.js.map +1 -0
- package/dist/shared/types.d.ts +148 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +15 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/translate/card.d.ts +2 -0
- package/dist/translate/card.d.ts.map +1 -0
- package/dist/translate/card.js +17 -0
- package/dist/translate/card.js.map +1 -0
- package/dist/translate/dict.d.ts +7 -0
- package/dist/translate/dict.d.ts.map +1 -0
- package/dist/translate/dict.js +895 -0
- package/dist/translate/dict.js.map +1 -0
- package/dist/translate/locale.d.ts +8 -0
- package/dist/translate/locale.d.ts.map +1 -0
- package/dist/translate/locale.js +75 -0
- package/dist/translate/locale.js.map +1 -0
- package/dist/translate/normalize.d.ts +4 -0
- package/dist/translate/normalize.d.ts.map +1 -0
- package/dist/translate/normalize.js +38 -0
- package/dist/translate/normalize.js.map +1 -0
- package/dist/translate/output.d.ts +3 -0
- package/dist/translate/output.d.ts.map +1 -0
- package/dist/translate/output.js +16 -0
- package/dist/translate/output.js.map +1 -0
- package/dist/worker/prompt.d.ts +11 -0
- package/dist/worker/prompt.d.ts.map +1 -0
- package/dist/worker/prompt.js +153 -0
- package/dist/worker/prompt.js.map +1 -0
- package/dist/worker/runner.d.ts +101 -0
- package/dist/worker/runner.d.ts.map +1 -0
- package/dist/worker/runner.js +448 -0
- package/dist/worker/runner.js.map +1 -0
- package/dist/workspace/index.d.ts +2 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/manager.d.ts +37 -0
- package/dist/workspace/manager.d.ts.map +1 -0
- package/dist/workspace/manager.js +157 -0
- package/dist/workspace/manager.js.map +1 -0
- package/package.json +70 -4
package/dist/cli/init.js
ADDED
|
@@ -0,0 +1,1296 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { consoleLinks, crossRegionHint, feishuApiBase, probeListChats, probeListMessages, probeTail, } from "../adapters/feishu/probe.js";
|
|
7
|
+
import { createBotChat, fetchTenantTokenFor, lookupFeishuUserId, } from "../adapters/feishu/source.js";
|
|
8
|
+
import { JiraTracker } from "../adapters/jira/tracker.js";
|
|
9
|
+
import { DEFAULTS } from "../config/config-types.js";
|
|
10
|
+
import { parseWorkflowContent } from "../config/loader.js";
|
|
11
|
+
import { expandHome } from "../config/resolver.js";
|
|
12
|
+
import { setLocale, translate } from "../translate/locale.js";
|
|
13
|
+
import { translatingWritable } from "../translate/output.js";
|
|
14
|
+
import { createPromptInterface } from "./prompts.js";
|
|
15
|
+
import { createStyle } from "./style.js";
|
|
16
|
+
import { resolveWorkflowPathOrReport } from "./workflow-path.js";
|
|
17
|
+
const EXAMPLE_FILE = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.minimal.md.example");
|
|
18
|
+
const EXAMPLE_FILE_CODE_MR = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.code-mr.md.example");
|
|
19
|
+
const EXAMPLE_FILE_GRILL = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.grill-openspec.md.example");
|
|
20
|
+
const EXAMPLE_FILE_EN = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.minimal.en.md.example");
|
|
21
|
+
const EXAMPLE_FILE_CODE_MR_EN = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.code-mr.en.md.example");
|
|
22
|
+
const EXAMPLE_FILE_GRILL_EN = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.grill-openspec.en.md.example");
|
|
23
|
+
const EXAMPLE_FILE_FEISHU_DIRECT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.feishu-direct.md.example");
|
|
24
|
+
const EXAMPLE_FILE_FEISHU_DIRECT_EN = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "workflows", "WORKFLOW.feishu-direct.en.md.example");
|
|
25
|
+
const CODE_MR_MARKER = "<!-- tasking-workflow: code-mr -->";
|
|
26
|
+
const FEISHU_DIRECT_MARKER = "<!-- tasking-workflow: feishu-direct -->";
|
|
27
|
+
const GRILL_MARKER = "## 🔍 拷问 / Grill Questions";
|
|
28
|
+
const EN_LANG_MARKER = "<!-- tasking-workflow-lang: en -->";
|
|
29
|
+
const DIFF_PRINT_LIMIT = 50;
|
|
30
|
+
export const SUPPORTED_WORKFLOWS = [
|
|
31
|
+
"minimal",
|
|
32
|
+
"code-mr",
|
|
33
|
+
"grill-openspec",
|
|
34
|
+
"feishu-direct",
|
|
35
|
+
];
|
|
36
|
+
export const SUPPORTED_LANGUAGES = ["zh", "en"];
|
|
37
|
+
function resolveExampleFile(workflow, lang) {
|
|
38
|
+
if (workflow === "feishu-direct") {
|
|
39
|
+
return lang === "en" ? EXAMPLE_FILE_FEISHU_DIRECT_EN : EXAMPLE_FILE_FEISHU_DIRECT;
|
|
40
|
+
}
|
|
41
|
+
if (lang === "en") {
|
|
42
|
+
if (workflow === "grill-openspec")
|
|
43
|
+
return EXAMPLE_FILE_GRILL_EN;
|
|
44
|
+
if (workflow === "code-mr")
|
|
45
|
+
return EXAMPLE_FILE_CODE_MR_EN;
|
|
46
|
+
return EXAMPLE_FILE_EN;
|
|
47
|
+
}
|
|
48
|
+
if (workflow === "grill-openspec")
|
|
49
|
+
return EXAMPLE_FILE_GRILL;
|
|
50
|
+
if (workflow === "code-mr")
|
|
51
|
+
return EXAMPLE_FILE_CODE_MR;
|
|
52
|
+
return EXAMPLE_FILE;
|
|
53
|
+
}
|
|
54
|
+
function normalizeWorkflow(value) {
|
|
55
|
+
if (value === undefined || value === "")
|
|
56
|
+
return "feishu-direct";
|
|
57
|
+
if (value === "minimal" ||
|
|
58
|
+
value === "code-mr" ||
|
|
59
|
+
value === "grill-openspec" ||
|
|
60
|
+
value === "feishu-direct") {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
return "invalid";
|
|
64
|
+
}
|
|
65
|
+
function normalizeLang(value) {
|
|
66
|
+
if (value === undefined || value === "")
|
|
67
|
+
return "zh";
|
|
68
|
+
if (value === "zh" || value === "en")
|
|
69
|
+
return value;
|
|
70
|
+
return "invalid";
|
|
71
|
+
}
|
|
72
|
+
const ASSETS_SKILLS_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "skills");
|
|
73
|
+
const LAND_SKILL = { name: "land", files: ["SKILL.md", "land_watch.py"] };
|
|
74
|
+
const INSTALL_GLAB_SKILL = { name: "install-glab", files: ["SKILL.md"] };
|
|
75
|
+
const OPSX_SKILLS = [
|
|
76
|
+
{ name: "opsx-grill-with-docs", files: ["SKILL.md"] },
|
|
77
|
+
{ name: "opsx-propose-with-tdd", files: ["SKILL.md"] },
|
|
78
|
+
{ name: "opsx-implement", files: ["SKILL.md"] },
|
|
79
|
+
{ name: "openspec-archive-change", files: ["SKILL.md"] },
|
|
80
|
+
];
|
|
81
|
+
function skillsForWorkflow(workflow) {
|
|
82
|
+
if (workflow === "minimal" || workflow === "feishu-direct")
|
|
83
|
+
return [];
|
|
84
|
+
const base = [LAND_SKILL, INSTALL_GLAB_SKILL];
|
|
85
|
+
return workflow === "grill-openspec" ? [...base, ...OPSX_SKILLS] : base;
|
|
86
|
+
}
|
|
87
|
+
function copySkills(wfDir, workflow, log) {
|
|
88
|
+
for (const skill of skillsForWorkflow(workflow)) {
|
|
89
|
+
const destDir = join(wfDir, ".opencode", "skills", skill.name);
|
|
90
|
+
if (existsSync(destDir)) {
|
|
91
|
+
log("info", `${skill.name} already installed`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
mkdirSync(destDir, { recursive: true });
|
|
96
|
+
let copied = false;
|
|
97
|
+
for (const file of skill.files) {
|
|
98
|
+
const src = join(ASSETS_SKILLS_DIR, skill.name, file);
|
|
99
|
+
if (!existsSync(src))
|
|
100
|
+
continue;
|
|
101
|
+
copyFileSync(src, join(destDir, file));
|
|
102
|
+
copied = true;
|
|
103
|
+
}
|
|
104
|
+
log(copied ? "ok" : "fail", copied ? `${skill.name} installed` : `${skill.name} source missing`);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
108
|
+
log("fail", `${skill.name} copy failed: ${msg}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export async function runInit(cwd, opts) {
|
|
113
|
+
const modeCount = [opts.force, opts.update ?? false, opts.restore ?? false].filter(Boolean).length;
|
|
114
|
+
if (modeCount > 1) {
|
|
115
|
+
const errOutput = opts.output ?? process.stderr;
|
|
116
|
+
errOutput.write("--force, --update, and --restore are mutually exclusive\n");
|
|
117
|
+
return 1;
|
|
118
|
+
}
|
|
119
|
+
const resolved = resolveWorkflowPathOrReport(cwd, opts.workflowPath, (message) => (opts.output ?? process.stderr).write(`${message}\n`));
|
|
120
|
+
if (resolved === null)
|
|
121
|
+
return 1;
|
|
122
|
+
const wfPath = resolved.path;
|
|
123
|
+
if (opts.update) {
|
|
124
|
+
return runUpdate(resolved, opts.output ?? process.stdout, opts.workflow, opts.lang);
|
|
125
|
+
}
|
|
126
|
+
if (opts.restore) {
|
|
127
|
+
if (opts.workflowPath !== undefined && !existsSync(wfPath)) {
|
|
128
|
+
(opts.output ?? process.stderr).write(`error: ${resolved.name} not found at ${wfPath}. Run 'tasking init' first.\n`);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
return runRestore(resolved, opts.output ?? process.stdout);
|
|
132
|
+
}
|
|
133
|
+
const workflow = normalizeWorkflow(opts.workflow);
|
|
134
|
+
if (workflow === "invalid") {
|
|
135
|
+
console.error(`unknown workflow: ${opts.workflow}. Supported values: ${SUPPORTED_WORKFLOWS.join(", ")}`);
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
const lang = normalizeLang(opts.lang);
|
|
139
|
+
if (lang === "invalid") {
|
|
140
|
+
console.error(`unknown language: ${opts.lang}. Supported values: ${SUPPORTED_LANGUAGES.join(", ")}`);
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
if (existsSync(wfPath) && !opts.force) {
|
|
144
|
+
console.error(`${resolved.name} already exists at ${wfPath}. Use --force to overwrite.`);
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
mkdirSync(dirname(wfPath), { recursive: true });
|
|
148
|
+
const isTTY = opts.input
|
|
149
|
+
? Boolean(opts.input.isTTY)
|
|
150
|
+
: Boolean(process.stdin.isTTY);
|
|
151
|
+
const interactive = (!opts.nonInteractive && isTTY) || Boolean(opts.promptInterface);
|
|
152
|
+
if (!interactive) {
|
|
153
|
+
setLocale(lang === "en" ? "en" : "zh");
|
|
154
|
+
const output = translatingWritable(opts.output ?? process.stdout);
|
|
155
|
+
return runNonInteractiveInit(wfPath, output, workflow, lang);
|
|
156
|
+
}
|
|
157
|
+
const input = opts.input ?? process.stdin;
|
|
158
|
+
const output = translatingWritable(opts.output ?? process.stdout);
|
|
159
|
+
return runInteractiveInit(wfPath, input, output, opts.fetchImpl, opts.promptInterface, opts.workflow, opts.lang);
|
|
160
|
+
}
|
|
161
|
+
function backupExistingWorkflow(wfPath) {
|
|
162
|
+
if (!existsSync(wfPath))
|
|
163
|
+
return null;
|
|
164
|
+
const backupPath = `${wfPath}.bak`;
|
|
165
|
+
copyFileSync(wfPath, backupPath);
|
|
166
|
+
return backupPath;
|
|
167
|
+
}
|
|
168
|
+
function runNonInteractiveInit(wfPath, output, workflow, lang) {
|
|
169
|
+
const style = createStyle(false);
|
|
170
|
+
const content = generateWorkflowContent(null, workflow, null, lang);
|
|
171
|
+
const backupPath = backupExistingWorkflow(wfPath);
|
|
172
|
+
writeFileSync(wfPath, content, "utf8");
|
|
173
|
+
copySkill(dirname(wfPath), output, workflow);
|
|
174
|
+
const wsRoot = resolve(homedir(), "tasking_workspaces");
|
|
175
|
+
if (!existsSync(wsRoot)) {
|
|
176
|
+
mkdirSync(wsRoot, { recursive: true });
|
|
177
|
+
}
|
|
178
|
+
output.write(`${style.statusIcon("ok")} tasking initialized\n`);
|
|
179
|
+
if (backupPath) {
|
|
180
|
+
output.write(`${style.statusIcon("warn")} existing ${basename(wfPath)} backed up to ${backupPath}\n`);
|
|
181
|
+
}
|
|
182
|
+
output.write(` Config file: ${wfPath}\n`);
|
|
183
|
+
output.write(` Workflow: ${workflow}\n`);
|
|
184
|
+
output.write(` Language: ${lang}\n`);
|
|
185
|
+
output.write(` Workspace root: ${wsRoot}\n`);
|
|
186
|
+
const skillsPath = join(dirname(wfPath), ".opencode", "skills");
|
|
187
|
+
output.write(` Skills dir: ${skillsPath}\n`);
|
|
188
|
+
if (workflow === "feishu-direct") {
|
|
189
|
+
output.write(" Feishu: enabled (direct-only); fill app_id/app_secret/intake_chat_id in WORKFLOW.md\n" +
|
|
190
|
+
" guide: docs/feishu-quickstart.md\n");
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
output.write(" Feishu bridge: disabled; enable & configure in WORKFLOW.md feishu: block (docs/feishu-quickstart.md)\n");
|
|
194
|
+
}
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
function detectWorkflow(body) {
|
|
198
|
+
if (body.includes(FEISHU_DIRECT_MARKER))
|
|
199
|
+
return "feishu-direct";
|
|
200
|
+
if (body.includes(GRILL_MARKER))
|
|
201
|
+
return "grill-openspec";
|
|
202
|
+
if (body.includes(CODE_MR_MARKER))
|
|
203
|
+
return "code-mr";
|
|
204
|
+
return "minimal";
|
|
205
|
+
}
|
|
206
|
+
function detectTemplateLanguage(content) {
|
|
207
|
+
return content.includes(EN_LANG_MARKER) ? "en" : "zh";
|
|
208
|
+
}
|
|
209
|
+
function runUpdate(resolved, output, workflowRaw, langRaw) {
|
|
210
|
+
const { path: wfPath, dir: wfDir, name } = resolved;
|
|
211
|
+
if (!existsSync(wfPath)) {
|
|
212
|
+
output.write(`error: ${name} not found at ${wfPath}. Run 'tasking init' first.\n`);
|
|
213
|
+
return 1;
|
|
214
|
+
}
|
|
215
|
+
const style = createStyle(false);
|
|
216
|
+
const userContent = readFileSync(wfPath, "utf8");
|
|
217
|
+
let workflow;
|
|
218
|
+
if (workflowRaw !== undefined) {
|
|
219
|
+
const normalized = normalizeWorkflow(workflowRaw);
|
|
220
|
+
if (normalized === "invalid") {
|
|
221
|
+
output.write(`error: unknown workflow: ${workflowRaw}. Supported values: ${SUPPORTED_WORKFLOWS.join(", ")}\n`);
|
|
222
|
+
return 1;
|
|
223
|
+
}
|
|
224
|
+
workflow = normalized;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
workflow = detectWorkflow(parseWorkflowContent(userContent, wfPath).prompt_template);
|
|
228
|
+
}
|
|
229
|
+
let lang;
|
|
230
|
+
if (langRaw !== undefined) {
|
|
231
|
+
const normalizedLang = normalizeLang(langRaw);
|
|
232
|
+
if (normalizedLang === "invalid") {
|
|
233
|
+
output.write(`error: unknown language: ${langRaw}. Supported values: ${SUPPORTED_LANGUAGES.join(", ")}\n`);
|
|
234
|
+
return 1;
|
|
235
|
+
}
|
|
236
|
+
lang = normalizedLang;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
lang = detectTemplateLanguage(userContent);
|
|
240
|
+
}
|
|
241
|
+
output.write(`${style.statusIcon("info")} Workflow: ${workflow}`);
|
|
242
|
+
if (workflowRaw !== undefined) {
|
|
243
|
+
output.write(" (explicit --workflow)");
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
output.write(" (detected from WORKFLOW.md sentinel markers)");
|
|
247
|
+
}
|
|
248
|
+
output.write("\n");
|
|
249
|
+
output.write(`${style.statusIcon("info")} Template language: ${lang}`);
|
|
250
|
+
if (langRaw !== undefined) {
|
|
251
|
+
output.write(" (explicit --lang)");
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
output.write(" (detected from WORKFLOW.md sentinel marker)");
|
|
255
|
+
}
|
|
256
|
+
output.write("\n");
|
|
257
|
+
const synced = syncAllSkills(wfDir, output, style, workflow);
|
|
258
|
+
output.write("\n");
|
|
259
|
+
reportWorkflowDrift(resolved, output, style, workflow, lang);
|
|
260
|
+
output.write("\n");
|
|
261
|
+
output.write(`${style.statusIcon("ok")} skills updated`);
|
|
262
|
+
if (synced.updated > 0) {
|
|
263
|
+
output.write(` (${synced.updated} updated, backups in .opencode/skills/<name>/<file>.bak)`);
|
|
264
|
+
}
|
|
265
|
+
output.write("\n");
|
|
266
|
+
output.write(` ${name} untouched — reconcile any listed fields/diff manually\n`);
|
|
267
|
+
return 0;
|
|
268
|
+
}
|
|
269
|
+
function runRestore(resolved, output) {
|
|
270
|
+
const { path: wfPath, dir: wfDir } = resolved;
|
|
271
|
+
const wfBak = `${wfPath}.bak`;
|
|
272
|
+
if (existsSync(wfBak)) {
|
|
273
|
+
renameSync(wfBak, wfPath);
|
|
274
|
+
output.write(`restored ${wfPath}\n`);
|
|
275
|
+
}
|
|
276
|
+
const skillsRoot = join(wfDir, ".opencode", "skills");
|
|
277
|
+
if (!existsSync(skillsRoot)) {
|
|
278
|
+
output.write("no skill backups found\n");
|
|
279
|
+
return 0;
|
|
280
|
+
}
|
|
281
|
+
const backups = collectBackupFiles(skillsRoot);
|
|
282
|
+
if (backups.length === 0) {
|
|
283
|
+
output.write("no skill backups found\n");
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
for (const bak of backups) {
|
|
287
|
+
const original = bak.replace(/\.bak$/, "");
|
|
288
|
+
renameSync(bak, original);
|
|
289
|
+
output.write(`restored ${original}\n`);
|
|
290
|
+
}
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
function syncAllSkills(wfDir, output, style, workflow) {
|
|
294
|
+
const result = { installed: 0, updated: 0, skipped: 0 };
|
|
295
|
+
for (const skill of skillsForWorkflow(workflow)) {
|
|
296
|
+
const destDir = join(wfDir, ".opencode", "skills", skill.name);
|
|
297
|
+
for (const file of skill.files) {
|
|
298
|
+
const src = join(ASSETS_SKILLS_DIR, skill.name, file);
|
|
299
|
+
const dest = join(destDir, file);
|
|
300
|
+
if (!existsSync(src)) {
|
|
301
|
+
output.write(`${style.statusIcon("fail")} ${skill.name}/${file} source missing\n`);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (!existsSync(dest)) {
|
|
305
|
+
try {
|
|
306
|
+
mkdirSync(destDir, { recursive: true });
|
|
307
|
+
copyFileSync(src, dest);
|
|
308
|
+
result.installed++;
|
|
309
|
+
output.write(`${style.statusIcon("ok")} ${skill.name}/${file} installed\n`);
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
313
|
+
output.write(`${style.statusIcon("fail")} ${skill.name}/${file} install failed: ${msg}\n`);
|
|
314
|
+
}
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (filesEqual(src, dest)) {
|
|
318
|
+
result.skipped++;
|
|
319
|
+
output.write(`${style.statusIcon("info")} ${skill.name}/${file} up to date\n`);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
copyFileSync(dest, `${dest}.bak`);
|
|
324
|
+
copyFileSync(src, dest);
|
|
325
|
+
result.updated++;
|
|
326
|
+
output.write(`${style.statusIcon("warn")} ${skill.name}/${file} updated (backup: ${relPath(wfDir, `${dest}.bak`)})\n`);
|
|
327
|
+
}
|
|
328
|
+
catch (err) {
|
|
329
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
330
|
+
output.write(`${style.statusIcon("fail")} ${skill.name}/${file} update failed: ${msg}\n`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
function filesEqual(a, b) {
|
|
337
|
+
return readFileSync(a).equals(readFileSync(b));
|
|
338
|
+
}
|
|
339
|
+
function relPath(root, target) {
|
|
340
|
+
const rel = target.startsWith(root) ? target.slice(root.length + 1) : target;
|
|
341
|
+
return rel.replace(/\\/g, "/");
|
|
342
|
+
}
|
|
343
|
+
function reportWorkflowDrift(resolved, output, style, workflow, lang) {
|
|
344
|
+
const { path: wfPath, dir: wfDir, name } = resolved;
|
|
345
|
+
const templatePath = resolveExampleFile(workflow, lang);
|
|
346
|
+
let user;
|
|
347
|
+
let template;
|
|
348
|
+
let baselineConfig;
|
|
349
|
+
try {
|
|
350
|
+
user = parseWorkflowContent(readFileSync(wfPath, "utf8"), wfPath);
|
|
351
|
+
const templateRaw = readFileSync(templatePath, "utf8");
|
|
352
|
+
template = parseWorkflowContent(templateRaw, templatePath);
|
|
353
|
+
const userFeishuEnabled = isPlainRecord(user.config.feishu) && user.config.feishu.enabled === true;
|
|
354
|
+
const baseline = applyTemplateTrimming(templateRaw, workflow, feishuSectionActive(workflow, userFeishuEnabled), lang);
|
|
355
|
+
baselineConfig = parseWorkflowContent(baseline, templatePath).config;
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
359
|
+
output.write(`${style.statusIcon("warn")} ${name} drift report skipped: ${msg}\n`);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const newFields = [];
|
|
363
|
+
collectNewConfigFields(baselineConfig, user.config, "", newFields);
|
|
364
|
+
output.write("Config (fields missing vs a fresh init today — they fall back to DEFAULTS):\n");
|
|
365
|
+
if (newFields.length === 0) {
|
|
366
|
+
output.write(" no missing config fields\n");
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
for (const field of newFields) {
|
|
370
|
+
const fallback = lookupDefaultValue(field.path);
|
|
371
|
+
const value = fallback.found ? fallback.value : field.value;
|
|
372
|
+
output.write(` - ${field.path} (default: ${formatDefaultValue(value)})\n`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const diff = diffLines(template.prompt_template, user.prompt_template);
|
|
376
|
+
output.write("Prompt body:\n");
|
|
377
|
+
if (diff.length === 0) {
|
|
378
|
+
output.write(" identical\n");
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
const shown = diff.length > DIFF_PRINT_LIMIT ? DIFF_PRINT_LIMIT : diff.length;
|
|
382
|
+
for (let i = 0; i < shown; i++) {
|
|
383
|
+
output.write(` ${diff[i] ?? ""}\n`);
|
|
384
|
+
}
|
|
385
|
+
if (diff.length > DIFF_PRINT_LIMIT) {
|
|
386
|
+
output.write(` … ${diff.length - DIFF_PRINT_LIMIT} more changed lines (full diff in reference file below)\n`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const ref = syncDriftReference(wfDir, templatePath, name, newFields.length > 0 || diff.length > 0);
|
|
390
|
+
if (ref) {
|
|
391
|
+
output.write(` Reference template: ${ref}\n`);
|
|
392
|
+
output.write(` See exact locations (full diff vs new template): git diff --no-index ${name} ${ref}\n`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function lookupDefaultValue(path) {
|
|
396
|
+
let current = DEFAULTS;
|
|
397
|
+
for (const segment of path.split(".")) {
|
|
398
|
+
if (!isPlainRecord(current)) {
|
|
399
|
+
return { found: false, value: undefined };
|
|
400
|
+
}
|
|
401
|
+
const record = current;
|
|
402
|
+
if (!(segment in record))
|
|
403
|
+
return { found: false, value: undefined };
|
|
404
|
+
current = record[segment];
|
|
405
|
+
}
|
|
406
|
+
return { found: true, value: current };
|
|
407
|
+
}
|
|
408
|
+
function formatDefaultValue(value) {
|
|
409
|
+
if (Array.isArray(value))
|
|
410
|
+
return JSON.stringify(value);
|
|
411
|
+
if (value === null)
|
|
412
|
+
return "null";
|
|
413
|
+
if (typeof value === "object")
|
|
414
|
+
return JSON.stringify(value);
|
|
415
|
+
return String(value);
|
|
416
|
+
}
|
|
417
|
+
function syncDriftReference(wfDir, templatePath, baseName, hasDrift) {
|
|
418
|
+
const refPath = join(wfDir, ".tasking", `${baseName}.reference`);
|
|
419
|
+
if (!hasDrift) {
|
|
420
|
+
if (existsSync(refPath))
|
|
421
|
+
rmSync(refPath, { force: true });
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
mkdirSync(dirname(refPath), { recursive: true });
|
|
425
|
+
copyFileSync(templatePath, refPath);
|
|
426
|
+
return relPath(wfDir, refPath);
|
|
427
|
+
}
|
|
428
|
+
function collectNewConfigFields(template, user, prefix, out) {
|
|
429
|
+
if (!isPlainRecord(template))
|
|
430
|
+
return;
|
|
431
|
+
const tpl = template;
|
|
432
|
+
const usr = isPlainRecord(user) ? user : undefined;
|
|
433
|
+
for (const [key, tval] of Object.entries(tpl)) {
|
|
434
|
+
const path = prefix === "" ? key : `${prefix}.${key}`;
|
|
435
|
+
const uval = usr?.[key];
|
|
436
|
+
if (uval === undefined) {
|
|
437
|
+
out.push({ path, value: tval });
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (isPlainRecord(tval) && isPlainRecord(uval)) {
|
|
441
|
+
collectNewConfigFields(tval, uval, path, out);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function diffLines(a, b) {
|
|
446
|
+
const aLines = a.split("\n");
|
|
447
|
+
const bLines = b.split("\n");
|
|
448
|
+
const n = aLines.length;
|
|
449
|
+
const m = bLines.length;
|
|
450
|
+
const dp = [];
|
|
451
|
+
for (let i = n; i >= 0; i--) {
|
|
452
|
+
const row = new Array(m + 1).fill(0);
|
|
453
|
+
if (i < n) {
|
|
454
|
+
const aLine = aLines[i] ?? "";
|
|
455
|
+
const next = dp[i + 1] ?? [];
|
|
456
|
+
for (let j = m - 1; j >= 0; j--) {
|
|
457
|
+
row[j] =
|
|
458
|
+
aLine === (bLines[j] ?? "")
|
|
459
|
+
? (next[j + 1] ?? 0) + 1
|
|
460
|
+
: Math.max(next[j] ?? 0, row[j + 1] ?? 0);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
dp[i] = row;
|
|
464
|
+
}
|
|
465
|
+
const out = [];
|
|
466
|
+
let i = 0;
|
|
467
|
+
let j = 0;
|
|
468
|
+
while (i < n && j < m) {
|
|
469
|
+
const aLine = aLines[i] ?? "";
|
|
470
|
+
const bLine = bLines[j] ?? "";
|
|
471
|
+
const next = dp[i + 1] ?? [];
|
|
472
|
+
if (aLine === bLine) {
|
|
473
|
+
i++;
|
|
474
|
+
j++;
|
|
475
|
+
}
|
|
476
|
+
else if ((next[j] ?? 0) >= (dp[i]?.[j + 1] ?? 0)) {
|
|
477
|
+
out.push(`- ${aLine}`);
|
|
478
|
+
i++;
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
out.push(`+ ${bLine}`);
|
|
482
|
+
j++;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
while (i < n) {
|
|
486
|
+
out.push(`- ${aLines[i] ?? ""}`);
|
|
487
|
+
i++;
|
|
488
|
+
}
|
|
489
|
+
while (j < m) {
|
|
490
|
+
out.push(`+ ${bLines[j] ?? ""}`);
|
|
491
|
+
j++;
|
|
492
|
+
}
|
|
493
|
+
return out;
|
|
494
|
+
}
|
|
495
|
+
function collectBackupFiles(dir) {
|
|
496
|
+
const result = [];
|
|
497
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
498
|
+
const full = join(dir, entry.name);
|
|
499
|
+
if (entry.isDirectory()) {
|
|
500
|
+
result.push(...collectBackupFiles(full));
|
|
501
|
+
}
|
|
502
|
+
else if (entry.name.endsWith(".bak")) {
|
|
503
|
+
result.push(full);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
async function runInteractiveInit(wfPath, input, output, fetchImpl, promptOverride, workflowRaw, langRaw) {
|
|
509
|
+
const useColor = Boolean(output.isTTY);
|
|
510
|
+
const style = createStyle(useColor);
|
|
511
|
+
const prompts = promptOverride ?? createPromptInterface(input, output, style);
|
|
512
|
+
if (langRaw !== undefined) {
|
|
513
|
+
setLocale(langRaw === "en" ? "en" : "zh");
|
|
514
|
+
}
|
|
515
|
+
else if (existsSync(wfPath)) {
|
|
516
|
+
try {
|
|
517
|
+
const existing = parseWorkflowContent(readFileSync(wfPath, "utf8"), wfPath);
|
|
518
|
+
setLocale(existing.config.interface_language === "en" ? "en" : "zh");
|
|
519
|
+
}
|
|
520
|
+
catch {
|
|
521
|
+
setLocale("zh");
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
const workflow = workflowRaw === undefined
|
|
525
|
+
? await selectTaskSource(prompts, output, style)
|
|
526
|
+
: workflowRaw;
|
|
527
|
+
const lang = langRaw !== undefined
|
|
528
|
+
? langRaw
|
|
529
|
+
: await selectTemplateLanguage(prompts, output, style);
|
|
530
|
+
setLocale(lang === "en" ? "en" : "zh");
|
|
531
|
+
printPrerequisites(style, output, workflow !== "feishu-direct");
|
|
532
|
+
let creds = null;
|
|
533
|
+
let feishuSetup = null;
|
|
534
|
+
let autoStates = null;
|
|
535
|
+
if (workflow === "feishu-direct") {
|
|
536
|
+
feishuSetup = await collectFeishuDirectConfig(prompts, output, style, fetchImpl, lang);
|
|
537
|
+
if (!feishuSetup) {
|
|
538
|
+
prompts.close();
|
|
539
|
+
return 1;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
output.write(style.boxHeader("Jira Setup"));
|
|
544
|
+
creds = await collectCredentials(prompts, output, style);
|
|
545
|
+
output.write(style.boxFooter());
|
|
546
|
+
if (!creds) {
|
|
547
|
+
prompts.close();
|
|
548
|
+
return 1;
|
|
549
|
+
}
|
|
550
|
+
const conn = await testJiraConnection(creds, fetchImpl, output, style);
|
|
551
|
+
const issueTypes = conn.issueTypes;
|
|
552
|
+
autoStates = await promptStateAutofill(conn.statuses, prompts, output, style, lang);
|
|
553
|
+
feishuSetup = await collectFeishuConfig(prompts, output, style, issueTypes, fetchImpl, lang);
|
|
554
|
+
}
|
|
555
|
+
prompts.close();
|
|
556
|
+
const content = generateWorkflowContent(creds, workflow, feishuSetup, lang, autoStates);
|
|
557
|
+
const backupPath = backupExistingWorkflow(wfPath);
|
|
558
|
+
writeFileSync(wfPath, content, "utf8");
|
|
559
|
+
printInitialization(style, output, wfPath, workflow, lang);
|
|
560
|
+
if (backupPath) {
|
|
561
|
+
output.write(`${style.statusIcon("warn")} 原 ${basename(wfPath)} 已备份至 ${backupPath}\n`);
|
|
562
|
+
}
|
|
563
|
+
const editorOk = process.stdout.isTTY ? openEditor(wfPath) : false;
|
|
564
|
+
printCompletionHint(output, style, editorOk, workflow, feishuSetup?.project?.name ?? null, autoStates !== null, lang);
|
|
565
|
+
return 0;
|
|
566
|
+
}
|
|
567
|
+
async function selectTaskSource(prompts, output, style) {
|
|
568
|
+
output.write(style.boxHeader("任务来源"));
|
|
569
|
+
output.write(style.boxLine(style.dim("只用飞书直连:群里 /chat 直接跑 opencode,无需 Jira。接 Jira:调度器轮询 Jira issue 派发(三个变体)。")));
|
|
570
|
+
const choice = await prompts.askSelect(`${style.bold("任务来源")}`, [
|
|
571
|
+
{ value: "feishu-direct", label: "只用飞书直连(默认)" },
|
|
572
|
+
{ value: "jira", label: "接 Jira" },
|
|
573
|
+
]);
|
|
574
|
+
output.write(style.boxFooter());
|
|
575
|
+
if (choice === "jira")
|
|
576
|
+
return selectWorkflow(prompts, output, style);
|
|
577
|
+
return "feishu-direct";
|
|
578
|
+
}
|
|
579
|
+
async function selectWorkflow(prompts, output, style) {
|
|
580
|
+
output.write(style.boxHeader("Workflow"));
|
|
581
|
+
output.write(style.boxLine(style.dim("minimal: do the task in the workspace, upload results to Jira, transition to terminal. code-mr: write code & create a merge request. grill-openspec: grill → propose → implement → archive.")));
|
|
582
|
+
const choice = await prompts.askSelect(`${style.bold("选择 Jira workflow 变体")}`, [
|
|
583
|
+
{ value: "minimal", label: "minimal" },
|
|
584
|
+
{ value: "code-mr", label: "code-mr" },
|
|
585
|
+
{ value: "grill-openspec", label: "grill-openspec" },
|
|
586
|
+
]);
|
|
587
|
+
output.write(style.boxFooter());
|
|
588
|
+
if (choice === "code-mr")
|
|
589
|
+
return "code-mr";
|
|
590
|
+
if (choice === "grill-openspec")
|
|
591
|
+
return "grill-openspec";
|
|
592
|
+
return "minimal";
|
|
593
|
+
}
|
|
594
|
+
async function selectTemplateLanguage(prompts, output, style) {
|
|
595
|
+
output.write(style.boxHeader("Template Language"));
|
|
596
|
+
output.write(style.boxLine(style.dim("Language of the generated WORKFLOW.md comments and guidance. Press enter for 中文.")));
|
|
597
|
+
const choice = await prompts.askSelect(`${style.bold("Template language")}`, [
|
|
598
|
+
{ value: "zh", label: "中文" },
|
|
599
|
+
{ value: "en", label: "English" },
|
|
600
|
+
]);
|
|
601
|
+
output.write(style.boxFooter());
|
|
602
|
+
return choice;
|
|
603
|
+
}
|
|
604
|
+
async function collectCredentials(prompts, output, style) {
|
|
605
|
+
const endpoint = await prompts.ask(`${style.bold("Jira REST API endpoint")} (e.g. https://your-domain.atlassian.net/rest/api/3)`);
|
|
606
|
+
if (!endpoint) {
|
|
607
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} endpoint is required`));
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
const api_key = await prompts.ask(`${style.bold("Jira API token")} (will be stored as $JIRA_API_KEY env var reference)`);
|
|
611
|
+
output.write(style.boxLine(style.dim("Tip: export JIRA_API_KEY=<token> in ~/.bashrc, or set it in env: section of WORKFLOW.md")));
|
|
612
|
+
const auth_mode = await prompts.askSelect(`${style.bold("Authentication mode")}`, [
|
|
613
|
+
{ value: "basic", label: "basic" },
|
|
614
|
+
{ value: "bearer", label: "bearer" },
|
|
615
|
+
]);
|
|
616
|
+
let api_user = null;
|
|
617
|
+
if (auth_mode === "basic") {
|
|
618
|
+
api_user = await prompts.ask(`${style.bold("Jira username/email")} (required for basic auth)`);
|
|
619
|
+
}
|
|
620
|
+
const project_key = await prompts.ask(`${style.bold("Jira project key")} (e.g. ENG)`);
|
|
621
|
+
if (!project_key) {
|
|
622
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} project_key is required`));
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
625
|
+
return { endpoint, api_key, auth_mode, api_user, project_key };
|
|
626
|
+
}
|
|
627
|
+
async function testJiraConnection(creds, fetchImpl, output, style) {
|
|
628
|
+
const config = {
|
|
629
|
+
kind: "jira",
|
|
630
|
+
endpoint: creds.endpoint,
|
|
631
|
+
api_key: creds.api_key || process.env.JIRA_API_KEY || "",
|
|
632
|
+
api_user: creds.api_user,
|
|
633
|
+
auth_mode: creds.auth_mode,
|
|
634
|
+
review_state: null,
|
|
635
|
+
project_key: creds.project_key,
|
|
636
|
+
project_slug: null,
|
|
637
|
+
assignee: null,
|
|
638
|
+
required_labels: [],
|
|
639
|
+
active_states: [],
|
|
640
|
+
terminal_states: [],
|
|
641
|
+
};
|
|
642
|
+
const tracker = new JiraTracker(config, fetchImpl);
|
|
643
|
+
let version = "unknown";
|
|
644
|
+
try {
|
|
645
|
+
const info = await tracker.fetchServerInfo({ timeoutMs: 5000 });
|
|
646
|
+
if (info && typeof info.version === "string")
|
|
647
|
+
version = info.version;
|
|
648
|
+
}
|
|
649
|
+
catch (err) {
|
|
650
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
651
|
+
output.write(style.boxHeader("Connection Test"));
|
|
652
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} Jira connection test failed: ${msg}`));
|
|
653
|
+
output.write(style.boxLine(style.dim(` Endpoint: ${creds.endpoint}`)));
|
|
654
|
+
output.write(style.boxLine(style.dim(" Common causes:")));
|
|
655
|
+
output.write(style.boxLine(style.dim(" - Wrong API version (Jira Server: /rest/api/2/, Jira Cloud: /rest/api/3/)")));
|
|
656
|
+
output.write(style.boxLine(style.dim(" - Missing context path (e.g., http://host/jira/rest/api/2/)")));
|
|
657
|
+
output.write(style.boxLine(style.dim(" - Jira URL changed or is unreachable")));
|
|
658
|
+
output.write(style.boxLine(style.dim(" You can fix credentials later and re-run 'tasking init --force'")));
|
|
659
|
+
output.write(style.boxFooter());
|
|
660
|
+
return { issueTypes: [], statuses: [] };
|
|
661
|
+
}
|
|
662
|
+
output.write(style.boxHeader("Connection Test"));
|
|
663
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} Jira connection successful (v${version})`));
|
|
664
|
+
let statuses = [];
|
|
665
|
+
try {
|
|
666
|
+
statuses = await tracker.fetchProjectStatuses({ timeoutMs: 5000 });
|
|
667
|
+
if (statuses.length > 0) {
|
|
668
|
+
output.write(style.boxLine(" Project statuses:"));
|
|
669
|
+
for (const name of statuses) {
|
|
670
|
+
output.write(style.boxLine(` ${style.statusIcon("info")} ${name}`));
|
|
671
|
+
}
|
|
672
|
+
output.write(style.boxLine(style.dim(" Assign these to active_states/review_state/terminal_states in WORKFLOW.md")));
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
output.write(style.boxLine(" No statuses found for this project."));
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
catch (err) {
|
|
679
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
680
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} Project key '${creds.project_key}' test failed: ${msg}`));
|
|
681
|
+
output.write(style.boxLine(style.dim(" Check that:")));
|
|
682
|
+
output.write(style.boxLine(style.dim(" - The project key is correct (case-sensitive)")));
|
|
683
|
+
output.write(style.boxLine(style.dim(" - Your token has access to this project")));
|
|
684
|
+
output.write(style.boxLine(style.dim(" You can fix credentials later and re-run 'tasking init --force'")));
|
|
685
|
+
}
|
|
686
|
+
let issueTypes = [];
|
|
687
|
+
try {
|
|
688
|
+
issueTypes = await tracker.fetchIssueTypes({ timeoutMs: 5000 });
|
|
689
|
+
if (issueTypes.length > 0) {
|
|
690
|
+
output.write(style.boxLine(" Project issue types:"));
|
|
691
|
+
for (const name of issueTypes) {
|
|
692
|
+
output.write(style.boxLine(` ${style.statusIcon("info")} ${name}`));
|
|
693
|
+
}
|
|
694
|
+
output.write(style.boxLine(style.dim(" Set feishu.create_issue_type to one of these in WORKFLOW.md")));
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
catch { }
|
|
698
|
+
output.write(style.boxFooter());
|
|
699
|
+
return { issueTypes, statuses };
|
|
700
|
+
}
|
|
701
|
+
function probeStatusIcon(style, status) {
|
|
702
|
+
switch (status) {
|
|
703
|
+
case "ok":
|
|
704
|
+
return style.statusIcon("ok");
|
|
705
|
+
case "missing":
|
|
706
|
+
return style.statusIcon("fail");
|
|
707
|
+
case "unknown":
|
|
708
|
+
return style.statusIcon("warn");
|
|
709
|
+
default:
|
|
710
|
+
return style.statusIcon("info");
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function printProbeItem(output, style, item) {
|
|
714
|
+
const tail = item.hint !== null && item.status !== "ok" ? ` — ${translate(item.hint)}` : "";
|
|
715
|
+
output.write(style.boxLine(` ${probeStatusIcon(style, item.status)} ${translate(item.label)}(${item.scope})${tail}`));
|
|
716
|
+
}
|
|
717
|
+
function printNextStepLinks(output, style, links) {
|
|
718
|
+
output.write(style.boxLine(style.dim(` 下一步: 订阅事件 ${links.event} | 发布版本 ${links.version}`)));
|
|
719
|
+
}
|
|
720
|
+
async function pickOrCreateIntakeChat(prompts, output, style, token, initialChats, appId, fetchImpl, edition) {
|
|
721
|
+
const CREATE_LABEL = "➕ 新建 intake 群(并拉你进群)";
|
|
722
|
+
const REFRESH_LABEL = "⟳ 刷新群列表";
|
|
723
|
+
const CREATE_VALUE = "__create__";
|
|
724
|
+
const REFRESH_VALUE = "__refresh__";
|
|
725
|
+
let chats = initialChats;
|
|
726
|
+
for (;;) {
|
|
727
|
+
const nameCounts = new Map();
|
|
728
|
+
for (const c of chats)
|
|
729
|
+
nameCounts.set(c.name, (nameCounts.get(c.name) ?? 0) + 1);
|
|
730
|
+
const options = [
|
|
731
|
+
{ value: CREATE_VALUE, label: CREATE_LABEL },
|
|
732
|
+
{ value: REFRESH_VALUE, label: REFRESH_LABEL },
|
|
733
|
+
...chats.map((c) => ({
|
|
734
|
+
value: c.chat_id,
|
|
735
|
+
label: ((nameCounts.get(c.name) ?? 0) > 1 ? `${c.name}(${c.chat_id})` : c.name),
|
|
736
|
+
})),
|
|
737
|
+
];
|
|
738
|
+
const picked = await prompts.askSelect(`${style.bold("选择 intake 群")}`, options);
|
|
739
|
+
if (picked === REFRESH_VALUE) {
|
|
740
|
+
const { chats: refreshed } = await probeListChats(token, fetchImpl, appId, edition);
|
|
741
|
+
if (refreshed !== null)
|
|
742
|
+
chats = refreshed;
|
|
743
|
+
output.write(style.boxLine(style.dim(` 已刷新(${chats.length} 个群)`)));
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (picked === CREATE_VALUE) {
|
|
747
|
+
const groupNameAnswer = await prompts.ask(`${style.bold("新群名称")}(回车默认 tasking-intake)`);
|
|
748
|
+
const groupName = groupNameAnswer === "" ? "tasking-intake" : groupNameAnswer;
|
|
749
|
+
const inviteAnswer = await prompts.ask(`${style.bold("你的飞书邮箱或手机号")}(建群后拉你进群,需 contact:user.id:readonly;回车跳过)`);
|
|
750
|
+
let memberIds = [];
|
|
751
|
+
if (inviteAnswer !== "") {
|
|
752
|
+
const lookup = await lookupFeishuUserId(token, inviteAnswer, fetchImpl, edition);
|
|
753
|
+
if (lookup.ok) {
|
|
754
|
+
memberIds = [lookup.open_id];
|
|
755
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} 已定位你的账号,建群时拉你进群`));
|
|
756
|
+
}
|
|
757
|
+
else if (lookup.reason === "permission") {
|
|
758
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} 无法查询用户:缺 contact:user.id:readonly → 开通: ${consoleLinks(appId, edition).permission} (开通后需重新发布版本)`));
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} 查询用户失败:${lookup.detail}`));
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
const created = await createBotChat(token, groupName, fetchImpl, memberIds, edition);
|
|
765
|
+
if (created.ok) {
|
|
766
|
+
if (memberIds.length > 0) {
|
|
767
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} 已建群并选用:${groupName}(${created.chat_id})——你已在群里`));
|
|
768
|
+
return created.chat_id;
|
|
769
|
+
}
|
|
770
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} 群已建(${created.chat_id}),但只有机器人成员——你在飞书看不到它,未选用`));
|
|
771
|
+
output.write(style.boxLine(style.dim(" 建议:在飞书手动建群并把 tasking 机器人拉进群,然后回来选「⟳ 刷新群列表」")));
|
|
772
|
+
const { chats: refreshed } = await probeListChats(token, fetchImpl, appId, edition);
|
|
773
|
+
if (refreshed !== null)
|
|
774
|
+
chats = refreshed;
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} 建群失败:${created.detail}`));
|
|
778
|
+
if (created.reason === "permission") {
|
|
779
|
+
output.write(style.boxLine(` 缺 im:chat(建群)→ 开通: ${consoleLinks(appId, edition).permission} (搜索 "im:chat",开通后需重新发布版本)`));
|
|
780
|
+
}
|
|
781
|
+
output.write(style.boxLine(style.dim(" 已降级回群选择——可手选已有群,或开通权限后重试新建")));
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
const pickedIndex = options.findIndex((o) => o.value === picked) - 2;
|
|
785
|
+
const chosen = chats[pickedIndex >= 0 ? pickedIndex : 0];
|
|
786
|
+
output.write(style.boxLine(style.dim(` 已选群:${chosen?.name ?? ""}(${chosen?.chat_id ?? ""})`)));
|
|
787
|
+
return chosen?.chat_id ?? "";
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
async function selectFeishuEdition(prompts, output, style, lang) {
|
|
791
|
+
const cnFirst = [
|
|
792
|
+
{ value: "feishu", label: "国内版(飞书)(默认)" },
|
|
793
|
+
{ value: "lark", label: "海外版(Lark)" },
|
|
794
|
+
];
|
|
795
|
+
const larkFirst = [
|
|
796
|
+
{ value: "lark", label: "海外版(Lark)(默认)" },
|
|
797
|
+
{ value: "feishu", label: "国内版(飞书)" },
|
|
798
|
+
];
|
|
799
|
+
const options = lang === "en" ? larkFirst : cnFirst;
|
|
800
|
+
const edition = await prompts.askSelect(`${style.bold("飞书版本")}`, options);
|
|
801
|
+
output.write(style.boxLine(style.dim(` API 域名: ${feishuApiBase(edition)}`)));
|
|
802
|
+
return edition;
|
|
803
|
+
}
|
|
804
|
+
async function collectFeishuDirectConfig(prompts, output, style, fetchImpl, lang) {
|
|
805
|
+
output.write(style.boxHeader("Feishu Setup"));
|
|
806
|
+
output.write(style.boxLine(style.dim("飞书直连专用部署:/chat 在配置目录创建 opencode 会话(无需 Jira)。详见 docs/feishu-quickstart.md")));
|
|
807
|
+
const edition = await selectFeishuEdition(prompts, output, style, lang);
|
|
808
|
+
const app_id = await prompts.ask(`${style.bold("Feishu app_id")} (${feishuApiBase(edition)} 应用凭证)`);
|
|
809
|
+
let app_secret = await prompts.ask(`${style.bold("Feishu app_secret")} (直接明文写入 WORKFLOW.md;留空则改用 $FEISHU_APP_SECRET 环境变量)`);
|
|
810
|
+
let token = null;
|
|
811
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
812
|
+
const result = await fetchTenantTokenFor(app_id, app_secret, fetchImpl, edition);
|
|
813
|
+
if (result.ok) {
|
|
814
|
+
token = result.token;
|
|
815
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} 飞书凭据验证通过`));
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} 验证未通过:${result.reason}`));
|
|
819
|
+
output.write(style.boxLine(style.dim(` ${crossRegionHint(edition)}`)));
|
|
820
|
+
if (attempt === 3)
|
|
821
|
+
break;
|
|
822
|
+
const reEntered = await prompts.ask(`${style.bold("Feishu app_secret")}(重输重试;直接回车跳过验证继续)`);
|
|
823
|
+
if (reEntered === "")
|
|
824
|
+
break;
|
|
825
|
+
app_secret = reEntered;
|
|
826
|
+
}
|
|
827
|
+
if (token === null) {
|
|
828
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} 已跳过验证,继续配置(tasking start 前请确认凭据可用)`));
|
|
829
|
+
}
|
|
830
|
+
let intake_chat_id;
|
|
831
|
+
if (token === null) {
|
|
832
|
+
intake_chat_id = await prompts.ask(`${style.bold("Feishu intake_chat_id")} (承载 /chat 与会话话题的群,oc_ 开头)`);
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
const { item: chatsItem, chats } = await probeListChats(token, fetchImpl, app_id, edition);
|
|
836
|
+
printProbeItem(output, style, chatsItem);
|
|
837
|
+
if (chats === null || chats.length === 0) {
|
|
838
|
+
printNextStepLinks(output, style, consoleLinks(app_id, edition));
|
|
839
|
+
intake_chat_id = await prompts.ask(`${style.bold("Feishu intake_chat_id")} (承载 /chat 与会话话题的群,oc_ 开头)`);
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
intake_chat_id = await pickOrCreateIntakeChat(prompts, output, style, token, chats, app_id, fetchImpl, edition);
|
|
843
|
+
}
|
|
844
|
+
if (intake_chat_id !== "") {
|
|
845
|
+
printProbeItem(output, style, await probeListMessages(token, intake_chat_id, fetchImpl, app_id, edition));
|
|
846
|
+
}
|
|
847
|
+
for (const item of await probeTail(token, app_id, null, fetchImpl, edition)) {
|
|
848
|
+
printProbeItem(output, style, item);
|
|
849
|
+
}
|
|
850
|
+
printNextStepLinks(output, style, consoleLinks(app_id, edition));
|
|
851
|
+
}
|
|
852
|
+
printFeishuSecretHint(output, style, app_secret);
|
|
853
|
+
let project = null;
|
|
854
|
+
const projectName = await prompts.ask(`${style.bold("常用项目名")}(/chat <项目名> <消息> 使用;直接回车跳过)`);
|
|
855
|
+
if (projectName !== "") {
|
|
856
|
+
for (;;) {
|
|
857
|
+
const projectDir = await prompts.ask(`${style.bold("项目目录绝对路径")}(${projectName};回车放弃)`);
|
|
858
|
+
if (projectDir === "")
|
|
859
|
+
break;
|
|
860
|
+
const expandedDir = expandHome(projectDir);
|
|
861
|
+
if (!existsSync(expandedDir) || !statSync(expandedDir).isDirectory()) {
|
|
862
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} 路径不存在或不是目录: ${projectDir}`));
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
project = { name: projectName.toLowerCase(), path: realpathSync(expandedDir) };
|
|
866
|
+
break;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
output.write(style.boxFooter());
|
|
870
|
+
return {
|
|
871
|
+
edition,
|
|
872
|
+
app_id,
|
|
873
|
+
app_secret: app_secret === "" ? null : app_secret,
|
|
874
|
+
intake_chat_id,
|
|
875
|
+
create_issue_type: null,
|
|
876
|
+
project,
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
async function collectFeishuConfig(prompts, output, style, issueTypes, fetchImpl, lang) {
|
|
880
|
+
output.write(style.boxHeader("Feishu Setup"));
|
|
881
|
+
output.write(style.boxLine(style.dim("评论桥:飞书话题 ↔ Jira 评论双向镜像(/issue、/state、/help)。详见 docs/feishu-quickstart.md")));
|
|
882
|
+
const enable = await prompts.askSelect(`${style.bold("Enable Feishu bridge")}`, [
|
|
883
|
+
{ value: "no", label: "no" },
|
|
884
|
+
{ value: "yes", label: "yes" },
|
|
885
|
+
]);
|
|
886
|
+
if (enable !== "yes") {
|
|
887
|
+
output.write(style.boxLine(`${style.statusIcon("info")} Feishu bridge disabled; 详见 docs/feishu-quickstart.md`));
|
|
888
|
+
output.write(style.boxFooter());
|
|
889
|
+
return null;
|
|
890
|
+
}
|
|
891
|
+
const edition = await selectFeishuEdition(prompts, output, style, lang);
|
|
892
|
+
const app_id = await prompts.ask(`${style.bold("Feishu app_id")} (${feishuApiBase(edition)} 应用凭证)`);
|
|
893
|
+
const app_secret = await prompts.ask(`${style.bold("Feishu app_secret")} (直接明文写入 WORKFLOW.md;留空则改用 $FEISHU_APP_SECRET 环境变量)`);
|
|
894
|
+
const intake_chat_id = await prompts.ask(`${style.bold("Feishu intake_chat_id")} (承载所有 issue 线程的群)`);
|
|
895
|
+
const tokenResult = await fetchTenantTokenFor(app_id, app_secret, fetchImpl, edition);
|
|
896
|
+
if (!tokenResult.ok) {
|
|
897
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} 飞书凭据验证未通过:${tokenResult.reason}(不影响生成配置,start 前请修正)`));
|
|
898
|
+
output.write(style.boxLine(style.dim(` ${crossRegionHint(edition)}`)));
|
|
899
|
+
}
|
|
900
|
+
else {
|
|
901
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} 飞书凭据验证通过`));
|
|
902
|
+
printProbeItem(output, style, (await probeListChats(tokenResult.token, fetchImpl, app_id, edition)).item);
|
|
903
|
+
if (intake_chat_id !== "") {
|
|
904
|
+
printProbeItem(output, style, await probeListMessages(tokenResult.token, intake_chat_id, fetchImpl, app_id, edition));
|
|
905
|
+
}
|
|
906
|
+
for (const item of await probeTail(tokenResult.token, app_id, null, fetchImpl, edition)) {
|
|
907
|
+
printProbeItem(output, style, item);
|
|
908
|
+
}
|
|
909
|
+
printNextStepLinks(output, style, consoleLinks(app_id, edition));
|
|
910
|
+
}
|
|
911
|
+
const typeOptions = ["Task", ...issueTypes.filter((t) => t !== "Task")];
|
|
912
|
+
const create_issue_type = await prompts.askSelect(`${style.bold("Default issue type for /issue")}`, typeOptions.map((t) => ({ value: t, label: t })));
|
|
913
|
+
printFeishuSecretHint(output, style, app_secret);
|
|
914
|
+
output.write(style.boxFooter());
|
|
915
|
+
return {
|
|
916
|
+
edition,
|
|
917
|
+
app_id,
|
|
918
|
+
app_secret: app_secret === "" ? null : app_secret,
|
|
919
|
+
intake_chat_id,
|
|
920
|
+
create_issue_type,
|
|
921
|
+
project: null,
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
function printFeishuSecretHint(output, style, appSecret) {
|
|
925
|
+
if (appSecret !== "") {
|
|
926
|
+
output.write(style.boxLine(style.dim(" app_secret 已明文写入 WORKFLOW.md;如需保密可改用环境变量:export FEISHU_APP_SECRET=<secret>,再把该行改回 $FEISHU_APP_SECRET")));
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
output.write(style.boxLine(style.dim("Tip: 已保留 $FEISHU_APP_SECRET 引用——export FEISHU_APP_SECRET=<secret> in ~/.bashrc, or set it in env: section of WORKFLOW.md")));
|
|
930
|
+
}
|
|
931
|
+
export const VARIANT_ACTIVE_SECTIONS = {
|
|
932
|
+
"feishu-direct": ["tracker", "feishu"],
|
|
933
|
+
minimal: ["tracker", "hooks", "feishu"],
|
|
934
|
+
"code-mr": ["tracker", "hooks", "env", "feishu"],
|
|
935
|
+
"grill-openspec": ["tracker", "hooks", "env", "feishu"],
|
|
936
|
+
};
|
|
937
|
+
export const TEMPLATE_SECTIONS = [
|
|
938
|
+
"tracker",
|
|
939
|
+
"polling",
|
|
940
|
+
"workspace",
|
|
941
|
+
"hooks",
|
|
942
|
+
"agent",
|
|
943
|
+
"opencode",
|
|
944
|
+
"router",
|
|
945
|
+
"feishu",
|
|
946
|
+
"server",
|
|
947
|
+
"logging",
|
|
948
|
+
"env",
|
|
949
|
+
];
|
|
950
|
+
const OPTIONAL_SECTION_MARKERS = {
|
|
951
|
+
zh: "# —— 可选:以下为默认值,改动才解注释 ——",
|
|
952
|
+
en: "# —— optional: defaults below; uncomment only to change ——",
|
|
953
|
+
};
|
|
954
|
+
const TOP_LEVEL_KEY = /^([a-z_]+):/;
|
|
955
|
+
const ANY_SECTION_KEY = /^(?:# )?([a-z_]+):/;
|
|
956
|
+
function frontmatterBounds(lines) {
|
|
957
|
+
if ((lines[0] ?? "").trim() !== "---")
|
|
958
|
+
return null;
|
|
959
|
+
for (let i = 1; i < lines.length; i++) {
|
|
960
|
+
if ((lines[i] ?? "").trim() === "---")
|
|
961
|
+
return { start: 1, end: i };
|
|
962
|
+
}
|
|
963
|
+
return null;
|
|
964
|
+
}
|
|
965
|
+
export function templateTopLevelKeys(content) {
|
|
966
|
+
const lines = content.split("\n");
|
|
967
|
+
const bounds = frontmatterBounds(lines);
|
|
968
|
+
if (!bounds)
|
|
969
|
+
return [];
|
|
970
|
+
const keys = new Set();
|
|
971
|
+
for (let i = bounds.start; i < bounds.end; i++) {
|
|
972
|
+
const m = ANY_SECTION_KEY.exec(lines[i] ?? "");
|
|
973
|
+
if (m?.[1])
|
|
974
|
+
keys.add(m[1]);
|
|
975
|
+
}
|
|
976
|
+
return [...keys];
|
|
977
|
+
}
|
|
978
|
+
function commentOut(line) {
|
|
979
|
+
if (line.trim() === "")
|
|
980
|
+
return line;
|
|
981
|
+
if (line.trimStart().startsWith("#"))
|
|
982
|
+
return line;
|
|
983
|
+
return line.replace(/^([ \t]*)/, "$1# ");
|
|
984
|
+
}
|
|
985
|
+
export function trimFrontmatter(content, opts) {
|
|
986
|
+
const lines = content.split("\n");
|
|
987
|
+
const bounds = frontmatterBounds(lines);
|
|
988
|
+
if (!bounds)
|
|
989
|
+
return content;
|
|
990
|
+
const active = new Set(VARIANT_ACTIVE_SECTIONS[opts.workflow]);
|
|
991
|
+
const out = [];
|
|
992
|
+
let currentKey = null;
|
|
993
|
+
let markerFor = "\u0000";
|
|
994
|
+
for (let i = bounds.start; i < bounds.end; i++) {
|
|
995
|
+
const line = lines[i] ?? "";
|
|
996
|
+
const m = TOP_LEVEL_KEY.exec(line);
|
|
997
|
+
if (m?.[1])
|
|
998
|
+
currentKey = m[1];
|
|
999
|
+
const sectionActive = currentKey === null || active.has(currentKey) || currentKey === "interface_language";
|
|
1000
|
+
if (sectionActive) {
|
|
1001
|
+
const isKeyLine = m?.[1] === currentKey;
|
|
1002
|
+
const feishuDisabled = currentKey === "feishu" && !opts.feishuEnabled;
|
|
1003
|
+
if (feishuDisabled && !isKeyLine && !/^ {2}enabled:/.test(line)) {
|
|
1004
|
+
out.push(commentOut(line));
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
out.push(line);
|
|
1008
|
+
}
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (markerFor !== currentKey) {
|
|
1012
|
+
out.push(OPTIONAL_SECTION_MARKERS[opts.lang]);
|
|
1013
|
+
markerFor = currentKey ?? "\u0000";
|
|
1014
|
+
}
|
|
1015
|
+
out.push(commentOut(line));
|
|
1016
|
+
}
|
|
1017
|
+
return [lines[0], ...out, ...lines.slice(bounds.end)].join("\n");
|
|
1018
|
+
}
|
|
1019
|
+
export const STATE_BUCKETS = {
|
|
1020
|
+
active: [
|
|
1021
|
+
"待办",
|
|
1022
|
+
"to do",
|
|
1023
|
+
"todo",
|
|
1024
|
+
"处理中",
|
|
1025
|
+
"进行中",
|
|
1026
|
+
"in progress",
|
|
1027
|
+
"合并中",
|
|
1028
|
+
"merging",
|
|
1029
|
+
"重置处理",
|
|
1030
|
+
"reset",
|
|
1031
|
+
],
|
|
1032
|
+
review: ["代码评审中", "评审中", "待评审", "in review", "review"],
|
|
1033
|
+
terminal: [
|
|
1034
|
+
"完成",
|
|
1035
|
+
"done",
|
|
1036
|
+
"关闭",
|
|
1037
|
+
"closed",
|
|
1038
|
+
"取消",
|
|
1039
|
+
"cancelled",
|
|
1040
|
+
"canceled",
|
|
1041
|
+
"重复",
|
|
1042
|
+
"duplicate",
|
|
1043
|
+
"resolved",
|
|
1044
|
+
],
|
|
1045
|
+
};
|
|
1046
|
+
export function classifyProjectStatuses(names) {
|
|
1047
|
+
const buckets = { active: [], review: [], terminal: [], unmatched: [] };
|
|
1048
|
+
for (const name of names) {
|
|
1049
|
+
const norm = name.trim().toLowerCase();
|
|
1050
|
+
if (STATE_BUCKETS.review.includes(norm))
|
|
1051
|
+
buckets.review.push(name);
|
|
1052
|
+
else if (STATE_BUCKETS.active.includes(norm))
|
|
1053
|
+
buckets.active.push(name);
|
|
1054
|
+
else if (STATE_BUCKETS.terminal.includes(norm))
|
|
1055
|
+
buckets.terminal.push(name);
|
|
1056
|
+
else
|
|
1057
|
+
buckets.unmatched.push(name);
|
|
1058
|
+
}
|
|
1059
|
+
return buckets;
|
|
1060
|
+
}
|
|
1061
|
+
async function promptStateAutofill(statuses, prompts, output, style, lang) {
|
|
1062
|
+
const zh = lang === "zh";
|
|
1063
|
+
const buckets = classifyProjectStatuses(statuses);
|
|
1064
|
+
if (buckets.active.length === 0 || buckets.terminal.length === 0) {
|
|
1065
|
+
if (statuses.length > 0) {
|
|
1066
|
+
output.write(style.boxLine(style.dim(zh
|
|
1067
|
+
? " (状态名无法完整映射到 active/terminal,保留模板默认,可在 WORKFLOW.md 手改)"
|
|
1068
|
+
: " (statuses could not be fully mapped to active/terminal; template defaults kept — edit WORKFLOW.md if needed)")));
|
|
1069
|
+
if (buckets.unmatched.length > 0) {
|
|
1070
|
+
output.write(style.boxLine(style.dim(` ${zh ? "未采用" : "unmatched"}: ${buckets.unmatched.join(" / ")}`)));
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
return null;
|
|
1074
|
+
}
|
|
1075
|
+
output.write(style.boxLine(zh ? " 建议的状态预填:" : " Suggested state mapping:"));
|
|
1076
|
+
output.write(style.boxLine(` active: ${buckets.active.join(" / ")}`));
|
|
1077
|
+
output.write(style.boxLine(` review: ${buckets.review.join(" / ") || (zh ? "(无)" : "(none)")}`));
|
|
1078
|
+
output.write(style.boxLine(` terminal: ${buckets.terminal.join(" / ")}`));
|
|
1079
|
+
if (buckets.unmatched.length > 0) {
|
|
1080
|
+
output.write(style.boxLine(style.dim(` ${zh ? "未采用" : "unmatched"}: ${buckets.unmatched.join(" / ")}`)));
|
|
1081
|
+
}
|
|
1082
|
+
const confirmLabel = zh ? "确认写入(默认)" : "Confirm (default)";
|
|
1083
|
+
const choice = await prompts.askSelect(`${style.bold(zh ? "写入状态配置" : "Write state config")}`, [
|
|
1084
|
+
{ value: "confirm", label: confirmLabel },
|
|
1085
|
+
{ value: "keep", label: zh ? "保持模板默认" : "Keep template defaults" },
|
|
1086
|
+
]);
|
|
1087
|
+
if (choice !== "confirm")
|
|
1088
|
+
return null;
|
|
1089
|
+
return {
|
|
1090
|
+
active_states: buckets.active,
|
|
1091
|
+
terminal_states: buckets.terminal,
|
|
1092
|
+
review_state: buckets.review[0] ?? null,
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function yamlScalar(value) {
|
|
1096
|
+
if (value === null)
|
|
1097
|
+
return "null";
|
|
1098
|
+
return /[:#[\]{},&*!|>'"%@`]|^\s|\s$/.test(value) ? JSON.stringify(value) : value;
|
|
1099
|
+
}
|
|
1100
|
+
function replaceYamlList(content, key, values) {
|
|
1101
|
+
const re = new RegExp(`^(\\s*)${key}:\\n(?:[ \\t]*- .*\\n)*`, "m");
|
|
1102
|
+
return content.replace(re, (_m, indent) => `${indent}${key}:\n${values.map((v) => `${indent} - ${yamlScalar(v)}`).join("\n")}\n`);
|
|
1103
|
+
}
|
|
1104
|
+
export function applyTemplateTrimming(content, workflow, feishuEnabled, lang) {
|
|
1105
|
+
const trimmed = trimFrontmatter(content, {
|
|
1106
|
+
workflow,
|
|
1107
|
+
feishuEnabled: feishuSectionActive(workflow, feishuEnabled),
|
|
1108
|
+
lang,
|
|
1109
|
+
});
|
|
1110
|
+
if (lang === "en") {
|
|
1111
|
+
return trimmed.replace(/^interface_language: zh$/m, "interface_language: en");
|
|
1112
|
+
}
|
|
1113
|
+
return trimmed.replace(/^interface_language: zh\n/m, "");
|
|
1114
|
+
}
|
|
1115
|
+
function feishuSectionActive(workflow, feishuEnabled) {
|
|
1116
|
+
return workflow === "feishu-direct" || feishuEnabled;
|
|
1117
|
+
}
|
|
1118
|
+
function isPlainRecord(value) {
|
|
1119
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1120
|
+
}
|
|
1121
|
+
export function generateWorkflowContent(creds, workflow, feishu = null, lang = "zh", states = null) {
|
|
1122
|
+
const template = readFileSync(resolveExampleFile(workflow, lang), "utf8");
|
|
1123
|
+
let content = template;
|
|
1124
|
+
if (creds !== null) {
|
|
1125
|
+
content = content.replace(/endpoint: .*/, `endpoint: ${creds.endpoint}`);
|
|
1126
|
+
content = content.replace(/api_key: .*/, "api_key: $JIRA_API_KEY");
|
|
1127
|
+
content = content.replace(/auth_mode: .*/, `auth_mode: ${creds.auth_mode}`);
|
|
1128
|
+
if (creds.api_user) {
|
|
1129
|
+
content = content.replace(/api_user: .*/, `api_user: ${creds.api_user}`);
|
|
1130
|
+
}
|
|
1131
|
+
else {
|
|
1132
|
+
content = content.replace(/api_user: .*/, "api_user: null");
|
|
1133
|
+
}
|
|
1134
|
+
content = content.replace(/project_key: .*/, `project_key: ${creds.project_key}`);
|
|
1135
|
+
}
|
|
1136
|
+
if (feishu) {
|
|
1137
|
+
content = content.replace(/^([ \t]*)edition: .*$/m, `$1edition: ${feishu.edition}`);
|
|
1138
|
+
content = content.replace(/app_id: \$FEISHU_APP_ID/, `app_id: ${feishu.app_id}`);
|
|
1139
|
+
if (feishu.app_secret !== null) {
|
|
1140
|
+
content = content.replace(/app_secret: \$FEISHU_APP_SECRET/, `app_secret: ${feishu.app_secret}`);
|
|
1141
|
+
}
|
|
1142
|
+
content = content.replace(/intake_chat_id: \$FEISHU_INTAKE_CHAT_ID/, `intake_chat_id: ${feishu.intake_chat_id}`);
|
|
1143
|
+
if (feishu.project) {
|
|
1144
|
+
content = content.replace(/^([ \t]*)projects:[ \t]*$/m, `$1projects:\n$1 ${feishu.project.name}:\n$1 path: ${feishu.project.path}`);
|
|
1145
|
+
content = content.replace(/path_roots: \[\]/, `path_roots: [${JSON.stringify(feishu.project.path)}]`);
|
|
1146
|
+
}
|
|
1147
|
+
if (feishu.create_issue_type !== null) {
|
|
1148
|
+
content = content.replace(/create_issue_type: .*/, `create_issue_type: ${feishu.create_issue_type}`);
|
|
1149
|
+
}
|
|
1150
|
+
content = content.replace(/^(feishu:\n(?:\s*#.*\n)*\s*enabled:) false/m, "$1 true");
|
|
1151
|
+
}
|
|
1152
|
+
if (states !== null) {
|
|
1153
|
+
content = replaceYamlList(content, "active_states", states.active_states);
|
|
1154
|
+
content = replaceYamlList(content, "terminal_states", states.terminal_states);
|
|
1155
|
+
content = content.replace(/^(\s*)review_state: .*$/m, `$1review_state: ${yamlScalar(states.review_state)}`);
|
|
1156
|
+
}
|
|
1157
|
+
return applyTemplateTrimming(content, workflow, feishu !== null, lang);
|
|
1158
|
+
}
|
|
1159
|
+
function copySkill(wfDir, output, workflow) {
|
|
1160
|
+
copySkills(wfDir, workflow, (status, message) => {
|
|
1161
|
+
if (status === "fail")
|
|
1162
|
+
output.write(`Warning: ${message}\n`);
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
function printPrerequisites(style, output, includeVcs) {
|
|
1166
|
+
output.write(style.boxHeader("Prerequisites"));
|
|
1167
|
+
try {
|
|
1168
|
+
const result = spawnSync("which", ["opencode"], { stdio: "pipe" });
|
|
1169
|
+
if (result.status === 0) {
|
|
1170
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} opencode found in PATH`));
|
|
1171
|
+
}
|
|
1172
|
+
else {
|
|
1173
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} opencode not found in PATH, daemon cannot execute tasks`));
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
catch {
|
|
1177
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} opencode could not check`));
|
|
1178
|
+
}
|
|
1179
|
+
if (!includeVcs) {
|
|
1180
|
+
output.write(style.boxFooter());
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
try {
|
|
1184
|
+
const result = spawnSync("which", ["glab"], { stdio: "pipe" });
|
|
1185
|
+
if (result.status === 0) {
|
|
1186
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} glab found in PATH`));
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} glab not found in PATH, agent cannot create or merge MRs`));
|
|
1190
|
+
output.write(style.boxLine(style.dim(" Install: brew install glab (or run the install-glab skill in the workspace to self-install)")));
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
catch {
|
|
1194
|
+
output.write(style.boxLine(`${style.statusIcon("fail")} glab could not check`));
|
|
1195
|
+
}
|
|
1196
|
+
if (process.env.GITLAB_TOKEN && process.env.GITLAB_HOST) {
|
|
1197
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} GitLab GITLAB_TOKEN and GITLAB_HOST set`));
|
|
1198
|
+
}
|
|
1199
|
+
else {
|
|
1200
|
+
if (!process.env.GITLAB_TOKEN) {
|
|
1201
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} GitLab GITLAB_TOKEN not set`));
|
|
1202
|
+
}
|
|
1203
|
+
if (!process.env.GITLAB_HOST) {
|
|
1204
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} GitLab GITLAB_HOST not set`));
|
|
1205
|
+
}
|
|
1206
|
+
output.write(style.boxLine(style.dim(" Set GITLAB_TOKEN and GITLAB_HOST — export in ~/.bashrc or fill env: in WORKFLOW.md")));
|
|
1207
|
+
}
|
|
1208
|
+
output.write(style.boxFooter());
|
|
1209
|
+
}
|
|
1210
|
+
function printInitialization(style, output, wfPath, workflow, lang) {
|
|
1211
|
+
output.write(style.boxHeader("Initialization"));
|
|
1212
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} ${basename(wfPath)} written`));
|
|
1213
|
+
output.write(style.boxLine(`${style.statusIcon("info")} Workflow: ${workflow}`));
|
|
1214
|
+
output.write(style.boxLine(`${style.statusIcon("info")} Language: ${lang}`));
|
|
1215
|
+
copySkillStyled(dirname(wfPath), output, style, workflow);
|
|
1216
|
+
const wsRoot = resolve(homedir(), "tasking_workspaces");
|
|
1217
|
+
if (existsSync(wsRoot)) {
|
|
1218
|
+
output.write(style.boxLine(`${style.statusIcon("info")} Workspace root already exists`));
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
mkdirSync(wsRoot, { recursive: true });
|
|
1222
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} Workspace root created`));
|
|
1223
|
+
}
|
|
1224
|
+
output.write(style.boxFooter());
|
|
1225
|
+
}
|
|
1226
|
+
function copySkillStyled(wfDir, output, style, workflow) {
|
|
1227
|
+
copySkills(wfDir, workflow, (status, message) => {
|
|
1228
|
+
output.write(style.boxLine(`${style.statusIcon(status)} ${message}`));
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
function openEditor(filePath) {
|
|
1232
|
+
const visual = process.env.VISUAL;
|
|
1233
|
+
const editor = process.env.EDITOR;
|
|
1234
|
+
const candidates = [visual, editor, "code"].filter((c) => Boolean(c));
|
|
1235
|
+
for (const cmd of candidates) {
|
|
1236
|
+
try {
|
|
1237
|
+
if (spawnSync("which", [cmd], { stdio: "pipe" }).status !== 0)
|
|
1238
|
+
continue;
|
|
1239
|
+
const child = spawn(cmd, [filePath], { detached: true, stdio: "ignore" });
|
|
1240
|
+
child.once("error", () => { });
|
|
1241
|
+
child.unref();
|
|
1242
|
+
return true;
|
|
1243
|
+
}
|
|
1244
|
+
catch {
|
|
1245
|
+
// try next
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
return false;
|
|
1249
|
+
}
|
|
1250
|
+
function printCompletionHint(output, style, editorOk, workflow, projectName, statesApplied, lang) {
|
|
1251
|
+
output.write(style.boxHeader("Next Steps"));
|
|
1252
|
+
if (workflow === "feishu-direct") {
|
|
1253
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} ${translate("配置完成!")}`));
|
|
1254
|
+
output.write(style.boxLine(` ${translate("运行:")}${style.green(style.bold("tasking start"))}`));
|
|
1255
|
+
if (projectName !== null) {
|
|
1256
|
+
output.write(style.boxLine(translate(` 然后在群里发:/chat <项目名> <消息>(如 /chat ${projectName} 帮我看个报错)`)));
|
|
1257
|
+
}
|
|
1258
|
+
else {
|
|
1259
|
+
output.write(style.boxLine(" 然后在群里发:/chat /绝对路径 <消息>"));
|
|
1260
|
+
output.write(style.boxLine(`${style.statusIcon("warn")} ${translate("path 模式当前不限制目录(path_roots: []),建议在 WORKFLOW.md 配置 projects 或 path_roots")}`));
|
|
1261
|
+
}
|
|
1262
|
+
if (editorOk) {
|
|
1263
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} Config file opened in editor`));
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
else {
|
|
1267
|
+
output.write(style.boxLine("Edit these fields in WORKFLOW.md:"));
|
|
1268
|
+
if (statesApplied) {
|
|
1269
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} ${lang === "zh"
|
|
1270
|
+
? "状态已按项目实际预填(active/terminal/review)"
|
|
1271
|
+
: "states prefilled from your project (active/terminal/review)"}`));
|
|
1272
|
+
}
|
|
1273
|
+
else {
|
|
1274
|
+
output.write(style.boxLine(` ${style.dim("· active_states Jira states that trigger dispatch")}`));
|
|
1275
|
+
output.write(style.boxLine(` ${style.dim("· terminal_states Jira states that trigger cleanup")}`));
|
|
1276
|
+
output.write(style.boxLine(` ${style.dim("· review_state intermediate review state name")}`));
|
|
1277
|
+
}
|
|
1278
|
+
output.write(style.boxLine(` ${style.dim("· after_create workspace setup hook (git clone, deps)")}`));
|
|
1279
|
+
if (workflow === "code-mr" || workflow === "grill-openspec") {
|
|
1280
|
+
output.write(style.boxLine(` ${style.dim(lang === "zh"
|
|
1281
|
+
? "· env.GITLAB_TOKEN / GITLAB_HOST 供 agent 建 MR(glab)"
|
|
1282
|
+
: "· env.GITLAB_TOKEN / GITLAB_HOST used by the agent to create MRs (glab)")}`));
|
|
1283
|
+
}
|
|
1284
|
+
output.write(style.boxLine(""));
|
|
1285
|
+
if (editorOk) {
|
|
1286
|
+
output.write(style.boxLine(`${style.statusIcon("ok")} Config file opened in editor`));
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
output.write(style.boxLine(`${style.statusIcon("info")} Config file: edit WORKFLOW.md manually`));
|
|
1290
|
+
}
|
|
1291
|
+
output.write(style.boxLine(""));
|
|
1292
|
+
output.write(style.boxLine(`Then run: ${style.green(style.bold("tasking start"))}`));
|
|
1293
|
+
}
|
|
1294
|
+
output.write(style.boxFooter());
|
|
1295
|
+
}
|
|
1296
|
+
//# sourceMappingURL=init.js.map
|