diff --git a/docs/generated/commands.md b/docs/generated/commands.md index 69941db..39bc2f1 100644 --- a/docs/generated/commands.md +++ b/docs/generated/commands.md @@ -1,5 +1,5 @@ - + # Generated command reference This reference is generated from the validated, versioned command manifest. Availability is evaluated at runtime; a listed command may still require authentication, a hosted capability, or local tooling. diff --git a/docs/releases/OPERATOR-PACKET-v0.4.0.md b/docs/releases/OPERATOR-PACKET-v0.4.0.md index f1bad1c..7f725b7 100644 --- a/docs/releases/OPERATOR-PACKET-v0.4.0.md +++ b/docs/releases/OPERATOR-PACKET-v0.4.0.md @@ -12,7 +12,7 @@ before evaluating release readiness. | Release scope | Shared Cloud managed-agent inventory, creation, customization and Online DM chat; guided ATS device setup, native strategy preparation and bounded browser observation. | | Version decision | A minor release for the new account-agent workflow and bundled ATS runtime dependency. | | Source identity | Canonical ATS adapter commit `ecdbc5c296f28f2331aea4e031c459f1171b99ea`; per-file SHA-256 custody is recorded in `packages/ats-skills-source.json`. The Agent PR records its final candidate commit. | -| Runtime dependency policy | Exactly `aether-ats-skills` 0.2.0 from the checked-in `packages/ats-skills` workspace, published as a versioned dependency and bundled into the CLI. Its exact registry dependencies are `aether-browser` 0.2.2 and `aether-context` 0.3.1. No additional runtime, optional or peer dependencies; no installation hooks. | +| Runtime dependency policy | Exactly `aether-ats-skills` 0.2.0 and `aether-rc-qr` 0.1.0 are direct runtime dependencies, both source-controlled workspaces and bundled into the CLI. ATS's exact registry dependencies are `aether-browser` 0.2.2 and `aether-context` 0.3.1. The reviewed QR workspace has no registry runtime dependencies. No other runtime, optional or peer dependencies; no installation hooks. | | Source custody | ATS owns the canonical source. The Agent copy must match its recorded upstream source and digest; it is not a separate implementation. | | Required Cloud companion | Cloud #1691 at `13a6ef5857d14d036d7275d123c521a889d804f2`: `/agent/managed`, verified `/identity`, typed ATS profile and additive inventory contract `/1.1`, restacked after Cloud #1687 without replacing its admission/runtime ownership. This client also reads legacy `/1` inventories; local setup requires the verified subject endpoint. | | Local prerequisites | The ATS Python engine and a reachable Agent Browser runtime are separate prerequisites. The npm context dependency is a launcher, not proof that Python memory is installed or verified. | diff --git a/package-lock.json b/package-lock.json index b7178d8..ec01297 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,14 +8,17 @@ "name": "aether-agents", "version": "0.4.0", "bundleDependencies": [ - "aether-ats-skills" + "aether-ats-skills", + "aether-rc-qr" ], "license": "Apache-2.0", "workspaces": [ - "packages/ats-skills" + "packages/ats-skills", + "packages/qrcode-terminal" ], "dependencies": { - "aether-ats-skills": "0.2.0" + "aether-ats-skills": "0.2.0", + "aether-rc-qr": "0.1.0" }, "bin": { "aether": "dist/src/main.js", @@ -407,6 +410,10 @@ "node": ">=18" } }, + "node_modules/aether-rc-qr": { + "resolved": "packages/qrcode-terminal", + "link": true + }, "node_modules/typescript": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", @@ -463,6 +470,11 @@ "engines": { "node": ">=20" } + }, + "packages/qrcode-terminal": { + "name": "aether-rc-qr", + "version": "0.1.0", + "license": "Apache-2.0 AND MIT" } } } diff --git a/package.json b/package.json index 305c5d6..ea9e9f9 100644 --- a/package.json +++ b/package.json @@ -29,10 +29,12 @@ "NOTICE.md", "ATS_ACCEPTABLE_USE_POLICY.md", "packages/ats-skills", + "packages/qrcode-terminal", "packages/ats-skills-source.json" ], "workspaces": [ - "packages/ats-skills" + "packages/ats-skills", + "packages/qrcode-terminal" ], "engines": { "node": ">=24" @@ -85,9 +87,11 @@ "typescript": "7.0.2" }, "dependencies": { - "aether-ats-skills": "0.2.0" + "aether-ats-skills": "0.2.0", + "aether-rc-qr": "0.1.0" }, "bundledDependencies": [ - "aether-ats-skills" + "aether-ats-skills", + "aether-rc-qr" ] } diff --git a/packages/qrcode-terminal/LICENSE b/packages/qrcode-terminal/LICENSE new file mode 100644 index 0000000..54831bb --- /dev/null +++ b/packages/qrcode-terminal/LICENSE @@ -0,0 +1,222 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +============================================================== +This product also include the following software: +============================================================== + + QRCode for JavaScript + + Copyright (c) 2009 Kazuhiko Arase + + URL: http://www.d-project.com/ + + Licensed under the MIT license: + http://www.opensource.org/licenses/mit-license.php + + The word "QR Code" is registered trademark of + DENSO WAVE INCORPORATED + http://www.denso-wave.com/qrcode/faqpatent-e.html + +Located in ./vendor/QRCode +- project has been modified to work in Node and some refactoring was done for code cleanup diff --git a/packages/qrcode-terminal/NOTICE.md b/packages/qrcode-terminal/NOTICE.md new file mode 100644 index 0000000..bdee5d7 --- /dev/null +++ b/packages/qrcode-terminal/NOTICE.md @@ -0,0 +1,8 @@ +This package contains the runtime-only files from qrcode-terminal 0.12.0 +(https://github.com/gtanner/qrcode-terminal), licensed under Apache-2.0. +The vendored QRCode implementation is by Kazuhiko Arase, copyright 2009, +licensed under MIT. Its source notices are preserved. + +The Aether workspace package name and manifest are local. Examples, tests, +command-line entry points and packaging metadata from the upstream package are +omitted; the QR generation algorithm and renderer are unchanged. diff --git a/packages/qrcode-terminal/lib/main.js b/packages/qrcode-terminal/lib/main.js new file mode 100644 index 0000000..37c63b1 --- /dev/null +++ b/packages/qrcode-terminal/lib/main.js @@ -0,0 +1,100 @@ +var QRCode = require('./../vendor/QRCode'), + QRErrorCorrectLevel = require('./../vendor/QRCode/QRErrorCorrectLevel'), + black = "\033[40m \033[0m", + white = "\033[47m \033[0m", + toCell = function (isBlack) { + return isBlack ? black : white; + }, + repeat = function (color) { + return { + times: function (count) { + return new Array(count).join(color); + } + }; + }, + fill = function(length, value) { + var arr = new Array(length); + for (var i = 0; i < length; i++) { + arr[i] = value; + } + return arr; + }; + +module.exports = { + + error: QRErrorCorrectLevel.L, + + generate: function (input, opts, cb) { + if (typeof opts === 'function') { + cb = opts; + opts = {}; + } + + var qrcode = new QRCode(-1, this.error); + qrcode.addData(input); + qrcode.make(); + + var output = ''; + if (opts && opts.small) { + var BLACK = true, WHITE = false; + var moduleCount = qrcode.getModuleCount(); + var moduleData = qrcode.modules.slice(); + + var oddRow = moduleCount % 2 === 1; + if (oddRow) { + moduleData.push(fill(moduleCount, WHITE)); + } + + var platte= { + WHITE_ALL: '\u2588', + WHITE_BLACK: '\u2580', + BLACK_WHITE: '\u2584', + BLACK_ALL: ' ', + }; + + var borderTop = repeat(platte.BLACK_WHITE).times(moduleCount + 3); + var borderBottom = repeat(platte.WHITE_BLACK).times(moduleCount + 3); + output += borderTop + '\n'; + + for (var row = 0; row < moduleCount; row += 2) { + output += platte.WHITE_ALL; + + for (var col = 0; col < moduleCount; col++) { + if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === WHITE) { + output += platte.WHITE_ALL; + } else if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === BLACK) { + output += platte.WHITE_BLACK; + } else if (moduleData[row][col] === BLACK && moduleData[row + 1][col] === WHITE) { + output += platte.BLACK_WHITE; + } else { + output += platte.BLACK_ALL; + } + } + + output += platte.WHITE_ALL + '\n'; + } + + if (!oddRow) { + output += borderBottom; + } + } else { + var border = repeat(white).times(qrcode.getModuleCount() + 3); + + output += border + '\n'; + qrcode.modules.forEach(function (row) { + output += white; + output += row.map(toCell).join(''); + output += white + '\n'; + }); + output += border; + } + + if (cb) cb(output); + else console.log(output); + }, + + setErrorLevel: function (error) { + this.error = QRErrorCorrectLevel[error] || this.error; + } + +}; diff --git a/packages/qrcode-terminal/package.json b/packages/qrcode-terminal/package.json new file mode 100644 index 0000000..ca59d77 --- /dev/null +++ b/packages/qrcode-terminal/package.json @@ -0,0 +1,9 @@ +{ + "name": "aether-rc-qr", + "version": "0.1.0", + "description": "Reviewed terminal QR renderer for Aether RC observer invitations", + "main": "lib/main.js", + "types": "src/index.d.ts", + "license": "Apache-2.0 AND MIT", + "files": ["lib", "vendor", "src/index.d.ts", "LICENSE", "NOTICE.md"] +} diff --git a/packages/qrcode-terminal/src/index.d.ts b/packages/qrcode-terminal/src/index.d.ts new file mode 100644 index 0000000..2f96ab9 --- /dev/null +++ b/packages/qrcode-terminal/src/index.d.ts @@ -0,0 +1,4 @@ +declare const qr: { + generate(input: string, options: { small: boolean }, callback: (rendered: string) => void): void; +}; +export = qr; diff --git a/packages/qrcode-terminal/vendor/QRCode/LICENSE b/packages/qrcode-terminal/vendor/QRCode/LICENSE new file mode 100644 index 0000000..150770c --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2009 Kazuhiko Arase + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/qrcode-terminal/vendor/QRCode/QR8bitByte.js b/packages/qrcode-terminal/vendor/QRCode/QR8bitByte.js new file mode 100644 index 0000000..8460b91 --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QR8bitByte.js @@ -0,0 +1,22 @@ +var QRMode = require('./QRMode'); + +function QR8bitByte(data) { + this.mode = QRMode.MODE_8BIT_BYTE; + this.data = data; +} + +QR8bitByte.prototype = { + + getLength : function() { + return this.data.length; + }, + + write : function(buffer) { + for (var i = 0; i < this.data.length; i++) { + // not JIS ... + buffer.put(this.data.charCodeAt(i), 8); + } + } +}; + +module.exports = QR8bitByte; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRBitBuffer.js b/packages/qrcode-terminal/vendor/QRCode/QRBitBuffer.js new file mode 100644 index 0000000..3e857b5 --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRBitBuffer.js @@ -0,0 +1,38 @@ +function QRBitBuffer() { + this.buffer = []; + this.length = 0; +} + +QRBitBuffer.prototype = { + + get : function(index) { + var bufIndex = Math.floor(index / 8); + return ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1; + }, + + put : function(num, length) { + for (var i = 0; i < length; i++) { + this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1); + } + }, + + getLengthInBits : function() { + return this.length; + }, + + putBit : function(bit) { + + var bufIndex = Math.floor(this.length / 8); + if (this.buffer.length <= bufIndex) { + this.buffer.push(0); + } + + if (bit) { + this.buffer[bufIndex] |= (0x80 >>> (this.length % 8) ); + } + + this.length++; + } +}; + +module.exports = QRBitBuffer; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js b/packages/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js new file mode 100644 index 0000000..14e08fb --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js @@ -0,0 +1,6 @@ +module.exports = { + L : 1, + M : 0, + Q : 3, + H : 2 +}; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRMaskPattern.js b/packages/qrcode-terminal/vendor/QRCode/QRMaskPattern.js new file mode 100644 index 0000000..f6fdeb5 --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRMaskPattern.js @@ -0,0 +1,10 @@ +module.exports = { + PATTERN000 : 0, + PATTERN001 : 1, + PATTERN010 : 2, + PATTERN011 : 3, + PATTERN100 : 4, + PATTERN101 : 5, + PATTERN110 : 6, + PATTERN111 : 7 +}; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRMath.js b/packages/qrcode-terminal/vendor/QRCode/QRMath.js new file mode 100644 index 0000000..11e324c --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRMath.js @@ -0,0 +1,44 @@ +var QRMath = { + + glog : function(n) { + + if (n < 1) { + throw new Error("glog(" + n + ")"); + } + + return QRMath.LOG_TABLE[n]; + }, + + gexp : function(n) { + + while (n < 0) { + n += 255; + } + + while (n >= 256) { + n -= 255; + } + + return QRMath.EXP_TABLE[n]; + }, + + EXP_TABLE : new Array(256), + + LOG_TABLE : new Array(256) + +}; + +for (var i = 0; i < 8; i++) { + QRMath.EXP_TABLE[i] = 1 << i; +} +for (var i = 8; i < 256; i++) { + QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] + ^ QRMath.EXP_TABLE[i - 5] + ^ QRMath.EXP_TABLE[i - 6] + ^ QRMath.EXP_TABLE[i - 8]; +} +for (var i = 0; i < 255; i++) { + QRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i; +} + +module.exports = QRMath; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRMode.js b/packages/qrcode-terminal/vendor/QRCode/QRMode.js new file mode 100644 index 0000000..050c8a3 --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRMode.js @@ -0,0 +1,6 @@ +module.exports = { + MODE_NUMBER : 1 << 0, + MODE_ALPHA_NUM : 1 << 1, + MODE_8BIT_BYTE : 1 << 2, + MODE_KANJI : 1 << 3 +}; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRPolynomial.js b/packages/qrcode-terminal/vendor/QRCode/QRPolynomial.js new file mode 100644 index 0000000..f8754cb --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRPolynomial.js @@ -0,0 +1,66 @@ +var QRMath = require('./QRMath'); + +function QRPolynomial(num, shift) { + if (num.length === undefined) { + throw new Error(num.length + "/" + shift); + } + + var offset = 0; + + while (offset < num.length && num[offset] === 0) { + offset++; + } + + this.num = new Array(num.length - offset + shift); + for (var i = 0; i < num.length - offset; i++) { + this.num[i] = num[i + offset]; + } +} + +QRPolynomial.prototype = { + + get : function(index) { + return this.num[index]; + }, + + getLength : function() { + return this.num.length; + }, + + multiply : function(e) { + + var num = new Array(this.getLength() + e.getLength() - 1); + + for (var i = 0; i < this.getLength(); i++) { + for (var j = 0; j < e.getLength(); j++) { + num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i) ) + QRMath.glog(e.get(j) ) ); + } + } + + return new QRPolynomial(num, 0); + }, + + mod : function(e) { + + if (this.getLength() - e.getLength() < 0) { + return this; + } + + var ratio = QRMath.glog(this.get(0) ) - QRMath.glog(e.get(0) ); + + var num = new Array(this.getLength() ); + + for (var i = 0; i < this.getLength(); i++) { + num[i] = this.get(i); + } + + for (var x = 0; x < e.getLength(); x++) { + num[x] ^= QRMath.gexp(QRMath.glog(e.get(x) ) + ratio); + } + + // recursive call + return new QRPolynomial(num, 0).mod(e); + } +}; + +module.exports = QRPolynomial; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRRSBlock.js b/packages/qrcode-terminal/vendor/QRCode/QRRSBlock.js new file mode 100644 index 0000000..becd24d --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRRSBlock.js @@ -0,0 +1,298 @@ +var QRErrorCorrectLevel = require('./QRErrorCorrectLevel'); + +function QRRSBlock(totalCount, dataCount) { + this.totalCount = totalCount; + this.dataCount = dataCount; +} + +QRRSBlock.RS_BLOCK_TABLE = [ + + // L + // M + // Q + // H + + // 1 + [1, 26, 19], + [1, 26, 16], + [1, 26, 13], + [1, 26, 9], + + // 2 + [1, 44, 34], + [1, 44, 28], + [1, 44, 22], + [1, 44, 16], + + // 3 + [1, 70, 55], + [1, 70, 44], + [2, 35, 17], + [2, 35, 13], + + // 4 + [1, 100, 80], + [2, 50, 32], + [2, 50, 24], + [4, 25, 9], + + // 5 + [1, 134, 108], + [2, 67, 43], + [2, 33, 15, 2, 34, 16], + [2, 33, 11, 2, 34, 12], + + // 6 + [2, 86, 68], + [4, 43, 27], + [4, 43, 19], + [4, 43, 15], + + // 7 + [2, 98, 78], + [4, 49, 31], + [2, 32, 14, 4, 33, 15], + [4, 39, 13, 1, 40, 14], + + // 8 + [2, 121, 97], + [2, 60, 38, 2, 61, 39], + [4, 40, 18, 2, 41, 19], + [4, 40, 14, 2, 41, 15], + + // 9 + [2, 146, 116], + [3, 58, 36, 2, 59, 37], + [4, 36, 16, 4, 37, 17], + [4, 36, 12, 4, 37, 13], + + // 10 + [2, 86, 68, 2, 87, 69], + [4, 69, 43, 1, 70, 44], + [6, 43, 19, 2, 44, 20], + [6, 43, 15, 2, 44, 16], + + // 11 + [4, 101, 81], + [1, 80, 50, 4, 81, 51], + [4, 50, 22, 4, 51, 23], + [3, 36, 12, 8, 37, 13], + + // 12 + [2, 116, 92, 2, 117, 93], + [6, 58, 36, 2, 59, 37], + [4, 46, 20, 6, 47, 21], + [7, 42, 14, 4, 43, 15], + + // 13 + [4, 133, 107], + [8, 59, 37, 1, 60, 38], + [8, 44, 20, 4, 45, 21], + [12, 33, 11, 4, 34, 12], + + // 14 + [3, 145, 115, 1, 146, 116], + [4, 64, 40, 5, 65, 41], + [11, 36, 16, 5, 37, 17], + [11, 36, 12, 5, 37, 13], + + // 15 + [5, 109, 87, 1, 110, 88], + [5, 65, 41, 5, 66, 42], + [5, 54, 24, 7, 55, 25], + [11, 36, 12], + + // 16 + [5, 122, 98, 1, 123, 99], + [7, 73, 45, 3, 74, 46], + [15, 43, 19, 2, 44, 20], + [3, 45, 15, 13, 46, 16], + + // 17 + [1, 135, 107, 5, 136, 108], + [10, 74, 46, 1, 75, 47], + [1, 50, 22, 15, 51, 23], + [2, 42, 14, 17, 43, 15], + + // 18 + [5, 150, 120, 1, 151, 121], + [9, 69, 43, 4, 70, 44], + [17, 50, 22, 1, 51, 23], + [2, 42, 14, 19, 43, 15], + + // 19 + [3, 141, 113, 4, 142, 114], + [3, 70, 44, 11, 71, 45], + [17, 47, 21, 4, 48, 22], + [9, 39, 13, 16, 40, 14], + + // 20 + [3, 135, 107, 5, 136, 108], + [3, 67, 41, 13, 68, 42], + [15, 54, 24, 5, 55, 25], + [15, 43, 15, 10, 44, 16], + + // 21 + [4, 144, 116, 4, 145, 117], + [17, 68, 42], + [17, 50, 22, 6, 51, 23], + [19, 46, 16, 6, 47, 17], + + // 22 + [2, 139, 111, 7, 140, 112], + [17, 74, 46], + [7, 54, 24, 16, 55, 25], + [34, 37, 13], + + // 23 + [4, 151, 121, 5, 152, 122], + [4, 75, 47, 14, 76, 48], + [11, 54, 24, 14, 55, 25], + [16, 45, 15, 14, 46, 16], + + // 24 + [6, 147, 117, 4, 148, 118], + [6, 73, 45, 14, 74, 46], + [11, 54, 24, 16, 55, 25], + [30, 46, 16, 2, 47, 17], + + // 25 + [8, 132, 106, 4, 133, 107], + [8, 75, 47, 13, 76, 48], + [7, 54, 24, 22, 55, 25], + [22, 45, 15, 13, 46, 16], + + // 26 + [10, 142, 114, 2, 143, 115], + [19, 74, 46, 4, 75, 47], + [28, 50, 22, 6, 51, 23], + [33, 46, 16, 4, 47, 17], + + // 27 + [8, 152, 122, 4, 153, 123], + [22, 73, 45, 3, 74, 46], + [8, 53, 23, 26, 54, 24], + [12, 45, 15, 28, 46, 16], + + // 28 + [3, 147, 117, 10, 148, 118], + [3, 73, 45, 23, 74, 46], + [4, 54, 24, 31, 55, 25], + [11, 45, 15, 31, 46, 16], + + // 29 + [7, 146, 116, 7, 147, 117], + [21, 73, 45, 7, 74, 46], + [1, 53, 23, 37, 54, 24], + [19, 45, 15, 26, 46, 16], + + // 30 + [5, 145, 115, 10, 146, 116], + [19, 75, 47, 10, 76, 48], + [15, 54, 24, 25, 55, 25], + [23, 45, 15, 25, 46, 16], + + // 31 + [13, 145, 115, 3, 146, 116], + [2, 74, 46, 29, 75, 47], + [42, 54, 24, 1, 55, 25], + [23, 45, 15, 28, 46, 16], + + // 32 + [17, 145, 115], + [10, 74, 46, 23, 75, 47], + [10, 54, 24, 35, 55, 25], + [19, 45, 15, 35, 46, 16], + + // 33 + [17, 145, 115, 1, 146, 116], + [14, 74, 46, 21, 75, 47], + [29, 54, 24, 19, 55, 25], + [11, 45, 15, 46, 46, 16], + + // 34 + [13, 145, 115, 6, 146, 116], + [14, 74, 46, 23, 75, 47], + [44, 54, 24, 7, 55, 25], + [59, 46, 16, 1, 47, 17], + + // 35 + [12, 151, 121, 7, 152, 122], + [12, 75, 47, 26, 76, 48], + [39, 54, 24, 14, 55, 25], + [22, 45, 15, 41, 46, 16], + + // 36 + [6, 151, 121, 14, 152, 122], + [6, 75, 47, 34, 76, 48], + [46, 54, 24, 10, 55, 25], + [2, 45, 15, 64, 46, 16], + + // 37 + [17, 152, 122, 4, 153, 123], + [29, 74, 46, 14, 75, 47], + [49, 54, 24, 10, 55, 25], + [24, 45, 15, 46, 46, 16], + + // 38 + [4, 152, 122, 18, 153, 123], + [13, 74, 46, 32, 75, 47], + [48, 54, 24, 14, 55, 25], + [42, 45, 15, 32, 46, 16], + + // 39 + [20, 147, 117, 4, 148, 118], + [40, 75, 47, 7, 76, 48], + [43, 54, 24, 22, 55, 25], + [10, 45, 15, 67, 46, 16], + + // 40 + [19, 148, 118, 6, 149, 119], + [18, 75, 47, 31, 76, 48], + [34, 54, 24, 34, 55, 25], + [20, 45, 15, 61, 46, 16] +]; + +QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) { + + var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel); + + if (rsBlock === undefined) { + throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel); + } + + var length = rsBlock.length / 3; + + var list = []; + + for (var i = 0; i < length; i++) { + + var count = rsBlock[i * 3 + 0]; + var totalCount = rsBlock[i * 3 + 1]; + var dataCount = rsBlock[i * 3 + 2]; + + for (var j = 0; j < count; j++) { + list.push(new QRRSBlock(totalCount, dataCount) ); + } + } + + return list; +}; + +QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) { + + switch(errorCorrectLevel) { + case QRErrorCorrectLevel.L : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; + case QRErrorCorrectLevel.M : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; + case QRErrorCorrectLevel.Q : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; + case QRErrorCorrectLevel.H : + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; + default : + return undefined; + } +}; + +module.exports = QRRSBlock; diff --git a/packages/qrcode-terminal/vendor/QRCode/QRUtil.js b/packages/qrcode-terminal/vendor/QRCode/QRUtil.js new file mode 100644 index 0000000..31008cb --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/QRUtil.js @@ -0,0 +1,272 @@ +var QRMode = require('./QRMode'); +var QRPolynomial = require('./QRPolynomial'); +var QRMath = require('./QRMath'); +var QRMaskPattern = require('./QRMaskPattern'); + +var QRUtil = { + + PATTERN_POSITION_TABLE : [ + [], + [6, 18], + [6, 22], + [6, 26], + [6, 30], + [6, 34], + [6, 22, 38], + [6, 24, 42], + [6, 26, 46], + [6, 28, 50], + [6, 30, 54], + [6, 32, 58], + [6, 34, 62], + [6, 26, 46, 66], + [6, 26, 48, 70], + [6, 26, 50, 74], + [6, 30, 54, 78], + [6, 30, 56, 82], + [6, 30, 58, 86], + [6, 34, 62, 90], + [6, 28, 50, 72, 94], + [6, 26, 50, 74, 98], + [6, 30, 54, 78, 102], + [6, 28, 54, 80, 106], + [6, 32, 58, 84, 110], + [6, 30, 58, 86, 114], + [6, 34, 62, 90, 118], + [6, 26, 50, 74, 98, 122], + [6, 30, 54, 78, 102, 126], + [6, 26, 52, 78, 104, 130], + [6, 30, 56, 82, 108, 134], + [6, 34, 60, 86, 112, 138], + [6, 30, 58, 86, 114, 142], + [6, 34, 62, 90, 118, 146], + [6, 30, 54, 78, 102, 126, 150], + [6, 24, 50, 76, 102, 128, 154], + [6, 28, 54, 80, 106, 132, 158], + [6, 32, 58, 84, 110, 136, 162], + [6, 26, 54, 82, 110, 138, 166], + [6, 30, 58, 86, 114, 142, 170] + ], + + G15 : (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0), + G18 : (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0), + G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), + + getBCHTypeInfo : function(data) { + var d = data << 10; + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { + d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) ); + } + return ( (data << 10) | d) ^ QRUtil.G15_MASK; + }, + + getBCHTypeNumber : function(data) { + var d = data << 12; + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { + d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) ); + } + return (data << 12) | d; + }, + + getBCHDigit : function(data) { + + var digit = 0; + + while (data !== 0) { + digit++; + data >>>= 1; + } + + return digit; + }, + + getPatternPosition : function(typeNumber) { + return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; + }, + + getMask : function(maskPattern, i, j) { + + switch (maskPattern) { + + case QRMaskPattern.PATTERN000 : return (i + j) % 2 === 0; + case QRMaskPattern.PATTERN001 : return i % 2 === 0; + case QRMaskPattern.PATTERN010 : return j % 3 === 0; + case QRMaskPattern.PATTERN011 : return (i + j) % 3 === 0; + case QRMaskPattern.PATTERN100 : return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 === 0; + case QRMaskPattern.PATTERN101 : return (i * j) % 2 + (i * j) % 3 === 0; + case QRMaskPattern.PATTERN110 : return ( (i * j) % 2 + (i * j) % 3) % 2 === 0; + case QRMaskPattern.PATTERN111 : return ( (i * j) % 3 + (i + j) % 2) % 2 === 0; + + default : + throw new Error("bad maskPattern:" + maskPattern); + } + }, + + getErrorCorrectPolynomial : function(errorCorrectLength) { + + var a = new QRPolynomial([1], 0); + + for (var i = 0; i < errorCorrectLength; i++) { + a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0) ); + } + + return a; + }, + + getLengthInBits : function(mode, type) { + + if (1 <= type && type < 10) { + + // 1 - 9 + + switch(mode) { + case QRMode.MODE_NUMBER : return 10; + case QRMode.MODE_ALPHA_NUM : return 9; + case QRMode.MODE_8BIT_BYTE : return 8; + case QRMode.MODE_KANJI : return 8; + default : + throw new Error("mode:" + mode); + } + + } else if (type < 27) { + + // 10 - 26 + + switch(mode) { + case QRMode.MODE_NUMBER : return 12; + case QRMode.MODE_ALPHA_NUM : return 11; + case QRMode.MODE_8BIT_BYTE : return 16; + case QRMode.MODE_KANJI : return 10; + default : + throw new Error("mode:" + mode); + } + + } else if (type < 41) { + + // 27 - 40 + + switch(mode) { + case QRMode.MODE_NUMBER : return 14; + case QRMode.MODE_ALPHA_NUM : return 13; + case QRMode.MODE_8BIT_BYTE : return 16; + case QRMode.MODE_KANJI : return 12; + default : + throw new Error("mode:" + mode); + } + + } else { + throw new Error("type:" + type); + } + }, + + getLostPoint : function(qrCode) { + + var moduleCount = qrCode.getModuleCount(); + var lostPoint = 0; + var row = 0; + var col = 0; + + + // LEVEL1 + + for (row = 0; row < moduleCount; row++) { + + for (col = 0; col < moduleCount; col++) { + + var sameCount = 0; + var dark = qrCode.isDark(row, col); + + for (var r = -1; r <= 1; r++) { + + if (row + r < 0 || moduleCount <= row + r) { + continue; + } + + for (var c = -1; c <= 1; c++) { + + if (col + c < 0 || moduleCount <= col + c) { + continue; + } + + if (r === 0 && c === 0) { + continue; + } + + if (dark === qrCode.isDark(row + r, col + c) ) { + sameCount++; + } + } + } + + if (sameCount > 5) { + lostPoint += (3 + sameCount - 5); + } + } + } + + // LEVEL2 + + for (row = 0; row < moduleCount - 1; row++) { + for (col = 0; col < moduleCount - 1; col++) { + var count = 0; + if (qrCode.isDark(row, col ) ) count++; + if (qrCode.isDark(row + 1, col ) ) count++; + if (qrCode.isDark(row, col + 1) ) count++; + if (qrCode.isDark(row + 1, col + 1) ) count++; + if (count === 0 || count === 4) { + lostPoint += 3; + } + } + } + + // LEVEL3 + + for (row = 0; row < moduleCount; row++) { + for (col = 0; col < moduleCount - 6; col++) { + if (qrCode.isDark(row, col) && + !qrCode.isDark(row, col + 1) && + qrCode.isDark(row, col + 2) && + qrCode.isDark(row, col + 3) && + qrCode.isDark(row, col + 4) && + !qrCode.isDark(row, col + 5) && + qrCode.isDark(row, col + 6) ) { + lostPoint += 40; + } + } + } + + for (col = 0; col < moduleCount; col++) { + for (row = 0; row < moduleCount - 6; row++) { + if (qrCode.isDark(row, col) && + !qrCode.isDark(row + 1, col) && + qrCode.isDark(row + 2, col) && + qrCode.isDark(row + 3, col) && + qrCode.isDark(row + 4, col) && + !qrCode.isDark(row + 5, col) && + qrCode.isDark(row + 6, col) ) { + lostPoint += 40; + } + } + } + + // LEVEL4 + + var darkCount = 0; + + for (col = 0; col < moduleCount; col++) { + for (row = 0; row < moduleCount; row++) { + if (qrCode.isDark(row, col) ) { + darkCount++; + } + } + } + + var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; + lostPoint += ratio * 10; + + return lostPoint; + } + +}; + +module.exports = QRUtil; diff --git a/packages/qrcode-terminal/vendor/QRCode/index.js b/packages/qrcode-terminal/vendor/QRCode/index.js new file mode 100644 index 0000000..0fb6c39 --- /dev/null +++ b/packages/qrcode-terminal/vendor/QRCode/index.js @@ -0,0 +1,462 @@ +//--------------------------------------------------------------------- +// QRCode for JavaScript +// +// Copyright (c) 2009 Kazuhiko Arase +// +// URL: http://www.d-project.com/ +// +// Licensed under the MIT license: +// http://www.opensource.org/licenses/mit-license.php +// +// The word "QR Code" is registered trademark of +// DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/faqpatent-e.html +// +//--------------------------------------------------------------------- +// Modified to work in node for this project (and some refactoring) +//--------------------------------------------------------------------- + +var QR8bitByte = require('./QR8bitByte'); +var QRUtil = require('./QRUtil'); +var QRPolynomial = require('./QRPolynomial'); +var QRRSBlock = require('./QRRSBlock'); +var QRBitBuffer = require('./QRBitBuffer'); + +function QRCode(typeNumber, errorCorrectLevel) { + this.typeNumber = typeNumber; + this.errorCorrectLevel = errorCorrectLevel; + this.modules = null; + this.moduleCount = 0; + this.dataCache = null; + this.dataList = []; +} + +QRCode.prototype = { + + addData : function(data) { + var newData = new QR8bitByte(data); + this.dataList.push(newData); + this.dataCache = null; + }, + + isDark : function(row, col) { + if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) { + throw new Error(row + "," + col); + } + return this.modules[row][col]; + }, + + getModuleCount : function() { + return this.moduleCount; + }, + + make : function() { + // Calculate automatically typeNumber if provided is < 1 + if (this.typeNumber < 1 ){ + var typeNumber = 1; + for (typeNumber = 1; typeNumber < 40; typeNumber++) { + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel); + + var buffer = new QRBitBuffer(); + var totalDataCount = 0; + for (var i = 0; i < rsBlocks.length; i++) { + totalDataCount += rsBlocks[i].dataCount; + } + + for (var x = 0; x < this.dataList.length; x++) { + var data = this.dataList[x]; + buffer.put(data.mode, 4); + buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) ); + data.write(buffer); + } + if (buffer.getLengthInBits() <= totalDataCount * 8) + break; + } + this.typeNumber = typeNumber; + } + this.makeImpl(false, this.getBestMaskPattern() ); + }, + + makeImpl : function(test, maskPattern) { + + this.moduleCount = this.typeNumber * 4 + 17; + this.modules = new Array(this.moduleCount); + + for (var row = 0; row < this.moduleCount; row++) { + + this.modules[row] = new Array(this.moduleCount); + + for (var col = 0; col < this.moduleCount; col++) { + this.modules[row][col] = null;//(col + row) % 3; + } + } + + this.setupPositionProbePattern(0, 0); + this.setupPositionProbePattern(this.moduleCount - 7, 0); + this.setupPositionProbePattern(0, this.moduleCount - 7); + this.setupPositionAdjustPattern(); + this.setupTimingPattern(); + this.setupTypeInfo(test, maskPattern); + + if (this.typeNumber >= 7) { + this.setupTypeNumber(test); + } + + if (this.dataCache === null) { + this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList); + } + + this.mapData(this.dataCache, maskPattern); + }, + + setupPositionProbePattern : function(row, col) { + + for (var r = -1; r <= 7; r++) { + + if (row + r <= -1 || this.moduleCount <= row + r) continue; + + for (var c = -1; c <= 7; c++) { + + if (col + c <= -1 || this.moduleCount <= col + c) continue; + + if ( (0 <= r && r <= 6 && (c === 0 || c === 6) ) || + (0 <= c && c <= 6 && (r === 0 || r === 6) ) || + (2 <= r && r <= 4 && 2 <= c && c <= 4) ) { + this.modules[row + r][col + c] = true; + } else { + this.modules[row + r][col + c] = false; + } + } + } + }, + + getBestMaskPattern : function() { + + var minLostPoint = 0; + var pattern = 0; + + for (var i = 0; i < 8; i++) { + + this.makeImpl(true, i); + + var lostPoint = QRUtil.getLostPoint(this); + + if (i === 0 || minLostPoint > lostPoint) { + minLostPoint = lostPoint; + pattern = i; + } + } + + return pattern; + }, + + createMovieClip : function(target_mc, instance_name, depth) { + + var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth); + var cs = 1; + + this.make(); + + for (var row = 0; row < this.modules.length; row++) { + + var y = row * cs; + + for (var col = 0; col < this.modules[row].length; col++) { + + var x = col * cs; + var dark = this.modules[row][col]; + + if (dark) { + qr_mc.beginFill(0, 100); + qr_mc.moveTo(x, y); + qr_mc.lineTo(x + cs, y); + qr_mc.lineTo(x + cs, y + cs); + qr_mc.lineTo(x, y + cs); + qr_mc.endFill(); + } + } + } + + return qr_mc; + }, + + setupTimingPattern : function() { + + for (var r = 8; r < this.moduleCount - 8; r++) { + if (this.modules[r][6] !== null) { + continue; + } + this.modules[r][6] = (r % 2 === 0); + } + + for (var c = 8; c < this.moduleCount - 8; c++) { + if (this.modules[6][c] !== null) { + continue; + } + this.modules[6][c] = (c % 2 === 0); + } + }, + + setupPositionAdjustPattern : function() { + + var pos = QRUtil.getPatternPosition(this.typeNumber); + + for (var i = 0; i < pos.length; i++) { + + for (var j = 0; j < pos.length; j++) { + + var row = pos[i]; + var col = pos[j]; + + if (this.modules[row][col] !== null) { + continue; + } + + for (var r = -2; r <= 2; r++) { + + for (var c = -2; c <= 2; c++) { + + if (Math.abs(r) === 2 || + Math.abs(c) === 2 || + (r === 0 && c === 0) ) { + this.modules[row + r][col + c] = true; + } else { + this.modules[row + r][col + c] = false; + } + } + } + } + } + }, + + setupTypeNumber : function(test) { + + var bits = QRUtil.getBCHTypeNumber(this.typeNumber); + var mod; + + for (var i = 0; i < 18; i++) { + mod = (!test && ( (bits >> i) & 1) === 1); + this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod; + } + + for (var x = 0; x < 18; x++) { + mod = (!test && ( (bits >> x) & 1) === 1); + this.modules[x % 3 + this.moduleCount - 8 - 3][Math.floor(x / 3)] = mod; + } + }, + + setupTypeInfo : function(test, maskPattern) { + + var data = (this.errorCorrectLevel << 3) | maskPattern; + var bits = QRUtil.getBCHTypeInfo(data); + var mod; + + // vertical + for (var v = 0; v < 15; v++) { + + mod = (!test && ( (bits >> v) & 1) === 1); + + if (v < 6) { + this.modules[v][8] = mod; + } else if (v < 8) { + this.modules[v + 1][8] = mod; + } else { + this.modules[this.moduleCount - 15 + v][8] = mod; + } + } + + // horizontal + for (var h = 0; h < 15; h++) { + + mod = (!test && ( (bits >> h) & 1) === 1); + + if (h < 8) { + this.modules[8][this.moduleCount - h - 1] = mod; + } else if (h < 9) { + this.modules[8][15 - h - 1 + 1] = mod; + } else { + this.modules[8][15 - h - 1] = mod; + } + } + + // fixed module + this.modules[this.moduleCount - 8][8] = (!test); + + }, + + mapData : function(data, maskPattern) { + + var inc = -1; + var row = this.moduleCount - 1; + var bitIndex = 7; + var byteIndex = 0; + + for (var col = this.moduleCount - 1; col > 0; col -= 2) { + + if (col === 6) col--; + + while (true) { + + for (var c = 0; c < 2; c++) { + + if (this.modules[row][col - c] === null) { + + var dark = false; + + if (byteIndex < data.length) { + dark = ( ( (data[byteIndex] >>> bitIndex) & 1) === 1); + } + + var mask = QRUtil.getMask(maskPattern, row, col - c); + + if (mask) { + dark = !dark; + } + + this.modules[row][col - c] = dark; + bitIndex--; + + if (bitIndex === -1) { + byteIndex++; + bitIndex = 7; + } + } + } + + row += inc; + + if (row < 0 || this.moduleCount <= row) { + row -= inc; + inc = -inc; + break; + } + } + } + + } + +}; + +QRCode.PAD0 = 0xEC; +QRCode.PAD1 = 0x11; + +QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) { + + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel); + + var buffer = new QRBitBuffer(); + + for (var i = 0; i < dataList.length; i++) { + var data = dataList[i]; + buffer.put(data.mode, 4); + buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) ); + data.write(buffer); + } + + // calc num max data. + var totalDataCount = 0; + for (var x = 0; x < rsBlocks.length; x++) { + totalDataCount += rsBlocks[x].dataCount; + } + + if (buffer.getLengthInBits() > totalDataCount * 8) { + throw new Error("code length overflow. (" + + buffer.getLengthInBits() + + ">" + + totalDataCount * 8 + + ")"); + } + + // end code + if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { + buffer.put(0, 4); + } + + // padding + while (buffer.getLengthInBits() % 8 !== 0) { + buffer.putBit(false); + } + + // padding + while (true) { + + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break; + } + buffer.put(QRCode.PAD0, 8); + + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break; + } + buffer.put(QRCode.PAD1, 8); + } + + return QRCode.createBytes(buffer, rsBlocks); +}; + +QRCode.createBytes = function(buffer, rsBlocks) { + + var offset = 0; + + var maxDcCount = 0; + var maxEcCount = 0; + + var dcdata = new Array(rsBlocks.length); + var ecdata = new Array(rsBlocks.length); + + for (var r = 0; r < rsBlocks.length; r++) { + + var dcCount = rsBlocks[r].dataCount; + var ecCount = rsBlocks[r].totalCount - dcCount; + + maxDcCount = Math.max(maxDcCount, dcCount); + maxEcCount = Math.max(maxEcCount, ecCount); + + dcdata[r] = new Array(dcCount); + + for (var i = 0; i < dcdata[r].length; i++) { + dcdata[r][i] = 0xff & buffer.buffer[i + offset]; + } + offset += dcCount; + + var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); + var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1); + + var modPoly = rawPoly.mod(rsPoly); + ecdata[r] = new Array(rsPoly.getLength() - 1); + for (var x = 0; x < ecdata[r].length; x++) { + var modIndex = x + modPoly.getLength() - ecdata[r].length; + ecdata[r][x] = (modIndex >= 0)? modPoly.get(modIndex) : 0; + } + + } + + var totalCodeCount = 0; + for (var y = 0; y < rsBlocks.length; y++) { + totalCodeCount += rsBlocks[y].totalCount; + } + + var data = new Array(totalCodeCount); + var index = 0; + + for (var z = 0; z < maxDcCount; z++) { + for (var s = 0; s < rsBlocks.length; s++) { + if (z < dcdata[s].length) { + data[index++] = dcdata[s][z]; + } + } + } + + for (var xx = 0; xx < maxEcCount; xx++) { + for (var t = 0; t < rsBlocks.length; t++) { + if (xx < ecdata[t].length) { + data[index++] = ecdata[t][xx]; + } + } + } + + return data; + +}; + +module.exports = QRCode; diff --git a/scripts/release-truth.ts b/scripts/release-truth.ts index acf29d2..441d5bb 100644 --- a/scripts/release-truth.ts +++ b/scripts/release-truth.ts @@ -226,6 +226,16 @@ export function packageClaimsFromFiles(files: Readonly>): ].map((path) => `packages/ats-skills/${path}`) }); continue; } + if (item === "packages/qrcode-terminal") { + claims.push({ id: "package.json#files:packages/qrcode-terminal", source: "package.json#files", requiredPaths: [ + "package.json", "LICENSE", "NOTICE.md", "src/index.d.ts", "lib/main.js", "vendor/QRCode/LICENSE", + "vendor/QRCode/index.js", "vendor/QRCode/QR8bitByte.js", "vendor/QRCode/QRBitBuffer.js", + "vendor/QRCode/QRErrorCorrectLevel.js", "vendor/QRCode/QRMaskPattern.js", "vendor/QRCode/QRMath.js", + "vendor/QRCode/QRMode.js", "vendor/QRCode/QRPolynomial.js", "vendor/QRCode/QRRSBlock.js", + "vendor/QRCode/QRUtil.js", + ].map((path) => `packages/qrcode-terminal/${path}`) }); + continue; + } if (typeof item === "string" && item !== "dist/src" && !item.endsWith("/")) { claims.push({ id: `package.json#files:${item}`, source: "package.json#files", requiredPaths: [item.replace(/^\.\//, "")] }); } diff --git a/scripts/verify-production.ts b/scripts/verify-production.ts index 9775502..0c9de46 100644 --- a/scripts/verify-production.ts +++ b/scripts/verify-production.ts @@ -57,12 +57,20 @@ const REQUIRED_PUBLIC_ASSETS = ["assets/aether-agent-hero.png"] as const; const ALLOWED_PUBLIC_ASSETS = new Set(REQUIRED_PUBLIC_ASSETS); const MAX_UNPACKED_BYTES = 5_000_000; -const ATS_DEPENDENCY = { "aether-ats-skills": "0.2.0" }; +const RUNTIME_DEPENDENCIES = { "aether-ats-skills": "0.2.0", "aether-rc-qr": "0.1.0" }; const ATS_SOURCE_FILES = ["package.json", "README.md", "LICENSE", "SETTINGS.md", "src/index.js", "src/index.d.ts", "src/browser.js", "src/browser_recovery.js", "src/browser_transport.js", "src/vision_skill.js", "src/settings.js", "src/strategy_library.js", "src/journal.js", "src/memory_lease.js", "python/bridge.py", "python/memory_lease.py", "bin/aether-ats-skills.js"]; +const QR_SOURCE_FILES = [ + "package.json", "LICENSE", "NOTICE.md", "src/index.d.ts", "lib/main.js", "vendor/QRCode/LICENSE", + "vendor/QRCode/index.js", "vendor/QRCode/QR8bitByte.js", "vendor/QRCode/QRBitBuffer.js", + "vendor/QRCode/QRErrorCorrectLevel.js", "vendor/QRCode/QRMaskPattern.js", "vendor/QRCode/QRMath.js", + "vendor/QRCode/QRMode.js", "vendor/QRCode/QRPolynomial.js", "vendor/QRCode/QRRSBlock.js", + "vendor/QRCode/QRUtil.js", +]; const RUNTIME_PACKAGES = { "aether-ats-skills": { version: "0.2.0", entry: "src/index.js" }, "aether-browser": { version: "0.2.2", entry: "src/index.js" }, "aether-context": { version: "0.3.1", entry: "bin/aether-context.js" }, + "aether-rc-qr": { version: "0.1.0", entry: "lib/main.js" }, } as const; function exactRecord(value: unknown, expected: Record): boolean { @@ -72,7 +80,7 @@ function exactRecord(value: unknown, expected: Record): boolean } function runtimeRoots(name: keyof typeof RUNTIME_PACKAGES): string[] { - return name === "aether-ats-skills" ? [`node_modules/${name}/`] + return name === "aether-ats-skills" || name === "aether-rc-qr" ? [`node_modules/${name}/`] : [`node_modules/${name}/`, `node_modules/aether-ats-skills/node_modules/${name}/`]; } @@ -85,12 +93,16 @@ function allowedRuntimePath(path: string): boolean { const relative = path.slice("packages/ats-skills/".length); return ATS_SOURCE_FILES.includes(relative) || strategyAsset(relative); } + if (path.startsWith("packages/qrcode-terminal/")) { + return QR_SOURCE_FILES.includes(path.slice("packages/qrcode-terminal/".length)); + } for (const name of Object.keys(RUNTIME_PACKAGES) as (keyof typeof RUNTIME_PACKAGES)[]) { for (const prefix of runtimeRoots(name)) { if (!path.startsWith(prefix)) continue; const relative = path.slice(prefix.length); if (/^(?:package\.json|README\.md|LICENSE(?:\.md)?)$/.test(relative)) return true; if (name === "aether-ats-skills" && relative === "SETTINGS.md") return true; + if (name === "aether-rc-qr") return QR_SOURCE_FILES.includes(relative); if (name === "aether-context") return relative === "bin/aether-context.js"; if (/^src\/[A-Za-z0-9_-]+\.(?:js|d\.ts)$/.test(relative)) return true; if (name === "aether-ats-skills" && (["python/bridge.py", "python/memory_lease.py", "bin/aether-ats-skills.js"].includes(relative) || strategyAsset(relative))) return true; @@ -123,9 +135,10 @@ export function validateManifest(manifest: PackageManifest, expectedTag?: string errors.push("package repository.url must match the trusted publisher repository"); } - if (!exactRecord(manifest.dependencies, ATS_DEPENDENCY)) errors.push("runtime dependencies must be exactly the reviewed bundled aether-ats-skills source package"); - if (!Array.isArray(manifest.bundledDependencies) || manifest.bundledDependencies.length !== 1 || manifest.bundledDependencies[0] !== "aether-ats-skills") { - errors.push("bundledDependencies must contain exactly aether-ats-skills"); + if (!exactRecord(manifest.dependencies, RUNTIME_DEPENDENCIES)) errors.push("runtime dependencies must be exactly the reviewed ATS and QR packages"); + if (!Array.isArray(manifest.bundledDependencies) || manifest.bundledDependencies.length !== 2 || + manifest.bundledDependencies[0] !== "aether-ats-skills" || manifest.bundledDependencies[1] !== "aether-rc-qr") { + errors.push("bundledDependencies must contain exactly aether-ats-skills and aether-rc-qr"); } for (const kind of ["optionalDependencies", "peerDependencies"] as const) { if (manifest[kind] !== undefined && !exactRecord(manifest[kind], {})) errors.push(`${kind} must not widen the reviewed runtime dependency graph`); @@ -133,7 +146,9 @@ export function validateManifest(manifest: PackageManifest, expectedTag?: string const files = Array.isArray(manifest.files) ? manifest.files : []; if (!files.includes("dist/src")) errors.push("package files must include dist/src"); - for (const path of ["packages/ats-skills", "packages/ats-skills-source.json"]) if (!files.includes(path)) errors.push(`package files must include reviewed ATS source ${path}`); + for (const path of ["packages/ats-skills", "packages/ats-skills-source.json", "packages/qrcode-terminal"]) { + if (!files.includes(path)) errors.push(`package files must include reviewed source ${path}`); + } for (const path of REQUIRED_GENERATED_DOCS) if (!files.includes(path)) errors.push(`package files must include generated public document ${path}`); for (const path of REQUIRED_PUBLIC_ASSETS) if (!files.includes(path)) errors.push(`package files must include public asset ${path}`); if (files.includes("dist") || files.some((value) => typeof value === "string" && value.includes("test"))) { @@ -192,6 +207,11 @@ export function validatePack(report: PackReport, manifest: PackageManifest): str for (const path of ["packages/ats-skills-source.json", ...ATS_SOURCE_FILES.map((file) => `packages/ats-skills/${file}`)]) { if (!paths.has(path)) errors.push(`package is missing reviewed ATS source ${path}`); } + for (const file of QR_SOURCE_FILES) { + for (const prefix of ["packages/qrcode-terminal/", "node_modules/aether-rc-qr/"]) { + if (!paths.has(`${prefix}${file}`)) errors.push(`package is missing reviewed QR source ${prefix}${file}`); + } + } if (report.unpackedSize > MAX_UNPACKED_BYTES) { errors.push(`unpacked package exceeds ${MAX_UNPACKED_BYTES} bytes`); } diff --git a/src/commands/command_manifest_data.ts b/src/commands/command_manifest_data.ts index c5687b4..e5746f4 100644 --- a/src/commands/command_manifest_data.ts +++ b/src/commands/command_manifest_data.ts @@ -705,7 +705,7 @@ export const COMMAND_MANIFEST_SOURCE: readonly CommandManifestEntry[] = [ "deprecatedAliases": [], "args": "", "summary": "publish a viewer-only observation stream for this session", - "detailedHelp": "aether rc \npublish a viewer-only observation stream for this session\n\nstart [--name ] begin publishing\nstatus what is being published\nexposure what an observer can see\nviewers who is observing\noff end publishing and revoke the session\n\nObservation only. Run `aether rc exposure` for the full disclosure.", + "detailedHelp": "aether rc \npublish a viewer-only observation stream for this session\n\nstart [--name ] begin publishing and make an observer link\nlink make a fresh one-time observer link\nstatus what is being published\nexposure what an observer can see\nviewers who is observing\noff end publishing and revoke the session\n\nObservation only. Run `aether rc exposure` for the full disclosure.", "section": "Account", "hidden": true, "permissionClass": "account", diff --git a/src/commands/rc.ts b/src/commands/rc.ts index 030d6a7..aba557f 100644 --- a/src/commands/rc.ts +++ b/src/commands/rc.ts @@ -5,6 +5,7 @@ // aether rc exposure the same, framed as "what can be seen" // aether rc viewers who is currently observing // aether rc off stop, locally first and server-final +// aether rc link mint a fresh one-time observer invitation // // THIS COMMAND CANNOT CONTROL ANYTHING // @@ -36,6 +37,7 @@ import { RcError, attachHost, flushOutbox, + mintObserverGrant, registerSession, revokeHost, type RcHostDeps, @@ -54,6 +56,7 @@ import { sessionOpenedEvent, } from "../core/rc/producers.js"; import { VIEWER_CAPABILITIES } from "../core/rc/viewer_profile.js"; +import { newObserverId, observerLink, observerQr } from "../core/rc/observer_handoff.js"; /** Printed verbatim on every human-facing RC surface. Spec §7. */ export const RC_NO_CONTROL_LINE = "No terminal or tool control"; @@ -247,6 +250,28 @@ export interface RcCommandDeps { repo: (cwd: string) => RepoSummary; out: (text: string) => void; err: (text: string) => void; + isTTY: boolean; + columns: number | undefined; +} + +async function printObserverLink( + deps: RcCommandDeps, + hostDeps: RcHostDeps, + sessionId: string, +): Promise { + try { + const grant = await mintObserverGrant(hostDeps, sessionId, newObserverId()); + const link = observerLink(grant); + deps.out(`\nObserver link (expires ${grant.expires_at}):\n${link}\n`); + const qr = deps.isTTY ? observerQr(link, deps.columns) : null; + if (qr) deps.out(`${qr}\n`); + else deps.out("Open the link directly; this terminal cannot fit a scannable QR.\n"); + return true; + } catch (error) { + const code = error instanceof RcError ? error.code : "RC_BROKER_UNREACHABLE"; + deps.err(`${code}: RC is running, but an observer link could not be minted. Retry with \`aether rc link\`.\n`); + return false; + } } function viewOf(record: OutboxRecord, deps: RcCommandDeps, observers: number | null): RcStatusView { @@ -331,9 +356,11 @@ async function start( const presence = hostPresenceEvent(enrolled.device_id, "live"); enqueueEvent(record, presence.event_type, presence.payload); saveOutbox(hostDeps.outboxPath, record); - await flushOutbox(hostDeps, record); + const flushed = await flushOutbox(hostDeps, record); deps.out(renderStatus(viewOf(record, deps, null))); + if (flushed.ok) await printObserverLink(deps, hostDeps, session.session_id); + else deps.err(`${flushed.code}: RC is running, but its opening events are pending. Retry with \`aether rc link\`.\n`); return EXIT_OK; } catch (error) { if (error instanceof RcError) { @@ -367,6 +394,8 @@ export async function cmdRc( repo: overrides.repo ?? repoSummary, out: overrides.out ?? ((text): void => void process.stdout.write(text)), err: overrides.err ?? ((text): void => void process.stderr.write(text)), + isTTY: overrides.isTTY ?? Boolean(process.stdout.isTTY), + columns: overrides.columns ?? process.stdout.columns, }; // Connector state is read once, best-effort, before anything renders. A @@ -395,6 +424,20 @@ export async function cmdRc( deps.out(renderStatus(viewOf(record, deps, null))); return EXIT_OK; + case "link": + if (!record.session_id || record.revoke_pending) { + deps.err("RC is not running for this project\n"); + return EXIT_OPERATIONAL; + } + { + const flushed = await flushOutbox(hostDeps, record); + if (!flushed.ok) { + deps.err(`${flushed.code}: RC opening events are still pending. Retry \`aether rc link\` after reconnecting.\n`); + return EXIT_OPERATIONAL; + } + return await printObserverLink(deps, hostDeps, record.session_id) ? EXIT_OK : EXIT_OPERATIONAL; + } + case "exposure": deps.out(renderExposure(viewOf(record, deps, null))); return EXIT_OK; @@ -423,7 +466,7 @@ export async function cmdRc( default: deps.err( - `unknown subcommand: ${String(argv[0])}\nusage: aether rc \n`, + `unknown subcommand: ${String(argv[0])}\nusage: aether rc \n`, ); return EXIT_USAGE; } diff --git a/src/core/rc/host.ts b/src/core/rc/host.ts index 90e1e44..e2ce124 100644 --- a/src/core/rc/host.ts +++ b/src/core/rc/host.ts @@ -114,6 +114,39 @@ export interface RemoteSessionSummary { expires_at?: string; } +/** One-time observer invitation. Never put this response in the durable outbox. */ +export interface ObserverGrant { + session_id: string; + purpose: "observe"; + device_id: string; + token: string; + expires_at: string; +} + +export async function mintObserverGrant( + deps: RcHostDeps, + sessionId: string, + observerId: string, +): Promise { + try { + const grant = await deps.api.postJson( + `/remote/sessions/${encodeURIComponent(sessionId)}/grants`, + { purpose: "observe", device_id: observerId }, + undefined, + REQUEST_TIMEOUT_MS, + ); + if (grant.session_id !== sessionId || grant.purpose !== "observe" || + grant.device_id !== observerId || !/^rsgt_[0-9a-f]{48}$/.test(grant.token) || + !Number.isFinite(Date.parse(grant.expires_at)) || Date.parse(grant.expires_at) <= Date.now()) { + throw new RcError("RC_RECEIPTS_UNPROVEN", "the broker returned an invalid observer grant"); + } + return grant; + } catch (error) { + if (error instanceof RcError) throw error; + rethrow(error); + } +} + export type FlushOutcome = | { ok: true; sent: number; cursor: number } | { ok: false; code: RcCode; detail: string }; diff --git a/src/core/rc/observer_handoff.ts b/src/core/rc/observer_handoff.ts new file mode 100644 index 0000000..7729a86 --- /dev/null +++ b/src/core/rc/observer_handoff.ts @@ -0,0 +1,26 @@ +// The invitation exists only in memory and on the operator's terminal. The +// fragment does not travel in the initial HTTP request or Referer header. +import { randomBytes } from "node:crypto"; +import { stripVTControlCharacters } from "node:util"; +import qrcode from "aether-rc-qr"; +import type { ObserverGrant } from "./host.js"; + +export const RC_VIEW_ORIGIN = "https://app.aethersystems.net"; + +export function newObserverId(): string { + return `viewer_${randomBytes(16).toString("hex")}`; +} + +export function observerLink(grant: ObserverGrant): string { + const url = new URL("/rc", RC_VIEW_ORIGIN); + url.hash = new URLSearchParams({ grant: grant.token, device_id: grant.device_id }).toString(); + return url.toString(); +} + +export function observerQr(link: string, columns: number | undefined): string | null { + if (!columns || columns < 40) return null; + let rendered = ""; + qrcode.generate(link, { small: true }, (value: string) => { rendered = value; }); + const maxWidth = Math.max(...rendered.split("\n").map((line) => stripVTControlCharacters(line).length)); + return maxWidth <= columns ? rendered : null; +} diff --git a/test/migration_guard.test.ts b/test/migration_guard.test.ts index f4b996a..e3e00ed 100644 --- a/test/migration_guard.test.ts +++ b/test/migration_guard.test.ts @@ -34,11 +34,11 @@ test("TypeScript 7 toolchain and Node 24 contract stay pinned", () => { assert.equal(pkg.scripts?.["typecheck"], "tsc -p tsconfig.json --noEmit"); }); -test("published package restricts runtime dependencies to the bundled ATS source and excludes compiled tests", () => { +test("published package restricts runtime dependencies to reviewed bundled ATS and QR packages", () => { const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as PackageManifest; - assert.deepEqual(pkg.workspaces, ["packages/ats-skills"]); - assert.deepEqual(pkg.dependencies, { "aether-ats-skills": "0.2.0" }); - assert.deepEqual(pkg.bundledDependencies, ["aether-ats-skills"]); + assert.deepEqual(pkg.workspaces, ["packages/ats-skills", "packages/qrcode-terminal"]); + assert.deepEqual(pkg.dependencies, { "aether-ats-skills": "0.2.0", "aether-rc-qr": "0.1.0" }); + assert.deepEqual(pkg.bundledDependencies, ["aether-ats-skills", "aether-rc-qr"]); assert.deepEqual(pkg.optionalDependencies ?? {}, {}); assert.deepEqual(pkg.peerDependencies ?? {}, {}); assert.ok(pkg.files?.includes("dist/src")); diff --git a/test/production_hardening.test.ts b/test/production_hardening.test.ts index 0d8a9ae..96d49de 100644 --- a/test/production_hardening.test.ts +++ b/test/production_hardening.test.ts @@ -12,6 +12,14 @@ import { } from "../scripts/verify-production.js"; import { DEFAULT_CONFIG } from "../src/core/config.js"; +const QR_FILES = [ + "package.json", "LICENSE", "NOTICE.md", "src/index.d.ts", "lib/main.js", "vendor/QRCode/LICENSE", + "vendor/QRCode/index.js", "vendor/QRCode/QR8bitByte.js", "vendor/QRCode/QRBitBuffer.js", + "vendor/QRCode/QRErrorCorrectLevel.js", "vendor/QRCode/QRMaskPattern.js", "vendor/QRCode/QRMath.js", + "vendor/QRCode/QRMode.js", "vendor/QRCode/QRPolynomial.js", "vendor/QRCode/QRRSBlock.js", + "vendor/QRCode/QRUtil.js", +]; + const manifest = { name: "aether-agents", version: "1.2.3", @@ -22,11 +30,11 @@ const manifest = { "dist/src", "ATS_ACCEPTABLE_USE_POLICY.md", "README.md", "assets/aether-agent-hero.png", "COMMANDS.md", "LICENSE", "NOTICE.md", "docs/generated/commands.md", "docs/generated/model-catalogue.md", "docs/model-catalogue/catalogue.json", "docs/model-catalogue/index.html", - "packages/ats-skills", "packages/ats-skills-source.json", + "packages/ats-skills", "packages/qrcode-terminal", "packages/ats-skills-source.json", ], engines: { node: ">=24" }, - dependencies: { "aether-ats-skills": "0.2.0" }, - bundledDependencies: ["aether-ats-skills"], + dependencies: { "aether-ats-skills": "0.2.0", "aether-rc-qr": "0.1.0" }, + bundledDependencies: ["aether-ats-skills", "aether-rc-qr"], repository: { type: "git", url: "https://github.com/AetherAI3/aether-agent" }, scripts: { prepack: "npm run build" }, }; @@ -72,6 +80,7 @@ const pack: PackReport = { "node_modules/aether-browser/src/index.js", "node_modules/aether-context/package.json", "node_modules/aether-context/bin/aether-context.js", + ...QR_FILES.flatMap((file) => [`packages/qrcode-terminal/${file}`, `node_modules/aether-rc-qr/${file}`]), "packages/ats-skills-source.json", ...["package.json", "README.md", "LICENSE", "SETTINGS.md", "src/index.js", "src/index.d.ts", "src/browser.js", "src/browser_recovery.js", "src/browser_transport.js", "src/vision_skill.js", "src/settings.js", "src/strategy_library.js", "src/journal.js", "src/memory_lease.js", "python/bridge.py", "python/memory_lease.py", "bin/aether-ats-skills.js"].map((path) => `packages/ats-skills/${path}`), ].map((path) => ({ path, size: 1 })), diff --git a/test/rc_journey.test.ts b/test/rc_journey.test.ts index 38624e2..9d73e88 100644 --- a/test/rc_journey.test.ts +++ b/test/rc_journey.test.ts @@ -11,11 +11,9 @@ // registers and attaches -> events observable -> heartbeat -> restart // restores durable state -> `rc off` revokes and stays off // -// ON OPENING A VIEWER PAGE: the Cloud exposes no viewer PAGE route. There is an -// SSE stream at /remote/sessions/{id}/observe and a one-shot grant mint, and -// nothing that renders. So the browser's job in this journey is the connector -// authorization and nothing else. Inventing a viewer URL to make the browser -// integration look complete is exactly what this lane was told not to do. +// The viewer handoff is covered separately by rc_observer_handoff.test.ts. This +// journey only opens a browser for connector authorization; it never treats +// that launch as proof that a remote viewer reached the live session. // // No socket is opened, no browser is launched, no request leaves the process. diff --git a/test/rc_observer_handoff.test.ts b/test/rc_observer_handoff.test.ts new file mode 100644 index 0000000..1a466f3 --- /dev/null +++ b/test/rc_observer_handoff.test.ts @@ -0,0 +1,60 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mintObserverGrant, RcError, type RcHostDeps } from "../src/core/rc/host.js"; +import { observerLink, observerQr } from "../src/core/rc/observer_handoff.js"; +import type { ApiClient } from "../src/core/transport.js"; + +const SESSION = "rs_" + "1".repeat(32); +const DEVICE = "viewer_" + "2".repeat(32); +const TOKEN = "rsgt_" + "a".repeat(48); +function grant() { return { + session_id: SESSION, + purpose: "observe" as const, + device_id: DEVICE, + token: TOKEN, + expires_at: new Date(Date.now() + 300_000).toISOString(), +}; } + +function deps(response: unknown): RcHostDeps { + return { + api: { async postJson(path: string, body: unknown) { + assert.equal(path, `/remote/sessions/${SESSION}/grants`); + assert.deepEqual(body, { purpose: "observe", device_id: DEVICE }); + return response; + } } as unknown as ApiClient, + outboxPath: "unused", + projectRoot: "unused", + }; +} + +test("observer grant is bound and its token stays in the URL fragment", async () => { + const minted = await mintObserverGrant(deps(grant()), SESSION, DEVICE); + const link = new URL(observerLink(minted)); + assert.equal(link.origin, "https://app.aethersystems.net"); + assert.equal(link.pathname, "/rc"); + assert.equal(link.search, ""); + assert.equal(new URLSearchParams(link.hash.slice(1)).get("grant"), TOKEN); + assert.equal(new URLSearchParams(link.hash.slice(1)).get("device_id"), DEVICE); +}); + +test("invalid or mismatched broker response never becomes a link", async () => { + for (const bad of [ + { ...grant(), session_id: "rs_other" }, + { ...grant(), purpose: "control" }, + { ...grant(), device_id: "viewer_other" }, + { ...grant(), token: "short" }, + { ...grant(), expires_at: "invalid" }, + { ...grant(), expires_at: new Date(Date.now() - 1_000).toISOString() }, + ]) { + await assert.rejects(mintObserverGrant(deps(bad), SESSION, DEVICE), + (error: unknown) => error instanceof RcError && error.code === "RC_RECEIPTS_UNPROVEN"); + } +}); + +test("headless and narrow terminals get a link without a broken QR", () => { + const link = observerLink(grant()); + assert.equal(observerQr(link, undefined), null); + assert.equal(observerQr(link, 39), null); + const qr = observerQr(link, 120); + assert.ok(qr?.includes("\n")); +}); diff --git a/test/rc_packaging.test.ts b/test/rc_packaging.test.ts index 323b544..a3223da 100644 --- a/test/rc_packaging.test.ts +++ b/test/rc_packaging.test.ts @@ -60,13 +60,13 @@ test("the compiled output for every new module exists after a build", () => { // ── bounded dependencies, and nothing reaching outside them ──────────────── -test("the package declares only the bundled ATS runtime dependency", () => { - // Deliberate, and load-bearing for the supply-chain story: the sole runtime - // dependency is source-controlled and bundled with the published package. - // RC and browser modules themselves remain builtin-or-relative only below. - assert.deepEqual(pkg.workspaces ?? [], ["packages/ats-skills"]); +test("the package declares only reviewed bundled ATS and QR dependencies", () => { + // Both runtime dependencies are exact and bundled in the published package. + // The QR import is restricted to the observer invitation renderer below. + assert.deepEqual(pkg.workspaces ?? [], ["packages/ats-skills", "packages/qrcode-terminal"]); assert.deepEqual(pkg.dependencies ?? {}, { "aether-ats-skills": "0.2.0", + "aether-rc-qr": "0.1.0", }); }); @@ -98,8 +98,9 @@ test("no RC or browser module imports a package that is not declared", () => { for (const file of files) { for (const specifier of importsOf(readFileSync(file, "utf8"))) { - const ok = specifier.startsWith("node:") || specifier.startsWith("."); - assert.ok(ok, `${file} imports ${specifier}, which is neither a builtin nor relative`); + const ok = specifier.startsWith("node:") || specifier.startsWith(".") || + (file.endsWith("observer_handoff.ts") && specifier === "aether-rc-qr"); + assert.ok(ok, `${file} imports ${specifier}, which is not a reviewed dependency`); } } });