maoda-commander-tt 0.0.20 → 0.0.22
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/main.js +260 -19
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2078,9 +2078,9 @@ var ShortcutBaseCommand = class extends BaseCommand {
|
|
|
2078
2078
|
stdio: "inherit",
|
|
2079
2079
|
shell: true
|
|
2080
2080
|
});
|
|
2081
|
-
return new Promise((
|
|
2081
|
+
return new Promise((resolve9) => {
|
|
2082
2082
|
child.on("error", (error) => {
|
|
2083
|
-
|
|
2083
|
+
resolve9(
|
|
2084
2084
|
this._makeError(
|
|
2085
2085
|
1,
|
|
2086
2086
|
`\u6267\u884C ${cmdLine} \u5931\u8D25: ${error.message}`
|
|
@@ -2089,11 +2089,11 @@ var ShortcutBaseCommand = class extends BaseCommand {
|
|
|
2089
2089
|
});
|
|
2090
2090
|
child.on("close", (code, signal) => {
|
|
2091
2091
|
if (code === 0) {
|
|
2092
|
-
|
|
2092
|
+
resolve9(this._makeOk());
|
|
2093
2093
|
return;
|
|
2094
2094
|
}
|
|
2095
2095
|
const signalText = signal ? `, signal: ${signal}` : "";
|
|
2096
|
-
|
|
2096
|
+
resolve9(
|
|
2097
2097
|
this._makeError(
|
|
2098
2098
|
code ?? 1,
|
|
2099
2099
|
`\u6267\u884C ${cmdLine} \u5931\u8D25${signalText}`
|
|
@@ -2188,9 +2188,9 @@ var AiBaseCommand = class extends BaseCommand {
|
|
|
2188
2188
|
cwd: process.cwd(),
|
|
2189
2189
|
stdio: "inherit"
|
|
2190
2190
|
});
|
|
2191
|
-
return new Promise((
|
|
2191
|
+
return new Promise((resolve9) => {
|
|
2192
2192
|
child.on("error", (error) => {
|
|
2193
|
-
|
|
2193
|
+
resolve9(
|
|
2194
2194
|
this._makeError(
|
|
2195
2195
|
1,
|
|
2196
2196
|
`\u6267\u884C ${command} ${args.join(" ")} \u5931\u8D25: ${error.message}`
|
|
@@ -2199,11 +2199,11 @@ var AiBaseCommand = class extends BaseCommand {
|
|
|
2199
2199
|
});
|
|
2200
2200
|
child.on("close", (code, signal) => {
|
|
2201
2201
|
if (code === 0) {
|
|
2202
|
-
|
|
2202
|
+
resolve9(this._makeOk());
|
|
2203
2203
|
return;
|
|
2204
2204
|
}
|
|
2205
2205
|
const signalText = signal ? `, signal: ${signal}` : "";
|
|
2206
|
-
|
|
2206
|
+
resolve9(
|
|
2207
2207
|
this._makeError(
|
|
2208
2208
|
code ?? 1,
|
|
2209
2209
|
`\u6267\u884C ${command} ${args.join(" ")} \u5931\u8D25${signalText}`
|
|
@@ -2508,7 +2508,7 @@ var AiImageCommandV2 = class extends AiBaseCommand {
|
|
|
2508
2508
|
`\u521B\u5EFA codex \u7A7A\u5DE5\u4F5C\u76EE\u5F55\u5931\u8D25: ${CODEX_EMPTY_WORKDIR}: ${message}`
|
|
2509
2509
|
);
|
|
2510
2510
|
}
|
|
2511
|
-
const codexPrompt = `\u751F\u6210\u56FE\u7247
|
|
2511
|
+
const codexPrompt = `\u751F\u6210\u56FE\u7247(\u4F7F\u7528\u975ECLI\u6A21\u5F0F\u6765\u751F\u6210\uFF0C\u4F7F\u7528\u53EF\u652F\u6301\u7684\u9AD8\u753B\u8D28)\uFF0C\u5177\u4F53\u8981\u6C42\u5982\u4E0B:
|
|
2512
2512
|
${prompt}`;
|
|
2513
2513
|
const args = [
|
|
2514
2514
|
"exec",
|
|
@@ -2523,9 +2523,9 @@ var AiImageCommandV2 = class extends AiBaseCommand {
|
|
|
2523
2523
|
cwd: process.cwd(),
|
|
2524
2524
|
stdio: "ignore"
|
|
2525
2525
|
});
|
|
2526
|
-
return new Promise((
|
|
2526
|
+
return new Promise((resolve9) => {
|
|
2527
2527
|
child.on("error", (error) => {
|
|
2528
|
-
|
|
2528
|
+
resolve9(
|
|
2529
2529
|
this._makeError(
|
|
2530
2530
|
1,
|
|
2531
2531
|
`\u6267\u884C codex ${args.join(" ")} \u5931\u8D25: ${error.message}`
|
|
@@ -2534,11 +2534,11 @@ var AiImageCommandV2 = class extends AiBaseCommand {
|
|
|
2534
2534
|
});
|
|
2535
2535
|
child.on("close", (code, signal) => {
|
|
2536
2536
|
if (code === 0) {
|
|
2537
|
-
|
|
2537
|
+
resolve9(this._makeOk());
|
|
2538
2538
|
return;
|
|
2539
2539
|
}
|
|
2540
2540
|
const signalText = signal ? `, signal: ${signal}` : "";
|
|
2541
|
-
|
|
2541
|
+
resolve9(
|
|
2542
2542
|
this._makeError(
|
|
2543
2543
|
code ?? 1,
|
|
2544
2544
|
`\u6267\u884C codex ${args.join(" ")} \u5931\u8D25${signalText}`
|
|
@@ -3430,7 +3430,7 @@ function extractErrorText(payload) {
|
|
|
3430
3430
|
return void 0;
|
|
3431
3431
|
}
|
|
3432
3432
|
function delay(ms) {
|
|
3433
|
-
return new Promise((
|
|
3433
|
+
return new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
3434
3434
|
}
|
|
3435
3435
|
async function appendPollingUrl(pollingUrl, generationId) {
|
|
3436
3436
|
const locationResult = await resolveConfigLocation();
|
|
@@ -3631,7 +3631,7 @@ var AiQueryTaskCommand = class extends AiBaseCommand {
|
|
|
3631
3631
|
PPE_ENV,
|
|
3632
3632
|
"--json"
|
|
3633
3633
|
];
|
|
3634
|
-
return new Promise((
|
|
3634
|
+
return new Promise((resolve9) => {
|
|
3635
3635
|
const child = spawn4(BIN, args, { cwd: process.cwd() });
|
|
3636
3636
|
let stdout = "";
|
|
3637
3637
|
let stderr = "";
|
|
@@ -3642,7 +3642,7 @@ var AiQueryTaskCommand = class extends AiBaseCommand {
|
|
|
3642
3642
|
stderr += chunk.toString();
|
|
3643
3643
|
});
|
|
3644
3644
|
child.on("error", (error) => {
|
|
3645
|
-
|
|
3645
|
+
resolve9(
|
|
3646
3646
|
makeError(
|
|
3647
3647
|
1,
|
|
3648
3648
|
`\u6267\u884C ${BIN} ${args.join(" ")} \u5931\u8D25: ${error.message}`
|
|
@@ -3651,13 +3651,13 @@ var AiQueryTaskCommand = class extends AiBaseCommand {
|
|
|
3651
3651
|
});
|
|
3652
3652
|
child.on("close", (code, signal) => {
|
|
3653
3653
|
if (code === 0) {
|
|
3654
|
-
|
|
3654
|
+
resolve9(makeOkWith({ stdout, stderr }));
|
|
3655
3655
|
return;
|
|
3656
3656
|
}
|
|
3657
3657
|
const signalText = signal ? `, signal: ${signal}` : "";
|
|
3658
3658
|
const stderrText = stderr.trim() ? `
|
|
3659
3659
|
${stderr.trim()}` : "";
|
|
3660
|
-
|
|
3660
|
+
resolve9(
|
|
3661
3661
|
makeError(
|
|
3662
3662
|
code ?? 1,
|
|
3663
3663
|
`\u6267\u884C ${BIN} ${args.join(" ")} \u5931\u8D25${signalText}${stderrText}`
|
|
@@ -3697,7 +3697,7 @@ function tryParseJson(text) {
|
|
|
3697
3697
|
}
|
|
3698
3698
|
}
|
|
3699
3699
|
function delay2(ms) {
|
|
3700
|
-
return new Promise((
|
|
3700
|
+
return new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
3701
3701
|
}
|
|
3702
3702
|
|
|
3703
3703
|
// src/commands/ai/ai-command.ts
|
|
@@ -3720,6 +3720,246 @@ var AiCommand = class extends BaseSubcommandHost {
|
|
|
3720
3720
|
}
|
|
3721
3721
|
};
|
|
3722
3722
|
|
|
3723
|
+
// src/commands/tool/tool-canvas-command.ts
|
|
3724
|
+
import { readdir as readdir2, readFile as readFile4, stat as stat4 } from "fs/promises";
|
|
3725
|
+
import { homedir as homedir8 } from "os";
|
|
3726
|
+
import { join as join12, resolve as resolve8 } from "path";
|
|
3727
|
+
var MINIMAX_DIR_LIST = ["~/Movies/Hub/Projects/"];
|
|
3728
|
+
var CANVAS_JSON_RELATIVE_PATH = join12(".hilo", "canvas.json");
|
|
3729
|
+
var EMPTY_NODE_ID_PREFIX = "empty";
|
|
3730
|
+
var MARKER_PREFIX = "==";
|
|
3731
|
+
var ToolCanvasCommand = class extends BaseCommand {
|
|
3732
|
+
_meta() {
|
|
3733
|
+
return {
|
|
3734
|
+
name: "canvas",
|
|
3735
|
+
description: "\u67E5\u627E Minimax canvas \u7A7A\u8349\u7A3F\u8282\u70B9"
|
|
3736
|
+
};
|
|
3737
|
+
}
|
|
3738
|
+
_configureArguments(cmd) {
|
|
3739
|
+
cmd.argument("[keyword]", "\u53EF\u9009\uFF1A\u8FC7\u6EE4 prompt \u4E2D\u7684 == \u540E\u7F00");
|
|
3740
|
+
}
|
|
3741
|
+
async _execute(ctx) {
|
|
3742
|
+
const keyword = String(ctx.args[0] ?? "").trim();
|
|
3743
|
+
const result = await findLatestCanvasDraft(keyword);
|
|
3744
|
+
if (!result) {
|
|
3745
|
+
const marker = keyword ? `${MARKER_PREFIX}${keyword}` : MARKER_PREFIX;
|
|
3746
|
+
return this._makeError(1, `\u672A\u627E\u5230\u5305\u542B ${marker} \u7684\u7A7A\u8349\u7A3F node`);
|
|
3747
|
+
}
|
|
3748
|
+
this._outputJson({
|
|
3749
|
+
basePath: result.basePath,
|
|
3750
|
+
type: result.type,
|
|
3751
|
+
prompt: result.prompt
|
|
3752
|
+
});
|
|
3753
|
+
return this._makeOk();
|
|
3754
|
+
}
|
|
3755
|
+
_outputJson(data) {
|
|
3756
|
+
this._output(JSON.stringify(data, null, 2));
|
|
3757
|
+
}
|
|
3758
|
+
};
|
|
3759
|
+
async function findLatestCanvasDraft(keyword) {
|
|
3760
|
+
const markerRegExp = createMarkerRegExp(keyword);
|
|
3761
|
+
const matches = [];
|
|
3762
|
+
for (const rawDir of MINIMAX_DIR_LIST) {
|
|
3763
|
+
const rootDir = expandHomeDir(rawDir);
|
|
3764
|
+
const rootStat = await safeStat(rootDir);
|
|
3765
|
+
if (!rootStat?.isDirectory()) {
|
|
3766
|
+
continue;
|
|
3767
|
+
}
|
|
3768
|
+
const projectEntries = await readdir2(rootDir, { withFileTypes: true });
|
|
3769
|
+
for (const projectEntry of projectEntries) {
|
|
3770
|
+
if (!projectEntry.isDirectory()) {
|
|
3771
|
+
continue;
|
|
3772
|
+
}
|
|
3773
|
+
const projectDir = resolve8(rootDir, projectEntry.name);
|
|
3774
|
+
const canvasPath = join12(projectDir, CANVAS_JSON_RELATIVE_PATH);
|
|
3775
|
+
const canvasStat = await safeStat(canvasPath);
|
|
3776
|
+
if (!canvasStat?.isFile()) {
|
|
3777
|
+
continue;
|
|
3778
|
+
}
|
|
3779
|
+
const projectMatches = await collectMatchesFromCanvas({
|
|
3780
|
+
projectDir,
|
|
3781
|
+
canvasPath,
|
|
3782
|
+
canvasStat,
|
|
3783
|
+
markerRegExp
|
|
3784
|
+
});
|
|
3785
|
+
matches.push(...projectMatches);
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
matches.sort(compareCanvasMatches);
|
|
3789
|
+
return matches[0];
|
|
3790
|
+
}
|
|
3791
|
+
async function collectMatchesFromCanvas(options) {
|
|
3792
|
+
const { projectDir, canvasPath, canvasStat, markerRegExp } = options;
|
|
3793
|
+
const canvasJson = await readJsonFile(canvasPath);
|
|
3794
|
+
const canvas = asRecord(canvasJson);
|
|
3795
|
+
const nodes = Array.isArray(canvas?.nodes) ? canvas.nodes : [];
|
|
3796
|
+
const matches = [];
|
|
3797
|
+
nodes.forEach((node, nodeIndex) => {
|
|
3798
|
+
const payload = getDraftPayload(node);
|
|
3799
|
+
if (!payload || !markerRegExp.test(payload.prompt)) {
|
|
3800
|
+
return;
|
|
3801
|
+
}
|
|
3802
|
+
const promptParts = parsePromptJson(payload.promptJson);
|
|
3803
|
+
if (!promptParts) {
|
|
3804
|
+
return;
|
|
3805
|
+
}
|
|
3806
|
+
const prompt = stringifyPromptParts(promptParts);
|
|
3807
|
+
matches.push({
|
|
3808
|
+
basePath: projectDir,
|
|
3809
|
+
type: payload.type,
|
|
3810
|
+
prompt: removeMarkerLine(prompt, markerRegExp),
|
|
3811
|
+
canvasPath,
|
|
3812
|
+
updatedAtMs: canvasStat.mtimeMs,
|
|
3813
|
+
nodeIndex
|
|
3814
|
+
});
|
|
3815
|
+
});
|
|
3816
|
+
return matches;
|
|
3817
|
+
}
|
|
3818
|
+
function createMarkerRegExp(keyword) {
|
|
3819
|
+
const marker = `${MARKER_PREFIX}${keyword}`;
|
|
3820
|
+
return new RegExp(escapeRegExp(marker));
|
|
3821
|
+
}
|
|
3822
|
+
function removeMarkerLine(prompt, markerRegExp) {
|
|
3823
|
+
return prompt.split(/\r?\n/).filter((line) => !markerRegExp.test(line)).join("\n");
|
|
3824
|
+
}
|
|
3825
|
+
function escapeRegExp(value) {
|
|
3826
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3827
|
+
}
|
|
3828
|
+
function getDraftPayload(node) {
|
|
3829
|
+
const nodeRecord = asRecord(node);
|
|
3830
|
+
if (!nodeRecord) {
|
|
3831
|
+
return void 0;
|
|
3832
|
+
}
|
|
3833
|
+
const type = nodeRecord.type;
|
|
3834
|
+
if (type !== "image" && type !== "video") {
|
|
3835
|
+
return void 0;
|
|
3836
|
+
}
|
|
3837
|
+
const id = nodeRecord.id;
|
|
3838
|
+
if (typeof id !== "string" || !id.startsWith(EMPTY_NODE_ID_PREFIX)) {
|
|
3839
|
+
return void 0;
|
|
3840
|
+
}
|
|
3841
|
+
const data = asRecord(nodeRecord.data);
|
|
3842
|
+
const popoverDraft = asRecord(data?.popoverDraft);
|
|
3843
|
+
if (!popoverDraft) {
|
|
3844
|
+
return void 0;
|
|
3845
|
+
}
|
|
3846
|
+
const payload = asRecord(
|
|
3847
|
+
type === "image" ? popoverDraft.i2i : popoverDraft.i2v
|
|
3848
|
+
);
|
|
3849
|
+
if (!payload) {
|
|
3850
|
+
return void 0;
|
|
3851
|
+
}
|
|
3852
|
+
const prompt = payload.prompt;
|
|
3853
|
+
if (typeof prompt !== "string") {
|
|
3854
|
+
return void 0;
|
|
3855
|
+
}
|
|
3856
|
+
return {
|
|
3857
|
+
type,
|
|
3858
|
+
prompt,
|
|
3859
|
+
promptJson: payload.promptJson
|
|
3860
|
+
};
|
|
3861
|
+
}
|
|
3862
|
+
function parsePromptJson(value) {
|
|
3863
|
+
const parsed = parsePromptJsonValue(value);
|
|
3864
|
+
if (Array.isArray(parsed)) {
|
|
3865
|
+
return parsed;
|
|
3866
|
+
}
|
|
3867
|
+
const parsedRecord = asRecord(parsed);
|
|
3868
|
+
const content = parsedRecord?.content;
|
|
3869
|
+
return Array.isArray(content) ? content : void 0;
|
|
3870
|
+
}
|
|
3871
|
+
function parsePromptJsonValue(value) {
|
|
3872
|
+
if (typeof value !== "string") {
|
|
3873
|
+
return value;
|
|
3874
|
+
}
|
|
3875
|
+
try {
|
|
3876
|
+
return JSON.parse(value);
|
|
3877
|
+
} catch {
|
|
3878
|
+
return void 0;
|
|
3879
|
+
}
|
|
3880
|
+
}
|
|
3881
|
+
function stringifyPromptParts(parts) {
|
|
3882
|
+
return parts.map((part) => stringifyPromptPart(part)).join("");
|
|
3883
|
+
}
|
|
3884
|
+
function stringifyPromptPart(part) {
|
|
3885
|
+
const partRecord = asRecord(part);
|
|
3886
|
+
if (!partRecord) {
|
|
3887
|
+
return "";
|
|
3888
|
+
}
|
|
3889
|
+
const type = partRecord.type;
|
|
3890
|
+
if (type === "text") {
|
|
3891
|
+
const text = partRecord.text;
|
|
3892
|
+
return typeof text === "string" ? text : "";
|
|
3893
|
+
}
|
|
3894
|
+
if (type === "hardBreak") {
|
|
3895
|
+
return "\n";
|
|
3896
|
+
}
|
|
3897
|
+
if (type === "canvasFileRef") {
|
|
3898
|
+
const attrs = asRecord(partRecord.attrs);
|
|
3899
|
+
const filename = attrs?.filename;
|
|
3900
|
+
return typeof filename === "string" ? ` ${filename} ` : "";
|
|
3901
|
+
}
|
|
3902
|
+
const content = partRecord.content;
|
|
3903
|
+
if (Array.isArray(content)) {
|
|
3904
|
+
return stringifyPromptParts(content);
|
|
3905
|
+
}
|
|
3906
|
+
return "";
|
|
3907
|
+
}
|
|
3908
|
+
async function readJsonFile(filePath) {
|
|
3909
|
+
try {
|
|
3910
|
+
const content = await readFile4(filePath, "utf8");
|
|
3911
|
+
return JSON.parse(content);
|
|
3912
|
+
} catch {
|
|
3913
|
+
return void 0;
|
|
3914
|
+
}
|
|
3915
|
+
}
|
|
3916
|
+
async function safeStat(path10) {
|
|
3917
|
+
try {
|
|
3918
|
+
return await stat4(path10);
|
|
3919
|
+
} catch {
|
|
3920
|
+
return void 0;
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
function expandHomeDir(path10) {
|
|
3924
|
+
if (path10 === "~") {
|
|
3925
|
+
return homedir8();
|
|
3926
|
+
}
|
|
3927
|
+
if (path10.startsWith("~/")) {
|
|
3928
|
+
return join12(homedir8(), path10.slice(2));
|
|
3929
|
+
}
|
|
3930
|
+
return resolve8(path10);
|
|
3931
|
+
}
|
|
3932
|
+
function asRecord(value) {
|
|
3933
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
3934
|
+
return void 0;
|
|
3935
|
+
}
|
|
3936
|
+
return value;
|
|
3937
|
+
}
|
|
3938
|
+
function compareCanvasMatches(a, b) {
|
|
3939
|
+
const updatedAtDiff = b.updatedAtMs - a.updatedAtMs;
|
|
3940
|
+
if (updatedAtDiff !== 0) {
|
|
3941
|
+
return updatedAtDiff;
|
|
3942
|
+
}
|
|
3943
|
+
const canvasPathDiff = a.canvasPath.localeCompare(b.canvasPath);
|
|
3944
|
+
if (canvasPathDiff !== 0) {
|
|
3945
|
+
return canvasPathDiff;
|
|
3946
|
+
}
|
|
3947
|
+
return a.nodeIndex - b.nodeIndex;
|
|
3948
|
+
}
|
|
3949
|
+
|
|
3950
|
+
// src/commands/tool/tool-command.ts
|
|
3951
|
+
var ToolCommand = class extends BaseSubcommandHost {
|
|
3952
|
+
_meta() {
|
|
3953
|
+
return {
|
|
3954
|
+
name: "tool",
|
|
3955
|
+
description: "\u5E38\u7528\u5DE5\u5177\u547D\u4EE4"
|
|
3956
|
+
};
|
|
3957
|
+
}
|
|
3958
|
+
_registerSubcommands() {
|
|
3959
|
+
this._addSubcommand(new ToolCanvasCommand());
|
|
3960
|
+
}
|
|
3961
|
+
};
|
|
3962
|
+
|
|
3723
3963
|
// src/main.ts
|
|
3724
3964
|
var require2 = createRequire(import.meta.url);
|
|
3725
3965
|
var pkg = require2("../package.json");
|
|
@@ -3735,6 +3975,7 @@ async function bootstrap() {
|
|
|
3735
3975
|
app.registerCommand(new GitCommand(), { hidden: true });
|
|
3736
3976
|
app.registerCommand(new ShortcutCommand(), { hidden: true });
|
|
3737
3977
|
app.registerCommand(new AiCommand(), { hidden: true });
|
|
3978
|
+
app.registerCommand(new ToolCommand(), { hidden: true });
|
|
3738
3979
|
const result = await app.run();
|
|
3739
3980
|
if (!result.ok) {
|
|
3740
3981
|
process.stderr.write(`Fatal: ${result.msg}
|