@codua/codeoutline-win32-x64 0.1.2 → 0.1.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/DISTRIBUTION.md CHANGED
@@ -97,3 +97,144 @@ workflow does not mean its remote runs have passed. Windows npm launchers forwar
97
97
  console signals; forcefully killing the Node process alone cannot forward a
98
98
  signal. For supervised HTTP services on Windows, use the native launcher or stop
99
99
  the process tree. Closing MCP stdin causes the native stdio service to exit.
100
+
101
+ ## Signed self-updates
102
+
103
+ Starting with 0.1.3, npm and native launchers can run signed versions stored in
104
+ `~/.codeoutline/updates` (the user profile on Windows). npm remains the initial
105
+ installation and recovery version. An older npm installation needs one npm upgrade
106
+ to acquire this updater. Updating does not change npm's recorded package version;
107
+ `codeoutline --version` reports the version actually running.
108
+
109
+ ```sh
110
+ codeoutline update --check
111
+ codeoutline update
112
+ codeoutline update --rollback
113
+ ```
114
+
115
+ Every command starts the newest verified installed version without requesting the
116
+ network. `serve` then checks for updates in a background thread, so an unreachable
117
+ update server never delays startup or requests; a verified update applies to the
118
+ next launch, and failed checks are reported on stderr.
119
+ Set `CODEOUTLINE_AUTO_UPDATE=0` to disable automatic checks. Manual update still works.
120
+ Rollback switches between the two installed versions; after the first update it
121
+ returns to the initial installation. Accepted sequence numbers are retained, so a
122
+ rolled-back release is not immediately reinstalled by automatic checks.
123
+
124
+ The default endpoint is `https://43.133.255.193:51215`, project `codeoutline`,
125
+ channel `stable`. Packages pin the signing public key and the server's TLS CA in
126
+ `keys/`. Private signing keys stay outside the repository and update server.
127
+ `CODEOUTLINE_UPDATE_URL`, `CODEOUTLINE_UPDATE_PROJECT`,
128
+ `CODEOUTLINE_UPDATE_CHANNEL`, `CODEOUTLINE_UPDATE_DIR`,
129
+ `CODEOUTLINE_UPDATE_PUBLIC_KEY`, `CODEOUTLINE_UPDATE_CA`, and
130
+ `CODEOUTLINE_UPDATE_TARGET` override these settings for testing or private deployments.
131
+ Treat these overrides and the initial installation as trusted configuration.
132
+
133
+ To publish, stage a fresh native package for each target with
134
+ `UPDATE_SEQUENCE=N`; N must increase for every release (the 0.1.3 baseline is 3).
135
+ Use `tools/update-release.lua` for a script-only change: it reuses the previous
136
+ platform runtimes, replaces Lua scripts and native launchers, and produces signed
137
+ complete bundles for all three platforms. Upload these as drafts before publishing
138
+ the version to the desired channel. The updater
139
+ checks signatures, file hashes, platform, version, sequence and runtime health
140
+ before activating the directory. CI must produce each platform runtime; a Windows
141
+ package cannot update a Linux or macOS installation.
142
+
143
+ ### Make an all-platform script update with xnet
144
+
145
+ For automatic releases, commit the feature changes and the release tools first,
146
+ then run one command from a clean `main` checkout:
147
+
148
+ ```powershell
149
+ .\bin\xnet.exe tools/release.lua LOG_STDERR=1 LOG_FILE=0
150
+ ```
151
+
152
+ The tool prompts for a new version and rejects versions already present in local
153
+ or remote tags, any XUpgate release (including drafts), npm, or the output folder.
154
+ It assigns the next unused update sequence, runs local tests, updates the source
155
+ version and sequence files, commits only those files as `release: <version>`, and
156
+ pushes the commit and tag atomically. Full mode waits for the tagged GitHub Actions
157
+ CI, downloads and verifies artifacts for that exact commit, signs and uploads all
158
+ three XUpgate drafts, publishes the three npm platform packages then the entry
159
+ package, creates the GitHub release, and finally switches XUpgate stable.
160
+
161
+ Full mode requires Git, Node/npm, OpenSSL and GitHub CLI (`gh`) on PATH, a signed-in
162
+ GitHub account (`gh auth login`), and npm credentials usable for publishing. npm
163
+ may still ask for account-required authentication; configure appropriate publishing
164
+ credentials before attempting unattended releases. Private key and administrator
165
+ credential defaults match the local development setup; `KEY`, `CREDENTIAL_FILE`,
166
+ `URL`, `CA_FILE`, and `RELEASE_DIR` override them.
167
+
168
+ Pass `PROXY=socks5://127.0.0.1:1080` (or set `CODEOUTLINE_RELEASE_PROXY`) when
169
+ GitHub access requires a proxy. The tool uses SOCKS remote DNS (`socks5h`) and
170
+ applies the proxy to Git, GitHub CLI, npm, and XUpgate requests, including child
171
+ upload/publish commands. It changes neither global Git/npm configuration nor the
172
+ calling terminal's proxy environment.
173
+
174
+ For script changes that only need XUpgate, use `MODE=update`. It reuses baseline
175
+ runtimes, checks that their runtime commit matches the current submodule, and does
176
+ not require GitHub CLI or npm publishing authentication:
177
+
178
+ ```powershell
179
+ .\bin\xnet.exe tools/release.lua MODE=update BASE=C:/release/0.1.3 LOG_STDERR=1 LOG_FILE=0
180
+ ```
181
+
182
+ This mode still commits/pushes the release version and tag; CI runs on the tag but
183
+ the local tool does not wait for or publish its npm/GitHub artifacts. npm read
184
+ access remains necessary for duplicate-version checks. The initial npm launcher
185
+ is only upgraded by full npm publication, not an XUpgate script bundle.
186
+
187
+ Use `DRY_RUN=1` to exercise prompting and remote version checks without changing
188
+ files, commits, tags or publications. An explicit `VERSION` is also accepted; a
189
+ duplicate then stops instead of prompting. The default output is `C:/release/<version>`
190
+ on Windows and `dist/releases/<version>` elsewhere. Signed bundles are under
191
+ `<output>/bundles/xupgate`. Full mode stores the downloaded CI artifacts under
192
+ `<output>/ci`. `release-state.json` records the chosen version, sequence and commit.
193
+
194
+ Failures stop the release. Already-created commits/tags, immutable uploads and npm
195
+ versions are retained rather than reverted. Inspect the error before retrying;
196
+ after a partial release, use the recorded version and existing artifacts with the
197
+ individual upload/publish commands instead of rebuilding that version.
198
+
199
+ Run from the repository root. `BASE` contains the extracted CI packages under
200
+ `codeoutline-<target>/native/package`. `OUTPUT` must be a new directory.
201
+ Python is not required. OpenSSL must be on PATH for offline private-key signing;
202
+ the tool verifies each signature against the bundled public key before saving it.
203
+ It verifies the base packages' recorded hashes and preserves their runtime commits.
204
+ Manual bundles record the real source commit/dirty state and are not marked as CI
205
+ release builds. Review and test the staged files before uploading.
206
+
207
+ ```powershell
208
+ .\bin\xnet.exe tools/update-release.lua ACTION=build BASE=C:/release/0.1.3 OUTPUT=C:/release/0.1.4 VERSION=0.1.4 SEQUENCE=4 KEY=C:/private/codeoutline.private.pem LOG_STDERR=1 LOG_FILE=0
209
+ ```
210
+
211
+ Native directories are written under `OUTPUT/native/<target>`. Uploadable signed
212
+ JSON files are under `OUTPUT/xupgate/<target>.json`. The private key is never
213
+ included. The version argument sets the staged version without editing the source
214
+ checkout; npm's Node launcher is outside these native bundles.
215
+
216
+ Use administrator credentials via `XUPGATE_PUBLISH_TOKEN` or an environment file
217
+ containing one `ADMIN_TOKEN=...` line. Credentials are read without printing them.
218
+ The upload step checks existing remote hashes, so an interrupted upload can be
219
+ retried with the same artifacts. Do not rebuild or overwrite an uploaded version.
220
+
221
+ ```powershell
222
+ .\bin\xnet.exe tools/update-release.lua ACTION=upload OUTPUT=C:/release/0.1.4 VERSION=0.1.4 SEQUENCE=4 CREDENTIAL_FILE=C:/private/xupgate-admin.env LOG_STDERR=1 LOG_FILE=0
223
+ .\bin\xnet.exe tools/update-release.lua ACTION=publish OUTPUT=C:/release/0.1.4 VERSION=0.1.4 SEQUENCE=4 CHANNEL=stable CREDENTIAL_FILE=C:/private/xupgate-admin.env LOG_STDERR=1 LOG_FILE=0
224
+ ```
225
+
226
+ `ACTION=publish` verifies that all three matching platform releases exist before
227
+ switching the channel. Both network actions default to the packaged HTTPS server
228
+ and pinned CA; `URL` and `CA_FILE` can override them for another deployment.
229
+ Existing services keep running; an installed update applies on the next launch.
230
+
231
+ The opt-in deployed integration test needs Python, OpenSSL, a staged Windows
232
+ package, and the sibling XUpgate release builder:
233
+
234
+ ```powershell
235
+ python tests/update-deployed.py --stage .update-test/final --credential-file C:/private/xupgate-admin.env
236
+ ```
237
+
238
+ The credential file contains `ADMIN_TOKEN=...`. The test creates a separate project,
239
+ exercises manual and automatic updates, rollback and tamper rejection, and disables
240
+ the project on exit. It never publishes to the production CodeOutline channel.
package/bin/xnet.exe CHANGED
Binary file
package/build-info.json CHANGED
@@ -1 +1 @@
1
- {"runtimeCommit":"f2c3ddfcbd3f04d7dd71543d0878d06e033519a0","lua":"LuaJIT 2.1.1774896198","sourceCommit":"130ebb1f85ca78c52119407f04a45fcb51a51ba6","sourceDirty":false,"releaseReady":true,"note":"Release build from a clean checkout","version":"0.1.2","target":"win32-x64","sha256":{"README.zh-CN.md":"4c2ff0fe0b73b3052f067926e45f9f9792571d9d529c731567b2c0d3b1d2c844","scripts/codeoutline/lang/python.lua":"f7219c04914673ee6bae387c222b09acd433596c746237bdd6650a4f4087b17c","DISTRIBUTION.md":"0de1a4699845a93c811a60bbb1dd3f7c1c4f39916c26e912fed5e621bcaf8b91","scripts/codeoutline/index_worker.lua":"47f80807a458d5c706b1a54f60fb2200ae51f022b21d9039df44611035e9ac40","licenses/mbedtls.txt":"9b405ef4c89342f5eae1dd828882f931747f71001cfba7d114801039b52ad09b","scripts/codeoutline/lang/rust.lua":"f7c21751b1ab08512a406f45bd53546dddfa98ff680b1374d29a4152ae110023","scripts/codeoutline/text.lua":"75f9af87ff5ce62def74f69d8972a6b11ff660723fc5cf515369ee3012ff0675","scripts/codeoutline/main.lua":"287c48d3006bf94fcf84e5e14b9a0a7379857c450f05bd850e3cb29119615d90","scripts/codeoutline/cli.lua":"ba996c3c3def65aab08ba60141a7a98a19dfcc1bbe004ab5d8ea14a7f9f9a08b","scripts/codeoutline/version.lua":"76d6123c414a5d03314de604c292f44e63e51ea3246f2702fca7ab93083b8dae","scripts/codeoutline/lang/c.lua":"1251352bcfac6b6d3704460e00b06cf4f41232144748b41b89db04a5ab594073","scripts/codeoutline/mcp.lua":"f14a2d0b9625544ad32309358121a5ff304839780f52d5c1c8ec548d56c5e901","scripts/codeoutline/command.lua":"e0fabf964487972eee3440f9b4b5e4b85bc713dd0266d7a429a53a96249150a6","scripts/codeoutline/xscan.lua":"508d1fdccee4e856e0f198992bec45d7c8a9a3c191e0a5f71717741db9e00325","scripts/codeoutline/parse.lua":"ccda7a087dc90109fce7a1e64ebe1de0d7c7036990b81b3423ff14b4299bf38f","scripts/codeoutline/common.lua":"ee775ed5b2f7ada7a02851f44b51bd4008bceacbf9700576a474e6732e3c03c2","scripts/codeoutline/lang/csharp.lua":"36ac648b8691c85b8c75d5bcb146fcdfc87992a278e4798f3eb194124e3df2bb","scripts/codeoutline/control.lua":"1dfbea9f1397d9fb3c321c48a8d8ee7fc7928e864588226e55247bd548255bb4","lib/xhttp_codec.lua":"a5b0f127105ba6dbd4a518a214ca55e22c7510e6b2fc8c25c325898d8346ef8c","licenses/xnet2lua.txt":"1aa8af3df70f60f1ebf2d23e14c27af1606057ad9c32a9a0d15fd76cff257532","licenses/libdeflate.txt":"41b60f2caab6bffdd5ba360687bd23ca653c0a1235c00380ecffc939b4cd8d75","scripts/codeoutline/explore.lua":"d9e4e0d0179d00205df96ad0e7442e7bbc87e27481e6d27eb772ca302b5f35d3","LICENSE":"1b63179362acd482b4a9a07ca526b3fce6d9103dcded361de2159ade174568b6","licenses/luajit.txt":"1b10a02c9474cb908da2d87bc908edd8798f9ad28d9a8c53fbd05c13227f7394","THIRD_PARTY.md":"a70238f26ec05b7be4b813fa49c337cfb4d3cd64c36fcd27401d121e0e6e38df","README.md":"a1757e831f9d60d14cf318bd47cf8d9481a3e65b7bf99922064445d5d4913c89","scripts/codeoutline/graph.lua":"1ef35f2e92e9db3bbe9b612bb0cb336a9b57b440c9a066e7ba3ef81574326834","licenses/rpmalloc.txt":"f6c10eb9ec349900767c3dcb8bc71fe4fba2aefea329f05e2608827188016c0f","licenses/lua-cmsgpack.txt":"8edfdc5282278a1268d8a6ee52f9245f1a5fe3d1c8065be00330196b1de49873","scripts/codeoutline/lang/js.lua":"7a25a195356deeef7da3fdaf6e8a483b2a3a230cae3064e5dde2a3556fdcbda9","scripts/codeoutline/lang/go.lua":"f5717cbeabe6d30dad72c473fa445480d7fb6b5546bb262e5f4c46185f0959da","scripts/codeoutline/lang/cpp.lua":"96aebcd8972d5272c11446257f37fe90c10f4130c3c1b5bb71c793d7c25456f4","scripts/codeoutline/http.lua":"33802130445b348ce607e9891d4a9789d34b18338bf5d296f56e0b3c7b0c5493","bin/xnet.exe":"8c04f418e6784ff77405ba6ae50301cea0022af585269a4b57564854723cc442","scripts/codeoutline/path.lua":"407bd960c1ad04e5006b321ce33263393bb40eee5dee5c123be9b36d3ad10937","scripts/codeoutline/lang/lua.lua":"33b038192425e4db29251674e30c73b7a1af849789c49ff6430ee409c062f812","scripts/codeoutline/service.lua":"597c435309abc0d8149b5e88095896c3bba6516146fd587d53b4b6fbf23a553c","scripts/codeoutline/lang/java.lua":"435b6ddcd231679db9e705a604344a3fb6c00b84cc20b2ecd210423ee0b376a6","scripts/codeoutline/index.lua":"08c585a7cb264962ac04beb3bf5bc8a9dd22b4f85644b6fdd6a4e527843fbee9"}}
1
+ {"sha256":{"scripts/codeoutline/explore.lua":"d9e4e0d0179d00205df96ad0e7442e7bbc87e27481e6d27eb772ca302b5f35d3","scripts/xupgate/http_codec.lua":"a5b0f127105ba6dbd4a518a214ca55e22c7510e6b2fc8c25c325898d8346ef8c","scripts/codeoutline/lang/js.lua":"7a25a195356deeef7da3fdaf6e8a483b2a3a230cae3064e5dde2a3556fdcbda9","scripts/codeoutline/graph.lua":"1ef35f2e92e9db3bbe9b612bb0cb336a9b57b440c9a066e7ba3ef81574326834","scripts/xupgate/proxy.lua":"5bf532e7005f44555d6a5277336e5ad395af060585c13a1cdc2441de50e0dcff","keys/update-public.pem":"7ff853339e19631b20ed3fa2cf221daa31c581e2e84d161b344b8f06de6562a8","scripts/codeoutline/lang/lua.lua":"33b038192425e4db29251674e30c73b7a1af849789c49ff6430ee409c062f812","scripts/codeoutline/update_worker.lua":"b067e2ca95e729cb6b392171a2ddd80d06f7c313f3ab0484978664940364eb68","scripts/xupgate/signature.lua":"f07de8a4093d08cc69d3c1d8296d23318c5d81344ece788d4453a9b3b700f000","licenses/xnet2lua.txt":"1aa8af3df70f60f1ebf2d23e14c27af1606057ad9c32a9a0d15fd76cff257532","scripts/codeoutline/lang/python.lua":"f7219c04914673ee6bae387c222b09acd433596c746237bdd6650a4f4087b17c","scripts/codeoutline/version.lua":"955291f8ce69995ab9b24f691bbc2b5bed4b768242c077ae15c1fcb270cb4791","licenses/luajit.txt":"1b10a02c9474cb908da2d87bc908edd8798f9ad28d9a8c53fbd05c13227f7394","scripts/codeoutline/lang/rust.lua":"f7c21751b1ab08512a406f45bd53546dddfa98ff680b1374d29a4152ae110023","scripts/codeoutline/xscan.lua":"508d1fdccee4e856e0f198992bec45d7c8a9a3c191e0a5f71717741db9e00325","codeoutline":"8d00b52027511d56136c8bd345666d2a14ad49591313c80a016d6032f708c02b","codeoutline.cmd":"6414f7fac4c7e384d5b8e9e5e8a89731f7950b48dbe08bcbe149c1a70dbc4407","scripts/codeoutline/main.lua":"0a340e38b5a86753091d72f07a379203656fc39feaa3b54e505a8e93a6deefb0","licenses/libdeflate.txt":"41b60f2caab6bffdd5ba360687bd23ca653c0a1235c00380ecffc939b4cd8d75","LICENSE":"1b63179362acd482b4a9a07ca526b3fce6d9103dcded361de2159ade174568b6","README.zh-CN.md":"4c2ff0fe0b73b3052f067926e45f9f9792571d9d529c731567b2c0d3b1d2c844","licenses/rpmalloc.txt":"f6c10eb9ec349900767c3dcb8bc71fe4fba2aefea329f05e2608827188016c0f","licenses/mbedtls.txt":"9b405ef4c89342f5eae1dd828882f931747f71001cfba7d114801039b52ad09b","scripts/codeoutline/mcp.lua":"f14a2d0b9625544ad32309358121a5ff304839780f52d5c1c8ec548d56c5e901","README.md":"a1757e831f9d60d14cf318bd47cf8d9481a3e65b7bf99922064445d5d4913c89","scripts/codeoutline/path.lua":"407bd960c1ad04e5006b321ce33263393bb40eee5dee5c123be9b36d3ad10937","scripts/xupgate/client.lua":"4bcefd14802f5d44c7c7e5b5aeda25247957212605f426da8c9dfb84ed7f9758","scripts/codeoutline/cli.lua":"ba996c3c3def65aab08ba60141a7a98a19dfcc1bbe004ab5d8ea14a7f9f9a08b","DISTRIBUTION.md":"3b5b1ee53e37873a9fc0c4c65e590f63c42bf989fbd3e2e2ebce5565cbc578af","scripts/codeoutline/parse.lua":"ccda7a087dc90109fce7a1e64ebe1de0d7c7036990b81b3423ff14b4299bf38f","THIRD_PARTY.md":"a70238f26ec05b7be4b813fa49c337cfb4d3cd64c36fcd27401d121e0e6e38df","scripts/codeoutline/lang/c.lua":"1251352bcfac6b6d3704460e00b06cf4f41232144748b41b89db04a5ab594073","lib/xhttp_codec.lua":"a5b0f127105ba6dbd4a518a214ca55e22c7510e6b2fc8c25c325898d8346ef8c","scripts/xupgate/common.lua":"7eb979277887dfae16b325ffdab493673f01b96d00b9c1de11d8aca297368752","keys/update-ca.crt":"d9b5ec3d4628de9c5559871f39841a5f84d47c53ded4d58d6e3bba2b4c669a02","scripts/codeoutline/command.lua":"a2e6f938897407f99573779b71948968cd743e331ca2cd0076cc1a9170559c30","scripts/codeoutline/index.lua":"08c585a7cb264962ac04beb3bf5bc8a9dd22b4f85644b6fdd6a4e527843fbee9","scripts/codeoutline/update_sequence.lua":"cb35cf7e03925c2e901c14aee2deae88aaaff6922644b2f73b428dcba8020e90","scripts/codeoutline/lang/cpp.lua":"96aebcd8972d5272c11446257f37fe90c10f4130c3c1b5bb71c793d7c25456f4","scripts/codeoutline/lang/csharp.lua":"36ac648b8691c85b8c75d5bcb146fcdfc87992a278e4798f3eb194124e3df2bb","bin/xnet.exe":"20e40fbc28bc1496bb3f598c5776cb93a56cc74fccade4d6994c3f4e390580e0","scripts/codeoutline/service.lua":"597c435309abc0d8149b5e88095896c3bba6516146fd587d53b4b6fbf23a553c","scripts/codeoutline/control.lua":"1dfbea9f1397d9fb3c321c48a8d8ee7fc7928e864588226e55247bd548255bb4","scripts/codeoutline/common.lua":"ee775ed5b2f7ada7a02851f44b51bd4008bceacbf9700576a474e6732e3c03c2","scripts/codeoutline/index_worker.lua":"47f80807a458d5c706b1a54f60fb2200ae51f022b21d9039df44611035e9ac40","scripts/codeoutline/lang/go.lua":"f5717cbeabe6d30dad72c473fa445480d7fb6b5546bb262e5f4c46185f0959da","licenses/lua-cmsgpack.txt":"8edfdc5282278a1268d8a6ee52f9245f1a5fe3d1c8065be00330196b1de49873","scripts/codeoutline/text.lua":"75f9af87ff5ce62def74f69d8972a6b11ff660723fc5cf515369ee3012ff0675","scripts/xupgate/http_client.lua":"a189506c3d0fcc454f5e001fdeecdd6349a1019ea0970d11ce2fbfdf035166d6","scripts/codeoutline/http.lua":"33802130445b348ce607e9891d4a9789d34b18338bf5d296f56e0b3c7b0c5493","scripts/codeoutline/updater.lua":"633348e78ca018afca33bfedd3f17340a6400462bd3b5aaa6c57e83919d76f2a","scripts/codeoutline/lang/java.lua":"435b6ddcd231679db9e705a604344a3fb6c00b84cc20b2ecd210423ee0b376a6"},"updateSequence":4,"runtimeCommit":"f2c3ddfcbd3f04d7dd71543d0878d06e033519a0","lua":"LuaJIT 2.1.1774896198","version":"0.1.4","sourceCommit":"23b74bb62f48d65049d60ae36eb3501b4f713f56","target":"win32-x64","releaseReady":true,"note":"Release build from a clean checkout","sourceDirty":false}
package/codeoutline CHANGED
@@ -2,4 +2,12 @@
2
2
  set -eu
