pi-crew 0.6.3 → 0.6.4
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/CHANGELOG.md +34 -0
- package/README.md +12 -1
- package/docs/ui-optimization-plan.md +447 -0
- package/package.json +1 -1
- package/src/extension/register.ts +19 -1
- package/src/extension/registration/brief-tool-overrides.ts +400 -0
- package/src/extension/registration/commands.ts +25 -0
- package/src/extension/registration/subagent-tools.ts +8 -3
- package/src/extension/registration/team-tool.ts +18 -11
- package/src/extension/team-tool/run.ts +4 -3
- package/src/extension/team-tool-types.ts +2 -0
- package/src/state/session-state-map.ts +51 -0
- package/src/ui/powerbar-publisher.ts +1 -1
- package/src/ui/status-colors.ts +5 -1
- package/src/ui/theme-adapter.ts +80 -1
- package/src/ui/tool-progress-formatter.ts +9 -5
- package/src/ui/tool-render.ts +4 -0
- package/src/ui/tool-renderers/brief-mode.ts +207 -0
- package/src/ui/tool-renderers/index.ts +627 -0
- package/src/ui/widget/index.ts +224 -0
- package/src/ui/widget/widget-formatters.ts +148 -0
- package/src/ui/widget/widget-model.ts +90 -0
- package/src/ui/widget/widget-renderer.ts +130 -0
- package/src/ui/widget/widget-types.ts +37 -0
- package/src/utils/guards.ts +110 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized type guard library for pi-crew.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by @ayulab/runtime-core — all unknown-to-narrowed checks
|
|
5
|
+
* go through these helpers instead of inline typeof/instanceof.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ── Primitive guards ──────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/** Narrow `unknown` to `Record<string, unknown>`. */
|
|
11
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Narrow `unknown` to `string`. */
|
|
16
|
+
export function isString(value: unknown): value is string {
|
|
17
|
+
return typeof value === "string";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Narrow `unknown` to a non-empty string. */
|
|
21
|
+
export function isNonEmptyString(value: unknown): value is string {
|
|
22
|
+
return typeof value === "string" && value.length > 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Narrow `unknown` to `number` (excludes NaN). */
|
|
26
|
+
export function isNumber(value: unknown): value is number {
|
|
27
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Narrow `unknown` to `boolean`. */
|
|
31
|
+
export function isBoolean(value: unknown): value is boolean {
|
|
32
|
+
return typeof value === "boolean";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Narrow `unknown` to `readonly string[]`. */
|
|
36
|
+
export function isStringArray(value: unknown): value is readonly string[] {
|
|
37
|
+
return Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Higher-order guard: build a guard that checks every element of an array.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const isNumberArray = isArrayOf(isNumber);
|
|
45
|
+
*/
|
|
46
|
+
export function isArrayOf<T>(
|
|
47
|
+
guard: (item: unknown) => item is T,
|
|
48
|
+
): (value: unknown) => value is readonly T[] {
|
|
49
|
+
return (value: unknown): value is readonly T[] =>
|
|
50
|
+
Array.isArray(value) && value.every(guard);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ── Record field extractors ───────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
/** Extract a string field from a record, returning `undefined` if absent. */
|
|
56
|
+
export function getStringField(value: unknown, key: string): string | undefined {
|
|
57
|
+
if (!isRecord(value)) return undefined;
|
|
58
|
+
const field = value[key];
|
|
59
|
+
return typeof field === "string" ? field : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Extract a number field from a record, returning `undefined` if absent. */
|
|
63
|
+
export function getNumberField(value: unknown, key: string): number | undefined {
|
|
64
|
+
if (!isRecord(value)) return undefined;
|
|
65
|
+
const field = value[key];
|
|
66
|
+
return typeof field === "number" && !Number.isNaN(field) ? field : undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Extract a boolean field from a record, returning `undefined` if absent. */
|
|
70
|
+
export function getBooleanField(value: unknown, key: string): boolean | undefined {
|
|
71
|
+
if (!isRecord(value)) return undefined;
|
|
72
|
+
const field = value[key];
|
|
73
|
+
return typeof field === "boolean" ? field : undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Extract a nested record field from a record, returning `undefined` if absent. */
|
|
77
|
+
export function getRecordField(value: unknown, key: string): Record<string, unknown> | undefined {
|
|
78
|
+
if (!isRecord(value)) return undefined;
|
|
79
|
+
const field = value[key];
|
|
80
|
+
return isRecord(field) ? field : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Extract an array field from a record, returning `undefined` if absent. */
|
|
84
|
+
export function getArrayField(value: unknown, key: string): unknown[] | undefined {
|
|
85
|
+
if (!isRecord(value)) return undefined;
|
|
86
|
+
const field = value[key];
|
|
87
|
+
return Array.isArray(field) ? field : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ── Error helpers ─────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Extract a human-readable message from an unknown error value.
|
|
94
|
+
*
|
|
95
|
+
* Prefer this over manual `instanceof Error` checks to keep error
|
|
96
|
+
* handling uniform across the codebase.
|
|
97
|
+
*/
|
|
98
|
+
export function errorMessage(err: unknown): string {
|
|
99
|
+
return err instanceof Error ? err.message : String(err);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── Utility types ─────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
/** A non-empty readonly array type. */
|
|
105
|
+
export type NonEmptyReadonlyArray<T> = readonly [T, ...T[]];
|
|
106
|
+
|
|
107
|
+
/** Narrow a readonly array to a non-empty readonly array. */
|
|
108
|
+
export function hasItems<T>(items: readonly T[]): items is NonEmptyReadonlyArray<T> {
|
|
109
|
+
return items.length > 0;
|
|
110
|
+
}
|