@pippit-dev/cli 0.0.27 → 0.0.29
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/checksums.txt +6 -6
- package/cmd/short_drama/short_drama.go +2 -2
- package/cmd/update/update.go +15 -3
- package/cmd/update/update_test.go +42 -8
- package/internal/common/client.go +0 -2
- package/internal/{short_drama → common}/get_thread.go +3 -4
- package/package.json +2 -2
- package/scripts/install-wizard.js +23 -6
- package/scripts/run.js +1 -1
- package/scripts/telemetry.js +0 -2
package/checksums.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
c444ddc4fab86a19832f60148c8ce6d51e269796fa15f72a54465b7d763ee70e pippit-tool-cli-0.0.29-darwin-amd64.tar.gz
|
|
2
|
+
64c24941c80b7ce592ca0875fae671fa704e0798416d1f13a2168cd6d37b28b2 pippit-tool-cli-0.0.29-darwin-arm64.tar.gz
|
|
3
|
+
551e089b4a533a9ca6fcdb8c3978b48442a2b16ed4d91ed10e789454910f402d pippit-tool-cli-0.0.29-linux-amd64.tar.gz
|
|
4
|
+
b968b76e2486a04b82bf4fed90859428e076f827a61f692522cf6023772830a6 pippit-tool-cli-0.0.29-linux-arm64.tar.gz
|
|
5
|
+
661f9bd514d04ff1a38143f2b0196fa5dffbd7a8634fac27072d0f9ce71026c1 pippit-tool-cli-0.0.29-windows-amd64.zip
|
|
6
|
+
26bc973e153cf781244cc1cc6175af2d6650563083e9ac1a2061f28932ff6560 pippit-tool-cli-0.0.29-windows-arm64.zip
|
|
@@ -143,7 +143,7 @@ func newShortDramaDownloadResultCommand(stdout, stderr io.Writer, runner *common
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
func newShortDramaGetThreadCommand(stdout, stderr io.Writer, runner *common.Runner) *cobra.Command {
|
|
146
|
-
var opts
|
|
146
|
+
var opts common.GetThreadOptions
|
|
147
147
|
|
|
148
148
|
cmd := &cobra.Command{
|
|
149
149
|
Use: "+get-thread",
|
|
@@ -161,7 +161,7 @@ func newShortDramaGetThreadCommand(stdout, stderr io.Writer, runner *common.Runn
|
|
|
161
161
|
}
|
|
162
162
|
opts.RunID = strings.TrimSpace(opts.RunID)
|
|
163
163
|
|
|
164
|
-
result, err :=
|
|
164
|
+
result, err := common.GetThread(cmd.Context(), &opts, runner)
|
|
165
165
|
if err != nil {
|
|
166
166
|
return err
|
|
167
167
|
}
|
package/cmd/update/update.go
CHANGED
|
@@ -11,6 +11,7 @@ import (
|
|
|
11
11
|
"path/filepath"
|
|
12
12
|
"runtime"
|
|
13
13
|
"strings"
|
|
14
|
+
"sync"
|
|
14
15
|
"time"
|
|
15
16
|
|
|
16
17
|
"github.com/Pippit-dev/pippit-cli/internal/version"
|
|
@@ -23,6 +24,7 @@ const (
|
|
|
23
24
|
defaultTelemetryBaseURL = "https://xyq.jianying.com"
|
|
24
25
|
telemetryPath = "/api/biz/v1/skill/report_telemetry"
|
|
25
26
|
telemetryAuthHeader = "Bearer pippit-cli-skill-telemetry"
|
|
27
|
+
telemetryWaitTimeout = time.Second
|
|
26
28
|
)
|
|
27
29
|
|
|
28
30
|
var legacyGlobalSkills = []string{
|
|
@@ -35,7 +37,7 @@ var telemetrySkillNames = []string{
|
|
|
35
37
|
"xyq-short-drama-skill",
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
var telemetryHTTPClient = &http.Client{Timeout:
|
|
40
|
+
var telemetryHTTPClient = &http.Client{Timeout: telemetryWaitTimeout}
|
|
39
41
|
|
|
40
42
|
// NewCommand builds the update command.
|
|
41
43
|
func NewCommand(stdout, stderr io.Writer) *cobra.Command {
|
|
@@ -137,6 +139,7 @@ func reportBundledSkillTelemetry(event string, source string, stderr io.Writer)
|
|
|
137
139
|
if os.Getenv("PIPPIT_CLI_DISABLE_TELEMETRY") == "1" {
|
|
138
140
|
return
|
|
139
141
|
}
|
|
142
|
+
var wg sync.WaitGroup
|
|
140
143
|
for _, skillName := range telemetrySkillNames {
|
|
141
144
|
payload := telemetryPayload{
|
|
142
145
|
Event: event,
|
|
@@ -146,12 +149,23 @@ func reportBundledSkillTelemetry(event string, source string, stderr io.Writer)
|
|
|
146
149
|
Platform: runtime.GOOS,
|
|
147
150
|
Arch: runtime.GOARCH,
|
|
148
151
|
}
|
|
152
|
+
wg.Add(1)
|
|
149
153
|
go func(payload telemetryPayload) {
|
|
154
|
+
defer wg.Done()
|
|
150
155
|
if err := reportSkillTelemetry(payload); err != nil && os.Getenv("PIPPIT_CLI_DEBUG_TELEMETRY") == "1" {
|
|
151
156
|
fmt.Fprintf(stderr, "[pippit-tool-cli] telemetry failed: %v\n", err)
|
|
152
157
|
}
|
|
153
158
|
}(payload)
|
|
154
159
|
}
|
|
160
|
+
done := make(chan struct{})
|
|
161
|
+
go func() {
|
|
162
|
+
wg.Wait()
|
|
163
|
+
close(done)
|
|
164
|
+
}()
|
|
165
|
+
select {
|
|
166
|
+
case <-done:
|
|
167
|
+
case <-time.After(telemetryWaitTimeout):
|
|
168
|
+
}
|
|
155
169
|
}
|
|
156
170
|
|
|
157
171
|
func reportSkillTelemetry(payload telemetryPayload) error {
|
|
@@ -166,8 +180,6 @@ func reportSkillTelemetry(payload telemetryPayload) error {
|
|
|
166
180
|
}
|
|
167
181
|
req.Header.Set("Content-Type", "application/json")
|
|
168
182
|
req.Header.Set("Authorization", telemetryAuthHeader)
|
|
169
|
-
req.Header.Set("x-use-ppe", "1")
|
|
170
|
-
req.Header.Set("x-tt-env", "ppe_harness_novel_v2")
|
|
171
183
|
|
|
172
184
|
resp, err := telemetryHTTPClient.Do(req)
|
|
173
185
|
if err != nil {
|
|
@@ -10,6 +10,7 @@ import (
|
|
|
10
10
|
"runtime"
|
|
11
11
|
"strings"
|
|
12
12
|
"testing"
|
|
13
|
+
"time"
|
|
13
14
|
)
|
|
14
15
|
|
|
15
16
|
func TestInstallSkillsInstallsAllBundledSkills(t *testing.T) {
|
|
@@ -76,14 +77,12 @@ func TestCleanupLegacyGlobalSkills(t *testing.T) {
|
|
|
76
77
|
|
|
77
78
|
func TestReportSkillTelemetry(t *testing.T) {
|
|
78
79
|
var gotAuth string
|
|
79
|
-
var gotHeaders http.Header
|
|
80
80
|
var gotPayload telemetryPayload
|
|
81
81
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
82
82
|
if r.URL.Path != telemetryPath {
|
|
83
83
|
t.Fatalf("path = %q, want %q", r.URL.Path, telemetryPath)
|
|
84
84
|
}
|
|
85
85
|
gotAuth = r.Header.Get("Authorization")
|
|
86
|
-
gotHeaders = r.Header.Clone()
|
|
87
86
|
if err := json.NewDecoder(r.Body).Decode(&gotPayload); err != nil {
|
|
88
87
|
t.Fatalf("decode request body: %v", err)
|
|
89
88
|
}
|
|
@@ -106,17 +105,52 @@ func TestReportSkillTelemetry(t *testing.T) {
|
|
|
106
105
|
if gotAuth != telemetryAuthHeader {
|
|
107
106
|
t.Fatalf("Authorization = %q, want %q", gotAuth, telemetryAuthHeader)
|
|
108
107
|
}
|
|
109
|
-
if got := gotHeaders.Get("x-use-ppe"); got != "1" {
|
|
110
|
-
t.Fatalf("x-use-ppe = %q, want 1", got)
|
|
111
|
-
}
|
|
112
|
-
if got := gotHeaders.Get("x-tt-env"); got != "ppe_harness_novel_v2" {
|
|
113
|
-
t.Fatalf("x-tt-env = %q, want ppe_harness_novel_v2", got)
|
|
114
|
-
}
|
|
115
108
|
if gotPayload.Event != "update" || gotPayload.SkillName != "xyq-skill" || gotPayload.Source != "cli_update" {
|
|
116
109
|
t.Fatalf("payload = %#v", gotPayload)
|
|
117
110
|
}
|
|
118
111
|
}
|
|
119
112
|
|
|
113
|
+
func TestReportBundledSkillTelemetryWaitsBriefly(t *testing.T) {
|
|
114
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
115
|
+
time.Sleep(2 * time.Second)
|
|
116
|
+
_, _ = w.Write([]byte(`{"ret":"0","errmsg":""}`))
|
|
117
|
+
}))
|
|
118
|
+
defer server.Close()
|
|
119
|
+
|
|
120
|
+
t.Setenv("PIPPIT_CLI_TELEMETRY_BASE_URL", server.URL)
|
|
121
|
+
start := time.Now()
|
|
122
|
+
reportBundledSkillTelemetry("update", "cli_update", &bytes.Buffer{})
|
|
123
|
+
if elapsed := time.Since(start); elapsed > 1500*time.Millisecond {
|
|
124
|
+
t.Fatalf("reportBundledSkillTelemetry() blocked for %v, want <= 1.5s", elapsed)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
func TestReportBundledSkillTelemetryReportsBothSkills(t *testing.T) {
|
|
129
|
+
skillNames := make(chan string, len(telemetrySkillNames))
|
|
130
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
131
|
+
var payload telemetryPayload
|
|
132
|
+
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
|
133
|
+
t.Fatalf("decode request body: %v", err)
|
|
134
|
+
}
|
|
135
|
+
skillNames <- payload.SkillName
|
|
136
|
+
_, _ = w.Write([]byte(`{"ret":"0","errmsg":""}`))
|
|
137
|
+
}))
|
|
138
|
+
defer server.Close()
|
|
139
|
+
|
|
140
|
+
t.Setenv("PIPPIT_CLI_TELEMETRY_BASE_URL", server.URL)
|
|
141
|
+
reportBundledSkillTelemetry("update", "cli_update", &bytes.Buffer{})
|
|
142
|
+
|
|
143
|
+
got := map[string]bool{}
|
|
144
|
+
for i := 0; i < len(telemetrySkillNames); i++ {
|
|
145
|
+
got[<-skillNames] = true
|
|
146
|
+
}
|
|
147
|
+
for _, skillName := range telemetrySkillNames {
|
|
148
|
+
if !got[skillName] {
|
|
149
|
+
t.Fatalf("missing telemetry for %s, got %#v", skillName, got)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
120
154
|
func TestTelemetryBaseURL(t *testing.T) {
|
|
121
155
|
t.Setenv("PIPPIT_CLI_TELEMETRY_BASE_URL", " ")
|
|
122
156
|
t.Setenv("XYQ_OPENAPI_BASE", "https://example.com///")
|
|
@@ -202,8 +202,6 @@ func (c *httpClient) injectHeaders(req *http.Request) {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
req.Header.Set("User-Agent", "Pippit-CLI/1.0")
|
|
205
|
-
req.Header.Set("x-use-ppe", "1")
|
|
206
|
-
req.Header.Set("x-tt-env", "ppe_harness_novel_v2")
|
|
207
205
|
}
|
|
208
206
|
|
|
209
207
|
func (c *httpClient) do(req *http.Request, out any) error {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
package
|
|
1
|
+
package common
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"context"
|
|
5
5
|
"fmt"
|
|
6
6
|
|
|
7
|
-
"github.com/Pippit-dev/pippit-cli/internal/common"
|
|
8
7
|
"github.com/Pippit-dev/pippit-cli/internal/config"
|
|
9
8
|
)
|
|
10
9
|
|
|
@@ -29,7 +28,7 @@ type getThreadResponse struct {
|
|
|
29
28
|
} `json:"data"`
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
func GetThread(ctx context.Context, opts *GetThreadOptions, runner *
|
|
31
|
+
func GetThread(ctx context.Context, opts *GetThreadOptions, runner *Runner) (*GetThreadResult, error) {
|
|
33
32
|
if runner == nil || runner.Client == nil {
|
|
34
33
|
return nil, fmt.Errorf("get_thread runner client is required")
|
|
35
34
|
}
|
|
@@ -61,7 +60,7 @@ func GetThread(ctx context.Context, opts *GetThreadOptions, runner *common.Runne
|
|
|
61
60
|
}, nil
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
func getThreadPath(runner *
|
|
63
|
+
func getThreadPath(runner *Runner) string {
|
|
65
64
|
if runner != nil && runner.Config != nil && runner.Config.Paths != nil && runner.Config.Paths.GetThread != "" {
|
|
66
65
|
return runner.Config.Paths.GetThread
|
|
67
66
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pippit-dev/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "Pippit CLI",
|
|
5
5
|
"bin": {
|
|
6
6
|
"pippit-tool-cli": "scripts/run.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
9
|
"postinstall": "node scripts/install.js",
|
|
10
|
-
"test": "node scripts/version-check.test.js && node scripts/skills.test.js && go test ./... && go vet ./..."
|
|
10
|
+
"test": "node scripts/version-check.test.js && node scripts/skills.test.js && node scripts/install-wizard.test.js && go test ./... && go vet ./..."
|
|
11
11
|
},
|
|
12
12
|
"os": [
|
|
13
13
|
"darwin",
|
|
@@ -6,7 +6,15 @@ const { isWindows, run, runSilent } = require("./platform");
|
|
|
6
6
|
const { DEFAULT_PKG, installGlobalPackageSkills } = require("./skills");
|
|
7
7
|
const { reportBundledSkillTelemetry } = require("./telemetry");
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const VERSION = require("../package.json").version.replace(/-.*$/, "");
|
|
10
|
+
|
|
11
|
+
function defaultInstallPackage() {
|
|
12
|
+
return `${DEFAULT_PKG}@${VERSION}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function installPackage() {
|
|
16
|
+
return process.env.PIPPIT_CLI_INSTALL_PACKAGE || defaultInstallPackage();
|
|
17
|
+
}
|
|
10
18
|
|
|
11
19
|
function getGloballyInstalledVersion() {
|
|
12
20
|
try {
|
|
@@ -38,13 +46,14 @@ function whichPippitToolCli() {
|
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
function main() {
|
|
49
|
+
const pkg = installPackage();
|
|
41
50
|
const installed = getGloballyInstalledVersion();
|
|
42
51
|
if (installed) {
|
|
43
|
-
console.log(`Updating global pippit-tool-cli (${installed}) via ${
|
|
52
|
+
console.log(`Updating global pippit-tool-cli (${installed}) via ${pkg}...`);
|
|
44
53
|
} else {
|
|
45
|
-
console.log(`Installing ${
|
|
54
|
+
console.log(`Installing ${pkg} globally...`);
|
|
46
55
|
}
|
|
47
|
-
run("npm", ["install", "-g",
|
|
56
|
+
run("npm", ["install", "-g", pkg], {
|
|
48
57
|
timeout: 120000,
|
|
49
58
|
env: { ...process.env, PIPPIT_CLI_SKIP_SKILLS: "1" },
|
|
50
59
|
});
|
|
@@ -57,7 +66,7 @@ function main() {
|
|
|
57
66
|
throw err;
|
|
58
67
|
}
|
|
59
68
|
console.log("Existing global package does not contain skills; reinstalling...");
|
|
60
|
-
run("npm", ["install", "-g",
|
|
69
|
+
run("npm", ["install", "-g", pkg], { timeout: 120000 });
|
|
61
70
|
installGlobalPackageSkills(DEFAULT_PKG);
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -73,4 +82,12 @@ function main() {
|
|
|
73
82
|
console.log("Try: pippit-tool-cli short-drama +submit-run --message \"写一个短剧开头\"");
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
main
|
|
85
|
+
if (require.main === module) {
|
|
86
|
+
main();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = {
|
|
90
|
+
defaultInstallPackage,
|
|
91
|
+
installPackage,
|
|
92
|
+
main,
|
|
93
|
+
};
|
package/scripts/run.js
CHANGED
|
@@ -38,7 +38,7 @@ if (process.platform === "win32" && fs.existsSync(oldBin)) {
|
|
|
38
38
|
// Match the lark-cli install entry: `npx @pippit-dev/cli@latest install`
|
|
39
39
|
// should run the JS setup flow before the native binary exists.
|
|
40
40
|
if (args[0] === "install") {
|
|
41
|
-
require("./install-wizard.js");
|
|
41
|
+
require("./install-wizard.js").main();
|
|
42
42
|
} else {
|
|
43
43
|
maybeWarnNewVersion(args);
|
|
44
44
|
|
package/scripts/telemetry.js
CHANGED