3
3
  base=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
4
4
  if [ -n "${CODEOUTLINE_LOG_DIR:-}" ]; then log_out="LOG_DIR=$CODEOUTLINE_LOG_DIR"; else log_out=LOG_FILE=0; fi
5
+ if [ "${1:-}" != "update" ]; then
6
+ if [ "${CODEOUTLINE_AUTO_UPDATE:-}" = "" ]; then
7
+ if [ "${1:-}" = "serve" ]; then CODEOUTLINE_AUTO_UPDATE=1; else CODEOUTLINE_AUTO_UPDATE=0; fi
8
+ export CODEOUTLINE_AUTO_UPDATE
9
+ fi
10
+ selected=$("$base/bin/xnet" "$base/scripts/codeoutline/updater.lua" LOG_STDERR=1 LOG_FILE=0 LOG_LEVEL=ERROR ACTION=select) || selected="$base"
11
+ base="$selected"
12
+ fi
5
13
  exec "$base/bin/xnet" "$base/scripts/codeoutline/command.lua" LOG_STDERR=1 "LOG_LEVEL=${CODEOUTLINE_LOG_LEVEL:-WARN}" "$log_out" "$@"
package/codeoutline.cmd CHANGED
@@ -1,7 +1,14 @@
1
- @echo off
2
- setlocal
3
- if not defined CODEOUTLINE_LOG_LEVEL set "CODEOUTLINE_LOG_LEVEL=WARN"
4
- set "CODEOUTLINE_LOG_OUT=LOG_FILE=0"
5
- if defined CODEOUTLINE_LOG_DIR set "CODEOUTLINE_LOG_OUT=LOG_DIR=%CODEOUTLINE_LOG_DIR%"
6
- "%~dp0bin\xnet.exe" "%~dp0scripts\codeoutline\command.lua" LOG_STDERR=1 "LOG_LEVEL=%CODEOUTLINE_LOG_LEVEL%" "%CODEOUTLINE_LOG_OUT%" %*
7
- exit /b %errorlevel%
1
+ @echo off
2
+ setlocal
3
+ if not defined CODEOUTLINE_LOG_LEVEL set "CODEOUTLINE_LOG_LEVEL=WARN"
4
+ set "CODEOUTLINE_LOG_OUT=LOG_FILE=0"
5
+ if defined CODEOUTLINE_LOG_DIR set "CODEOUTLINE_LOG_OUT=LOG_DIR=%CODEOUTLINE_LOG_DIR%"
6
+ set "CODEOUTLINE_BASE=%~dp0"
7
+ if "%~1"=="update" goto run
8
+ if not defined CODEOUTLINE_AUTO_UPDATE (
9
+ if "%~1"=="serve" (set "CODEOUTLINE_AUTO_UPDATE=1") else (set "CODEOUTLINE_AUTO_UPDATE=0")
10
+ )
11
+ for /f "usebackq delims=" %%R in (`""%~dp0bin\xnet.exe" "%~dp0scripts\codeoutline\updater.lua" LOG_STDERR=1 LOG_FILE=0 LOG_LEVEL=ERROR ACTION=select"`) do set "CODEOUTLINE_BASE=%%R\"
12
+ :run
13
+ "%CODEOUTLINE_BASE%bin\xnet.exe" "%CODEOUTLINE_BASE%scripts\codeoutline\command.lua" LOG_STDERR=1 "LOG_LEVEL=%CODEOUTLINE_LOG_LEVEL%" "%CODEOUTLINE_LOG_OUT%" %*
14
+ exit /b %errorlevel%
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDTDCCAjSgAwIBAgIUGk0p4hd1nhA01S7DyxwhvrKrcBYwDQYJKoZIhvcNAQEL
3
+ BQAwGTEXMBUGA1UEAwwONDMuMTMzLjI1NS4xOTMwHhcNMjYxMDAyMDk1MTM1WhcN
4
+ MjcxMDAyMDk1MTM1WjAZMRcwFQYDVQQDDA40My4xMzMuMjU1LjE5MzCCASIwDQYJ
5
+ KoZIhvcNAQEBBQADggEPADCCAQoCggEBAPog84zcjJT+Vv2UKbU9h/GIwZzBMQP4
6
+ p+vgubALn2s7DAbvS0vlKx0IG3QwP4bD3nlyzreGRisnYclV318/TWGtGUv+XH3U
7
+ xTSl5UXn3ReIm7qSylN2rDOqKjRzLozUk1an4UoQ/JWq8tNJzdyvGN9M+Cg+WvFK
8
+ 1LkiTOjjKno7Q6lPixigcIlkWf714sV0M9wYBYD7zYISiiYOSav3Dp2YjPROluZh
9
+ jc5mQovHAAkZUrs3Sm8u+K74H3TwFb/IMpMmLFcTgsXupPdKnn3be42w4wrAQu4x
10
+ 3Hi2tl4xRJhF61XsGx3gaXXAM2+rfjH7InpaSY+XUf45G3+7UJQ1cw8CAwEAAaOB
11
+ izCBiDAdBgNVHQ4EFgQUOzjvn3TnsLqiYNy97yCk+FFC9OQwHwYDVR0jBBgwFoAU
12
+ Ozjvn3TnsLqiYNy97yCk+FFC9OQwDwYDVR0TAQH/BAUwAwEB/zAgBgNVHREEGTAX
13
+ hwQrhf/BhwR/AAABgglsb2NhbGhvc3QwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJ
14
+ KoZIhvcNAQELBQADggEBAE2iU6xmda3INrREUbvnJvY4UiBK1OfenvObO8avJ8VX
15
+ XeHvW3a4m7bGee90qm2+dTXL/elxPoWn04ph0CxjWTdI4pX9UhnS3SnYvRhALdOZ
16
+ hzDKY1oZkA0nXt3lXXCLfAN/mLi2xaMCVby2M6WX67MZBbdnWp+lpl037gHmRRcm
17
+ /aQtUJRnlQV1wwoxQWluhIJit6UP2Bx+DJgcQ/FlJjZnSdgb+ZpJ3SMrqyewmcnT
18
+ o+b/WKVWwUXFySrSuNmQ7bbbpCXOQTelE+iUM6PnuX5vX8CN2bQwuAV5T+9eSq6P
19
+ d/Ag5Bgs1g1VUkIeftzkQxZutroCk1PLVwEBZ8mtXaM=
20
+ -----END CERTIFICATE-----
@@ -0,0 +1,9 @@
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArD2e8eaxNcdHZORDjU3E
3
+ +hfcn5zMuxEQdIr7EYVXOMlLg0nPaZ0OH97ZvoGRlDlr+inYJjLTAfGx5//GBt6d
4
+ ErCsa8D2brCFa65Wdj/hW+i2wDgDjovin1+rozNdD2mizucZNTiDjcYWOrbkiW0j
5
+ zp2lE+jDI2zJ8zJGFbMJ2u2Sxq8Ri3HbwqAsSHvBEzH/dg1UUldJZvN3ikyLHgae
6
+ P4IY6qlUrU09ZzzSEfcQSvSOHOay4Fx+GYpsQv7FswhS5t3153U6Nml47vbSoQDx
7
+ 9zeCIBVfhdE2KMGQn+HXb9wbgdVzmvkzB8/98CR9tj08zy/ETlU35TshziSd4Ade
8
+ awIDAQAB
9
+ -----END PUBLIC KEY-----
package/package.json CHANGED
@@ -1 +1 @@
1
- {"repository":{"url":"git+https://github.com/1dao/codeoutline.git","type":"git"},"cpu":["x64","arm64"],"license":"BSD-2-Clause","name":"@codua/codeoutline-win32-x64","description":"CodeOutline native runtime and Lua implementation for win32-x64","os":["win32"],"version":"0.1.2","files":["bin/","lib/","scripts/","licenses/","LICENSE","codeoutline","codeoutline.cmd","build-info.json","*.md"],"publishConfig":{"access":"public"}}
1
+ {"publishConfig":{"access":"public"},"description":"CodeOutline native runtime and Lua implementation for win32-x64","cpu":["x64","arm64"],"license":"BSD-2-Clause","repository":{"url":"git+https://github.com/1dao/codeoutline.git","type":"git"},"version":"0.1.4","name":"@codua/codeoutline-win32-x64","files":["bin/","lib/","keys/","scripts/","licenses/","LICENSE","codeoutline","codeoutline.cmd","build-info.json","*.md"],"os":["win32"]}
@@ -12,6 +12,7 @@ Usage:
12
12
  codeoutline status [--project PATH]
