wraptc 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wraptc +4 -4
- package/package.json +2 -2
- package/src/cli/__tests__/cli.test.ts +337 -0
- package/src/cli/index.ts +149 -0
- package/src/core/__tests__/fixtures/configs/project-config.json +14 -0
- package/src/core/__tests__/fixtures/configs/system-config.json +14 -0
- package/src/core/__tests__/fixtures/configs/user-config.json +15 -0
- package/src/core/__tests__/integration/integration.test.ts +241 -0
- package/src/core/__tests__/integration/mock-coder-adapter.test.ts +243 -0
- package/src/core/__tests__/test-utils.ts +136 -0
- package/src/core/__tests__/unit/adapters/runner.test.ts +302 -0
- package/src/core/__tests__/unit/basic-test.test.ts +44 -0
- package/src/core/__tests__/unit/basic.test.ts +12 -0
- package/src/core/__tests__/unit/config.test.ts +244 -0
- package/src/core/__tests__/unit/error-patterns.test.ts +181 -0
- package/src/core/__tests__/unit/memory-monitor.test.ts +354 -0
- package/src/core/__tests__/unit/plugin/registry.test.ts +356 -0
- package/src/core/__tests__/unit/providers/codex.test.ts +173 -0
- package/src/core/__tests__/unit/providers/configurable.test.ts +429 -0
- package/src/core/__tests__/unit/providers/gemini.test.ts +251 -0
- package/src/core/__tests__/unit/providers/opencode.test.ts +258 -0
- package/src/core/__tests__/unit/providers/qwen-code.test.ts +195 -0
- package/src/core/__tests__/unit/providers/simple-codex.test.ts +18 -0
- package/src/core/__tests__/unit/router.test.ts +967 -0
- package/src/core/__tests__/unit/state.test.ts +1079 -0
- package/src/core/__tests__/unit/unified/capabilities.test.ts +186 -0
- package/src/core/__tests__/unit/wrap-terminalcoder.test.ts +32 -0
- package/src/core/adapters/builtin/codex.ts +35 -0
- package/src/core/adapters/builtin/gemini.ts +34 -0
- package/src/core/adapters/builtin/index.ts +31 -0
- package/src/core/adapters/builtin/mock-coder.ts +148 -0
- package/src/core/adapters/builtin/qwen.ts +34 -0
- package/src/core/adapters/define.ts +48 -0
- package/src/core/adapters/index.ts +43 -0
- package/src/core/adapters/loader.ts +143 -0
- package/src/core/adapters/provider-bridge.ts +190 -0
- package/src/core/adapters/runner.ts +437 -0
- package/src/core/adapters/types.ts +172 -0
- package/src/core/config.ts +290 -0
- package/src/core/define-provider.ts +212 -0
- package/src/core/error-patterns.ts +147 -0
- package/src/core/index.ts +130 -0
- package/src/core/memory-monitor.ts +171 -0
- package/src/core/plugin/builtin.ts +87 -0
- package/src/core/plugin/index.ts +34 -0
- package/src/core/plugin/registry.ts +350 -0
- package/src/core/plugin/types.ts +209 -0
- package/src/core/provider-factory.ts +397 -0
- package/src/core/provider-loader.ts +171 -0
- package/src/core/providers/codex.ts +56 -0
- package/src/core/providers/configurable.ts +637 -0
- package/src/core/providers/custom.ts +261 -0
- package/src/core/providers/gemini.ts +41 -0
- package/src/core/providers/index.ts +383 -0
- package/src/core/providers/opencode.ts +168 -0
- package/src/core/providers/qwen-code.ts +41 -0
- package/src/core/router.ts +370 -0
- package/src/core/state.ts +258 -0
- package/src/core/types.ts +206 -0
- package/src/core/unified/capabilities.ts +184 -0
- package/src/core/unified/errors.ts +141 -0
- package/src/core/unified/index.ts +29 -0
- package/src/core/unified/output.ts +189 -0
- package/src/core/wrap-terminalcoder.ts +245 -0
- package/src/mcp/__tests__/server.test.ts +295 -0
- package/src/mcp/server.ts +284 -0
- package/src/test-fixtures/mock-coder.sh +194 -0
- package/dist/cli/index.js +0 -16501
- package/dist/core/index.js +0 -7531
- package/dist/mcp/server.js +0 -14568
- package/dist/wraptc-1.0.2.tgz +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Mock Terminal Coder - Simulates a terminal AI coder CLI for testing
|
|
3
|
+
#
|
|
4
|
+
# Usage:
|
|
5
|
+
# echo "prompt" | ./mock-coder.sh # stdin input
|
|
6
|
+
# ./mock-coder.sh "prompt" # positional input
|
|
7
|
+
# ./mock-coder.sh -p "prompt" # flag input
|
|
8
|
+
# ./mock-coder.sh --prompt "prompt" # long flag input
|
|
9
|
+
#
|
|
10
|
+
# Options:
|
|
11
|
+
# -o, --output <format> Output format: text, json, jsonl (default: text)
|
|
12
|
+
# -s, --stream Enable streaming output
|
|
13
|
+
# -d, --delay <ms> Delay between stream chunks (default: 100)
|
|
14
|
+
# --error <type> Simulate error: rate_limit, auth, timeout, unknown
|
|
15
|
+
# --exit-code <n> Exit with specific code
|
|
16
|
+
# -h, --help Show help
|
|
17
|
+
|
|
18
|
+
set -e
|
|
19
|
+
|
|
20
|
+
# Defaults
|
|
21
|
+
OUTPUT_FORMAT="text"
|
|
22
|
+
STREAMING=false
|
|
23
|
+
DELAY_MS=100
|
|
24
|
+
ERROR_TYPE=""
|
|
25
|
+
EXIT_CODE=0
|
|
26
|
+
PROMPT=""
|
|
27
|
+
|
|
28
|
+
# Parse arguments
|
|
29
|
+
while [[ $# -gt 0 ]]; do
|
|
30
|
+
case $1 in
|
|
31
|
+
-p | --prompt)
|
|
32
|
+
PROMPT="$2"
|
|
33
|
+
shift 2
|
|
34
|
+
;;
|
|
35
|
+
-o | --output)
|
|
36
|
+
OUTPUT_FORMAT="$2"
|
|
37
|
+
shift 2
|
|
38
|
+
;;
|
|
39
|
+
-s | --stream)
|
|
40
|
+
STREAMING=true
|
|
41
|
+
shift
|
|
42
|
+
;;
|
|
43
|
+
-d | --delay)
|
|
44
|
+
DELAY_MS="$2"
|
|
45
|
+
shift 2
|
|
46
|
+
;;
|
|
47
|
+
--error)
|
|
48
|
+
ERROR_TYPE="$2"
|
|
49
|
+
shift 2
|
|
50
|
+
;;
|
|
51
|
+
--exit-code)
|
|
52
|
+
EXIT_CODE="$2"
|
|
53
|
+
shift 2
|
|
54
|
+
;;
|
|
55
|
+
-h | --help)
|
|
56
|
+
echo "Mock Terminal Coder - For testing adapter wrappers"
|
|
57
|
+
echo ""
|
|
58
|
+
echo "Usage: mock-coder.sh [options] [prompt]"
|
|
59
|
+
echo ""
|
|
60
|
+
echo "Options:"
|
|
61
|
+
echo " -p, --prompt <text> Prompt text"
|
|
62
|
+
echo " -o, --output <fmt> Output format: text, json, jsonl"
|
|
63
|
+
echo " -s, --stream Enable streaming"
|
|
64
|
+
echo " -d, --delay <ms> Stream delay (default: 100)"
|
|
65
|
+
echo " --error <type> Simulate error: rate_limit, auth, timeout"
|
|
66
|
+
echo " --exit-code <n> Exit with code"
|
|
67
|
+
exit 0
|
|
68
|
+
;;
|
|
69
|
+
-*)
|
|
70
|
+
echo "Unknown option: $1" >&2
|
|
71
|
+
exit 1
|
|
72
|
+
;;
|
|
73
|
+
*)
|
|
74
|
+
# Positional argument = prompt
|
|
75
|
+
PROMPT="$1"
|
|
76
|
+
shift
|
|
77
|
+
;;
|
|
78
|
+
esac
|
|
79
|
+
done
|
|
80
|
+
|
|
81
|
+
# Read from stdin if no prompt given
|
|
82
|
+
if [[ -z "$PROMPT" ]]; then
|
|
83
|
+
if [[ ! -t 0 ]]; then
|
|
84
|
+
PROMPT=$(cat)
|
|
85
|
+
fi
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
if [[ -z "$PROMPT" ]]; then
|
|
89
|
+
echo "Error: No prompt provided" >&2
|
|
90
|
+
exit 1
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
# Handle error simulation
|
|
94
|
+
if [[ -n "$ERROR_TYPE" ]]; then
|
|
95
|
+
case $ERROR_TYPE in
|
|
96
|
+
rate_limit)
|
|
97
|
+
echo "Error 429: Rate limit exceeded. Please try again later." >&2
|
|
98
|
+
exit 1
|
|
99
|
+
;;
|
|
100
|
+
auth)
|
|
101
|
+
echo "Error 401: Unauthorized. Invalid API key." >&2
|
|
102
|
+
exit 1
|
|
103
|
+
;;
|
|
104
|
+
timeout)
|
|
105
|
+
echo "Error: Request timed out after 30 seconds." >&2
|
|
106
|
+
exit 1
|
|
107
|
+
;;
|
|
108
|
+
context_length)
|
|
109
|
+
echo "Error: Context length exceeded. Maximum is 8192 tokens." >&2
|
|
110
|
+
exit 1
|
|
111
|
+
;;
|
|
112
|
+
*)
|
|
113
|
+
echo "Error: Unknown error occurred." >&2
|
|
114
|
+
exit 1
|
|
115
|
+
;;
|
|
116
|
+
esac
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
# Generate response based on prompt
|
|
120
|
+
generate_response() {
|
|
121
|
+
local prompt="$1"
|
|
122
|
+
|
|
123
|
+
# Simple echo-back with mock "AI" response
|
|
124
|
+
# Note: Order matters! Check more specific patterns first
|
|
125
|
+
if [[ "$prompt" == *"hello"* ]] || [[ "$prompt" == *"Hello"* ]]; then
|
|
126
|
+
echo "Hello! I'm Mock Coder, a simulated AI assistant for testing."
|
|
127
|
+
elif [[ "$prompt" == *"explain"* ]]; then
|
|
128
|
+
# Check explain before code since "explain this code" contains both
|
|
129
|
+
echo "This code does the following:"
|
|
130
|
+
echo "1. Takes an input parameter"
|
|
131
|
+
echo "2. Processes it through the algorithm"
|
|
132
|
+
echo "3. Returns the computed result"
|
|
133
|
+
elif [[ "$prompt" == *"code"* ]] || [[ "$prompt" == *"function"* ]]; then
|
|
134
|
+
echo "Here's a sample function:"
|
|
135
|
+
echo ""
|
|
136
|
+
echo "function greet(name) {"
|
|
137
|
+
echo " return \`Hello, \${name}!\`;"
|
|
138
|
+
echo "}"
|
|
139
|
+
else
|
|
140
|
+
echo "I received your prompt: \"$prompt\""
|
|
141
|
+
echo "Here is my response as Mock Coder."
|
|
142
|
+
fi
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Output based on format
|
|
146
|
+
RESPONSE=$(generate_response "$PROMPT")
|
|
147
|
+
|
|
148
|
+
delay_seconds=$(echo "scale=3; $DELAY_MS / 1000" | bc 2>/dev/null || echo "0.1")
|
|
149
|
+
|
|
150
|
+
case $OUTPUT_FORMAT in
|
|
151
|
+
json)
|
|
152
|
+
if $STREAMING; then
|
|
153
|
+
# Stream JSON chunks
|
|
154
|
+
words=($RESPONSE)
|
|
155
|
+
accumulated=""
|
|
156
|
+
for word in "${words[@]}"; do
|
|
157
|
+
accumulated="$accumulated $word"
|
|
158
|
+
echo "{\"type\":\"chunk\",\"text\":\"$word \"}"
|
|
159
|
+
sleep "$delay_seconds"
|
|
160
|
+
done
|
|
161
|
+
echo "{\"type\":\"complete\",\"text\":\"$accumulated\"}"
|
|
162
|
+
else
|
|
163
|
+
# Single JSON response
|
|
164
|
+
escaped_response=$(echo "$RESPONSE" | sed 's/"/\\"/g' | tr '\n' ' ')
|
|
165
|
+
echo "{\"text\":\"$escaped_response\",\"usage\":{\"inputTokens\":$(echo -n "$PROMPT" | wc -w),\"outputTokens\":$(echo -n "$RESPONSE" | wc -w)}}"
|
|
166
|
+
fi
|
|
167
|
+
;;
|
|
168
|
+
jsonl)
|
|
169
|
+
if $STREAMING; then
|
|
170
|
+
# Stream JSONL (one object per line)
|
|
171
|
+
words=($RESPONSE)
|
|
172
|
+
for word in "${words[@]}"; do
|
|
173
|
+
echo "{\"chunk\":\"$word \"}"
|
|
174
|
+
sleep "$delay_seconds"
|
|
175
|
+
done
|
|
176
|
+
echo "{\"done\":true}"
|
|
177
|
+
else
|
|
178
|
+
echo "{\"response\":\"$RESPONSE\"}"
|
|
179
|
+
fi
|
|
180
|
+
;;
|
|
181
|
+
text | *)
|
|
182
|
+
if $STREAMING; then
|
|
183
|
+
# Stream text line by line
|
|
184
|
+
echo "$RESPONSE" | while IFS= read -r line || [[ -n "$line" ]]; do
|
|
185
|
+
echo "$line"
|
|
186
|
+
sleep "$delay_seconds"
|
|
187
|
+
done
|
|
188
|
+
else
|
|
189
|
+
echo "$RESPONSE"
|
|
190
|
+
fi
|
|
191
|
+
;;
|
|
192
|
+
esac
|
|
193
|
+
|
|
194
|
+
exit $EXIT_CODE
|