@crewx/sdk 0.9.0-rc.13 → 0.9.0-rc.131
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/README.md +1 -1
- package/dist/account/auth-client.d.ts +61 -0
- package/dist/account/auth-json-v2.d.ts +1 -0
- package/dist/account/auth-json.d.ts +30 -0
- package/dist/account/config.d.ts +37 -0
- package/dist/account/env-bootstrap.d.ts +11 -0
- package/dist/account/errors.d.ts +24 -0
- package/dist/account/index.d.ts +12 -0
- package/dist/account/index.js +2 -0
- package/dist/account/session-manager.d.ts +47 -0
- package/dist/activity-log/builder.d.ts +56 -6
- package/dist/agent/agent-list-view.d.ts +19 -0
- package/dist/boxing/box.types.d.ts +4 -0
- package/dist/config/canonicalize-agent-options.d.ts +18 -0
- package/dist/config/default-agent-models.d.ts +11 -0
- package/dist/config/global-settings.d.ts +33 -0
- package/dist/config/migrate-grok-mode.d.ts +6 -0
- package/dist/config/model-compat.d.ts +31 -0
- package/dist/config/models.generated.d.ts +37 -0
- package/dist/config/models.remote.d.ts +1 -0
- package/dist/config/overdrive.d.ts +7 -0
- package/dist/config/pricing.d.ts +6 -3
- package/dist/config/pricing.generated.d.ts +4 -0
- package/dist/config/pricing.types.d.ts +4 -0
- package/dist/config/timeout.config.d.ts +4 -0
- package/dist/config/wi-boards.d.ts +19 -0
- package/dist/context-budget/continuity.d.ts +61 -0
- package/dist/context-budget/index.d.ts +141 -0
- package/dist/conversation/index.d.ts +1 -1
- package/dist/conversation/sqlite-provider.d.ts +6 -2
- package/dist/conversation/to-template-messages.d.ts +9 -0
- package/dist/conversation/types.d.ts +47 -1
- package/dist/desktop/command-runner.d.ts +4 -0
- package/dist/desktop/default-adapters.d.ts +4 -0
- package/dist/desktop/global-install.d.ts +19 -0
- package/dist/desktop/index.d.ts +3 -0
- package/dist/desktop/index.js +3 -0
- package/dist/desktop/install.d.ts +5 -0
- package/dist/desktop/lnk.d.ts +22 -0
- package/dist/desktop/manifest.d.ts +21 -0
- package/dist/desktop/types.d.ts +67 -0
- package/dist/desktop/version.d.ts +1 -0
- package/dist/desktop/windows-paths.d.ts +21 -0
- package/dist/desktop/wrapper.d.ts +18 -0
- package/dist/esm/account/index.js +2 -0
- package/dist/esm/desktop/index.js +3 -0
- package/dist/esm/index.js +934 -224
- package/dist/esm/node/index.js +2 -0
- package/dist/esm/plugins/index.js +341 -214
- package/dist/esm/process/index.js +1 -0
- package/dist/esm/publish/index.js +2 -0
- package/dist/esm/repository/index.js +416 -211
- package/dist/esm/skills/index.js +2 -0
- package/dist/esm/testing/index.js +1 -1
- package/dist/events/types.d.ts +9 -0
- package/dist/facade/Crewx.d.ts +58 -5
- package/dist/facade/task-ticket.d.ts +14 -0
- package/dist/highlight/thread-highlight-prompt.d.ts +2 -0
- package/dist/highlight/thread-highlighter.d.ts +326 -0
- package/dist/index.browser.d.ts +17 -1
- package/dist/index.browser.js +6 -2
- package/dist/index.d.ts +122 -17
- package/dist/index.js +934 -224
- package/dist/internal/console-decoder.d.ts +38 -0
- package/dist/internal/windows-spawn.d.ts +10 -0
- package/dist/layout/types.d.ts +18 -1
- package/dist/lifecycle/process-lease.d.ts +80 -0
- package/dist/lifecycle/process-owner.d.ts +20 -0
- package/dist/lifecycle/task-heartbeat.d.ts +41 -0
- package/dist/lifecycle/task-stop.d.ts +82 -0
- package/dist/lifecycle/update-admission.d.ts +45 -0
- package/dist/local-server/base-url.d.ts +18 -0
- package/dist/local-server/index.d.ts +8 -0
- package/dist/local-server/opencode.d.ts +8 -0
- package/dist/local-server/probe.d.ts +3 -0
- package/dist/local-server/runtime.d.ts +26 -0
- package/dist/local-server/types.d.ts +43 -0
- package/dist/mcp-app/agent-access.d.ts +26 -0
- package/dist/mcp-app/apps-context.d.ts +6 -0
- package/dist/mcp-app/bundle-provenance.d.ts +3 -0
- package/dist/mcp-app/catalog.d.ts +7 -0
- package/dist/mcp-app/content-channel.d.ts +89 -0
- package/dist/mcp-app/content-declarations.d.ts +29 -0
- package/dist/mcp-app/dev-checks.d.ts +29 -0
- package/dist/mcp-app/discovery.d.ts +153 -0
- package/dist/mcp-app/errors.d.ts +7 -0
- package/dist/mcp-app/index.d.ts +33 -0
- package/dist/mcp-app/installed-app-ref.d.ts +25 -0
- package/dist/mcp-app/model-context.d.ts +29 -0
- package/dist/mcp-app/node-app-discovery-fs.d.ts +23 -0
- package/dist/mcp-app/product-bundle-assets.d.ts +27 -0
- package/dist/mcp-app/product-bundle-loader.d.ts +53 -0
- package/dist/mcp-app/projection.d.ts +14 -0
- package/dist/mcp-app/registry.d.ts +28 -0
- package/dist/mcp-app/skill-backend.d.ts +133 -0
- package/dist/mcp-app/state-set.d.ts +9 -0
- package/dist/mcp-app/types.d.ts +458 -0
- package/dist/mcp-app/workspace-app-assets.d.ts +42 -0
- package/dist/mcp-app/workspace-app-scan-cache.d.ts +24 -0
- package/dist/mcp-app/workspace-snapshot.d.ts +70 -0
- package/dist/migrations/0010_analyze_stats.sql +6 -0
- package/dist/migrations/0011_far_black_tarantula.sql +1 -0
- package/dist/migrations/0012_blue_turbo.sql +23 -0
- package/dist/migrations/0013_hesitant_adam_destine.sql +15 -0
- package/dist/migrations/0014_organic_mongu.sql +73 -0
- package/dist/migrations/0015_panoramic_gorilla_man.sql +71 -0
- package/dist/migrations/0016_fuzzy_hemingway.sql +14 -0
- package/dist/migrations/0017_project_stage_sdk_migration.sql +29 -0
- package/dist/migrations/0018_bored_jackal.sql +33 -0
- package/dist/migrations/0019_backfill_task_thread_ids.sql +74 -0
- package/dist/migrations/0020_useful_iron_lad.sql +55 -0
- package/dist/migrations/0021_dashing_peter_quill.sql +51 -0
- package/dist/migrations/0022_wandering_bucky.sql +1 -0
- package/dist/migrations/0023_red_payback.sql +1 -0
- package/dist/migrations/0024_storage_metadata.sql +262 -0
- package/dist/migrations/0025_task_heartbeat.sql +8 -0
- package/dist/migrations/0025_thread_app_instance_ledger.sql +2 -0
- package/dist/migrations/0026_mcp_action_source.sql +47 -0
- package/dist/migrations/0027_task_stop_scope_cleanup.sql +5 -0
- package/dist/migrations/0027_ui_instance_active_unique.sql +2 -0
- package/dist/migrations/0029_nice_rhino.sql +1 -0
- package/dist/migrations/0031_petite_arclight.sql +6 -0
- package/dist/migrations/0032_ui_instance_opened_by.sql +1 -0
- package/dist/migrations/0033_thread_creator_boundary_guard.sql +38 -0
- package/dist/migrations/0034_keen_fallen_one.sql +36 -0
- package/dist/migrations/meta/0010_snapshot.json +1335 -0
- package/dist/migrations/meta/0011_snapshot.json +1342 -0
- package/dist/migrations/meta/0012_snapshot.json +1494 -0
- package/dist/migrations/meta/0013_snapshot.json +1592 -0
- package/dist/migrations/meta/0014_snapshot.json +1975 -0
- package/dist/migrations/meta/0015_snapshot.json +2315 -0
- package/dist/migrations/meta/0016_snapshot.json +2419 -0
- package/dist/migrations/meta/0017_snapshot.json +2419 -0
- package/dist/migrations/meta/0018_snapshot.json +2570 -0
- package/dist/migrations/meta/0020_snapshot.json +2895 -0
- package/dist/migrations/meta/0021_snapshot.json +3031 -0
- package/dist/migrations/meta/0022_snapshot.json +3039 -0
- package/dist/migrations/meta/0023_snapshot.json +3047 -0
- package/dist/migrations/meta/0029_snapshot.json +3206 -0
- package/dist/migrations/meta/0031_snapshot.json +3251 -0
- package/dist/migrations/meta/0034_snapshot.json +3473 -0
- package/dist/migrations/meta/_journal.json +175 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +2 -0
- package/dist/paths.d.ts +1 -0
- package/dist/plugin/types.d.ts +1 -0
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +341 -214
- package/dist/plugins/sqlite-tracing.d.ts +46 -0
- package/dist/process/index.d.ts +2 -0
- package/dist/process/index.js +1 -0
- package/dist/process/process-control.d.ts +41 -0
- package/dist/prompt/tag-names.d.ts +20 -0
- package/dist/provider/acp/connection.d.ts +6 -0
- package/dist/provider/acp/meta.d.ts +11 -0
- package/dist/provider/bridge.d.ts +7 -1
- package/dist/provider/classify-task-error.d.ts +2 -0
- package/dist/provider/cli/adapter.types.d.ts +14 -2
- package/dist/provider/cli/adapters/agent-call.util.d.ts +1 -1
- package/dist/provider/cli/adapters/cli-knob.util.d.ts +7 -0
- package/dist/provider/cli/adapters/codex-item.d.ts +1 -0
- package/dist/provider/cli/adapters/event-timestamp.util.d.ts +1 -0
- package/dist/provider/cli/adapters/grok.d.ts +2 -0
- package/dist/provider/cli/adapters/index.d.ts +5 -0
- package/dist/provider/cli/index.d.ts +3 -2
- package/dist/provider/cli/meta.d.ts +5 -0
- package/dist/provider/cli/protocol-envelope.d.ts +3 -0
- package/dist/provider/errors.d.ts +5 -1
- package/dist/provider/idle-watchdog.d.ts +19 -0
- package/dist/provider/models.d.ts +17 -12
- package/dist/provider/order.d.ts +1 -1
- package/dist/provider/parse-usage.d.ts +6 -0
- package/dist/provider/provider-selection.d.ts +8 -0
- package/dist/provider/redact-technical-message.d.ts +1 -0
- package/dist/provider/task-error.types.d.ts +17 -0
- package/dist/publish/constants.d.ts +6 -0
- package/dist/publish/errors.d.ts +7 -0
- package/dist/publish/index.d.ts +50 -0
- package/dist/publish/index.js +2 -0
- package/dist/publish/manifest.d.ts +47 -0
- package/dist/publish/marketplace-api.constants.d.ts +1 -0
- package/dist/publish/pack.d.ts +6 -0
- package/dist/publish/scan.d.ts +9 -0
- package/dist/publish/secrets.d.ts +6 -0
- package/dist/publish/upload.d.ts +19 -0
- package/dist/remote/execution-profile.d.ts +9 -0
- package/dist/remote/index.d.ts +1 -0
- package/dist/remote/types.d.ts +28 -0
- package/dist/repository/agent-suggestion.repository.d.ts +34 -0
- package/dist/repository/base-sqlite-repository.d.ts +1 -0
- package/dist/repository/common-code.repository.d.ts +45 -0
- package/dist/repository/db.d.ts +12 -1
- package/dist/repository/index.d.ts +37 -5
- package/dist/repository/index.js +416 -211
- package/dist/repository/notification.repository.d.ts +58 -0
- package/dist/repository/project.repository.d.ts +90 -0
- package/dist/repository/request-log.repository.d.ts +1 -0
- package/dist/repository/storage-metadata.repository.d.ts +64 -0
- package/dist/repository/task-log-migration.d.ts +74 -0
- package/dist/repository/task-log.repository.d.ts +44 -0
- package/dist/repository/task-status.d.ts +14 -0
- package/dist/repository/task.repository.d.ts +224 -7
- package/dist/repository/thread-history.repository.d.ts +193 -0
- package/dist/repository/thread-origin-verdict.d.ts +27 -0
- package/dist/repository/thread-title.types.d.ts +29 -0
- package/dist/repository/thread.repository.d.ts +72 -6
- package/dist/repository/usage-backfill.d.ts +62 -0
- package/dist/repository/usage-from-logs.d.ts +21 -0
- package/dist/repository/workspace.repository.d.ts +3 -0
- package/dist/schema/agent-suggestions.d.ts +199 -0
- package/dist/schema/common-codes.d.ts +216 -0
- package/dist/schema/index.d.ts +11 -0
- package/dist/schema/notifications.d.ts +303 -0
- package/dist/schema/projects.d.ts +610 -0
- package/dist/schema/storage-metadata.d.ts +181 -0
- package/dist/schema/task-log-events.d.ts +119 -0
- package/dist/schema/tasks.d.ts +165 -0
- package/dist/schema/thread-creator-unverified.d.ts +45 -0
- package/dist/schema/thread-history.d.ts +734 -0
- package/dist/schema/threads.d.ts +59 -0
- package/dist/schema/ui-action-receipts.d.ts +358 -0
- package/dist/schema/ui-instance-repins.d.ts +222 -0
- package/dist/schema/ui-instances.d.ts +305 -0
- package/dist/schema/workspaces.d.ts +17 -0
- package/dist/skills/index.d.ts +15 -0
- package/dist/skills/index.js +2 -0
- package/dist/skills/types.d.ts +18 -0
- package/dist/task-log/anchor-child-tasks.d.ts +7 -0
- package/dist/task-log/delegation-trailer.d.ts +34 -0
- package/dist/template/engine.d.ts +2 -2
- package/dist/template/helpers/exec.browser.d.ts +4 -3
- package/dist/template/helpers/exec.d.ts +4 -3
- package/dist/template/types.d.ts +20 -0
- package/dist/testing/index.js +1 -1
- package/dist/types/index.d.ts +1572 -3
- package/dist/types/task-log.types.d.ts +2 -0
- package/dist/ui-card/index.d.ts +2 -0
- package/dist/ui-card/legacy-card-parser.d.ts +11 -0
- package/dist/ui-instance/definition.d.ts +6 -0
- package/dist/ui-instance/errors.d.ts +18 -0
- package/dist/ui-instance/index.d.ts +11 -0
- package/dist/ui-instance/json.d.ts +19 -0
- package/dist/ui-instance/lineage.d.ts +22 -0
- package/dist/ui-instance/runtime.d.ts +18 -0
- package/dist/ui-instance/store.d.ts +184 -0
- package/dist/ui-instance/types.d.ts +319 -0
- package/dist/ui-plugin/csp.d.ts +25 -0
- package/dist/ui-plugin/index.d.ts +4 -0
- package/dist/ui-plugin/limits.d.ts +27 -0
- package/dist/ui-plugin/manifest.d.ts +3 -0
- package/dist/ui-plugin/types.d.ts +190 -0
- package/dist/ui-plugin/validator.d.ts +15 -0
- package/dist/utils/crewx-executable.d.ts +76 -0
- package/dist/utils/crewx-home.d.ts +1 -0
- package/dist/utils/env-defaults.d.ts +2 -0
- package/dist/utils/id.d.ts +1 -1
- package/dist/utils/local-identity.d.ts +2 -0
- package/dist/utils/runner-env.d.ts +3 -0
- package/dist/utils/timestamp.d.ts +1 -0
- package/dist/utils/workspace.d.ts +1 -0
- package/dist/wi/create.d.ts +48 -0
- package/dist/wi/select.d.ts +20 -0
- package/package.json +49 -2
- package/templates/agents/default.yaml +284 -128
- package/templates/documents/crewx-manual.md +138 -138
- package/templates/documents/crewx-quick-guide.md +8 -7
- package/templates/workflows/wi-default-flow.yaml +65 -0
- package/templates/workflows/wi-plan-flow.yaml +140 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CrewxProjectConfig } from '../types';
|
|
2
|
+
export declare const DEFAULT_WI_BOARD_ID = "default";
|
|
3
|
+
export declare const ARCHIVE_WI_BOARD_ID = "archive";
|
|
4
|
+
export declare const DEFAULT_WI_WORKFLOW_ID = "wi-default-flow";
|
|
5
|
+
export declare const WI_PLAN_WORKFLOW_ID = "wi-plan-flow";
|
|
6
|
+
export declare const WI_DEFAULT_FLOW_FILENAME = "wi-default-flow.yaml";
|
|
7
|
+
export declare const WI_PLAN_FLOW_FILENAME = "wi-plan-flow.yaml";
|
|
8
|
+
export declare const WI_BOARD_ID_PATTERN: RegExp;
|
|
9
|
+
export declare function isReservedWiBoardId(id: string): boolean;
|
|
10
|
+
export interface ResolvedWiBoard {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
workflowId: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
goalId?: string;
|
|
16
|
+
system: boolean;
|
|
17
|
+
readOnly: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function resolveWiBoards(config: CrewxProjectConfig | undefined): ResolvedWiBoard[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ConversationHighlight, ConversationThreadState, SemanticContinuityContext, TemplateMessage } from '../conversation/types.js';
|
|
2
|
+
export declare const DEFAULT_PROTECTED_TURN_COUNT = 5;
|
|
3
|
+
export declare const DEFAULT_HIGHLIGHT_BUDGET_PERCENT = 5;
|
|
4
|
+
export declare const MAX_ACTIVE_HIGHLIGHTS = 12;
|
|
5
|
+
export declare const MAX_ACTIVE_HIGHLIGHT_CHARS = 2000;
|
|
6
|
+
export declare const MAX_THREAD_TITLE_CHARS = 200;
|
|
7
|
+
export declare const MAX_THREAD_STATE_VALUE_CHARS = 64;
|
|
8
|
+
export interface ConversationTurn {
|
|
9
|
+
taskId?: string;
|
|
10
|
+
messages: TemplateMessage[];
|
|
11
|
+
ordinal: number;
|
|
12
|
+
}
|
|
13
|
+
export interface GroupedConversationTurns {
|
|
14
|
+
turns: ConversationTurn[];
|
|
15
|
+
unpairedMessages: TemplateMessage[];
|
|
16
|
+
}
|
|
17
|
+
export interface ConversationTurnSelection {
|
|
18
|
+
includedTurns: ConversationTurn[];
|
|
19
|
+
omittedTurns: ConversationTurn[];
|
|
20
|
+
protectedTurns: ConversationTurn[];
|
|
21
|
+
tokenCount: number;
|
|
22
|
+
protectedTokenCount: number;
|
|
23
|
+
overBudget: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface SelectConversationTurnsOptions {
|
|
26
|
+
turns: readonly ConversationTurn[];
|
|
27
|
+
maxTokenCount: number;
|
|
28
|
+
countTokens: (text: string) => number;
|
|
29
|
+
protectedTurnCount?: number;
|
|
30
|
+
materializeTurn?: (turn: ConversationTurn) => string;
|
|
31
|
+
}
|
|
32
|
+
export interface ConversationHighlightSelection {
|
|
33
|
+
includedHighlights: ConversationHighlight[];
|
|
34
|
+
omittedHighlights: ConversationHighlight[];
|
|
35
|
+
truncatedHighlights: number;
|
|
36
|
+
representedTaskIds: string[];
|
|
37
|
+
unrepresentedTaskIds: string[];
|
|
38
|
+
tokenCount: number;
|
|
39
|
+
budgetTokens: number;
|
|
40
|
+
}
|
|
41
|
+
export interface SelectConversationHighlightsOptions {
|
|
42
|
+
highlights: readonly ConversationHighlight[];
|
|
43
|
+
omittedTaskIds: readonly string[];
|
|
44
|
+
taskOrder: readonly string[];
|
|
45
|
+
maxTokenCount: number;
|
|
46
|
+
countTokens: (text: string) => number;
|
|
47
|
+
applySafetyCap?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export declare function getConversationMessageTaskId(message: TemplateMessage): string | undefined;
|
|
50
|
+
export declare function groupConversationTurns(messages: readonly TemplateMessage[]): GroupedConversationTurns;
|
|
51
|
+
export declare function materializeConversationTurn(turn: ConversationTurn, includeActivityLog?: boolean): string;
|
|
52
|
+
export declare function selectConversationTurns(options: SelectConversationTurnsOptions): ConversationTurnSelection;
|
|
53
|
+
export declare function buildThreadStateContext(state: ConversationThreadState | undefined): ConversationThreadState | undefined;
|
|
54
|
+
export declare function selectConversationHighlights(options: SelectConversationHighlightsOptions): ConversationHighlightSelection;
|
|
55
|
+
export interface BuildSemanticContinuityContextOptions {
|
|
56
|
+
highlights: readonly ConversationHighlight[];
|
|
57
|
+
omittedTaskIds: readonly string[];
|
|
58
|
+
representedTaskIds: readonly string[];
|
|
59
|
+
applySafetyCap?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export declare function buildSemanticContinuityContext(options: BuildSemanticContinuityContextOptions): SemanticContinuityContext;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export declare const DEFAULT_INPUT_BUDGET_PERCENT = 60;
|
|
2
|
+
export declare const MIN_INPUT_BUDGET_PERCENT = 30;
|
|
3
|
+
export declare const MAX_INPUT_BUDGET_PERCENT = 80;
|
|
4
|
+
export declare const INPUT_BUDGET_TOKENIZER_ENCODING = "o200k_base";
|
|
5
|
+
export declare const FRESH_PROVIDER_INITIAL_INPUT_SEPARATOR = "\n\n---\n\n";
|
|
6
|
+
export declare const FRESH_PROVIDER_INITIAL_INPUT_FRAMING = "system_prompt\\n\\n---\\n\\nmessage";
|
|
7
|
+
export declare const RESUME_PROVIDER_INITIAL_INPUT_FRAMING = "message";
|
|
8
|
+
export type InputBudgetUnresolvedReason = 'invalid_input_budget_percent' | 'provider_catalog_unavailable' | 'model_not_found' | 'context_window_tokens_unavailable';
|
|
9
|
+
export type TokenizerFallbackReason = 'vendor_tokenizer_unavailable';
|
|
10
|
+
export interface ResolveInputBudgetOptions {
|
|
11
|
+
provider: string;
|
|
12
|
+
model: string;
|
|
13
|
+
inputBudgetPercent?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TokenizerOptions {
|
|
16
|
+
provider?: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TokenizerMetadata {
|
|
20
|
+
provider: string;
|
|
21
|
+
model: string;
|
|
22
|
+
encoding: typeof INPUT_BUDGET_TOKENIZER_ENCODING;
|
|
23
|
+
exact: boolean;
|
|
24
|
+
fallbackReason?: TokenizerFallbackReason;
|
|
25
|
+
}
|
|
26
|
+
export interface ResolvedInputBudget {
|
|
27
|
+
resolved: true;
|
|
28
|
+
requestedProvider: string;
|
|
29
|
+
provider: string;
|
|
30
|
+
model: string;
|
|
31
|
+
contextWindowTokens: number;
|
|
32
|
+
inputBudgetPercent: number;
|
|
33
|
+
inputBudgetTokens: number;
|
|
34
|
+
tokenizer: TokenizerMetadata;
|
|
35
|
+
}
|
|
36
|
+
export interface UnresolvedInputBudget {
|
|
37
|
+
resolved: false;
|
|
38
|
+
requestedProvider: string;
|
|
39
|
+
provider: string;
|
|
40
|
+
model: string;
|
|
41
|
+
reason: InputBudgetUnresolvedReason;
|
|
42
|
+
inputBudgetPercent?: number;
|
|
43
|
+
tokenizer: TokenizerMetadata;
|
|
44
|
+
}
|
|
45
|
+
export type ResolveInputBudgetResult = ResolvedInputBudget | UnresolvedInputBudget;
|
|
46
|
+
export type ContextBudgetPhase = 'fresh' | 'resume';
|
|
47
|
+
export type ProviderInitialInputFraming = typeof FRESH_PROVIDER_INITIAL_INPUT_FRAMING | typeof RESUME_PROVIDER_INITIAL_INPUT_FRAMING;
|
|
48
|
+
export interface ContextBudgetLayoutCapability {
|
|
49
|
+
layoutId: string;
|
|
50
|
+
supportsSemanticContinuity: boolean;
|
|
51
|
+
slot: string | null;
|
|
52
|
+
requiredForOmittedTurns: boolean;
|
|
53
|
+
warning?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ContextBudgetActivityDegradation {
|
|
56
|
+
taskId: string;
|
|
57
|
+
taskDistance: number;
|
|
58
|
+
action: 'reduced' | 'omitted';
|
|
59
|
+
}
|
|
60
|
+
export type ContextBudgetAssemblyErrorCode = 'INPUT_BUDGET_EXCEEDED' | 'CONTINUITY_SLOT_REQUIRED';
|
|
61
|
+
export declare class ContextBudgetLayoutError extends Error {
|
|
62
|
+
readonly layoutId: string;
|
|
63
|
+
readonly omittedTurnCount: number;
|
|
64
|
+
readonly code: "CONTINUITY_SLOT_REQUIRED";
|
|
65
|
+
constructor(message: string, layoutId: string, omittedTurnCount: number);
|
|
66
|
+
}
|
|
67
|
+
export interface ContextBudgetManifest {
|
|
68
|
+
phase: ContextBudgetPhase;
|
|
69
|
+
initialInputFraming: ProviderInitialInputFraming;
|
|
70
|
+
resolved: boolean;
|
|
71
|
+
reason?: InputBudgetUnresolvedReason;
|
|
72
|
+
requestedProvider: string;
|
|
73
|
+
requestedModel: string | null;
|
|
74
|
+
effectiveProvider: string;
|
|
75
|
+
effectiveModel: string | null;
|
|
76
|
+
contextWindowTokens: number | null;
|
|
77
|
+
inputBudgetPercent: number | null;
|
|
78
|
+
inputBudgetTokens: number | null;
|
|
79
|
+
tokenizer: TokenizerMetadata;
|
|
80
|
+
initialTokenCount: number | null;
|
|
81
|
+
finalTokenCount: number | null;
|
|
82
|
+
activityLogTokenCount: number | null;
|
|
83
|
+
activityIncludedEntries: number | null;
|
|
84
|
+
activityOmittedEntries: number | null;
|
|
85
|
+
activityRemovedForBudget: boolean;
|
|
86
|
+
activityNewestTaskTokenCap: number | null;
|
|
87
|
+
historyOriginalMessages: number;
|
|
88
|
+
historyIncludedMessages: number;
|
|
89
|
+
historyOmittedMessages: number;
|
|
90
|
+
turnOriginal: number;
|
|
91
|
+
turnIncluded: number;
|
|
92
|
+
turnOmitted: number;
|
|
93
|
+
highlightOriginal: number;
|
|
94
|
+
highlightIncluded: number;
|
|
95
|
+
highlightOmitted: number;
|
|
96
|
+
highlightTruncated: number;
|
|
97
|
+
representedOmittedTurns: number;
|
|
98
|
+
unrepresentedOmittedTurns: number;
|
|
99
|
+
activityDegraded: boolean;
|
|
100
|
+
activityIncludedTasks: number;
|
|
101
|
+
activityOmittedTasks: number;
|
|
102
|
+
activityDegradation: ContextBudgetActivityDegradation[];
|
|
103
|
+
highlightLookupFailed: boolean;
|
|
104
|
+
layoutCapability: ContextBudgetLayoutCapability;
|
|
105
|
+
overBudget: boolean;
|
|
106
|
+
overdriveProviderSuppressed?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export interface TokenCountResult {
|
|
109
|
+
tokenCount: number;
|
|
110
|
+
tokenizer: TokenizerMetadata;
|
|
111
|
+
}
|
|
112
|
+
export interface TokenCounter {
|
|
113
|
+
metadata: TokenizerMetadata;
|
|
114
|
+
countTokens(text: string): number;
|
|
115
|
+
}
|
|
116
|
+
export interface FreshProviderInitialInput {
|
|
117
|
+
systemPrompt?: string | null;
|
|
118
|
+
message: string;
|
|
119
|
+
}
|
|
120
|
+
type PieceCacheEventType = 'hit' | 'miss' | 'evict' | 'full_encode';
|
|
121
|
+
interface PieceCacheEvent {
|
|
122
|
+
type: PieceCacheEventType;
|
|
123
|
+
piece?: string;
|
|
124
|
+
tokenCount?: number;
|
|
125
|
+
reason?: 'special_token';
|
|
126
|
+
}
|
|
127
|
+
type PieceCacheObserver = (event: PieceCacheEvent) => void;
|
|
128
|
+
interface TokenCounterInternalOptions {
|
|
129
|
+
pieceCacheMaxEntries?: number;
|
|
130
|
+
observePieceCache?: PieceCacheObserver;
|
|
131
|
+
}
|
|
132
|
+
export declare function normalizeInputBudgetProvider(provider: string): string;
|
|
133
|
+
export declare function resolveTokenizerMetadata(options?: TokenizerOptions): TokenizerMetadata;
|
|
134
|
+
export declare function countTokens(text: string, options?: TokenizerOptions): TokenCountResult;
|
|
135
|
+
export declare function renderFreshProviderInitialInput(input: FreshProviderInitialInput): string;
|
|
136
|
+
export declare function countFreshProviderInitialInput(input: FreshProviderInitialInput, count: (text: string) => number): number;
|
|
137
|
+
export declare function createTokenCounter(options?: TokenizerOptions): TokenCounter;
|
|
138
|
+
export declare function __createTokenCounterForTest(options?: TokenizerOptions, internalOptions?: TokenCounterInternalOptions): TokenCounter;
|
|
139
|
+
export declare function resolveInputBudget(options: ResolveInputBudgetOptions): ResolveInputBudgetResult;
|
|
140
|
+
export { DEFAULT_HIGHLIGHT_BUDGET_PERCENT, DEFAULT_PROTECTED_TURN_COUNT, MAX_ACTIVE_HIGHLIGHT_CHARS, MAX_ACTIVE_HIGHLIGHTS, MAX_THREAD_STATE_VALUE_CHARS, MAX_THREAD_TITLE_CHARS, buildSemanticContinuityContext, buildThreadStateContext, getConversationMessageTaskId, groupConversationTurns, materializeConversationTurn, selectConversationHighlights, selectConversationTurns, } from './continuity.js';
|
|
141
|
+
export type { BuildSemanticContinuityContextOptions, ConversationHighlightSelection, ConversationTurn, ConversationTurnSelection, GroupedConversationTurns, SelectConversationHighlightsOptions, SelectConversationTurnsOptions, } from './continuity.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
2
|
export { toTaskReader } from './to-task-reader.js';
|
|
3
|
-
export { toTemplateMessages } from './to-template-messages.js';
|
|
3
|
+
export { LEGACY_UI_CARD_SAFE_SUMMARY, sanitizeLegacyUiCardText, sanitizeTemplateMessages, toTemplateMessages, } from './to-template-messages.js';
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import type { ConversationThread, FetchHistoryOptions, IConversationHistoryProvider, Platform } from './types';
|
|
1
|
+
import type { ConversationHighlight, ConversationThread, ConversationThreadState, FetchHistoryOptions, IConversationHistoryProvider, Platform, ThreadCreationOptions } from './types';
|
|
2
2
|
export declare class SqliteConversationProvider implements IConversationHistoryProvider {
|
|
3
3
|
private readonly dbPath;
|
|
4
4
|
constructor(dbPath?: string);
|
|
5
5
|
private getThreadRepo;
|
|
6
|
+
private getThreadHistoryRepo;
|
|
6
7
|
updateThread(id: string, patch: {
|
|
7
8
|
title?: string;
|
|
8
9
|
}): void;
|
|
9
|
-
ensureThread(threadId: string, platform: Platform, workspaceId?: string): Promise<{
|
|
10
|
+
ensureThread(threadId: string, platform: Platform, workspaceId?: string, creator?: ThreadCreationOptions): Promise<{
|
|
10
11
|
created: boolean;
|
|
11
12
|
}>;
|
|
12
13
|
fetchHistory(threadId: string, options?: FetchHistoryOptions): Promise<ConversationThread>;
|
|
14
|
+
fetchThreadState(threadId: string): Promise<ConversationThreadState | undefined>;
|
|
15
|
+
fetchHighlights(threadId: string): Promise<ConversationHighlight[] | undefined>;
|
|
13
16
|
saveUserMessage(threadId: string, text: string, _userId?: string, _metadata?: Record<string, unknown>): Promise<{
|
|
14
17
|
id: string;
|
|
15
18
|
firstMessage: boolean;
|
|
@@ -19,5 +22,6 @@ export declare class SqliteConversationProvider implements IConversationHistoryP
|
|
|
19
22
|
}>;
|
|
20
23
|
close(): void;
|
|
21
24
|
private normalizeStatus;
|
|
25
|
+
private readActiveHighlights;
|
|
22
26
|
private rowsToMessages;
|
|
23
27
|
}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import type { ConversationThread, TemplateMessage } from './types';
|
|
2
|
+
import type { UiAgentContextProjection } from '../ui-instance/types.js';
|
|
3
|
+
import type { McpAppStateDescriptor } from '../mcp-app/types.js';
|
|
4
|
+
export declare const LEGACY_UI_CARD_SAFE_SUMMARY = "[workflow card omitted from AI context]";
|
|
5
|
+
export declare const V2_UI_INSTANCE_SAFE_SUMMARY = "[workflow UI instance omitted from AI context]";
|
|
6
|
+
export declare function sanitizeUiInstanceReferenceText(text: string): string;
|
|
7
|
+
export declare function sanitizeLegacyUiCardText(text: string): string;
|
|
8
|
+
export declare function sanitizeTemplateMessages(messages: readonly TemplateMessage[]): TemplateMessage[];
|
|
9
|
+
export declare function appendUiProjections(messages: readonly TemplateMessage[], projections: readonly UiAgentContextProjection[] | undefined): TemplateMessage[];
|
|
10
|
+
export declare function appendMcpAppProjections(messages: readonly TemplateMessage[], descriptors: readonly McpAppStateDescriptor[] | undefined): TemplateMessage[];
|
|
2
11
|
export declare function toTemplateMessages(thread: ConversationThread): TemplateMessage[];
|
|
@@ -1,16 +1,56 @@
|
|
|
1
|
+
import type { ThreadCreationOptions } from '../repository/thread.repository';
|
|
2
|
+
export type { ThreadCreationOptions } from '../repository/thread.repository';
|
|
1
3
|
export interface ConversationMessage {
|
|
2
4
|
id: string;
|
|
3
5
|
userId?: string;
|
|
4
6
|
text: string;
|
|
5
7
|
isAssistant: boolean;
|
|
6
8
|
timestamp: number;
|
|
9
|
+
taskId?: string;
|
|
7
10
|
metadata?: Record<string, unknown>;
|
|
8
11
|
}
|
|
9
12
|
export type Platform = 'cli' | 'web' | 'api' | 'mcp' | `channel/${string}`;
|
|
13
|
+
export interface ConversationHighlight {
|
|
14
|
+
id: string;
|
|
15
|
+
text: string;
|
|
16
|
+
kind?: string;
|
|
17
|
+
source?: string;
|
|
18
|
+
coversFromTaskId?: string;
|
|
19
|
+
coversToTaskId?: string;
|
|
20
|
+
covers_from_task_id?: string;
|
|
21
|
+
covers_to_task_id?: string;
|
|
22
|
+
createdAt?: number | string;
|
|
23
|
+
created_at?: number | string;
|
|
24
|
+
}
|
|
25
|
+
export interface SemanticContinuityContext {
|
|
26
|
+
highlights: ConversationHighlight[];
|
|
27
|
+
truncatedHighlights?: number;
|
|
28
|
+
omittedTurns: {
|
|
29
|
+
count: number;
|
|
30
|
+
represented: number;
|
|
31
|
+
unrepresented: number;
|
|
32
|
+
taskIds: string[];
|
|
33
|
+
};
|
|
34
|
+
rendered?: string;
|
|
35
|
+
omittedRendered: string;
|
|
36
|
+
}
|
|
37
|
+
export type ConversationSemanticContinuityContext = SemanticContinuityContext;
|
|
38
|
+
export interface ConversationThreadStateValue {
|
|
39
|
+
code: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ConversationThreadState {
|
|
43
|
+
title?: string;
|
|
44
|
+
priority?: ConversationThreadStateValue;
|
|
45
|
+
state?: ConversationThreadStateValue;
|
|
46
|
+
rendered?: string;
|
|
47
|
+
}
|
|
48
|
+
export type ThreadStateContext = ConversationThreadState;
|
|
10
49
|
export interface ConversationThread {
|
|
11
50
|
threadId: string;
|
|
12
51
|
platform: Platform;
|
|
13
52
|
messages: ConversationMessage[];
|
|
53
|
+
highlights?: ConversationHighlight[];
|
|
14
54
|
metadata?: {
|
|
15
55
|
title?: string;
|
|
16
56
|
firstMessage?: string;
|
|
@@ -20,10 +60,13 @@ export interface ConversationThread {
|
|
|
20
60
|
};
|
|
21
61
|
}
|
|
22
62
|
export interface TemplateMessage {
|
|
63
|
+
id?: string;
|
|
23
64
|
text: string;
|
|
24
65
|
isAssistant: boolean;
|
|
66
|
+
taskId?: string;
|
|
25
67
|
timestamp?: number;
|
|
26
68
|
metadata?: Record<string, unknown>;
|
|
69
|
+
activity_log?: string;
|
|
27
70
|
files?: Array<{
|
|
28
71
|
name: string;
|
|
29
72
|
size?: number;
|
|
@@ -33,13 +76,16 @@ export interface TemplateMessage {
|
|
|
33
76
|
export interface FetchHistoryOptions {
|
|
34
77
|
limit?: number;
|
|
35
78
|
maxContextLength?: number;
|
|
79
|
+
includeHighlights?: boolean;
|
|
36
80
|
currentTraceId?: string;
|
|
37
81
|
}
|
|
38
82
|
export interface IConversationHistoryProvider {
|
|
39
|
-
ensureThread(threadId: string, platform: Platform, workspaceId?: string): Promise<{
|
|
83
|
+
ensureThread(threadId: string, platform: Platform, workspaceId?: string, creator?: ThreadCreationOptions): Promise<{
|
|
40
84
|
created: boolean;
|
|
41
85
|
}>;
|
|
42
86
|
fetchHistory(threadId: string, options?: FetchHistoryOptions): Promise<ConversationThread>;
|
|
87
|
+
fetchThreadState?(threadId: string): Promise<ConversationThreadState | undefined>;
|
|
88
|
+
fetchHighlights?(threadId: string): Promise<ConversationHighlight[] | undefined>;
|
|
43
89
|
saveUserMessage(threadId: string, text: string, userId?: string, metadata?: Record<string, unknown>): Promise<{
|
|
44
90
|
id: string;
|
|
45
91
|
firstMessage: boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CommandRunner, GlobalCrewxInfo, ShortcutProgressEvent } from './types';
|
|
2
|
+
export interface DetectGlobalCrewxOptions {
|
|
3
|
+
env: NodeJS.ProcessEnv;
|
|
4
|
+
cwd: string;
|
|
5
|
+
run: CommandRunner;
|
|
6
|
+
}
|
|
7
|
+
export declare function detectGlobalCrewx(opts: DetectGlobalCrewxOptions): Promise<GlobalCrewxInfo>;
|
|
8
|
+
export interface EnsureGlobalCrewxOptions {
|
|
9
|
+
env: NodeJS.ProcessEnv;
|
|
10
|
+
cwd: string;
|
|
11
|
+
run: CommandRunner;
|
|
12
|
+
targetVersion: string;
|
|
13
|
+
currentInfo?: GlobalCrewxInfo;
|
|
14
|
+
installRoot?: string;
|
|
15
|
+
onProgress?: (event: ShortcutProgressEvent) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function ensureGlobalCrewx(opts: EnsureGlobalCrewxOptions): Promise<{
|
|
18
|
+
info: GlobalCrewxInfo;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { getShortcutStatus, installShortcut, uninstallShortcut, dismissShortcutNotice, } from './install';
|
|
2
|
+
export { killProcessTree } from './command-runner';
|
|
3
|
+
export { ShortcutError, type ShortcutState, type DesktopSource, type GlobalCrewxInfo, type ShortcutStatus, type ShortcutInstallResult, type ShortcutProgressPhase, type ShortcutProgressEvent, type ShortcutEnvOptions, type InstallShortcutOptions, type ShortcutErrorCode, type CommandResult, type CommandRunner, type CommandRunOptions, type ShortcutFsLike, } from './types';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var p=require('path'),crypto=require('crypto'),fs=require('fs'),os=require('os'),child_process=require('child_process'),string_decoder=require('string_decoder'),module$1=require('module');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var p__namespace=/*#__PURE__*/_interopNamespace(p);var B=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var m=class extends Error{code;constructor(t,n){super(`${t}: ${n}`),this.code=t,this.name="ShortcutError";}};var q={existsSync:e=>fs.existsSync(e),readFileSync:e=>fs.readFileSync(e,"utf8"),readBinaryFileSync:e=>new Uint8Array(fs.readFileSync(e)),writeFileSync:(e,t)=>fs.writeFileSync(e,t,"utf8"),mkdirSync:e=>{fs.mkdirSync(e,{recursive:true});},unlinkSync:e=>{fs.unlinkSync(e);}},Y=os.homedir;function N(e){return typeof e!="string"?void 0:e.trim()||void 0}function O(e){return N(e)?.toLowerCase()??""}function b(e){try{return fs.statSync(e).isFile()}catch{return false}}function Ke(e,t){if(e===t)return true;let n=p__namespace.default.relative(e,t);return n!==""&&!n.startsWith("..")&&!p__namespace.default.isAbsolute(n)}function je(e,t){if(p__namespace.default.basename(e)!==".bin")return false;let n=p__namespace.default.dirname(e);if(p__namespace.default.basename(n)!=="node_modules")return false;let r=p__namespace.default.dirname(n);return Ke(r,t)}function Q(e,t={}){if(e.includes("/")||e.includes("\\")||p__namespace.default.isAbsolute(e))return e;let n=t.platform??process.platform,r=t.env??process.env,o=p__namespace.default.resolve(t.cwd??process.cwd()),c=(t.resolution??"global_first")==="global_first",s=r.PATH??r.Path??process.env.PATH??process.env.Path??"",i=n==="win32"?";":":",a=s.split(i).map(u=>u.trim()).filter(Boolean),l=p__namespace.default.extname(e).length>0,d=r.PATHEXT??r.Pathext??process.env.PATHEXT??process.env.Pathext??".EXE;.CMD;.BAT;.COM",f=n==="win32"?l?[""]:d.split(";").map(u=>u.trim()).filter(Boolean).map(u=>u.startsWith(".")?u:`.${u}`):[""];for(let u of a){let P=p__namespace.default.resolve(o,u);if(!(c&&je(P,o)))for(let h of f){let C=O(h),g=h.toUpperCase();for(let w of [h,C,g]){let y=p__namespace.default.join(P,`${e}${w}`);if(b(y))return y}}}return e}function ze(e){if(!b(e))return null;try{let t=fs.readFileSync(e,"utf8"),n=p__namespace.default.dirname(e),r=[];for(let i of t.matchAll(/"([^"\r\n]*)"/g)){let d=(i[1]??"").match(/%~?dp0%?\s*[\\/]*(.*)$/i)?.[1]?.trim();if(!d)continue;let f=d.replace(/[\\/]+/g,p__namespace.default.sep).replace(/^[\\/]+/,""),u=p__namespace.default.resolve(n,f);b(u)&&r.push(u);}let o=[],c=new Map;for(let i of t.matchAll(/SET\s+"(\w+)=%~?dp0%?[\\/]?([^"]+)"/gi)){let a=i[1].toUpperCase(),l=i[2].trim().replace(/[\\/]+/g,p__namespace.default.sep).replace(/^[\\/]+/,"");c.set(a,p__namespace.default.resolve(n,l));}for(let i of t.split(/\r?\n/))if(i.includes("%*"))for(let a of i.matchAll(/"%(\w+)%"/g)){let l=c.get(a[1].toUpperCase());l&&b(l)&&o.push(l);}let s=i=>i.find(a=>{let l=O(p__namespace.default.basename(a));return l!=="node.exe"&&l!=="node"})??null;return s(o)??s(r)}catch{return null}}function qe(e,t){if(typeof t=="string")return N(t)||null;if(!t||typeof t!="object")return null;if(e){let n=t[e],r=typeof n=="string"?N(n):void 0;if(r)return r}for(let n of Object.values(t)){let r=typeof n=="string"?N(n):void 0;if(r)return r}return null}function Ye(e,t){if(!t)return null;let n=p__namespace.default.dirname(e),r=[p__namespace.default.resolve(n,"..",t),p__namespace.default.resolve(n,"node_modules",t)];for(let o of r){let c=p__namespace.default.join(o,"package.json");if(b(c))try{let s=JSON.parse(fs.readFileSync(c,"utf8")),i=qe(t,s.bin);if(!i)continue;let a=p__namespace.default.resolve(o,i);if(b(a))return a}catch{}}return null}function Qe(e){let t=e.platform??process.platform,n=e.env??process.env,r=e.execPath??process.execPath,o=e.cwd,c=e.resolution;if(t!=="win32")return {command:Q(e.command,{cwd:o,env:n,platform:t,resolution:c}),leadingArgv:[],resolution:"direct"};let s=Q(e.command,{cwd:o,env:n,platform:t,resolution:c}),i=O(p__namespace.default.extname(s));if(i===".js"||i===".cjs"||i===".mjs")return {command:r,leadingArgv:[s],resolution:"node-entrypoint",windowsHide:true};if(i===".cmd"||i===".bat"){let a=ze(s)??Ye(s,e.packageName);return a?O(p__namespace.default.extname(a))===".exe"?{command:a,leadingArgv:[],resolution:"exe-entrypoint",windowsHide:true}:{command:r,leadingArgv:[a],resolution:"node-entrypoint",windowsHide:true}:{command:s,leadingArgv:[],resolution:"unresolved-wrapper"}}return {command:s,leadingArgv:[],resolution:"direct",windowsHide:true}}function Ze(e){if(e.candidate.resolution!=="unresolved-wrapper")return {command:e.candidate.command,leadingArgv:e.candidate.leadingArgv,resolution:e.candidate.resolution,windowsHide:e.candidate.windowsHide};throw new Error(`${p__namespace.default.basename(e.candidate.command)} wrapper resolved, but no executable/Node entrypoint could be resolved without shell execution.`)}function ee(e){let t=Qe(e);return Ze({candidate:t})}function te(e,t){return {command:e.command,argv:[...e.leadingArgv,...t],resolution:e.resolution,shell:e.shell,windowsHide:e.windowsHide}}var D="\uFFFD",$=8,re=1e3,tt=new Map([[437,"ibm437"],[720,"ibm720"],[737,"ibm737"],[775,"ibm775"],[850,"ibm850"],[852,"ibm852"],[855,"ibm855"],[857,"ibm857"],[858,"ibm858"],[862,"ibm862"],[864,"ibm864"],[932,"shift_jis"],[936,"gb18030"],[949,"euc-kr"],[950,"big5"],[866,"ibm866"],[869,"ibm869"],[1250,"windows-1250"],[1251,"windows-1251"],[1252,"windows-1252"],[1253,"windows-1253"],[1254,"windows-1254"],[1255,"windows-1255"],[1256,"windows-1256"],[1257,"windows-1257"],[1258,"windows-1258"]]),T;function U(e){let t=0;for(let n of e)n===D&&(t+=1);return t}function H(e,t){return U(t)<U(e)?t:e}function nt(e){let t=e.match(/(?:^|[^0-9])([0-9]{1,5})(?![0-9])/);if(!t)return null;let n=Number(t[1]);return Number.isInteger(n)&&n>0&&n<=65535?n:null}function rt(e){if(e!==65001)return tt.get(e)}function ot(e){let t=rt(e);if(!t)return null;try{return new TextDecoder(t)}catch{return null}}function st(){return new Promise(e=>{let t=false,n,r=o=>{t||(t=true,n&&clearTimeout(n),e(o));};n=setTimeout(()=>r(null),re),n.unref();try{child_process.execFile("chcp.com",[],{encoding:"ascii",timeout:re,windowsHide:!0},(c,s)=>{if(c){r(null);return}r(nt(String(s)));}).once("error",()=>r(null));}catch{r(null);}})}function ie(){return process.platform!=="win32"?Promise.resolve(null):(T||(T=st(),T.then(e=>{},()=>{})),T)}function it(){process.platform==="win32"&&ie();}function se(e,t){if(t.length>=$)return t.subarray(t.length-$);let n=$-t.length,r=e.length>n?e.subarray(e.length-n):e;return Buffer.concat([r,t])}var k=class{platform;detectCodePage;utf8Decoder=new string_decoder.StringDecoder("utf8");codePage;fallbackDecoder;replayTail=Buffer.alloc(0);pendingUtf8="";pendingFallback="";pendingBytes=Buffer.alloc(0);queue=Promise.resolve();ended=false;constructor(t={}){this.platform=t.platform??process.platform,this.detectCodePage=t.detectCodePage??ie,this.codePage=t.codePage;}write(t){let n=Buffer.from(t);return this.enqueue(()=>this.decodeChunk(n))}end(){return this.enqueue(()=>this.finish())}enqueue(t){let n=this.queue.then(t);return this.queue=n.then(()=>{},()=>{}),n}clearPendingCandidate(){this.pendingUtf8="",this.pendingFallback="",this.pendingBytes=Buffer.alloc(0);}async resolveCodePage(){if(this.codePage!==void 0)return this.codePage;try{this.codePage=await this.detectCodePage();}catch{this.codePage=null;}return this.codePage}async getFallbackDecoder(){if(this.fallbackDecoder!==void 0)return this.fallbackDecoder;let t=await this.resolveCodePage();return this.fallbackDecoder=t===null?null:ot(t),this.fallbackDecoder}async decodeChunk(t){if(this.ended)return "";let n=this.utf8Decoder.write(t),r=n.includes(D);if(r&&(this.utf8Decoder=new string_decoder.StringDecoder("utf8")),this.platform!=="win32")return n;if(this.fallbackDecoder){let a=this.fallbackDecoder.decode(t,{stream:true}),l=se(this.pendingBytes,t);if(r){let d=this.pendingUtf8+n,f=this.pendingFallback+a;return this.clearPendingCandidate(),H(d,f)}if(U(a)>0){let d=this.pendingUtf8+n;return this.clearPendingCandidate(),this.fallbackDecoder=void 0,this.replayTail=l,d}if(this.pendingUtf8||this.pendingFallback){if(this.pendingUtf8+=n,this.pendingFallback+=a,this.pendingBytes=l,n.length===0||a.length===0)return "";let d=this.pendingUtf8;return this.clearPendingCandidate(),d}return n.length===0&&a.length>0?(this.pendingUtf8=n,this.pendingFallback=a,this.pendingBytes=l,""):n}let o=this.replayTail;if(this.fallbackDecoder===void 0&&(this.replayTail=se(this.replayTail,t)),!r)return n;let c=this.fallbackDecoder===void 0,s=await this.getFallbackDecoder();if(!s)return this.replayTail=Buffer.alloc(0),n;c&&o.length>0&&s.decode(o,{stream:true}),this.replayTail=Buffer.alloc(0);let i=s.decode(t,{stream:true});return H(n,i)}async finish(){if(this.ended)return "";this.ended=true;let t=this.utf8Decoder.end();if(this.platform!=="win32")return t;if(this.fallbackDecoder===void 0&&t.includes(D)){let c=await this.getFallbackDecoder();c&&this.replayTail.length>0&&(c.decode(this.replayTail,{stream:true}),this.replayTail=Buffer.alloc(0));}let n=this.pendingUtf8+t,r=this.fallbackDecoder?.decode()??"",o=this.pendingFallback+r;return this.clearPendingCandidate(),n.includes(D)?H(n,o):n}};it();var ae=3e3;var ct=2e3,lt=25,ut=100;function ue(e){return e instanceof Error?e:e===void 0?void 0:new Error(String(e))}function ce(e){return typeof e=="object"&&e!==null&&"code"in e?String(e.code):void 0}function dt(e){return Number.isSafeInteger(e)&&e>0}function ft(e,t){return new Promise(n=>{let r;try{r=child_process.spawn(e,t,{windowsHide:!0});}catch(l){n({status:null,stdout:"",stderr:"",error:ue(l)});return}let o="",c="",s=false,i,a=setTimeout(()=>{try{r.kill();}catch{}i({status:null,stdout:o,stderr:c,error:new Error(`Command timed out after ${ae}ms`)});},ae);i=l=>{s||(s=true,clearTimeout(a),n(l));},r.stdout?.setEncoding("utf8"),r.stderr?.setEncoding("utf8"),r.stdout?.on("data",l=>{o+=String(l);}),r.stderr?.on("data",l=>{c+=String(l);}),r.once("error",l=>{i({status:null,stdout:o,stderr:c,error:l});}),r.once("close",l=>{i({status:l,stdout:o,stderr:c});});})}async function pt(e,t,n){return n.runCommandAsync?n.runCommandAsync(e,t):n.runCommand?n.runCommand(e,t):ft(e,t)}function mt(e){return new Promise(t=>{setTimeout(t,Math.max(0,e));})}function ht(){return new Promise(e=>{setImmediate(e);})}function A(e,t=process.kill){try{return t(e,0),"alive"}catch(n){return ce(n)==="ESRCH"?"not_found":ce(n)==="EPERM"?"alive":"unknown"}}function gt(e,t){let n=A(-e,t),r=A(e,t);return n==="alive"||r==="alive"?"alive":n==="unknown"||r==="unknown"?"unknown":"not_found"}async function de(e,t,n,r){let o=Math.max(0,n),c=Math.max(1,r.pollIntervalMs??lt),s=Date.now()+o,i,a=o===0,l=r.sleep?Promise.resolve().then(()=>r.sleep(o)).then(()=>{},()=>{}):new Promise(d=>{i=setTimeout(d,o);});l.then(()=>{a=true;});try{for(await ht();;){let d=gt(e,t);if(d==="not_found")return d;let f=s-Date.now();if(a||f<=0)return d;await Promise.race([l,mt(Math.min(c,f))]);}}finally{i!==void 0&&clearTimeout(i);}}async function le(e,t,n,r,o){let c=await de(e,t,o.hardConfirmMs??ut,{...o,sleep:void 0});return c==="not_found"?n?{status:"not_found",pid:e,method:r}:{status:"terminated",pid:e,method:r}:c==="alive"?{status:"failed",pid:e,method:r,error:"Process is still running after termination attempt"}:{status:"failed",pid:e,method:r,error:"Unable to verify process termination"}}async function fe(e,t={}){let n=t.platform??process.platform,r=n==="win32"?"taskkill":"process-group",o=u=>({status:"failed",pid:e,method:r,error:u});if(!dt(e))return o("Invalid process ID");let c=t.kill??process.kill,s=A(e,c);if(s==="not_found")return {status:"not_found",pid:e,method:r};if(s!=="alive")return o("Unable to determine whether the process is alive");if(n==="win32"){let u;try{u=await pt("taskkill",["/PID",String(e),"/T","/F"],t);}catch(h){u={status:null,stdout:"",stderr:"",error:ue(h)};}let P=A(e,c);return P==="not_found"?u.status===0&&!u.error?{status:"terminated",pid:e,method:r}:{status:"not_found",pid:e,method:r}:o(P==="alive"?"Process is still running after termination attempt":"Unable to verify process termination")}let i,a=t.signal??"SIGKILL";try{c(-e,a);}catch(u){i=u;}if(a==="SIGKILL")return le(e,c,i,r,t);if(await de(e,c,t.graceMs??ct,t)==="not_found")return i?{status:"not_found",pid:e,method:r}:{status:"terminated",pid:e,method:r};let d;try{c(-e,"SIGKILL");}catch(u){d=u;}let f=await le(e,c,d,r,t);return f.status==="terminated"?f:f.status==="not_found"?i?f:{status:"terminated",pid:e,method:r}:o(f.error??"Process termination failed")}var wt=["CREWX_ASSIGNED_TASK_ID","CREWX_DETACHED_RUNNER"];function Pt(e,t){let n={};for(let[r,o]of Object.entries(e))o!==void 0&&(t.includes(r)||(n[r]=o));return n}function pe(e){return Pt(e,wt)}var me=3e4;function he(e){if(typeof e.pid!="number"){try{e.kill();}catch{}return}fe(e.pid,{signal:"SIGKILL"}).then(t=>{if(t.status==="failed")try{e.kill("SIGKILL");}catch{}},()=>{try{e.kill("SIGKILL");}catch{}});}var ge=(e,t,n={})=>new Promise((r,o)=>{let c=pe(n.env??process.env),s=process.platform,i;try{let w=ee({command:e,platform:s,env:c,cwd:n.cwd,allowShellFallback:!1});i=te(w,t);}catch(w){o(w instanceof Error?w:new Error(String(w)));return}let a=child_process.spawn(i.command,i.argv,{cwd:n.cwd,env:c,shell:i.shell,windowsHide:i.windowsHide??true,detached:s!=="win32"}),l="",d="",f=false,u=new k({platform:s}),P=new k({platform:s}),h=Promise.resolve(),C=Promise.resolve(),g=setTimeout(()=>{f||(f=true,he(a),o(new Error(`Command timed out after ${n.timeoutMs??me}ms: ${e} ${t.join(" ")}`)));},n.timeoutMs??me);a.stdout?.on("data",w=>{h=h.then(async()=>{l+=await u.write(w);});}),a.stderr?.on("data",w=>{C=C.then(async()=>{d+=await P.write(w);});}),a.on("error",w=>{f||(f=true,clearTimeout(g),o(w));}),a.on("close",w=>{f||(async()=>{await Promise.all([h,C]);let[y,$e]=await Promise.all([u.end(),P.end()]);f||(l+=y,d+=$e,f=true,clearTimeout(g),r({code:w??0,stdout:l,stderr:d}));})().catch(y=>{f||(f=true,clearTimeout(g),o(y instanceof Error?y:new Error(String(y))));});});});function yt(){try{return (typeof B=="function"?B:module$1.createRequire(__filename)).resolve("@crewx/sdk/package.json")}catch{return null}}function vt(){let e=[yt(),p.join(__dirname,"../../package.json"),p.join(__dirname,"../../../package.json")].filter(t=>!!t);for(let t of e)try{let n=JSON.parse(fs.readFileSync(t,"utf8"));if(n.name==="@crewx/sdk"&&n.version)return n.version}catch{}return "0.0.0"}var Pe=vt();var E=p__namespace.win32;function V(e){return E.join(e,".crewx")}function Ee(e){return E.join(V(e),"shortcut.json")}function Ce(e){return E.join(V(e),"launcher.json")}function ye(e){return E.join(V(e),"bin","crewx-launcher.cmd")}function ve(e){return E.join(e,"CrewX.lnk")}function X(e,t){return E.normalize(e).toLowerCase()===E.normalize(t).toLowerCase()}var Rt="[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Environment]::GetFolderPath('DesktopDirectory')";async function Re(e){try{let n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",Rt],{env:e.env}),r=n.stdout.trim();if(n.code===0&&r)return {dir:r,source:"known-folder"}}catch{}let t=e.env.USERPROFILE||e.env.Userprofile||e.homedir();return t?{dir:E.join(t,"Desktop"),source:"fallback"}:null}function G(e,t){let n=E.resolve(t,"node_modules",".bin").toLowerCase();return e.split(";").filter(r=>r?E.resolve(r).toLowerCase()!==n:true).join(";")}function be(e){return e?/\\Program Files( \(x86\))?\\/i.test(e)&&/crewx/i.test(e):false}function bt(e,t){let n=a=>{let[l,...d]=a.split("-"),f=d.join("-")||void 0;return {parts:(l??"").split(".").map(P=>Number.parseInt(P,10)||0),pre:f}},r=n(e),o=n(t),c=Math.max(r.parts.length,o.parts.length);for(let a=0;a<c;a++){let l=r.parts[a]??0,d=o.parts[a]??0;if(l!==d)return l<d?-1:1}if(r.pre===o.pre)return 0;if(!r.pre&&o.pre)return 1;if(r.pre&&!o.pre)return -1;let s=Number.parseInt(r.pre.match(/(\d+)$/)?.[1]??"",10),i=Number.parseInt(o.pre.match(/(\d+)$/)?.[1]??"",10);return !Number.isNaN(s)&&!Number.isNaN(i)&&s!==i?s<i?-1:1:r.pre<o.pre?-1:r.pre>o.pre?1:0}function _(e,t){return bt(e,t)<0}var _e=p__namespace.win32,xe=1;function Ie(e,t){if(!e.existsSync(t))return null;try{let n=JSON.parse(e.readFileSync(t));return {schema:n.schema??xe,shortcutPath:n.shortcutPath,version:n.version,iconHash:typeof n.iconHash=="string"?n.iconHash:void 0,owned:!!n.owned,declined:!!n.declined,desktopSource:n.desktopSource,updatedAt:n.updatedAt}}catch{return null}}function W(e,t,n){let r={schema:xe,...n,updatedAt:new Date().toISOString()};e.mkdirSync(_e.dirname(t)),e.writeFileSync(t,JSON.stringify(r,null,2));}function M(e,t){if(!e.existsSync(t))return null;try{let n=JSON.parse(e.readFileSync(t));return {schema:n.schema??0,binPath:n.binPath,updatedAt:n.updatedAt}}catch{return null}}function Le(e,t,n){e.mkdirSync(_e.dirname(t)),e.writeFileSync(t,JSON.stringify(n,null,2));}var kt=p__namespace.win32,x=1;function _t(e){return e.replace(/%/g,"%%")}function xt(e){return ["@echo off","setlocal DisableDelayedExpansion","chcp 65001 >nul","",'set "CREWX_WORKDIR=%USERPROFILE%\\crewx"','if not exist "%CREWX_WORKDIR%" mkdir "%CREWX_WORKDIR%" >nul 2>nul','cd /d "%CREWX_WORKDIR%"',"",'set "CREWX_PORT_EFFECTIVE=%CREWX_PORT%"','if "%CREWX_PORT_EFFECTIVE%"=="" set "CREWX_PORT_EFFECTIVE=8150"','set "CREWX_HEALTH_URL=http://127.0.0.1:%CREWX_PORT_EFFECTIVE%/api/v1/health"','set "CREWX_ORIGIN_URL=http://127.0.0.1:%CREWX_PORT_EFFECTIVE%/"',"",e.bakedBinPath?`set "CREWX_FALLBACK_BIN=${_t(e.bakedBinPath)}"`:'set "CREWX_FALLBACK_BIN="','set "CREWX_RESOLVED_BIN=%CREWX_BIN%"','if "%CREWX_RESOLVED_BIN%"=="" set "CREWX_RESOLVED_BIN=%CREWX_FALLBACK_BIN%"','if "%CREWX_RESOLVED_BIN%"=="" (',` for /f "delims=" %%I in ('where crewx 2^>nul') do (`,' if not defined CREWX_RESOLVED_BIN set "CREWX_RESOLVED_BIN=%%I"'," )",")","",'powershell -NoProfile -NonInteractive -Command "try { $r = Invoke-WebRequest -Uri $env:CREWX_HEALTH_URL -TimeoutSec 1 -UseBasicParsing; if ($r.StatusCode -eq 200) { exit 0 } else { exit 1 } } catch { exit 1 }"',"if %ERRORLEVEL% EQU 0 (",' start "" "%CREWX_ORIGIN_URL%"'," exit /b 0",")","",'if "%CREWX_RESOLVED_BIN%"=="" ('," echo CrewX executable not found. Please reinstall the desktop shortcut."," pause"," exit /b 1",")","",'start "CrewX" /min "%CREWX_RESOLVED_BIN%"',""].join(`\r
|
|
2
|
+
`)}function Oe(e){let t=M(e.fs,e.launcherManifestPath),n=!!t&&t.schema>=x&&e.fs.existsSync(e.wrapperPath),r=n&&!t.binPath&&!!e.bakedBinPath;if(n&&!r)return {wrapperPath:e.wrapperPath,wrote:false,schema:t.schema};let c=xt({bakedBinPath:e.bakedBinPath});try{e.fs.mkdirSync(kt.dirname(e.wrapperPath)),e.fs.writeFileSync(e.wrapperPath,c),Le(e.fs,e.launcherManifestPath,{schema:x,binPath:e.bakedBinPath,updatedAt:new Date().toISOString()});}catch(s){throw s instanceof m?s:new m("WRITE_DENIED",`Could not write launcher wrapper: ${s instanceof Error?s.message:String(s)}`)}return {wrapperPath:e.wrapperPath,wrote:true,schema:x}}var It=["$ws = New-Object -ComObject WScript.Shell","$sc = $ws.CreateShortcut($env:CREWX_LNK_PATH)","$sc.TargetPath = $env:CREWX_LNK_TARGET","if ($env:CREWX_LNK_WORKDIR) { $sc.WorkingDirectory = $env:CREWX_LNK_WORKDIR }","$sc.WindowStyle = 7","if ($env:CREWX_LNK_ICON) { $sc.IconLocation = $env:CREWX_LNK_ICON }","$sc.Save()"].join("; "),Lt=["[Console]::OutputEncoding = [System.Text.Encoding]::UTF8","$ws = New-Object -ComObject WScript.Shell","$sc = $ws.CreateShortcut($env:CREWX_LNK_PATH)","[PSCustomObject]@{ TargetPath = $sc.TargetPath; WorkingDirectory = $sc.WorkingDirectory; IconLocation = $sc.IconLocation } | ConvertTo-Json -Compress"].join("; ");async function Te(e){let t={...e.env,CREWX_LNK_PATH:e.shortcutPath,CREWX_LNK_TARGET:e.targetPath,CREWX_LNK_WORKDIR:e.workingDirectory??"",CREWX_LNK_ICON:e.iconPath??""},n;try{n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",It],{env:t});}catch(r){throw new m("POWERSHELL_UNAVAILABLE",`Could not run PowerShell: ${r instanceof Error?r.message:String(r)}`)}if(n.code!==0)throw new m("POWERSHELL_UNAVAILABLE",`Failed to create desktop shortcut: ${n.stderr||n.stdout}`)}function De(e){let t=e.trim(),n=t.lastIndexOf(",");return n!==-1&&/^-?\d+$/.test(t.slice(n+1).trim())&&(t=t.slice(0,n).trim()),t.length>=2&&t.startsWith('"')&&t.endsWith('"')&&(t=t.slice(1,-1).trim()),t}async function Ae(e){try{let t={...e.env,CREWX_LNK_PATH:e.shortcutPath},n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",Lt],{env:t});if(n.code!==0||!n.stdout.trim())return null;let r=JSON.parse(n.stdout.trim());return {targetPath:r.TargetPath??"",workingDirectory:r.WorkingDirectory??"",iconLocation:r.IconLocation??""}}catch{return null}}var K=p__namespace.win32;async function I(e){let t=G(e.env.PATH??e.env.Path??"",e.cwd),n={...e.env,PATH:t,Path:t},r;try{r=await e.run("npm",["list","-g","crewx","--depth=0","--json"],{env:n});}catch{return {installed:false}}let o;try{o=JSON.parse(r.stdout||"{}");}catch{return {installed:false}}let c=o.dependencies?.crewx;if(!c?.version)return {installed:false};let s;try{let a=await e.run("npm",["prefix","-g"],{env:n});a.code===0&&(s=a.stdout.trim()||void 0);}catch{}let i=s?K.join(s,"crewx.cmd"):void 0;return {installed:true,version:c.version,binPath:i,prefix:s}}var Nt=/EACCES|EPERM|EROFS/,Ot=/ENOTFOUND|ETIMEDOUT|ECONNREFUSED|network|registry/i,Tt=/^\d+\.\d+\.\d+/;function Dt(e){return !!e&&e!=="0.0.0"&&Tt.test(e)}var J=10*6e4;async function Me(e){if(!Dt(e.targetVersion))throw new m("GLOBAL_INSTALL_FAILED",`RUNNING_VERSION_UNKNOWN: cannot reliably determine the running crewx version to install (got ${JSON.stringify(e.targetVersion)}); refusing to fall back to crewx@latest`);if(e.currentInfo?.installed&&e.currentInfo.version&&!_(e.currentInfo.version,e.targetVersion))return {info:e.currentInfo};let t=G(e.env.PATH??e.env.Path??"",e.cwd),n={...e.env,PATH:t,Path:t},r=`crewx@${e.targetVersion}`;e.onProgress?.({phase:"global-install",message:`Installing crewx globally (npm install -g ${r})`});let o;try{o=await e.run("npm",["install","-g",r,"--no-audit","--no-fund"],{env:n,timeoutMs:J});}catch(s){throw new m("NPM_UNAVAILABLE",`Could not run npm: ${s instanceof Error?s.message:String(s)}`)}if(o.code===0)return {info:await I({env:n,cwd:e.cwd,run:e.run})};let c=`${o.stdout}
|
|
3
|
+
${o.stderr}`;if(Nt.test(c)){e.onProgress?.({phase:"global-install",message:"Permission denied \u2014 retrying with a user-scoped npm prefix"});let s=e.env.LOCALAPPDATA||K.join(e.env.USERPROFILE??"","AppData","Local"),i={...n,npm_config_prefix:K.join(s,"crewx","npm")},a;try{a=await e.run("npm",["install","-g",r,"--no-audit","--no-fund"],{env:i,timeoutMs:J});}catch(l){throw new m("NPM_PERMISSION_DENIED",`Retry with user-scoped prefix failed: ${l instanceof Error?l.message:String(l)}`)}if(a.code===0)return {info:await I({env:i,cwd:e.cwd,run:e.run})};throw new m("NPM_PERMISSION_DENIED",`npm install -g failed after user-scoped prefix retry: ${a.stderr||a.stdout}`)}if(Ot.test(c)){if(!e.installRoot)throw new m("OFFLINE_NO_SOURCE","The npm registry is unreachable and no local installRoot was provided for an offline install");e.onProgress?.({phase:"global-install",message:`Registry unreachable \u2014 installing offline from ${e.installRoot}`});let s;try{s=await e.run("npm",["install","-g",e.installRoot,"--offline","--no-audit","--no-fund"],{env:n,timeoutMs:J});}catch(i){throw new m("GLOBAL_INSTALL_FAILED",`Offline install failed: ${i instanceof Error?i.message:String(i)}`)}if(s.code===0)return {info:await I({env:n,cwd:e.cwd,run:e.run})};throw new m("GLOBAL_INSTALL_FAILED",`Offline install failed: ${s.stderr||s.stdout}`)}throw new m("GLOBAL_INSTALL_FAILED",c.trim()||`npm install -g ${r} failed`)}function Wt(e){return e.run??ge}function Mt(e){return e.fs??q}async function F(e){let t=e.platform??process.platform,n=e.env??process.env,r=e.homedir??Y,o=Wt(e),c=Mt(e),s=e.runningVersion??Pe,i=e.cwd??process.cwd(),a=r(),l=Ee(a),d=Ce(a),f=ye(a),u=null;t==="win32"&&(u=await Re({env:n,homedir:r,run:o}));let P=u?ve(u.dir):null;return {platform:t,env:n,homedir:r,run:o,fs:c,runningVersion:s,cwd:i,installRoot:e.installRoot,shortcutManifestPath:l,launcherManifestPath:d,wrapperPath:f,desktop:u,shortcutPath:P}}function Fe(e){return e?p__namespace.win32.normalize(e).toLowerCase().endsWith(`${p__namespace.win32.sep}bin${p__namespace.win32.sep}crewx.ico`):false}function j(e,t){let n=e.readBinaryFileSync;if(n)try{return crypto.createHash("sha256").update(n(t)).digest("hex")}catch{return}}async function Ft(e){try{await e.run("ie4uinit.exe",["-show"],{env:e.env});}catch{}}async function v(e){if(e.platform!=="win32")return {supported:false,state:"unsupported",globalCrewx:null,runningVersion:e.runningVersion,errors:[],manifest:null,iconStale:false};let t=[];e.desktop||t.push("NO_DESKTOP_DIR: could not resolve the Windows Desktop directory");let n=Ie(e.fs,e.shortcutManifestPath),r=M(e.fs,e.launcherManifestPath),o=await I({env:e.env,cwd:e.cwd,run:e.run}),c=e.shortcutPath?e.fs.existsSync(e.shortcutPath):false,s,i=false,a,l;if(!c)s=n?.declined?"declined":"not-installed";else {let d=!!n?.owned&&!!e.shortcutPath&&n.shortcutPath===e.shortcutPath,f=false,u=e.shortcutPath?await Ae({run:e.run,env:e.env,shortcutPath:e.shortcutPath}):null;if(d||(u&&X(u.targetPath,e.wrapperPath)?d=true:u&&be(u.targetPath)&&(f=true)),f)s="foreign",t.push("NSIS_PRESENT: an NSIS-installed CrewX shortcut was detected");else if(!d)s="foreign";else if(n?.version&&_(e.runningVersion,n.version))s="superseded",t.push(`SUPERSEDED: running version ${e.runningVersion} is older than the installed shortcut's version ${n.version}; refusing to modify it`);else {let P=!r||r.schema<x||!e.fs.existsSync(e.wrapperPath);if(u){let h=De(u.iconLocation);if(!(!!h&&e.fs.existsSync(h)))i=true;else {a=h;let g=Be(o,e.fs);g?X(h,g)?(l=j(e.fs,h),i=!l||n?.iconHash!==l):i=true:Fe(h)?(l=j(e.fs,h),i=!l||n?.iconHash!==l):i=true;}}s=P||i?"stale":"installed";}}return {supported:true,state:s,shortcutPath:e.shortcutPath??void 0,desktopDir:e.desktop?.dir,desktopSource:e.desktop?.source,wrapperPath:e.wrapperPath,wrapperSchema:r?.schema,globalCrewx:o.installed?o:{installed:false},runningVersion:e.runningVersion,errors:t,manifest:n,iconStale:i,iconPath:a,iconHash:l}}function Be(e,t){if(!e?.installed||!e.prefix)return;let n=p__namespace.win32.join(e.prefix,"node_modules","crewx","bin","crewx.ico");return t.existsSync(n)?n:void 0}function R(e){let{manifest:t,iconStale:n,iconPath:r,iconHash:o,...c}=e;return c}async function Bt(e={}){let t=await F(e),n=await v(t);return R(n)}async function $t(e={}){let t=await F(e);e.onProgress?.({phase:"detect",message:"Checking current shortcut status"});let n=await v(t),r=R(n);if(!r.supported)return {...r,changed:false,installedGlobal:false};if(r.state==="superseded")return {...r,changed:false,installedGlobal:false};if(r.state==="foreign"){if(n.errors.some(g=>g.startsWith("NSIS_PRESENT")))throw new m("NSIS_PRESENT",`An NSIS-installed CrewX shortcut was detected at ${r.shortcutPath}`);if(!e.force)throw new m("FOREIGN_SHORTCUT",`An existing shortcut at ${r.shortcutPath} is not managed by CrewX`)}if(!t.desktop||!t.shortcutPath)throw new m("NO_DESKTOP_DIR","Could not resolve the Windows Desktop directory");let o=false,c=false,s=r.globalCrewx,i=[],a=n.manifest?.iconHash,l=false;if(!!s?.installed&&!!s.version&&_(s.version,t.runningVersion)||!s?.installed&&r.state!=="installed"){let g=await Me({env:t.env,cwd:t.cwd,run:t.run,targetVersion:t.runningVersion,currentInfo:s??void 0,installRoot:t.installRoot,onProgress:e.onProgress});s=g.info,c=g.info.installed,o=true,c||i.push(`GLOBAL_INSTALL_UNCONFIRMED: npm install -g crewx@${t.runningVersion} exited successfully but a follow-up check could not confirm the global install`);}if(e.onProgress?.({phase:"wrapper",message:"Ensuring launcher wrapper"}),Oe({fs:t.fs,wrapperPath:t.wrapperPath,launcherManifestPath:t.launcherManifestPath,bakedBinPath:s?.binPath}).wrote&&(o=true),!((r.state==="installed"||r.state==="stale")&&!n.iconStale)){let g=Be(s,t.fs)??(n.iconPath&&Fe(n.iconPath)&&t.fs.existsSync(n.iconPath)?n.iconPath:void 0);if(n.iconStale&&!g)throw new m("ICON_UNAVAILABLE",`Could not locate the global CrewX icon (bin\\crewx.ico) to repair the desktop shortcut at ${t.shortcutPath}; the existing shortcut was left untouched`);e.onProgress?.({phase:"lnk",message:"Creating desktop shortcut"}),await Te({run:t.run,env:t.env,shortcutPath:t.shortcutPath,targetPath:t.wrapperPath,iconPath:g}),o=true,l=n.iconStale;let w=g?j(t.fs,g):void 0;w&&(a=w);}o&&W(t.fs,t.shortcutManifestPath,{shortcutPath:t.shortcutPath,version:t.runningVersion,owned:true,declined:false,desktopSource:t.desktop.source,iconHash:a}),l&&await Ft(t);let h=await v(t),C=R(h);return {...C,errors:[...C.errors,...i],changed:o,installedGlobal:c}}async function Ht(e={}){let t=await F(e),n=await v(t),r=R(n);if(!r.supported)return r;if((r.state==="installed"||r.state==="stale")&&t.shortcutPath)try{t.fs.unlinkSync(t.shortcutPath);}catch{}W(t.fs,t.shortcutManifestPath,{shortcutPath:void 0,version:n.manifest?.version,owned:false,declined:true,desktopSource:void 0,iconHash:void 0});let o=await v(t);return R(o)}async function Ut(e={}){let t=await F(e),n=await v(t),r=R(n);if(!r.supported)return r;W(t.fs,t.shortcutManifestPath,{shortcutPath:n.manifest?.shortcutPath,version:n.manifest?.version,owned:n.manifest?.owned??false,declined:true,desktopSource:n.manifest?.desktopSource,iconHash:n.manifest?.iconHash});let o=await v(t);return R(o)}exports.ShortcutError=m;exports.dismissShortcutNotice=Ut;exports.getShortcutStatus=Bt;exports.installShortcut=$t;exports.killProcessTree=he;exports.uninstallShortcut=Ht;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type InstallShortcutOptions, type ShortcutEnvOptions, type ShortcutInstallResult, type ShortcutStatus } from './types';
|
|
2
|
+
export declare function getShortcutStatus(options?: ShortcutEnvOptions): Promise<ShortcutStatus>;
|
|
3
|
+
export declare function installShortcut(options?: InstallShortcutOptions): Promise<ShortcutInstallResult>;
|
|
4
|
+
export declare function uninstallShortcut(options?: ShortcutEnvOptions): Promise<ShortcutStatus>;
|
|
5
|
+
export declare function dismissShortcutNotice(options?: ShortcutEnvOptions): Promise<ShortcutStatus>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CommandRunner } from './types';
|
|
2
|
+
export interface WriteLnkOptions {
|
|
3
|
+
run: CommandRunner;
|
|
4
|
+
env: NodeJS.ProcessEnv;
|
|
5
|
+
shortcutPath: string;
|
|
6
|
+
targetPath: string;
|
|
7
|
+
workingDirectory?: string;
|
|
8
|
+
iconPath?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function writeLnk(opts: WriteLnkOptions): Promise<void>;
|
|
11
|
+
export interface LnkInfo {
|
|
12
|
+
targetPath: string;
|
|
13
|
+
workingDirectory: string;
|
|
14
|
+
iconLocation: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ReadLnkOptions {
|
|
17
|
+
run: CommandRunner;
|
|
18
|
+
env: NodeJS.ProcessEnv;
|
|
19
|
+
shortcutPath: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function normalizeIconLocation(raw: string): string;
|
|
22
|
+
export declare function readLnkTarget(opts: ReadLnkOptions): Promise<LnkInfo | null>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DesktopSource, ShortcutFsLike } from './types';
|
|
2
|
+
export declare const MANIFEST_SCHEMA_VERSION = 1;
|
|
3
|
+
export interface ShortcutManifest {
|
|
4
|
+
schema: number;
|
|
5
|
+
shortcutPath?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
iconHash?: string;
|
|
8
|
+
owned: boolean;
|
|
9
|
+
declined: boolean;
|
|
10
|
+
desktopSource?: DesktopSource;
|
|
11
|
+
updatedAt?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface LauncherManifest {
|
|
14
|
+
schema: number;
|
|
15
|
+
binPath?: string;
|
|
16
|
+
updatedAt?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function readShortcutManifest(fs: ShortcutFsLike, manifestPath: string): ShortcutManifest | null;
|
|
19
|
+
export declare function writeShortcutManifest(fs: ShortcutFsLike, manifestPath: string, data: Omit<ShortcutManifest, 'schema' | 'updatedAt'>): void;
|
|
20
|
+
export declare function readLauncherManifest(fs: ShortcutFsLike, manifestPath: string): LauncherManifest | null;
|
|
21
|
+
export declare function writeLauncherManifest(fs: ShortcutFsLike, manifestPath: string, data: LauncherManifest): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type ShortcutState = 'unsupported' | 'not-installed' | 'installed' | 'stale' | 'foreign' | 'superseded' | 'declined';
|
|
2
|
+
export type DesktopSource = 'known-folder' | 'fallback';
|
|
3
|
+
export interface GlobalCrewxInfo {
|
|
4
|
+
installed: boolean;
|
|
5
|
+
version?: string;
|
|
6
|
+
binPath?: string;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ShortcutStatus {
|
|
10
|
+
supported: boolean;
|
|
11
|
+
state: ShortcutState;
|
|
12
|
+
shortcutPath?: string;
|
|
13
|
+
desktopDir?: string;
|
|
14
|
+
desktopSource?: DesktopSource;
|
|
15
|
+
wrapperPath?: string;
|
|
16
|
+
wrapperSchema?: number;
|
|
17
|
+
globalCrewx: GlobalCrewxInfo | null;
|
|
18
|
+
runningVersion: string;
|
|
19
|
+
errors: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface ShortcutInstallResult extends ShortcutStatus {
|
|
22
|
+
changed: boolean;
|
|
23
|
+
installedGlobal: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type ShortcutProgressPhase = 'detect' | 'global-install' | 'wrapper' | 'lnk';
|
|
26
|
+
export interface ShortcutProgressEvent {
|
|
27
|
+
phase: ShortcutProgressPhase;
|
|
28
|
+
message: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CommandResult {
|
|
31
|
+
code: number;
|
|
32
|
+
stdout: string;
|
|
33
|
+
stderr: string;
|
|
34
|
+
}
|
|
35
|
+
export interface CommandRunOptions {
|
|
36
|
+
env?: NodeJS.ProcessEnv;
|
|
37
|
+
cwd?: string;
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
}
|
|
40
|
+
export type CommandRunner = (command: string, args: string[], opts?: CommandRunOptions) => Promise<CommandResult>;
|
|
41
|
+
export interface ShortcutFsLike {
|
|
42
|
+
existsSync(path: string): boolean;
|
|
43
|
+
readFileSync(path: string): string;
|
|
44
|
+
readBinaryFileSync?: (path: string) => Uint8Array;
|
|
45
|
+
writeFileSync(path: string, data: string): void;
|
|
46
|
+
mkdirSync(path: string): void;
|
|
47
|
+
unlinkSync(path: string): void;
|
|
48
|
+
}
|
|
49
|
+
export interface ShortcutEnvOptions {
|
|
50
|
+
platform?: NodeJS.Platform;
|
|
51
|
+
env?: NodeJS.ProcessEnv;
|
|
52
|
+
homedir?: () => string;
|
|
53
|
+
run?: CommandRunner;
|
|
54
|
+
fs?: ShortcutFsLike;
|
|
55
|
+
runningVersion?: string;
|
|
56
|
+
cwd?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface InstallShortcutOptions extends ShortcutEnvOptions {
|
|
59
|
+
force?: boolean;
|
|
60
|
+
onProgress?: (event: ShortcutProgressEvent) => void;
|
|
61
|
+
installRoot?: string;
|
|
62
|
+
}
|
|
63
|
+
export type ShortcutErrorCode = 'NOT_WINDOWS' | 'NO_DESKTOP_DIR' | 'NPM_UNAVAILABLE' | 'NPM_PERMISSION_DENIED' | 'OFFLINE_NO_SOURCE' | 'GLOBAL_INSTALL_FAILED' | 'POWERSHELL_UNAVAILABLE' | 'WRITE_DENIED' | 'FOREIGN_SHORTCUT' | 'NSIS_PRESENT' | 'ICON_UNAVAILABLE';
|
|
64
|
+
export declare class ShortcutError extends Error {
|
|
65
|
+
readonly code: ShortcutErrorCode;
|
|
66
|
+
constructor(code: ShortcutErrorCode, message: string);
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION: string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CommandRunner, DesktopSource } from './types';
|
|
2
|
+
export declare function crewxHomeDir(homedir: string): string;
|
|
3
|
+
export declare function shortcutManifestPath(homedir: string): string;
|
|
4
|
+
export declare function launcherManifestPath(homedir: string): string;
|
|
5
|
+
export declare function wrapperPath(homedir: string): string;
|
|
6
|
+
export declare function shortcutLnkPath(desktopDir: string): string;
|
|
7
|
+
export declare function samePath(a: string, b: string): boolean;
|
|
8
|
+
export interface ResolveDesktopDirOptions {
|
|
9
|
+
env: NodeJS.ProcessEnv;
|
|
10
|
+
homedir: () => string;
|
|
11
|
+
run: CommandRunner;
|
|
12
|
+
}
|
|
13
|
+
export interface ResolvedDesktopDir {
|
|
14
|
+
dir: string;
|
|
15
|
+
source: DesktopSource;
|
|
16
|
+
}
|
|
17
|
+
export declare function resolveDesktopDir(opts: ResolveDesktopDirOptions): Promise<ResolvedDesktopDir | null>;
|
|
18
|
+
export declare function filterWorkspaceLocalBin(pathValue: string, cwd: string): string;
|
|
19
|
+
export declare function looksLikeNsisInstall(targetPath: string): boolean;
|
|
20
|
+
export declare function compareVersions(a: string, b: string): -1 | 0 | 1;
|
|
21
|
+
export declare function isOlderVersion(a: string, b: string): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ShortcutFsLike } from './types';
|
|
2
|
+
export declare const WRAPPER_SCHEMA_VERSION = 1;
|
|
3
|
+
export interface BuildWrapperScriptOptions {
|
|
4
|
+
bakedBinPath?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function buildWrapperScript(opts: BuildWrapperScriptOptions): string;
|
|
7
|
+
export interface EnsureWrapperOptions {
|
|
8
|
+
fs: ShortcutFsLike;
|
|
9
|
+
wrapperPath: string;
|
|
10
|
+
launcherManifestPath: string;
|
|
11
|
+
bakedBinPath?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface EnsureWrapperResult {
|
|
14
|
+
wrapperPath: string;
|
|
15
|
+
wrote: boolean;
|
|
16
|
+
schema: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function ensureWrapper(opts: EnsureWrapperOptions): EnsureWrapperResult;
|