13
13
  codeoutline rebuild [--project PATH]
14
14
  codeoutline doctor [--project PATH]
15
+ codeoutline update [--check | --rollback] [--channel CHANNEL]
15
16
  codeoutline --version
16
17
 
17
18
  HTTP options: --allow-host HOST, --allow-origin ORIGIN (repeatable).
@@ -38,6 +39,7 @@ local function parse(args)
38
39
  serve = { stdio = true, http = true, project = true, host = true, port = true,
39
40
  ['allow-root'] = true, ['allow-host'] = true, ['allow-origin'] = true },
40
41
  explore = { project = true, query = true, budget = true },
42
+ update = { check = true, rollback = true, channel = true },
41
43
  status = { project = true }, rebuild = { project = true }, doctor = { project = true },
42
44
  }
43
45
  assert(allowed[command], 'unknown command: ' .. command)
@@ -46,7 +48,7 @@ local function parse(args)
46
48
  local name, value = clean[i]:match('^%-%-([%w-]+)=(.*)$')
47
49
  if not name then name = clean[i]:match('^%-%-([%w-]+)$') end
48
50
  assert(name and (allowed[command][name] or name == 'help'), 'unknown option: ' .. clean[i])
49
- local flag = name == 'stdio' or name == 'http' or name == 'help'
51
+ local flag = name == 'check' or name == 'rollback' or name == 'stdio' or name == 'http' or name == 'help'
50
52
  if flag then
