@hardlydifficult/chat 1.1.83 → 1.1.85
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/commands/createPrefixParser.d.ts +24 -0
- package/dist/commands/createPrefixParser.d.ts.map +1 -0
- package/dist/commands/createPrefixParser.js +60 -0
- package/dist/commands/createPrefixParser.js.map +1 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -1
- package/dist/commands/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating custom argument parsers with less boilerplate.
|
|
3
|
+
*
|
|
4
|
+
* Most commands follow the same pattern:
|
|
5
|
+
* 1. Match `!?<prefix> <rest>` on the normalized input
|
|
6
|
+
* 2. Return a usage error when the prefix is given with no arguments
|
|
7
|
+
* 3. Extract args from the original (case-preserved) input
|
|
8
|
+
* 4. Call a domain-specific parser on the extracted string
|
|
9
|
+
*
|
|
10
|
+
* `createPrefixParser` handles steps 1–3 and delegates step 4 to `parseArgs`.
|
|
11
|
+
*/
|
|
12
|
+
import type { ParseResult } from "./types";
|
|
13
|
+
/**
|
|
14
|
+
* Create a custom `ArgShape.parse` function for a prefixed command.
|
|
15
|
+
*
|
|
16
|
+
* @param prefix - The command prefix (e.g. `'scan'`, `'refresh-readme'`).
|
|
17
|
+
* @param parseArgs - Receives the raw argument string (case-preserved) and returns
|
|
18
|
+
* either a `Record` of parsed args (success) or a `string`
|
|
19
|
+
* error message (validation failure).
|
|
20
|
+
* @param usage - Shown when the prefix is typed with no arguments.
|
|
21
|
+
* Defaults to `Usage: <prefix> <args>`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createPrefixParser(prefix: string, parseArgs: (argsStr: string) => Record<string, unknown> | string, usage?: string): (normalizedInput: string, originalInput: string) => ParseResult | null;
|
|
24
|
+
//# sourceMappingURL=createPrefixParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPrefixParser.d.ts","sourceRoot":"","sources":["../../src/commands/createPrefixParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAO3C;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAChE,KAAK,CAAC,EAAE,MAAM,GACb,CAAC,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,KAAK,WAAW,GAAG,IAAI,CA6CxE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for creating custom argument parsers with less boilerplate.
|
|
4
|
+
*
|
|
5
|
+
* Most commands follow the same pattern:
|
|
6
|
+
* 1. Match `!?<prefix> <rest>` on the normalized input
|
|
7
|
+
* 2. Return a usage error when the prefix is given with no arguments
|
|
8
|
+
* 3. Extract args from the original (case-preserved) input
|
|
9
|
+
* 4. Call a domain-specific parser on the extracted string
|
|
10
|
+
*
|
|
11
|
+
* `createPrefixParser` handles steps 1–3 and delegates step 4 to `parseArgs`.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createPrefixParser = createPrefixParser;
|
|
15
|
+
/** Escape special regex characters in a string */
|
|
16
|
+
function escapeRegExp(s) {
|
|
17
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a custom `ArgShape.parse` function for a prefixed command.
|
|
21
|
+
*
|
|
22
|
+
* @param prefix - The command prefix (e.g. `'scan'`, `'refresh-readme'`).
|
|
23
|
+
* @param parseArgs - Receives the raw argument string (case-preserved) and returns
|
|
24
|
+
* either a `Record` of parsed args (success) or a `string`
|
|
25
|
+
* error message (validation failure).
|
|
26
|
+
* @param usage - Shown when the prefix is typed with no arguments.
|
|
27
|
+
* Defaults to `Usage: <prefix> <args>`.
|
|
28
|
+
*/
|
|
29
|
+
function createPrefixParser(prefix, parseArgs, usage) {
|
|
30
|
+
const lowerPrefix = prefix.toLowerCase();
|
|
31
|
+
const escaped = escapeRegExp(lowerPrefix);
|
|
32
|
+
// Pre-compile patterns
|
|
33
|
+
const matchPattern = new RegExp(`^!?${escaped}\\s+(.+)$`, "s");
|
|
34
|
+
const originalPattern = new RegExp(`^!?${escapeRegExp(prefix)}\\s+(.+)$`, "is");
|
|
35
|
+
return (normalizedInput, originalInput) => {
|
|
36
|
+
// Exact prefix with no args → show usage
|
|
37
|
+
if (normalizedInput === lowerPrefix ||
|
|
38
|
+
normalizedInput === `!${lowerPrefix}`) {
|
|
39
|
+
return {
|
|
40
|
+
valid: false,
|
|
41
|
+
error: usage ?? `Usage: ${prefix} <args>`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Try to match prefix + whitespace + rest
|
|
45
|
+
const normalizedMatch = matchPattern.exec(normalizedInput);
|
|
46
|
+
if (!normalizedMatch) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// Extract args from original input to preserve case
|
|
50
|
+
const originalMatch = originalPattern.exec(originalInput);
|
|
51
|
+
const argsStr = (originalMatch?.[1] ?? normalizedMatch[1]).trim();
|
|
52
|
+
// Delegate to domain-specific parser
|
|
53
|
+
const result = parseArgs(argsStr);
|
|
54
|
+
if (typeof result === "string") {
|
|
55
|
+
return { valid: false, error: result };
|
|
56
|
+
}
|
|
57
|
+
return { valid: true, args: result };
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=createPrefixParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPrefixParser.js","sourceRoot":"","sources":["../../src/commands/createP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OAAO,CAAC,CAAC;QAElC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QACzC,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACvC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/commands/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { CommandRegistry, type RegisteredCommand } from "./CommandRegistry";
|
|
|
3
3
|
export { CommandDispatcher, type DispatcherOptions } from "./CommandDispatcher";
|
|
4
4
|
export { setupJobLifecycle, type JobLifecycleOptions, type JobLifecycleHandle, EMOJI_CANCEL, EMOJI_DISMISS, } from "./jobLifecycle";
|
|
5
5
|
export { formatWorkerError, RECOVERABLE_WORKER_ERRORS } from "./workerErrors";
|
|
6
|
+
export { createPrefixParser } from "./createPrefixParser";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,OAAO,EACP,cAAc,EACd,QAAQ,EACR,WAAW,EACX,KAAK,EACL,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,EACL,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,OAAO,EACP,cAAc,EACd,QAAQ,EACR,WAAW,EACX,KAAK,EACL,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,EACL,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/commands/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RECOVERABLE_WORKER_ERRORS = exports.formatWorkerError = exports.EMOJI_DISMISS = exports.EMOJI_CANCEL = exports.setupJobLifecycle = exports.CommandDispatcher = exports.CommandRegistry = void 0;
|
|
3
|
+
exports.createPrefixParser = exports.RECOVERABLE_WORKER_ERRORS = exports.formatWorkerError = exports.EMOJI_DISMISS = exports.EMOJI_CANCEL = exports.setupJobLifecycle = exports.CommandDispatcher = exports.CommandRegistry = void 0;
|
|
4
4
|
// Registry & Dispatcher
|
|
5
5
|
var CommandRegistry_1 = require("./CommandRegistry");
|
|
6
6
|
Object.defineProperty(exports, "CommandRegistry", { enumerable: true, get: function () { return CommandRegistry_1.CommandRegistry; } });
|
|
@@ -15,4 +15,6 @@ Object.defineProperty(exports, "EMOJI_DISMISS", { enumerable: true, get: functio
|
|
|
15
15
|
var workerErrors_1 = require("./workerErrors");
|
|
16
16
|
Object.defineProperty(exports, "formatWorkerError", { enumerable: true, get: function () { return workerErrors_1.formatWorkerError; } });
|
|
17
17
|
Object.defineProperty(exports, "RECOVERABLE_WORKER_ERRORS", { enumerable: true, get: function () { return workerErrors_1.RECOVERABLE_WORKER_ERRORS; } });
|
|
18
|
+
var createPrefixParser_1 = require("./createPrefixParser");
|
|
19
|
+
Object.defineProperty(exports, "createPrefixParser", { enumerable: true, get: function () { return createPrefixParser_1.createPrefixParser; } });
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;AAUA,wBAAwB;AACxB,qDAA4E;AAAnE,kHAAA,eAAe,OAAA;AACxB,yDAAgF;AAAvE,sHAAA,iBAAiB,OAAA;AAE1B,gBAAgB;AAChB,+CAMwB;AALtB,iHAAA,iBAAiB,OAAA;AAGjB,4GAAA,YAAY,OAAA;AACZ,6GAAA,aAAa,OAAA;AAGf,UAAU;AACV,+CAA8E;AAArE,iHAAA,iBAAiB,OAAA;AAAE,yHAAA,yBAAyB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;AAUA,wBAAwB;AACxB,qDAA4E;AAAnE,kHAAA,eAAe,OAAA;AACxB,yDAAgF;AAAvE,sHAAA,iBAAiB,OAAA;AAE1B,gBAAgB;AAChB,+CAMwB;AALtB,iHAAA,iBAAiB,OAAA;AAGjB,4GAAA,YAAY,OAAA;AACZ,6GAAA,aAAa,OAAA;AAGf,UAAU;AACV,+CAA8E;AAArE,iHAAA,iBAAiB,OAAA;AAAE,yHAAA,yBAAyB,OAAA;AACrD,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA"}
|