dotdo 0.0.2 → 0.1.0
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/cli/README.md +238 -0
- package/cli/agent.ts +72 -0
- package/cli/bin.js +44 -0
- package/cli/bin.ts +38 -0
- package/cli/build.ts +157 -0
- package/cli/commands/auth/login.ts +14 -0
- package/cli/commands/auth/logout.ts +6 -0
- package/cli/commands/auth/whoami.ts +16 -0
- package/cli/commands/deploy-multi.ts +245 -0
- package/cli/commands/dev/deploy.ts +100 -0
- package/cli/commands/dev/dev.ts +95 -0
- package/cli/commands/dev/logs.ts +91 -0
- package/cli/commands/dev-local.ts +88 -0
- package/cli/commands/do-ops.ts +314 -0
- package/cli/commands/index.ts +100 -0
- package/cli/commands/init.ts +247 -0
- package/cli/commands/introspect/emitter.ts +315 -0
- package/cli/commands/introspect/index.ts +193 -0
- package/cli/commands/link.ts +598 -0
- package/cli/commands/snippets.ts +415 -0
- package/cli/commands/tunnel.ts +239 -0
- package/cli/device-auth.ts +289 -0
- package/cli/fallback.ts +12 -0
- package/cli/index.ts +121 -0
- package/cli/main.ts +246 -0
- package/cli/mcp-stdio.ts +790 -0
- package/cli/package.json +62 -0
- package/cli/runtime/do-registry.ts +193 -0
- package/cli/runtime/embedded-db.ts +344 -0
- package/cli/runtime/index.ts +9 -0
- package/cli/runtime/miniflare-adapter.ts +162 -0
- package/cli/sandbox.ts +82 -0
- package/cli/src/args.ts +174 -0
- package/cli/src/auth.ts +55 -0
- package/cli/src/commands/call.ts +84 -0
- package/cli/src/commands/charge.ts +96 -0
- package/cli/src/commands/config.ts +115 -0
- package/cli/src/commands/email.ts +112 -0
- package/cli/src/commands/llm.ts +115 -0
- package/cli/src/commands/queue.ts +134 -0
- package/cli/src/commands/text.ts +86 -0
- package/cli/src/config.ts +185 -0
- package/cli/src/output.ts +246 -0
- package/cli/src/rpc.ts +192 -0
- package/cli/utils/config.ts +282 -0
- package/cli/utils/detect.ts +73 -0
- package/cli/utils/index.ts +15 -0
- package/cli/utils/logger.ts +232 -0
- package/dist/ai/template-literals.js +2 -2
- package/dist/ai/template-literals.js.map +1 -1
- package/dist/api/middleware/auth.js +3 -2
- package/dist/api/middleware/auth.js.map +1 -1
- package/dist/db/iceberg/inverted-index.js +1 -1
- package/dist/db/iceberg/inverted-index.js.map +1 -1
- package/dist/db/iceberg/puffin.js.map +1 -1
- package/dist/db/json-indexes.js.map +1 -1
- package/dist/db/objects.js.map +1 -1
- package/dist/db/primitives/dag-scheduler/index.js +1 -1
- package/dist/db/primitives/dag-scheduler/index.js.map +1 -1
- package/dist/db/primitives/observability.js.map +1 -1
- package/dist/db/primitives/schema-evolution.js.map +1 -1
- package/dist/db/primitives/temporal-store.js.map +1 -1
- package/dist/db/primitives/typed-column-store.js.map +1 -1
- package/dist/db/primitives/utils/duration.js.map +1 -1
- package/dist/db/primitives/utils/murmur3.js +12 -14
- package/dist/db/primitives/utils/murmur3.js.map +1 -1
- package/dist/db/primitives/window-manager.js.map +1 -1
- package/dist/db/stores.js.map +1 -1
- package/dist/db/things.js.map +1 -1
- package/dist/lib/DODispatcher.js +2 -2
- package/dist/lib/DODispatcher.js.map +1 -1
- package/dist/lib/auto-wiring.js.map +1 -1
- package/dist/lib/channels/email.js +1 -1
- package/dist/lib/channels/email.js.map +1 -1
- package/dist/lib/channels/slack-blockkit.js.map +1 -1
- package/dist/lib/cloudflare/ai.js +1 -1
- package/dist/lib/cloudflare/ai.js.map +1 -1
- package/dist/lib/cloudflare/kv.js +1 -1
- package/dist/lib/cloudflare/kv.js.map +1 -1
- package/dist/lib/cloudflare/r2.js +3 -3
- package/dist/lib/cloudflare/r2.js.map +1 -1
- package/dist/lib/cloudflare/vectorize.js.map +1 -1
- package/dist/lib/cloudflare/workflows.js.map +1 -1
- package/dist/lib/executors/AgenticFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/CodeFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/GenerativeFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/HumanFunctionExecutor.js +1 -1
- package/dist/lib/executors/HumanFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/ParallelStepExecutor.js.map +1 -1
- package/dist/lib/experiments.js.map +1 -1
- package/dist/lib/flags/store.js.map +1 -1
- package/dist/lib/functions/FunctionComposition.js.map +1 -1
- package/dist/lib/functions/FunctionMiddleware.js.map +1 -1
- package/dist/lib/functions/FunctionRegistry.js.map +1 -1
- package/dist/lib/humans/templates.js.map +1 -1
- package/dist/lib/identity.js +2 -2
- package/dist/lib/identity.js.map +1 -1
- package/dist/lib/logging/index.js.map +1 -1
- package/dist/lib/mixins/bash.js +1 -73
- package/dist/lib/mixins/bash.js.map +1 -1
- package/dist/lib/mixins/git.js +0 -5
- package/dist/lib/mixins/git.js.map +1 -1
- package/dist/lib/mixins/npm.js.map +1 -1
- package/dist/lib/noun-id.js.map +1 -1
- package/dist/lib/rate-limit/sliding-window.js.map +1 -1
- package/dist/lib/rpc/bindings.js.map +1 -1
- package/dist/lib/safe-stringify.js.map +1 -1
- package/dist/lib/sandbox/miniflare-sandbox.js.map +1 -1
- package/dist/lib/sqids.js.map +1 -1
- package/dist/lib/sql/adapters/node-sql-parser.js.map +1 -1
- package/dist/lib/sql/adapters/pgsql-parser.js +19 -18
- package/dist/lib/sql/adapters/pgsql-parser.js.map +1 -1
- package/dist/metrics/hunch.js.map +1 -1
- package/dist/objects/API.js +1 -1
- package/dist/objects/API.js.map +1 -1
- package/dist/objects/Agent.js.map +1 -1
- package/dist/objects/Browser.js.map +1 -1
- package/dist/objects/CLI.js.map +1 -1
- package/dist/objects/DOBase.js.map +1 -1
- package/dist/objects/DOCache.js +153 -0
- package/dist/objects/DOCache.js.map +1 -0
- package/dist/objects/DOFull.js.map +1 -1
- package/dist/objects/Entity.js.map +1 -1
- package/dist/objects/Human.js.map +1 -1
- package/dist/objects/IcebergMetadataDO.js.map +1 -1
- package/dist/objects/IntegrationsDO.js.map +1 -1
- package/dist/objects/ObservabilityBroadcaster.js.map +1 -1
- package/dist/objects/Package.js.map +1 -1
- package/dist/objects/Product.js +1 -1
- package/dist/objects/Product.js.map +1 -1
- package/dist/objects/SaaS.js.map +1 -1
- package/dist/objects/SandboxDO.js.map +1 -1
- package/dist/objects/Service.js.map +1 -1
- package/dist/objects/VectorShardDO.js +9 -7
- package/dist/objects/VectorShardDO.js.map +1 -1
- package/dist/objects/Workflow.js.map +1 -1
- package/dist/objects/WorkflowFactory.js.map +1 -1
- package/dist/objects/WorkflowRuntime.js.map +1 -1
- package/dist/objects/lifecycle/Branch.js.map +1 -1
- package/dist/objects/lifecycle/Clone.js +1 -1
- package/dist/objects/lifecycle/Clone.js.map +1 -1
- package/dist/objects/lifecycle/Compact.js.map +1 -1
- package/dist/objects/lifecycle/Shard.js.map +1 -1
- package/dist/objects/persistence/checkpoint-manager.js.map +1 -1
- package/dist/objects/persistence/migration-runner.js.map +1 -1
- package/dist/objects/persistence/replication-manager.js +2 -2
- package/dist/objects/persistence/replication-manager.js.map +1 -1
- package/dist/objects/persistence/tiered-storage-manager.js.map +1 -1
- package/dist/objects/persistence/wal-manager.js.map +1 -1
- package/dist/objects/transport/auth-layer.js.map +1 -1
- package/dist/objects/transport/chain.js.map +1 -1
- package/dist/objects/transport/mcp-server.js +7 -6
- package/dist/objects/transport/mcp-server.js.map +1 -1
- package/dist/objects/transport/rest-autowire.js +3 -2
- package/dist/objects/transport/rest-autowire.js.map +1 -1
- package/dist/objects/transport/rest-router.js.map +1 -1
- package/dist/objects/transport/rpc-server.js +18 -15
- package/dist/objects/transport/rpc-server.js.map +1 -1
- package/dist/objects/transport/shared.js +2 -1
- package/dist/objects/transport/shared.js.map +1 -1
- package/dist/snippets/artifacts-ingest.js.map +1 -1
- package/dist/snippets/artifacts-serve.js.map +1 -1
- package/dist/snippets/search.js.map +1 -1
- package/dist/workflows/ScheduleManager.js.map +1 -1
- package/dist/workflows/StepResultStorage.js.map +1 -1
- package/dist/workflows/WaitForEventManager.js.map +1 -1
- package/dist/workflows/compat/backends/cloudflare-workflows.js.map +1 -1
- package/dist/workflows/compat/inngest/index.js.map +1 -1
- package/dist/workflows/compat/qstash/index.js.map +1 -1
- package/dist/workflows/compat/temporal/client.js.map +1 -1
- package/dist/workflows/compat/temporal/index.js.map +1 -1
- package/dist/workflows/compat/trigger/index.js.map +1 -1
- package/dist/workflows/compat/utils/index.js.map +1 -1
- package/dist/workflows/context/correlation.js +2 -2
- package/dist/workflows/context/correlation.js.map +1 -1
- package/dist/workflows/context/experiment.js +1 -1
- package/dist/workflows/context/experiment.js.map +1 -1
- package/dist/workflows/context/flag.js +1 -1
- package/dist/workflows/context/flag.js.map +1 -1
- package/dist/workflows/context/measure.js +1 -1
- package/dist/workflows/context/measure.js.map +1 -1
- package/dist/workflows/context/rate-limit.js.map +1 -1
- package/dist/workflows/data/entity-events/entity-events.js.map +1 -1
- package/dist/workflows/data/experiment/index.js.map +1 -1
- package/dist/workflows/data/goal/context.js +1 -1
- package/dist/workflows/data/goal/context.js.map +1 -1
- package/dist/workflows/data/measure/index.js +1 -1
- package/dist/workflows/data/measure/index.js.map +1 -1
- package/dist/workflows/data/stream/index.js +10 -76
- package/dist/workflows/data/stream/index.js.map +1 -1
- package/dist/workflows/data/track/context.js.map +1 -1
- package/dist/workflows/data/view/context.js.map +1 -1
- package/dist/workflows/domain.js.map +1 -1
- package/dist/workflows/flags.js +1 -1
- package/dist/workflows/flags.js.map +1 -1
- package/dist/workflows/hash.js.map +1 -1
- package/dist/workflows/on.js +1 -1
- package/dist/workflows/on.js.map +1 -1
- package/dist/workflows/schedule-builder.js.map +1 -1
- package/dist/workflows/visibility/index.js +0 -2
- package/dist/workflows/visibility/index.js.map +1 -1
- package/dist/workflows/visibility/query-parser.js.map +1 -1
- package/package.json +18 -3
- package/dist/api/analytics/router.js +0 -601
- package/dist/api/analytics/router.js.map +0 -1
- package/dist/api/index.js +0 -158
- package/dist/api/index.js.map +0 -1
- package/dist/api/middleware/error-handling.js +0 -176
- package/dist/api/middleware/error-handling.js.map +0 -1
- package/dist/api/middleware/request-id.js +0 -21
- package/dist/api/middleware/request-id.js.map +0 -1
- package/dist/api/pages.js +0 -1180
- package/dist/api/pages.js.map +0 -1
- package/dist/api/routes/api.js +0 -612
- package/dist/api/routes/api.js.map +0 -1
- package/dist/api/routes/browsers.js +0 -471
- package/dist/api/routes/browsers.js.map +0 -1
- package/dist/api/routes/do.js +0 -188
- package/dist/api/routes/do.js.map +0 -1
- package/dist/api/routes/mcp.js +0 -459
- package/dist/api/routes/mcp.js.map +0 -1
- package/dist/api/routes/obs.js +0 -445
- package/dist/api/routes/obs.js.map +0 -1
- package/dist/api/routes/openapi.js +0 -794
- package/dist/api/routes/openapi.js.map +0 -1
- package/dist/api/routes/rpc.js +0 -1103
- package/dist/api/routes/rpc.js.map +0 -1
- package/dist/api/routes/sandboxes.js +0 -389
- package/dist/api/routes/sandboxes.js.map +0 -1
- package/dist/api/test-do.js +0 -38
- package/dist/api/test-do.js.map +0 -1
- package/dist/api/types.js +0 -11
- package/dist/api/types.js.map +0 -1
- package/dist/cli/bin.js +0 -2
- package/dist/cli/main.js +0 -52342
- package/dist/do/bash.js +0 -35
- package/dist/do/bash.js.map +0 -1
- package/dist/do/fs.js +0 -25
- package/dist/do/fs.js.map +0 -1
- package/dist/do/full.js +0 -61
- package/dist/do/full.js.map +0 -1
- package/dist/do/git.js +0 -28
- package/dist/do/git.js.map +0 -1
- package/dist/do/index.js +0 -52
- package/dist/do/index.js.map +0 -1
- package/dist/lib/agent/tools/bash.js +0 -336
- package/dist/lib/agent/tools/bash.js.map +0 -1
- package/dist/lib/agent/tools/edit.js +0 -157
- package/dist/lib/agent/tools/edit.js.map +0 -1
- package/dist/lib/agent/tools/glob.js +0 -137
- package/dist/lib/agent/tools/glob.js.map +0 -1
- package/dist/lib/agent/tools/grep.js +0 -315
- package/dist/lib/agent/tools/grep.js.map +0 -1
- package/dist/lib/agent/tools/index.js +0 -71
- package/dist/lib/agent/tools/index.js.map +0 -1
- package/dist/lib/agent/tools/read.js +0 -212
- package/dist/lib/agent/tools/read.js.map +0 -1
- package/dist/lib/agent/tools/types.js +0 -197
- package/dist/lib/agent/tools/types.js.map +0 -1
- package/dist/lib/agent/tools/write.js +0 -159
- package/dist/lib/agent/tools/write.js.map +0 -1
- package/dist/lib/mixins/index.js +0 -29
- package/dist/lib/mixins/index.js.map +0 -1
- package/dist/primitives/bashx/src/ast/analyze.js +0 -1472
- package/dist/primitives/bashx/src/ast/analyze.js.map +0 -1
- package/dist/primitives/bashx/src/ast/parser.js +0 -1488
- package/dist/primitives/bashx/src/ast/parser.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/crypto.js +0 -1954
- package/dist/primitives/bashx/src/do/commands/crypto.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/data-processing.js +0 -1812
- package/dist/primitives/bashx/src/do/commands/data-processing.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/extended-utils.js +0 -804
- package/dist/primitives/bashx/src/do/commands/extended-utils.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/math-control.js +0 -1122
- package/dist/primitives/bashx/src/do/commands/math-control.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/posix-utils.js +0 -1015
- package/dist/primitives/bashx/src/do/commands/posix-utils.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/system-utils.js +0 -687
- package/dist/primitives/bashx/src/do/commands/system-utils.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/test-command.js +0 -523
- package/dist/primitives/bashx/src/do/commands/test-command.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/text-processing.js +0 -1550
- package/dist/primitives/bashx/src/do/commands/text-processing.js.map +0 -1
- package/dist/primitives/bashx/src/do/container-executor.js +0 -429
- package/dist/primitives/bashx/src/do/container-executor.js.map +0 -1
- package/dist/primitives/bashx/src/do/index.js +0 -668
- package/dist/primitives/bashx/src/do/index.js.map +0 -1
- package/dist/primitives/bashx/src/do/tiered-executor.js +0 -2647
- package/dist/primitives/bashx/src/do/tiered-executor.js.map +0 -1
- package/dist/primitives/bashx/src/do/worker.js +0 -352
- package/dist/primitives/bashx/src/do/worker.js.map +0 -1
- package/dist/primitives/bashx/src/types.js +0 -10
- package/dist/primitives/bashx/src/types.js.map +0 -1
- package/dist/primitives/fsx/core/backend.js +0 -480
- package/dist/primitives/fsx/core/backend.js.map +0 -1
- package/dist/primitives/fsx/core/constants.js +0 -140
- package/dist/primitives/fsx/core/constants.js.map +0 -1
- package/dist/primitives/fsx/core/fsx.js +0 -1184
- package/dist/primitives/fsx/core/fsx.js.map +0 -1
- package/dist/primitives/fsx/core/glob/glob.js +0 -438
- package/dist/primitives/fsx/core/glob/glob.js.map +0 -1
- package/dist/primitives/fsx/core/glob/index.js +0 -8
- package/dist/primitives/fsx/core/glob/index.js.map +0 -1
- package/dist/primitives/fsx/core/glob/match.js +0 -392
- package/dist/primitives/fsx/core/glob/match.js.map +0 -1
- package/dist/primitives/fsx/core/types.js +0 -307
- package/dist/primitives/fsx/core/types.js.map +0 -1
- package/dist/sdk/capnweb-compat.js +0 -42
- package/dist/sdk/capnweb-compat.js.map +0 -1
- package/dist/sdk/client.js +0 -20
- package/dist/sdk/client.js.map +0 -1
- package/dist/sdk/index.js +0 -17
- package/dist/sdk/index.js.map +0 -1
|
@@ -1,687 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* System Utilities Commands
|
|
3
|
-
*
|
|
4
|
-
* Native implementations for system utility commands:
|
|
5
|
-
* - sleep: Delay execution for a specified duration
|
|
6
|
-
* - yes: Output a string repeatedly
|
|
7
|
-
* - seq: Generate number sequences
|
|
8
|
-
* - pwd: Print working directory
|
|
9
|
-
* - whoami: Print current username
|
|
10
|
-
* - hostname: Print system hostname
|
|
11
|
-
* - printenv: Print environment variables
|
|
12
|
-
*
|
|
13
|
-
* @module bashx/do/commands/system-utils
|
|
14
|
-
*/
|
|
15
|
-
// ============================================================================
|
|
16
|
-
// SET OF COMMANDS
|
|
17
|
-
// ============================================================================
|
|
18
|
-
/**
|
|
19
|
-
* Set of system utility commands handled by this module
|
|
20
|
-
*/
|
|
21
|
-
export const SYSTEM_UTILS_COMMANDS = new Set([
|
|
22
|
-
'sleep',
|
|
23
|
-
'yes',
|
|
24
|
-
'seq',
|
|
25
|
-
'pwd',
|
|
26
|
-
'whoami',
|
|
27
|
-
'hostname',
|
|
28
|
-
'printenv',
|
|
29
|
-
]);
|
|
30
|
-
/**
|
|
31
|
-
* Check if a command is a system utility command
|
|
32
|
-
*/
|
|
33
|
-
export function isSystemUtilsCommand(cmd) {
|
|
34
|
-
return SYSTEM_UTILS_COMMANDS.has(cmd);
|
|
35
|
-
}
|
|
36
|
-
// ============================================================================
|
|
37
|
-
// TIMING UTILITIES
|
|
38
|
-
// ============================================================================
|
|
39
|
-
/**
|
|
40
|
-
* Time unit multipliers in milliseconds
|
|
41
|
-
*/
|
|
42
|
-
const TIME_UNIT_MS = {
|
|
43
|
-
s: 1000,
|
|
44
|
-
m: 60 * 1000,
|
|
45
|
-
h: 60 * 60 * 1000,
|
|
46
|
-
d: 24 * 60 * 60 * 1000,
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Parse a duration string into milliseconds
|
|
50
|
-
*
|
|
51
|
-
* @param duration - Duration string with optional unit suffix (s, m, h, d)
|
|
52
|
-
* @returns Duration in milliseconds
|
|
53
|
-
* @throws Error if duration format is invalid
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* parseDuration('5') // 5000 (seconds)
|
|
58
|
-
* parseDuration('1.5s') // 1500
|
|
59
|
-
* parseDuration('2m') // 120000
|
|
60
|
-
* parseDuration('1h') // 3600000
|
|
61
|
-
* parseDuration('1d') // 86400000
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export function parseDuration(duration) {
|
|
65
|
-
// Handle 'infinity' case
|
|
66
|
-
if (duration.toLowerCase() === 'infinity') {
|
|
67
|
-
return Infinity;
|
|
68
|
-
}
|
|
69
|
-
const match = duration.match(/^(\d+(?:\.\d+)?)(s|m|h|d)?$/i);
|
|
70
|
-
if (!match) {
|
|
71
|
-
throw new Error(`Invalid duration: ${duration}`);
|
|
72
|
-
}
|
|
73
|
-
const value = parseFloat(match[1]);
|
|
74
|
-
const unit = match[2]?.toLowerCase() || 's';
|
|
75
|
-
return value * (TIME_UNIT_MS[unit] ?? 1000);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Create a delay promise
|
|
79
|
-
*/
|
|
80
|
-
function delay(ms) {
|
|
81
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
82
|
-
}
|
|
83
|
-
// ============================================================================
|
|
84
|
-
// SLEEP COMMAND
|
|
85
|
-
// ============================================================================
|
|
86
|
-
/**
|
|
87
|
-
* Execute sleep command - delay for a specified duration
|
|
88
|
-
*
|
|
89
|
-
* Supports multiple duration arguments which are summed together.
|
|
90
|
-
* Durations can have suffixes: s (seconds, default), m (minutes),
|
|
91
|
-
* h (hours), d (days).
|
|
92
|
-
*
|
|
93
|
-
* @param args - Duration arguments
|
|
94
|
-
* @param options - Sleep options
|
|
95
|
-
* @returns Promise resolving to command result
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* await executeSleep(['1']) // Sleep 1 second
|
|
100
|
-
* await executeSleep(['0.5']) // Sleep 500ms
|
|
101
|
-
* await executeSleep(['1m']) // Sleep 1 minute
|
|
102
|
-
* await executeSleep(['1', '2']) // Sleep 3 seconds total
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export async function executeSleep(args, options = {}) {
|
|
106
|
-
if (args.length === 0) {
|
|
107
|
-
return {
|
|
108
|
-
stdout: '',
|
|
109
|
-
stderr: 'sleep: missing operand',
|
|
110
|
-
exitCode: 1,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
const maxDuration = options.maxDuration ?? 600000; // 10 minutes default max
|
|
114
|
-
try {
|
|
115
|
-
let totalMs = 0;
|
|
116
|
-
for (const duration of args) {
|
|
117
|
-
const ms = parseDuration(duration);
|
|
118
|
-
if (ms < 0) {
|
|
119
|
-
return {
|
|
120
|
-
stdout: '',
|
|
121
|
-
stderr: `sleep: invalid time interval '${duration}'`,
|
|
122
|
-
exitCode: 1,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
if (!isFinite(ms)) {
|
|
126
|
-
// Infinity - would sleep forever, but we'll cap it
|
|
127
|
-
return {
|
|
128
|
-
stdout: '',
|
|
129
|
-
stderr: 'sleep: cannot sleep indefinitely in this environment',
|
|
130
|
-
exitCode: 1,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
totalMs += ms;
|
|
134
|
-
}
|
|
135
|
-
// Apply safety limit
|
|
136
|
-
const actualDuration = Math.min(totalMs, maxDuration);
|
|
137
|
-
await delay(actualDuration);
|
|
138
|
-
return {
|
|
139
|
-
stdout: '',
|
|
140
|
-
stderr: '',
|
|
141
|
-
exitCode: 0,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
146
|
-
return {
|
|
147
|
-
stdout: '',
|
|
148
|
-
stderr: `sleep: ${message}`,
|
|
149
|
-
exitCode: 1,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
// ============================================================================
|
|
154
|
-
// YES COMMAND
|
|
155
|
-
// ============================================================================
|
|
156
|
-
/**
|
|
157
|
-
* Execute yes command - output string repeatedly
|
|
158
|
-
*
|
|
159
|
-
* Outputs "y" (or the specified string) repeatedly, one per line.
|
|
160
|
-
* Limited to maxLines for safety in non-streaming environments.
|
|
161
|
-
*
|
|
162
|
-
* @param args - Optional string to repeat (default: "y")
|
|
163
|
-
* @param options - Yes options
|
|
164
|
-
* @returns Command result
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* executeYes([]) // "y\ny\ny\n..." (1000 times)
|
|
169
|
-
* executeYes(['hello']) // "hello\nhello\nhello\n..." (1000 times)
|
|
170
|
-
* executeYes(['a', 'b']) // "a b\na b\na b\n..." (arguments joined)
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
export function executeYes(args, options = {}) {
|
|
174
|
-
const maxLines = options.maxLines ?? 1000;
|
|
175
|
-
const output = args.length > 0 ? args.join(' ') : 'y';
|
|
176
|
-
const lines = [];
|
|
177
|
-
for (let i = 0; i < maxLines; i++) {
|
|
178
|
-
lines.push(output);
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
stdout: lines.join('\n') + '\n',
|
|
182
|
-
stderr: '',
|
|
183
|
-
exitCode: 0,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
// ============================================================================
|
|
187
|
-
// SEQ COMMAND
|
|
188
|
-
// ============================================================================
|
|
189
|
-
/**
|
|
190
|
-
* Execute seq command - generate number sequence
|
|
191
|
-
*
|
|
192
|
-
* Generates a sequence of numbers from first to last with given increment.
|
|
193
|
-
*
|
|
194
|
-
* @param args - Number arguments: [last], [first, last], or [first, incr, last]
|
|
195
|
-
* @param options - Seq options
|
|
196
|
-
* @returns Command result
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```typescript
|
|
200
|
-
* executeSeq(['5']) // "1\n2\n3\n4\n5\n"
|
|
201
|
-
* executeSeq(['2', '5']) // "2\n3\n4\n5\n"
|
|
202
|
-
* executeSeq(['1', '2', '10']) // "1\n3\n5\n7\n9\n"
|
|
203
|
-
* executeSeq(['5', '-1', '1']) // "5\n4\n3\n2\n1\n"
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
export function executeSeq(args, options = {}) {
|
|
207
|
-
if (args.length === 0) {
|
|
208
|
-
return {
|
|
209
|
-
stdout: '',
|
|
210
|
-
stderr: 'seq: missing operand',
|
|
211
|
-
exitCode: 1,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
// Parse numeric arguments
|
|
215
|
-
const numArgs = [];
|
|
216
|
-
for (const arg of args) {
|
|
217
|
-
const num = parseFloat(arg);
|
|
218
|
-
if (isNaN(num)) {
|
|
219
|
-
return {
|
|
220
|
-
stdout: '',
|
|
221
|
-
stderr: `seq: invalid floating point argument: '${arg}'`,
|
|
222
|
-
exitCode: 1,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
numArgs.push(num);
|
|
226
|
-
}
|
|
227
|
-
// Determine first, increment, last
|
|
228
|
-
let first = 1;
|
|
229
|
-
let increment = 1;
|
|
230
|
-
let last;
|
|
231
|
-
if (numArgs.length === 1) {
|
|
232
|
-
last = numArgs[0];
|
|
233
|
-
}
|
|
234
|
-
else if (numArgs.length === 2) {
|
|
235
|
-
first = numArgs[0];
|
|
236
|
-
last = numArgs[1];
|
|
237
|
-
}
|
|
238
|
-
else if (numArgs.length >= 3) {
|
|
239
|
-
first = numArgs[0];
|
|
240
|
-
increment = numArgs[1];
|
|
241
|
-
last = numArgs[2];
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
return {
|
|
245
|
-
stdout: '',
|
|
246
|
-
stderr: 'seq: missing operand',
|
|
247
|
-
exitCode: 1,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
// Handle impossible ranges
|
|
251
|
-
if (increment === 0) {
|
|
252
|
-
return {
|
|
253
|
-
stdout: '',
|
|
254
|
-
stderr: 'seq: invalid Zero increment value',
|
|
255
|
-
exitCode: 1,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
// Handle backwards sequences
|
|
259
|
-
if ((increment > 0 && first > last) || (increment < 0 && first < last)) {
|
|
260
|
-
return {
|
|
261
|
-
stdout: '',
|
|
262
|
-
stderr: '',
|
|
263
|
-
exitCode: 0,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
const results = [];
|
|
267
|
-
const separator = options.separator ?? '\n';
|
|
268
|
-
// Calculate width for equal-width option
|
|
269
|
-
const firstStr = String(first);
|
|
270
|
-
const lastStr = String(last);
|
|
271
|
-
const maxWidth = Math.max(firstStr.length, lastStr.length);
|
|
272
|
-
// Determine decimal places
|
|
273
|
-
const firstDecimals = (firstStr.split('.')[1] || '').length;
|
|
274
|
-
const incrementDecimals = (String(increment).split('.')[1] || '').length;
|
|
275
|
-
const lastDecimals = (lastStr.split('.')[1] || '').length;
|
|
276
|
-
const decimalPlaces = Math.max(firstDecimals, incrementDecimals, lastDecimals);
|
|
277
|
-
// Safety limit
|
|
278
|
-
const maxIterations = 100000;
|
|
279
|
-
let iterations = 0;
|
|
280
|
-
if (increment > 0) {
|
|
281
|
-
for (let i = first; i <= last && iterations < maxIterations; i += increment) {
|
|
282
|
-
let numStr;
|
|
283
|
-
if (options.format) {
|
|
284
|
-
// Simple format support
|
|
285
|
-
numStr = formatNumber(i, options.format);
|
|
286
|
-
}
|
|
287
|
-
else if (decimalPlaces > 0) {
|
|
288
|
-
numStr = i.toFixed(decimalPlaces);
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
numStr = String(Math.round(i));
|
|
292
|
-
}
|
|
293
|
-
if (options.equalWidth && !options.format) {
|
|
294
|
-
numStr = numStr.padStart(maxWidth, '0');
|
|
295
|
-
}
|
|
296
|
-
results.push(numStr);
|
|
297
|
-
iterations++;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
for (let i = first; i >= last && iterations < maxIterations; i += increment) {
|
|
302
|
-
let numStr;
|
|
303
|
-
if (options.format) {
|
|
304
|
-
numStr = formatNumber(i, options.format);
|
|
305
|
-
}
|
|
306
|
-
else if (decimalPlaces > 0) {
|
|
307
|
-
numStr = i.toFixed(decimalPlaces);
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
numStr = String(Math.round(i));
|
|
311
|
-
}
|
|
312
|
-
if (options.equalWidth && !options.format) {
|
|
313
|
-
numStr = numStr.padStart(maxWidth, '0');
|
|
314
|
-
}
|
|
315
|
-
results.push(numStr);
|
|
316
|
-
iterations++;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return {
|
|
320
|
-
stdout: results.join(separator) + (results.length > 0 ? '\n' : ''),
|
|
321
|
-
stderr: '',
|
|
322
|
-
exitCode: 0,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Format a number using a printf-style format string
|
|
327
|
-
*/
|
|
328
|
-
function formatNumber(value, format) {
|
|
329
|
-
// Support %g, %f, %e formats
|
|
330
|
-
const match = format.match(/%(\d+)?(?:\.(\d+))?([gfeE])/);
|
|
331
|
-
if (!match) {
|
|
332
|
-
return String(value);
|
|
333
|
-
}
|
|
334
|
-
const width = match[1] ? parseInt(match[1], 10) : 0;
|
|
335
|
-
const precision = match[2] ? parseInt(match[2], 10) : undefined;
|
|
336
|
-
const type = match[3];
|
|
337
|
-
let result;
|
|
338
|
-
switch (type) {
|
|
339
|
-
case 'f':
|
|
340
|
-
result = precision !== undefined ? value.toFixed(precision) : value.toFixed(6);
|
|
341
|
-
break;
|
|
342
|
-
case 'e':
|
|
343
|
-
result = precision !== undefined ? value.toExponential(precision) : value.toExponential();
|
|
344
|
-
break;
|
|
345
|
-
case 'E':
|
|
346
|
-
result = (precision !== undefined ? value.toExponential(precision) : value.toExponential()).toUpperCase();
|
|
347
|
-
break;
|
|
348
|
-
case 'g':
|
|
349
|
-
default:
|
|
350
|
-
result = precision !== undefined ? value.toPrecision(precision) : String(value);
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
if (width > result.length) {
|
|
354
|
-
result = result.padStart(width, ' ');
|
|
355
|
-
}
|
|
356
|
-
return result;
|
|
357
|
-
}
|
|
358
|
-
// ============================================================================
|
|
359
|
-
// PWD COMMAND
|
|
360
|
-
// ============================================================================
|
|
361
|
-
/**
|
|
362
|
-
* Execute pwd command - print working directory
|
|
363
|
-
*
|
|
364
|
-
* Returns the current working directory. With -L flag (default), returns
|
|
365
|
-
* the logical path (may include symlinks). With -P flag, returns the
|
|
366
|
-
* physical path (symlinks resolved).
|
|
367
|
-
*
|
|
368
|
-
* @param args - Command arguments (-L or -P)
|
|
369
|
-
* @param context - Execution context with cwd
|
|
370
|
-
* @returns Command result
|
|
371
|
-
*
|
|
372
|
-
* @example
|
|
373
|
-
* ```typescript
|
|
374
|
-
* executePwd([], { cwd: '/home/user' })
|
|
375
|
-
* // => { stdout: '/home/user\n', ... }
|
|
376
|
-
*
|
|
377
|
-
* executePwd(['-P'], { cwd: '/home/user' })
|
|
378
|
-
* // => { stdout: '/home/user\n', ... } (symlinks resolved if any)
|
|
379
|
-
* ```
|
|
380
|
-
*/
|
|
381
|
-
export function executePwd(args, context = {}) {
|
|
382
|
-
// Parse flags
|
|
383
|
-
let usePhysical = false;
|
|
384
|
-
for (const arg of args) {
|
|
385
|
-
if (arg === '-P') {
|
|
386
|
-
usePhysical = true;
|
|
387
|
-
}
|
|
388
|
-
else if (arg === '-L') {
|
|
389
|
-
usePhysical = false;
|
|
390
|
-
}
|
|
391
|
-
else if (arg.startsWith('-') && arg !== '-') {
|
|
392
|
-
return {
|
|
393
|
-
stdout: '',
|
|
394
|
-
stderr: `pwd: invalid option -- '${arg.slice(1)}'`,
|
|
395
|
-
exitCode: 1,
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
// Get current working directory
|
|
400
|
-
let cwd = context.cwd || '/';
|
|
401
|
-
// In Workers environment, we don't have real symlink resolution,
|
|
402
|
-
// but we support the -P flag for compatibility
|
|
403
|
-
if (usePhysical) {
|
|
404
|
-
// Normalize path by removing . and .. components
|
|
405
|
-
cwd = normalizePath(cwd);
|
|
406
|
-
}
|
|
407
|
-
return {
|
|
408
|
-
stdout: cwd + '\n',
|
|
409
|
-
stderr: '',
|
|
410
|
-
exitCode: 0,
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Normalize a path by resolving . and .. components
|
|
415
|
-
*/
|
|
416
|
-
function normalizePath(path) {
|
|
417
|
-
const isAbsolute = path.startsWith('/');
|
|
418
|
-
const parts = path.split('/').filter(p => p && p !== '.');
|
|
419
|
-
const result = [];
|
|
420
|
-
for (const part of parts) {
|
|
421
|
-
if (part === '..') {
|
|
422
|
-
if (result.length > 0 && result[result.length - 1] !== '..') {
|
|
423
|
-
result.pop();
|
|
424
|
-
}
|
|
425
|
-
else if (!isAbsolute) {
|
|
426
|
-
result.push('..');
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
result.push(part);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
const normalized = result.join('/');
|
|
434
|
-
return isAbsolute ? '/' + normalized : normalized || '.';
|
|
435
|
-
}
|
|
436
|
-
// ============================================================================
|
|
437
|
-
// WHOAMI COMMAND
|
|
438
|
-
// ============================================================================
|
|
439
|
-
/**
|
|
440
|
-
* Execute whoami command - print current username
|
|
441
|
-
*
|
|
442
|
-
* Returns the username from context or environment variables.
|
|
443
|
-
* Checks in order: context.user, env.USER, env.LOGNAME, then defaults.
|
|
444
|
-
*
|
|
445
|
-
* @param _args - Command arguments (unused, for interface consistency)
|
|
446
|
-
* @param context - Execution context with user or env
|
|
447
|
-
* @returns Command result
|
|
448
|
-
*
|
|
449
|
-
* @example
|
|
450
|
-
* ```typescript
|
|
451
|
-
* executeWhoami([], { user: 'alice' })
|
|
452
|
-
* // => { stdout: 'alice\n', ... }
|
|
453
|
-
*
|
|
454
|
-
* executeWhoami([], { env: { USER: 'bob' } })
|
|
455
|
-
* // => { stdout: 'bob\n', ... }
|
|
456
|
-
* ```
|
|
457
|
-
*/
|
|
458
|
-
export function executeWhoami(_args, context = {}) {
|
|
459
|
-
// Check context.user first
|
|
460
|
-
if (context.user) {
|
|
461
|
-
return {
|
|
462
|
-
stdout: context.user + '\n',
|
|
463
|
-
stderr: '',
|
|
464
|
-
exitCode: 0,
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
// Check environment variables
|
|
468
|
-
const env = context.env || {};
|
|
469
|
-
const user = env.USER || env.LOGNAME || env.USERNAME;
|
|
470
|
-
if (user) {
|
|
471
|
-
return {
|
|
472
|
-
stdout: user + '\n',
|
|
473
|
-
stderr: '',
|
|
474
|
-
exitCode: 0,
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
// Default for Workers environment
|
|
478
|
-
return {
|
|
479
|
-
stdout: 'worker\n',
|
|
480
|
-
stderr: '',
|
|
481
|
-
exitCode: 0,
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
// ============================================================================
|
|
485
|
-
// HOSTNAME COMMAND
|
|
486
|
-
// ============================================================================
|
|
487
|
-
/**
|
|
488
|
-
* Execute hostname command - print system hostname
|
|
489
|
-
*
|
|
490
|
-
* Returns the hostname from context or environment variables.
|
|
491
|
-
* In Workers environment, defaults to 'worker.local'.
|
|
492
|
-
*
|
|
493
|
-
* @param args - Command arguments (supports -s for short hostname)
|
|
494
|
-
* @param context - Execution context with hostname
|
|
495
|
-
* @returns Command result
|
|
496
|
-
*
|
|
497
|
-
* @example
|
|
498
|
-
* ```typescript
|
|
499
|
-
* executeHostname([], { hostname: 'server.example.com.ai' })
|
|
500
|
-
* // => { stdout: 'server.example.com.ai\n', ... }
|
|
501
|
-
*
|
|
502
|
-
* executeHostname(['-s'], { hostname: 'server.example.com.ai' })
|
|
503
|
-
* // => { stdout: 'server\n', ... }
|
|
504
|
-
* ```
|
|
505
|
-
*/
|
|
506
|
-
export function executeHostname(args, context = {}) {
|
|
507
|
-
// Parse flags
|
|
508
|
-
let shortName = false;
|
|
509
|
-
for (const arg of args) {
|
|
510
|
-
if (arg === '-s' || arg === '--short') {
|
|
511
|
-
shortName = true;
|
|
512
|
-
}
|
|
513
|
-
else if (arg === '-f' || arg === '--fqdn' || arg === '--long') {
|
|
514
|
-
shortName = false;
|
|
515
|
-
}
|
|
516
|
-
else if (arg.startsWith('-') && arg !== '-') {
|
|
517
|
-
return {
|
|
518
|
-
stdout: '',
|
|
519
|
-
stderr: `hostname: invalid option -- '${arg.slice(1)}'`,
|
|
520
|
-
exitCode: 1,
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
// Get hostname from context or environment
|
|
525
|
-
let hostname = context.hostname;
|
|
526
|
-
if (!hostname) {
|
|
527
|
-
const env = context.env || {};
|
|
528
|
-
hostname = env.HOSTNAME || env.HOST || 'worker.local';
|
|
529
|
-
}
|
|
530
|
-
// Return short name if requested
|
|
531
|
-
if (shortName && hostname.includes('.')) {
|
|
532
|
-
hostname = hostname.split('.')[0];
|
|
533
|
-
}
|
|
534
|
-
return {
|
|
535
|
-
stdout: hostname + '\n',
|
|
536
|
-
stderr: '',
|
|
537
|
-
exitCode: 0,
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
// ============================================================================
|
|
541
|
-
// PRINTENV COMMAND
|
|
542
|
-
// ============================================================================
|
|
543
|
-
/**
|
|
544
|
-
* Execute printenv command - print environment variables
|
|
545
|
-
*
|
|
546
|
-
* With no arguments, prints all environment variables.
|
|
547
|
-
* With variable names as arguments, prints only those variables.
|
|
548
|
-
*
|
|
549
|
-
* @param args - Variable names to print (empty for all)
|
|
550
|
-
* @param context - Execution context with env
|
|
551
|
-
* @param options - Printenv options
|
|
552
|
-
* @returns Command result
|
|
553
|
-
*
|
|
554
|
-
* @example
|
|
555
|
-
* ```typescript
|
|
556
|
-
* executePrintenv([], { env: { FOO: 'bar', BAZ: 'qux' } })
|
|
557
|
-
* // => { stdout: 'FOO=bar\nBAZ=qux\n', ... }
|
|
558
|
-
*
|
|
559
|
-
* executePrintenv(['FOO'], { env: { FOO: 'bar', BAZ: 'qux' } })
|
|
560
|
-
* // => { stdout: 'bar\n', ... }
|
|
561
|
-
*
|
|
562
|
-
* executePrintenv(['MISSING'], { env: { FOO: 'bar' } })
|
|
563
|
-
* // => { exitCode: 1, ... }
|
|
564
|
-
* ```
|
|
565
|
-
*/
|
|
566
|
-
export function executePrintenv(args, context = {}, options = {}) {
|
|
567
|
-
const env = context.env || {};
|
|
568
|
-
const separator = options.null ? '\0' : '\n';
|
|
569
|
-
// Parse flags and collect variable names
|
|
570
|
-
const varNames = [];
|
|
571
|
-
for (const arg of args) {
|
|
572
|
-
if (arg === '-0' || arg === '--null') {
|
|
573
|
-
options.null = true;
|
|
574
|
-
}
|
|
575
|
-
else if (arg.startsWith('-') && arg !== '-') {
|
|
576
|
-
// Unknown flag - ignore (printenv is lenient)
|
|
577
|
-
varNames.push(arg);
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
varNames.push(arg);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
if (varNames.length === 0) {
|
|
584
|
-
// Print all environment variables
|
|
585
|
-
const lines = [];
|
|
586
|
-
for (const [key, value] of Object.entries(env)) {
|
|
587
|
-
if (value !== undefined) {
|
|
588
|
-
lines.push(`${key}=${value}`);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
// Sort for consistent output
|
|
592
|
-
lines.sort();
|
|
593
|
-
return {
|
|
594
|
-
stdout: lines.join(separator) + (lines.length > 0 ? separator : ''),
|
|
595
|
-
stderr: '',
|
|
596
|
-
exitCode: 0,
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
// Print specific variables
|
|
600
|
-
const outputs = [];
|
|
601
|
-
let allFound = true;
|
|
602
|
-
for (const name of varNames) {
|
|
603
|
-
const value = env[name];
|
|
604
|
-
if (value !== undefined) {
|
|
605
|
-
outputs.push(value);
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
allFound = false;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return {
|
|
612
|
-
stdout: outputs.join(separator) + (outputs.length > 0 ? separator : ''),
|
|
613
|
-
stderr: '',
|
|
614
|
-
exitCode: allFound ? 0 : 1,
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
// ============================================================================
|
|
618
|
-
// UNIFIED EXECUTOR
|
|
619
|
-
// ============================================================================
|
|
620
|
-
/**
|
|
621
|
-
* Execute a system utility command
|
|
622
|
-
*
|
|
623
|
-
* Routes to the appropriate command implementation based on command name.
|
|
624
|
-
*
|
|
625
|
-
* @param command - Command name
|
|
626
|
-
* @param args - Command arguments
|
|
627
|
-
* @param context - Execution context
|
|
628
|
-
* @returns Command result or null if command not supported
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* ```typescript
|
|
632
|
-
* const result = await executeSystemUtils('pwd', [], { cwd: '/home/user' })
|
|
633
|
-
* // => { stdout: '/home/user\n', stderr: '', exitCode: 0 }
|
|
634
|
-
* ```
|
|
635
|
-
*/
|
|
636
|
-
export async function executeSystemUtils(command, args, context = {}) {
|
|
637
|
-
if (!SYSTEM_UTILS_COMMANDS.has(command)) {
|
|
638
|
-
return null;
|
|
639
|
-
}
|
|
640
|
-
switch (command) {
|
|
641
|
-
case 'sleep':
|
|
642
|
-
return executeSleep(args);
|
|
643
|
-
case 'yes':
|
|
644
|
-
return executeYes(args);
|
|
645
|
-
case 'seq': {
|
|
646
|
-
// Parse seq-specific options
|
|
647
|
-
const seqOptions = {};
|
|
648
|
-
const numArgs = [];
|
|
649
|
-
for (let i = 0; i < args.length; i++) {
|
|
650
|
-
const arg = args[i];
|
|
651
|
-
if (arg === '-s' && args[i + 1] !== undefined) {
|
|
652
|
-
seqOptions.separator = args[++i]
|
|
653
|
-
.replace(/\\t/g, '\t')
|
|
654
|
-
.replace(/\\n/g, '\n');
|
|
655
|
-
}
|
|
656
|
-
else if (arg === '-w') {
|
|
657
|
-
seqOptions.equalWidth = true;
|
|
658
|
-
}
|
|
659
|
-
else if (arg === '-f' && args[i + 1] !== undefined) {
|
|
660
|
-
seqOptions.format = args[++i];
|
|
661
|
-
}
|
|
662
|
-
else if (!arg.startsWith('-')) {
|
|
663
|
-
numArgs.push(arg);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return executeSeq(numArgs, seqOptions);
|
|
667
|
-
}
|
|
668
|
-
case 'pwd': {
|
|
669
|
-
const pwdArgs = args.filter(a => a === '-L' || a === '-P');
|
|
670
|
-
return executePwd(pwdArgs, context);
|
|
671
|
-
}
|
|
672
|
-
case 'whoami':
|
|
673
|
-
return executeWhoami(args, context);
|
|
674
|
-
case 'hostname':
|
|
675
|
-
return executeHostname(args, context);
|
|
676
|
-
case 'printenv': {
|
|
677
|
-
const printenvOptions = {
|
|
678
|
-
null: args.includes('-0') || args.includes('--null'),
|
|
679
|
-
};
|
|
680
|
-
const varArgs = args.filter(a => a !== '-0' && a !== '--null');
|
|
681
|
-
return executePrintenv(varArgs, context, printenvOptions);
|
|
682
|
-
}
|
|
683
|
-
default:
|
|
684
|
-
return null;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
//# sourceMappingURL=system-utils.js.map
|