51
53
  assert(value == nil, '--' .. name .. ' does not take a value')
52
54
  value = true
@@ -124,6 +126,10 @@ local function run()
124
126
  local command, options = parse(arg or {})
125
127
  if command == '--help' or command == '-h' or options.help then io.write(help); return 0 end
126
128
  if command == '--version' then io.write(version, '\n'); return 0 end
129
+ if command == 'update' then
130
+ assert(not (options.check and options.rollback), '--check and --rollback are mutually exclusive')
131
+ return require('codeoutline.updater').run(options.check and 'check' or options.rollback and 'rollback' or 'update', options)
132
+ end
127
133
  if command == 'serve' then
128
134
  assert(not not options.stdio ~= not not options.http, 'serve requires exactly one of --stdio or --http')
129
135
  arg = { options.stdio and 'STDIO=1' or 'HTTP=1' }
@@ -43,6 +43,7 @@ end
43
43
  local shared = assert(xshared.create('codeoutline_control', 65536, 256))
44
44
  local jobs, next_id, job_count, worker_ready = {}, 0, 0, false
45
45
  local endpoint, stdio, input = nil, nil, ''
46
+ local updating = false
46
47
  local startup = xtimer.now_ms()
47
48
 
48
49
  local function submit(req, done)
@@ -67,6 +68,10 @@ return {
67
68
  __init = function()
68
69
  assert(xnet.init())
69
70
  assert(xthread.create_thread(2, 'INDEX', scripts .. '/codeoutline/index_worker.lua'))
71
+ -- Launchers enable this for serve. Updating never delays or blocks requests.
72
+ if os.getenv('CODEOUTLINE_AUTO_UPDATE') == '1' then
73
+ updating = xthread.create_thread(3, 'UPDATE', scripts .. '/codeoutline/update_worker.lua') and true
74
+ end
70
75
  if options.STDIO == '1' then
71
76
  assert(xutils.read_stdin, 'Rebuild runtime for nonblocking stdin support')
72
77
  stdio = mcp.new(config, submit, cancel)
@@ -96,6 +101,10 @@ return {
96
101
  elseif op == 'worker_result' then
97
102
  local job = jobs[id]
98
103
  if job then jobs[id], job_count = nil, job_count - 1; job.done(ok, result) end
104
+ elseif op == 'update_result' then
105
+ -- Arguments: error, installed version (nil when already current).
106
+ if id then notice('update unavailable: ' .. tostring(id))
107
+ elseif ok then notice('update ' .. tostring(ok) .. ' installed; restart to use it') end
99
108
  end
100
109
  end,
101
110
  __update = function()
@@ -127,6 +136,7 @@ return {
127
136
  if stdio then stdio:close() end
128
137
  if endpoint then endpoint.close() end
129
138
  xthread.shutdown_thread(2)
139
+ if updating then xthread.shutdown_thread(3) end
130
140
  xnet.uninit()
131
141
  end,
132
142
  }
@@ -0,0 +1 @@
1
+ return 4
@@ -0,0 +1,20 @@
1
+ -- Background update thread: network, verification and installation stay off the
2
+ -- service thread. An installed update applies to the next launch.
3
+ local source = assert(xutils.realpath(debug.getinfo(1, 'S').source:sub(2))):gsub('\\', '/')
4
+ local scripts = assert(source:match('^(.*)/codeoutline/[^/]+$'))
5
+ package.path = scripts .. '/?.lua;' .. package.path
6
+ local updater = require('codeoutline.updater')
7
+
8
+ return {
9
+ __init = function()
10
+ assert(xnet.init()); xtimer.init(16)
11
+ local ok, err = pcall(function()
12
+ require('xupgate.client').open(updater.config()).update(function(update_error, result)
13
+ xthread.post(1, 'update_result', update_error, result and result.version)
14
+ end)
15
+ end)
16
+ if not ok then xthread.post(1, 'update_result', tostring(err)) end
17
+ end,
18
+ __uninit = function() xnet.uninit() end,
19
+ __thread_handle = function() end,
20
+ }
@@ -0,0 +1,72 @@
1
+ -- Update commands and bootstrap selection. Installation stays in Lua.
2
+ local source=assert(xutils.realpath(debug.getinfo(1,'S').source:sub(2))):gsub('\\','/')
3
+ local install=assert(source:match('^(.*)/scripts/codeoutline/[^/]+$'))
4
+ package.path=install .. '/scripts/?.lua;' .. package.path
5
+ local c,u=require('xupgate.common'),require('xutils')
6
+ local M={}
7
+ function M.config(options)
8
+ options=options or {}
9
+ local build=c.decode_json(c.read(install .. '/build-info.json')) or {}
10
+ local home=os.getenv('USERPROFILE') or os.getenv('HOME')
11
+ local target=os.getenv('CODEOUTLINE_UPDATE_TARGET') or build.target
12
+ if not target then target=package.config:sub(1,1)=='\\' and 'win32-x64' or 'linux-x64' end
13
+ local cfg={
14
+ project=os.getenv('CODEOUTLINE_UPDATE_PROJECT') or 'codeoutline',
15
+ platform=target,url=os.getenv('CODEOUTLINE_UPDATE_URL') or 'https://43.133.255.193:51215',
16
+ channel=options.channel or os.getenv('CODEOUTLINE_UPDATE_CHANNEL') or 'stable',
17
+ publicKey=assert(c.read(os.getenv('CODEOUTLINE_UPDATE_PUBLIC_KEY') or install .. '/keys/update-public.pem'),'update public key missing'),
18
+ caFile=os.getenv('CODEOUTLINE_UPDATE_CA') or install .. '/keys/update-ca.crt',
19
+ directory=os.getenv('CODEOUTLINE_UPDATE_DIR') or assert(home,'set CODEOUTLINE_UPDATE_DIR') .. '/.codeoutline/updates',
20
+ minimumSequence=tonumber(os.getenv('CODEOUTLINE_UPDATE_MIN_SEQUENCE')) or build.updateSequence or 0,
21
+ http=require('xupgate.http_client'),
22
+ }
23
+ cfg.validate=function(root,m)
24
+ local info=c.decode_json(c.read(root .. '/build-info.json'))
25
+ assert(info and info.target==cfg.platform and info.version==m.version and info.updateSequence==m.sequence,'package platform/version/sequence mismatch')
26
+ assert(m.entry=='scripts/codeoutline/command.lua','invalid CodeOutline entry')
27
+ local expected=cfg.platform=='win32-x64' and 'bin/xnet.exe' or 'bin/xnet'
28
+ assert(m.runtime==expected,'package runtime missing')
29
+ local function quote(s)
30
+ assert(not s:find('[\r\n"%!&|<>^$;()]') and not s:find(string.char(96),1,true),'unsafe install path')
31
+ if package.config:sub(1,1)=='\\' then return '"' .. s .. '"' end
32
+ assert(not s:find("'",1,true),'unsafe install path');return "'" .. s .. "'"
33
+ end
34
+ local command=quote(root .. '/' .. m.runtime) .. ' ' .. quote(root .. '/' .. m.entry) .. ' LOG_STDERR=1 LOG_FILE=0 LOG_LEVEL=ERROR --version'
35
+ if package.config:sub(1,1)=='\\' then command='"' .. command .. '"' end
36
+ local pipe=assert(io.popen(command));local output=pipe:read('a');local ok=pipe:close()
37
+ assert(ok and output:match('^%s*(.-)%s*$')==m.version,'updated runtime health check failed')
38
+ return true
39
+ end
40
+ return cfg
41
+ end
42
+ function M.run(action,options)
43
+ local api=require('xupgate.client').open(M.config(options))
44
+ local function selected()
45
+ local ok,current=pcall(api.current)
46
+ if not ok then io.stderr:write('codeoutline: installed update invalid; using initial version\n')end
47
+ return ok and current and current.root or install
48
+ end
49
+ local function finish(err,result)
50
+ if action=='select' then
51
+ io.write(selected(),'\n');io.stdout:flush();xthread.stop(0)
52
+ else
53
+ io.write(assert(u.json_pack({ok=not err,error=err,result=result})),'\n');io.stdout:flush();xthread.stop(err and 1 or 0)
54
+ end
55
+ end
56
+ return {__init=function()
57
+ assert(xnet.init());xtimer.init(16)
58
+ -- Selection is local only; serve updates in its background thread.
59
+ if action=='select' then finish(nil)
60
+ elseif action=='rollback' then
61
+ local ok,result=pcall(api.rollback)
62
+ if not ok and tostring(result):find('no previous version',1,true)then ok,result=pcall(api.use_initial)end
63
+ finish(not ok and tostring(result) or nil,ok and result or nil)
64
+ elseif action=='current' then local ok,result=pcall(api.current);finish(not ok and tostring(result) or nil,ok and result or nil)
65
+ elseif action=='check' then api.check(finish)
66
+ else api.update(finish)end
67
+ end,__uninit=function()xnet.uninit()end,__thread_handle=function()end}
68
+ end
69
+ if ...=='codeoutline.updater' then return M end
70
+ local action='select'
71
+ for _,arg in ipairs(arg or {})do local v=arg:match('^ACTION=(.+)$');if v then action=v end end
72
+ return M.run(action)
@@ -1 +1 @@
1
- return '0.1.2'
1
+ return '0.1.4'
@@ -0,0 +1,135 @@
1
+ -- Async calls must originate from a network-active MAIN state.
2
+ -- Public key is pinned by the application, never fetched from the update server.
3
+ local c,u=require('xupgate.common'),require('xutils')
4
+ local M={}
5
+ local function shell_path(path)
6
+ assert(not path:find('[\r\n"%!&|<>^$;()]') and not path:find(string.char(96),1,true),'installation path contains shell metacharacters')
7
+ if package.config:sub(1,1)=='\\' then return '"' .. path .. '"' end
8
+ assert(not path:find("'",1,true),'unsupported installation path')
9
+ return "'" .. path .. "'"
10
+ end
11
+ local function command_ok(command)
12
+ local ok=os.execute(command);return ok==true or ok==0
13
+ end
14
+ function M.open(config)
15
+ assert(c.id(config.project) and c.id(config.platform),'invalid project/platform')
16
+ assert(type(config.publicKey)=='string','pinned publicKey required')
17
+ assert(config.minimumSequence==nil or (type(config.minimumSequence)=='number' and config.minimumSequence>=0 and config.minimumSequence%1==0),'invalid minimumSequence')
18
+ local base=assert(config.url):gsub('/+$','')
19
+ assert(base:match('^https://') or (config.allowLocalHttp and (base:match('^http://127%.0%.0%.1:%d+$') or base:match('^http://localhost:%d+$'))),'HTTPS required outside explicit loopback development')
20
+ assert(c.id(config.channel or 'stable'),'invalid channel')
21
+ assert(u.mkdir_p(config.directory))
22
+ local root=assert(u.realpath(config.directory)):gsub('\\','/') .. '/' .. config.project
23
+ assert(u.mkdir_p(root .. '/versions'))
24
+ local api={}
25
+ local function state()
26
+ local data=c.read(root .. '/current.json',1048576)
27
+ if not data then
28
+ assert(not u.stat(root .. '/current.json').exists,'local state unreadable')
29
+ return {schema=1,highSequence=config.minimumSequence or 0}
30
+ end
31
+ local value=assert(c.decode_json(data),'corrupt local state')
32
+ assert(value.schema==1 and type(value.highSequence)=='number' and value.highSequence>=0 and value.highSequence%1==0,'invalid local state')
33
+ value.highSequence=math.max(value.highSequence,config.minimumSequence or 0)
34
+ assert(not value.current or (type(value.current)=='string' and #value.current==64 and value.current:match('^[0-9a-f]+$')),'invalid current')
35
+ assert(not value.previous or (type(value.previous)=='string' and #value.previous==64 and value.previous:match('^[0-9a-f]+$')),'invalid previous')
36
+ return value
37
+ end
38
+ local function save(value)c.atomic(root .. '/current.json',assert(u.json_pack(value)))end
39
+ local function locked(fn)
40
+ local lock=root .. '/update.lock'
41
+ local command='mkdir ' .. shell_path(lock)
42
+ command=command .. (package.config:sub(1,1)=='\\' and ' 2>nul' or ' 2>/dev/null')
43
+ assert(command_ok(command),'another update is running; inspect stale update.lock after a crashed updater')
44
+ local ok,result=pcall(fn)
45
+ assert(u.rmtree(lock))
46
+ if not ok then error(result) end
47
+ return result
48
+ end
49
+ local function verified(envelope)
50
+ local m=c.manifest(envelope,config.publicKey)
51
+ assert(m.project==config.project and m.platform==config.platform,'manifest target mismatch')
52
+ return m
53
+ end
54
+ function api.current()
55
+ local s=state();if not s.current then return nil end
56
+ local dir=root .. '/versions/' .. s.current
57
+ local envelope=c.decode_json(assert(c.read(dir .. '/manifest.json',1048576)))
58
+ local m=verified(envelope)
59
+ assert(u.stat(dir .. '/complete').exists,'installation incomplete')
60
+ assert(u.sha256_hex(envelope.payload)==s.current,'invalid active identity')
61
+ local files=c.bundle(assert(c.read(dir .. '/bundle.json')),m)
62
+ for _,f in ipairs(files)do assert(c.read(dir .. '/files/' .. f.path)==f.data,'installed file changed')end
63
+ return {version=m.version,sequence=m.sequence,root=dir .. '/files',entry=m.entry,runtime=m.runtime,sha256=m.sha256}
64
+ end
65
+ function api.install(envelope,data)
66
+ local m=verified(envelope);local files=c.bundle(data,m)
67
+ local identity=u.sha256_hex(envelope.payload)
68
+ return locked(function()
69
+ local s=state()
70
+ assert(m.sequence>=s.highSequence,'downgrade/replay rejected; use explicit local rollback')
71
+ if s.current==identity then return api.current()end
72
+ if m.sequence==s.highSequence and s.current then assert(s.previous==identity,'different content at previously accepted sequence')end
73
+ local dir=root .. '/versions/' .. identity
74
+ if not u.stat(dir .. '/complete').exists then
75
+ assert(u.mkdir_p(dir .. '/files'))
76
+ for _,f in ipairs(files)do
77
+ c.write(dir .. '/files/' .. f.path,f.data)
78
+ if f.executable and package.config:sub(1,1)~='\\' then assert(command_ok('chmod 755 ' .. shell_path(dir .. '/files/' .. f.path)),'chmod failed')end
79
+ end
80
+ c.write(dir .. '/bundle.json',data)
81
+ c.write(dir .. '/manifest.json',assert(u.json_pack(envelope)))
82
+ c.atomic(dir .. '/complete','1\n')
83
+ end
84
+ if config.validate then assert(config.validate(dir .. '/files',m),'project health validation failed')end
85
+ save({schema=1,highSequence=math.max(s.highSequence,m.sequence),previous=s.current,current=identity})
86
+ local ok,result=pcall(api.current)
87
+ if not ok then save(s);error(result)end
88
+ return result
89
+ end)
90
+ end
91
+ function api.use_initial()
92
+ return locked(function()
93
+ local s=state()
94
+ save({schema=1,highSequence=s.highSequence,previous=s.current})
95
+ return {initial=true}
96
+ end)
97
+ end
98
+ function api.rollback()
99
+ return locked(function()
100
+ local s=state();assert(s.previous,'no previous version')
101
+ save({schema=1,highSequence=s.highSequence,current=s.previous,previous=s.current})
102
+ local ok,result=pcall(api.current)
103
+ if not ok then save(s);error(result)end
104
+ return result
105
+ end)
106
+ end
107
+ function api.check(callback)
108
+ local http=config.http or dofile('scripts/core/share/xhttp_client.lua')
109
+ http.request({url=base .. '/api/v1/projects/' .. config.project .. '/channels/' .. (config.channel or 'stable') .. '/' .. config.platform,timeout_ms=15000,max_redirects=0,verify=true,ca_file=config.caFile},function(err,resp)
110
+ if err then callback(err);return end
111
+ if resp.status==404 then callback(nil,nil);return end
112
+ if resp.status~=200 then callback('update check HTTP ' .. resp.status);return end
113
+ local ok,m=pcall(function()return verified(assert(c.decode_json(resp.body)))end)
114
+ if not ok then callback(tostring(m));return end
115
+ local loaded,s=pcall(state)
116
+ if not loaded then callback(tostring(s));return end
117
+ if m.sequence<=s.highSequence then callback(nil,nil);return end
118
+ callback(nil,{manifest=m,envelope=c.decode_json(resp.body)})
119
+ end)
120
+ end
121
+ function api.update(callback)
122
+ api.check(function(err,update)
123
+ if err or not update then callback(err,update);return end
124
+ local http=config.http or dofile('scripts/core/share/xhttp_client.lua')
125
+ http.request({url=base .. '/packages/' .. update.manifest.sha256 .. '.json',timeout_ms=120000,max_redirects=0,verify=true,ca_file=config.caFile,decompress=false},function(download_error,resp)
126
+ if download_error then callback(download_error);return end
127
+ if resp.status~=200 then callback('package HTTP ' .. resp.status);return end
128
+ local ok,result=pcall(api.install,update.envelope,resp.body)
129
+ callback(not ok and tostring(result) or nil,ok and result or nil)
130
+ end)
131
+ end)
132
+ end
133
+ return api
134
+ end
135
+ return M